From cec8d85cc6c0db0a2ef8fc5fdb6f3b454b403298 Mon Sep 17 00:00:00 2001 From: gjsjohnmurray Date: Tue, 13 Apr 2021 14:19:10 +0100 Subject: [PATCH] SNAPSHOT.1 --- images/serverManager.svg | 16 +---- images/toolsContainer.svg | 16 +---- package.json | 79 ++++++++++++++++++++++++- src/api/getPortalUriWithCredentials.ts | 7 ++- src/extension.ts | 82 ++++++++++++++++++++++++-- src/ui/serverManagerView.ts | 76 ++++++++++++++++++++++-- 6 files changed, 235 insertions(+), 41 deletions(-) diff --git a/images/serverManager.svg b/images/serverManager.svg index 53e5be5..31a3119 100644 --- a/images/serverManager.svg +++ b/images/serverManager.svg @@ -1,14 +1,4 @@ - - - - Slice - Created with Sketch. - - - - - - - - + + diff --git a/images/toolsContainer.svg b/images/toolsContainer.svg index 53e5be5..27343f8 100644 --- a/images/toolsContainer.svg +++ b/images/toolsContainer.svg @@ -1,14 +1,4 @@ - - - - Slice - Created with Sketch. - - - - - - - - + + diff --git a/package.json b/package.json index 904e501..432bc79 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "servermanager", "displayName": "InterSystems Server Manager", - "version": "2.0.0-SNAPSHOT", + "version": "2.0.0-SNAPSHOT.1", "publisher": "intersystems-community", "description": "Helper extension for defining connections to InterSystems servers.", "repository": { @@ -60,6 +60,7 @@ "main": "./out/extension", "activationEvents": [ "onView:intersystems-community_servermanager", + "onCommand:intersystems-community.servermanager.refreshTree", "onCommand:intersystems-community.servermanager.addServer", "onCommand:intersystems-community.servermanager.storePassword", "onCommand:intersystems-community.servermanager.clearPassword", @@ -241,7 +242,8 @@ { "command": "intersystems-community.servermanager.openManagementPortalInSimpleBrowser", "category": "InterSystems Server Manager", - "title": "Open Management Portal in Simple Browser Tab" + "title": "Open Management Portal in Simple Browser Tab", + "icon": "$(tools)" }, { "command": "intersystems-community.servermanager.storePassword", @@ -258,9 +260,73 @@ "command": "intersystems-community.servermanager.importServers", "category": "InterSystems Server Manager", "title": "Import Servers from Registry" + }, + { + "command": "intersystems-community.servermanager.setIconRed", + "title": "Red" + }, + { + "command": "intersystems-community.servermanager.setIconOrange", + "title": "Orange" + }, + { + "command": "intersystems-community.servermanager.setIconYellow", + "title": "Yellow" + }, + { + "command": "intersystems-community.servermanager.setIconGreen", + "title": "Green" + }, + { + "command": "intersystems-community.servermanager.setIconBlue", + "title": "Blue" + }, + { + "command": "intersystems-community.servermanager.setIconPurple", + "title": "Purple" + }, + { + "command": "intersystems-community.servermanager.resetIconColor", + "title": "default" + } + ], + "submenus": [ + { + "id": "intersystems-community.servermanager.iconColor", + "label": "Set Icon Color" } ], "menus": { + "intersystems-community.servermanager.iconColor": [ + { + "command": "intersystems-community.servermanager.setIconRed", + "group": "color" + }, + { + "command": "intersystems-community.servermanager.setIconOrange", + "group": "color" + }, + { + "command": "intersystems-community.servermanager.setIconYellow", + "group": "color" + }, + { + "command": "intersystems-community.servermanager.setIconGreen", + "group": "color" + }, + { + "command": "intersystems-community.servermanager.setIconBlue", + "group": "color" + }, + { + "command": "intersystems-community.servermanager.setIconPurple", + "group": "color" + }, + { + "command": "intersystems-community.servermanager.resetIconColor", + "group": "reset" + } + ], "commandPalette": [ { "command": "intersystems-community.servermanager.importServers", @@ -310,11 +376,20 @@ "when": "view == intersystems-community_servermanager && viewItem == starred.server.starred", "group": "inline@10" }, + { + "command": "intersystems-community.servermanager.openManagementPortalInSimpleBrowser", + "when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\./", + "group": "inline@80" + }, { "command": "intersystems-community.servermanager.openManagementPortalExternal", "when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\./", "group": "inline@90" }, + { + "submenu": "intersystems-community.servermanager.iconColor", + "group": "color" + }, { "command": "intersystems-community.servermanager.storePassword", "when": "view == intersystems-community_servermanager && viewItem =~ /\\.server\\./", diff --git a/src/api/getPortalUriWithCredentials.ts b/src/api/getPortalUriWithCredentials.ts index 1281c99..21347d1 100644 --- a/src/api/getPortalUriWithCredentials.ts +++ b/src/api/getPortalUriWithCredentials.ts @@ -1,9 +1,12 @@ import * as vscode from 'vscode'; import { Uri } from 'vscode'; -import { getServerSpec } from './getServerSpec'; +import { extensionId } from '../extension'; export async function getPortalUriWithCredentials(name: string, scope?: vscode.ConfigurationScope): Promise { - return getServerSpec(name, scope).then((spec) => { + + // Use our own API so that the Recent folder updates with our activity + const myApi = vscode.extensions.getExtension(extensionId)?.exports; + return myApi.getServerSpec(name, scope).then((spec) => { if (typeof spec !== 'undefined') { const webServer = spec.webServer; let queryString = ''; diff --git a/src/extension.ts b/src/extension.ts index 446a422..763553b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -56,14 +56,12 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand(`${extensionId}.addServer`, async () => { await addServer(); - view.refreshTree(); }) ); context.subscriptions.push( vscode.commands.registerCommand(`${extensionId}.addToStarred`, async (server?: ServerTreeItem) => { if (server?.contextValue?.match(/\.server\./) && server.name) { await view.addToFavorites(server.name); - view.refreshTree(); } }) ); @@ -71,7 +69,6 @@ export function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand(`${extensionId}.removeFromStarred`, async (server?: ServerTreeItem) => { if (server?.contextValue?.endsWith('.starred') && server.name) { await view.removeFromFavorites(server.name); - view.refreshTree(); } }) ); @@ -120,6 +117,62 @@ export function activate(context: vscode.ExtensionContext) { } }); }) + ); + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.setIconRed`, (server?: ServerTreeItem) => { + if (server?.name) { + view.setIconColor(server.name, 'red'); + view.refreshTree(); + } + }) + ); + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.setIconOrange`, (server?: ServerTreeItem) => { + if (server?.name) { + view.setIconColor(server.name, 'orange'); + view.refreshTree(); + } + }) + ); + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.setIconYellow`, (server?: ServerTreeItem) => { + if (server?.name) { + view.setIconColor(server.name, 'yellow'); + view.refreshTree(); + } + }) + ); + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.setIconGreen`, (server?: ServerTreeItem) => { + if (server?.name) { + view.setIconColor(server.name, 'green'); + view.refreshTree(); + } + }) + ); + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.setIconBlue`, (server?: ServerTreeItem) => { + if (server?.name) { + view.setIconColor(server.name, 'blue'); + view.refreshTree(); + } + }) + ); + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.setIconPurple`, (server?: ServerTreeItem) => { + if (server?.name) { + view.setIconColor(server.name, 'purple'); + view.refreshTree(); + } + }) + ); + context.subscriptions.push( + vscode.commands.registerCommand(`${extensionId}.resetIconColor`, (server?: ServerTreeItem) => { + if (server?.name) { + view.setIconColor(server.name, undefined); + view.refreshTree(); + } + }) ); context.subscriptions.push( vscode.commands.registerCommand(`${extensionId}.importServers`, async () => { @@ -128,10 +181,25 @@ export function activate(context: vscode.ExtensionContext) { }) ); + // Listen for relevant configuration changes + context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('intersystems.servers') || e.affectsConfiguration('objectscript.conn')) { + view.refreshTree(); + } + })); + + // Expose our API let api = { async pickServer(scope?: vscode.ConfigurationScope, options: vscode.QuickPickOptions = {}): Promise { - return await pickServer(scope, options); + const name = await pickServer(scope, options); + /* + if (name) { + view.addToRecents(name); + } + */ + + return name; }, getServerNames(scope?: vscode.ConfigurationScope): ServerName[] { return getServerNames(scope); @@ -142,7 +210,11 @@ export function activate(context: vscode.ExtensionContext) { }, async getServerSpec(name: string, scope?: vscode.ConfigurationScope, flushCredentialCache: boolean = false): Promise { - return await getServerSpec(name, scope, flushCredentialCache); + const spec = await getServerSpec(name, scope, flushCredentialCache); + if (spec) { + view.addToRecents(name); + } + return spec; }, onDidChangePassword(): vscode.Event { diff --git a/src/ui/serverManagerView.ts b/src/ui/serverManagerView.ts index 8ab6b6f..e340111 100644 --- a/src/ui/serverManagerView.ts +++ b/src/ui/serverManagerView.ts @@ -7,26 +7,59 @@ const SETTINGS_VERSION = 'v1'; namespace StorageIds { export const favorites = `tree.${SETTINGS_VERSION}.favorites`; + export const iconColors = `tree.${SETTINGS_VERSION}.iconColors`; } const favoritesMap = new Map(); +const colorsMap = new Map(); + +let recentsArray: string[] = []; + export class ServerManagerView { private _globalState: vscode.Memento; private _treeDataProvider: SMNodeProvider; + addToRecents(name: string) { + if (recentsArray[0] !== name) { + recentsArray = recentsArray.filter((n) => n !== name); + if (recentsArray.unshift(name) > 8) { + recentsArray.pop() + } + + // Delay the refresh to avoid startling the user by updating the tree the instant they click on a command button + setTimeout(() => this.refreshTree(), 1000); + } + } + async addToFavorites(name: string) { if (!favoritesMap.has(name)) { favoritesMap.set(name, null); await this._globalState.update(StorageIds.favorites, Array.from(favoritesMap.keys())); + this.refreshTree(); } } async removeFromFavorites(name: string) { if (favoritesMap.delete(name)) { await this._globalState.update(StorageIds.favorites, Array.from(favoritesMap.keys())); + this.refreshTree(); + } + }; + + async setIconColor(name: string, color: string | undefined) { + let changed = false; + if (typeof color === 'undefined') { + changed = colorsMap.delete(name); + } + else if (colorsMap.get(name) !== color) { + colorsMap.set(name, color); + changed = true; + } + if (changed) { + await this._globalState.update(StorageIds.iconColors, Array.from(colorsMap.entries())); } }; @@ -39,12 +72,16 @@ export class ServerManagerView { const treeDataProvider = new SMNodeProvider(); this._treeDataProvider = treeDataProvider; context.subscriptions.push( - vscode.window.createTreeView('intersystems-community_servermanager', { treeDataProvider, showCollapseAll: false }) + vscode.window.createTreeView('intersystems-community_servermanager', { treeDataProvider, showCollapseAll: true }) ); // load favoritesMap const favorites = this._globalState.get(StorageIds.favorites) || []; favorites.forEach((name) => favoritesMap.set(name, null)); + + // load colorsMap + const colors = this._globalState.get(StorageIds.iconColors) || []; + colors.forEach((pair) => colorsMap.set(pair[0], pair[1])); } } @@ -67,9 +104,13 @@ class SMNodeProvider implements vscode.TreeDataProvider { getChildren(element?: SMTreeItem): SMTreeItem[] { const children: SMTreeItem[] = []; if (!element) { - children.push(new SMTreeItem({label: 'Current', tooltip: 'Servers used by current workspace', codiconName: 'home', getChildren: currentServers})); - children.push(new SMTreeItem({label: 'Starred', tooltip: 'Favorite servers', codiconName: 'star-full', getChildren: favoriteServers})); - children.push(new SMTreeItem({label: 'Recent', tooltip: 'Recently used servers', codiconName: 'history'})); + if (vscode.workspace.workspaceFolders?.length || 0 > 0) { + children.push(new SMTreeItem({label: 'Current', tooltip: 'Servers used by current workspace', codiconName: 'home', getChildren: currentServers})); + } + if (favoritesMap.size > 0) { + children.push(new SMTreeItem({label: 'Starred', tooltip: 'Favorite servers', codiconName: 'star-full', getChildren: favoriteServers})); + } + children.push(new SMTreeItem({label: 'Recent', tooltip: 'Recently used servers', codiconName: 'history', getChildren: recentServers})); children.push(new SMTreeItem({label: 'Ordered', tooltip: 'All servers in settings.json order', codiconName: 'list-ordered', getChildren: allServers, params: {sorted: false}})); children.push(new SMTreeItem({label: 'Sorted', tooltip: 'All servers in alphabetical order', codiconName: 'triangle-down', getChildren: allServers, params: {sorted: true}})); return children; @@ -146,7 +187,16 @@ function currentServers(element?: SMTreeItem, params?: any): ServerTreeItem[] { children.set(serverName, new ServerTreeItem(serverSummary, 'current')); } } + const conn = vscode.workspace.getConfiguration('objectscript.conn', folder); + const connServer = conn.get('server'); + if (connServer) { + const serverSummary = getServerSummary(connServer); + if (serverSummary) { + children.set(connServer, new ServerTreeItem(serverSummary, 'current')); + } + } }); + return Array.from(children.values()).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0); } @@ -163,6 +213,19 @@ function favoriteServers(element?: SMTreeItem, params?: any): ServerTreeItem[] { return children.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0); } +function recentServers(element?: SMTreeItem, params?: any): ServerTreeItem[] { + const children: ServerTreeItem[] = []; + + recentsArray.map((name) => { + const serverSummary = getServerSummary(name); + if (serverSummary) { + children.push(new ServerTreeItem(serverSummary, 'recent')); + } + }); + + return children; +} + export class ServerTreeItem extends SMTreeItem { public readonly name: string; constructor( @@ -172,8 +235,9 @@ export class ServerTreeItem extends SMTreeItem { // Wrap detail (a uri string) as a null link to prevent it from being linkified super({label: serverName.name, tooltip: new vscode.MarkdownString(`[${serverName.detail}]()`).appendMarkdown(serverName.description ? `\n\n*${serverName.description}*` : '')}); this.name = serverName.name; - this.command = {command: 'intersystems-community.servermanager.openManagementPortalInSimpleBrowser', title: 'Open Management Portal in Simple Browser Tab', arguments: [this]}; + //this.command = {command: 'intersystems-community.servermanager.openManagementPortalInSimpleBrowser', title: 'Open Management Portal in Simple Browser Tab', arguments: [this]}; this.contextValue = `${parentFolderId}.server.${favoritesMap.has(this.name) ? 'starred' : ''}`; - this.iconPath = new vscode.ThemeIcon('server-environment'); + const color = colorsMap.get(this.name); + this.iconPath = new vscode.ThemeIcon('server-environment', color ? new vscode.ThemeColor('charts.' + color) : undefined); } }