Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection browser enhancements #1845

Merged
47 changes: 44 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,12 @@
"category": "IBM i",
"icon": "$(refresh)"
},
{
"command": "code-for-ibmi.sortConnections",
"title": "Sort Connections",
"category": "IBM i",
"icon": "$(list-ordered)"
},
{
"command": "code-for-ibmi.showAdditionalSettings",
"title": "Connection Settings",
Expand All @@ -1008,6 +1014,11 @@
"title": "Login Settings",
"category": "IBM i"
},
{
"command": "code-for-ibmi.renameConnection",
"title": "Rename Connection",
"category": "IBM i"
},
{
"command": "code-for-ibmi.deleteConnection",
"title": "Delete Connection",
Expand Down Expand Up @@ -1770,10 +1781,30 @@
"command": "code-for-ibmi.connectToAndReload",
"when": "never"
},
{
"command": "code-for-ibmi.refreshConnections",
"when": "never"
},
{
"command": "code-for-ibmi.renameConnection",
"when": "never"
},
{
"command": "code-for-ibmi.sortConnections",
"when": "never"
},
{
"command": "code-for-ibmi.deleteConnection",
"when": "never"
},
{
"command": "code-for-ibmi.disconnect",
"when": "code-for-ibmi:connected"
},
{
"command": "code-for-ibmi.showAdditionalSettings",
"when": "code-for-ibmi:connected"
},
{
"command": "code-for-ibmi.selectForCompare",
"when": "code-for-ibmi:connected"
Expand Down Expand Up @@ -1982,13 +2013,18 @@
"when": "view == connectionBrowser"
},
{
"command": "code-for-ibmi.refreshConnections",
"command": "code-for-ibmi.sortConnections",
"group": "navigation@2",
"when": "view == connectionBrowser"
},
{
"command": "code-for-ibmi.connectToPrevious",
"command": "code-for-ibmi.refreshConnections",
"group": "navigation@3",
"when": "view == connectionBrowser"
},
{
"command": "code-for-ibmi.connectToPrevious",
"group": "navigation@4",
"when": "view == connectionBrowser && code-for-ibmi:hasPreviousConnection"
},
{
Expand Down Expand Up @@ -2121,10 +2157,15 @@
],
"view/item/context": [
{
"command": "code-for-ibmi.deleteConnection",
"command": "code-for-ibmi.renameConnection",
"when": "view == connectionBrowser && viewItem == server",
"group": "2_delete@1"
},
{
"command": "code-for-ibmi.deleteConnection",
"when": "view == connectionBrowser && viewItem == server",
"group": "2_delete@2"
},
{
"command": "code-for-ibmi.showAdditionalSettings",
"when": "view == connectionBrowser && viewItem == server",
Expand Down
3 changes: 3 additions & 0 deletions src/locale/ids/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const da: Locale = {
'connectionBrowser.connectTo.lastUsed': `Senest brugt: {0}`,
'connectionBrowser.connectTo.title': `Seneste IBM i forbindelser`,
'connectionBrowser.connectTo.error': `Brug Servere vinduet til at vælge hvilket system, der skal forbindes til.`,
'connectionBrowser.renameConnection.prompt': `Omdøb forbindelse {0}`,
'connectionBrowser.renameConnection.alreadyExists': `Forbindelsen {0} findes allerede.`,
'connectionBrowser.renameConnection.invalid.input': `Nyt forbindelses navn skal være forskelligt fra det nuværende navn`,
'connectionBrowser.deleteConnection.warning': `Er du sikker på at du vil slette forbindelsen {0}?`,
'connectionBrowser.ServerItem.tooltip': ` (forrige forbindelse)`,
'connectionBrowser.ServerItem.title': `Forbind`,
Expand Down
3 changes: 3 additions & 0 deletions src/locale/ids/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const en: Locale = {
'connectionBrowser.connectTo.lastUsed': `Last used: {0}`,
'connectionBrowser.connectTo.title': `Last IBM i connections`,
'connectionBrowser.connectTo.error': `Use the Server Browser to select which system to connect to.`,
'connectionBrowser.renameConnection.prompt': `Rename connection {0}`,
'connectionBrowser.renameConnection.alreadyExists': `Connection {0} already exists.`,
'connectionBrowser.renameConnection.invalid.input': `New connection name must be different from its current name`,
'connectionBrowser.deleteConnection.warning': `Are you sure you want to delete the connection {0}?`,
'connectionBrowser.ServerItem.tooltip': ` (previous connection)`,
'connectionBrowser.ServerItem.title': `Connect`,
Expand Down
3 changes: 3 additions & 0 deletions src/locale/ids/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const fr: Locale = {
'connectionBrowser.connectTo.lastUsed': `Dernière utilisation: {0}`,
'connectionBrowser.connectTo.title': `Dernières connexions IBM i`,
'connectionBrowser.connectTo.error': `Utilisez l'Explorateur de Serveur pour sélectionner le serveur auquel se connecter.`,
'connectionBrowser.renameConnection.prompt': `Rename connection {0}`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebjulliand Could I ask you to translate these three new texts into French? 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing buddy!

'connectionBrowser.renameConnection.alreadyExists': `Connection {0} already exists.`,
'connectionBrowser.renameConnection.invalid.input': `New connection name must be different from its current name`,
'connectionBrowser.deleteConnection.warning': `Êtes vous sûr de vouloir supprimer la connexion {0}?`,
'connectionBrowser.ServerItem.tooltip': ` (précédente connexion)`,
'connectionBrowser.ServerItem.title': `Se Connecter`,
Expand Down
55 changes: 55 additions & 0 deletions src/views/ConnectionBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,61 @@ export class ObjectBrowserProvider {
this.refresh();
}),

vscode.commands.registerCommand(`code-for-ibmi.renameConnection`, async (server: Server) => {
if (!this._attemptingConnection && server) {
const existingConnections = GlobalConfiguration.get<ConnectionData[]>(`connections`) || [];
const newName = await vscode.window.showInputBox({
prompt: t(`connectionBrowser.renameConnection.prompt`, server.name),
value: server.name,
validateInput: newName => {
if (newName === server.name) {
return t(`connectionBrowser.renameConnection.invalid.input`);
} else if (existingConnections.findIndex(item => item.name === newName) !== -1) {
return t(`connectionBrowser.renameConnection.alreadyExists`, newName);
}
}
});

if (newName) {
let index;
// First rename the connection details
const connections = GlobalConfiguration.get<ConnectionData[]>(`connections`) || [];
index = connections.findIndex(connection => connection.name === server.name);
connections[index].name = newName;
await GlobalConfiguration.set(`connections`, connections);

// Then rename the connection settings
const connectionSettings = GlobalConfiguration.get<ConnectionConfiguration.Parameters[]>(`connectionSettings`) || [];
index = connectionSettings.findIndex(connection => connection.name === server.name);
connectionSettings[index].name = newName;
await GlobalConfiguration.set(`connectionSettings`, connectionSettings);

// Then rename the cached connection settings
const cachedConnectionSettings = GlobalStorage.get().getServerSettingsCache(server.name);
if(cachedConnectionSettings) {
GlobalStorage.get().setServerSettingsCache(newName, cachedConnectionSettings);
GlobalStorage.get().deleteServerSettingsCache(server.name);
}

// Then rename the password key
const secret = await context.secrets.get(`${server.name}_password`);
if (secret) {
await context.secrets.store(`${newName}_password`, secret);
await context.secrets.delete(`${server.name}_password`);
}

this.refresh();
}
}
}),

vscode.commands.registerCommand(`code-for-ibmi.sortConnections`, async () => {
let connections = GlobalConfiguration.get<ConnectionData[]>(`connections`) || [];
connections.sort((conn1, conn2) => conn1.name.localeCompare(conn2.name));
await GlobalConfiguration.set(`connections`, connections);
this.refresh();
}),

vscode.commands.registerCommand(`code-for-ibmi.deleteConnection`, (server: Server) => {
if (!this._attemptingConnection && server) {
vscode.window.showWarningMessage(
Expand Down
6 changes: 5 additions & 1 deletion src/webviews/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import vscode from "vscode";
import { ConnectionConfiguration, GlobalConfiguration } from "../../api/Configuration";
import { GlobalStorage } from '../../api/Storage';
import { ComplexTab, CustomUI, Section } from "../../api/CustomUI";
import { Tools } from "../../api/Tools";
import { isManaged } from "../../api/debug";
Expand Down Expand Up @@ -255,11 +256,14 @@ export class SettingsUI {
if (restartFields.some(item => data[item] && data[item] !== config[item])) {
restart = true;
}

const reloadBrowsers = config.protectedPaths.join(",") !== data.protectedPaths.join(",");
const removeCachedSettings = (!data.quickConnect && data.quickConnect !== config.quickConnect);

Object.assign(config, data);
await instance.setConfig(config);
if (removeCachedSettings)
GlobalStorage.get().deleteServerSettingsCache(config.name);

if (connection) {
if (restart) {
Expand Down