From 34288435eca0df4f3eec28922482cc3ff79178e8 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Fri, 12 Apr 2019 17:09:53 -0700 Subject: [PATCH] Fix Data Explorer context menu items visibility (#4996) * Fix Data Explorer context menu items visibility The when clause was making the menu items show up for all nodes in the Data Explorer - even ones that didn't make sense such as the Databases folders. This change makes it only appear for the Database and Server nodes (which is how the OE tree is set up) --- .../nodeActions.contribution.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/sql/workbench/parts/dataExplorer/electron-browser/nodeActions.contribution.ts b/src/sql/workbench/parts/dataExplorer/electron-browser/nodeActions.contribution.ts index e91fde0a8c..544a8cc770 100644 --- a/src/sql/workbench/parts/dataExplorer/electron-browser/nodeActions.contribution.ts +++ b/src/sql/workbench/parts/dataExplorer/electron-browser/nodeActions.contribution.ts @@ -3,10 +3,11 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { NodeContextKey } from 'sql/workbench/parts/dataExplorer/common/nodeContext'; import { localize } from 'vs/nls'; import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions'; import { DISCONNECT_COMMAND_ID, MANAGE_COMMAND_ID, NEW_QUERY_COMMAND_ID, REFRESH_COMMAND_ID } from './nodeCommands'; +import { ContextKeyExpr, ContextKeyRegexExpr } from 'vs/platform/contextkey/common/contextkey'; +import { NodeContextKey } from 'sql/workbench/parts/dataExplorer/common/nodeContext'; MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, { group: 'connection', @@ -18,6 +19,10 @@ MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, { when: NodeContextKey.IsConnected }); +// The weird regex is because we want this to generically apply to Database and Server nodes but right now +// there isn't a consistent standard for the values there. We can't just search for database or server being +// in the string at all because there's lots of node types which have those values (such as ServerLevelLogin) +// that we don't want these menu items showing up on. MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, { group: 'connection', order: 2, @@ -25,9 +30,13 @@ MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, { id: NEW_QUERY_COMMAND_ID, title: localize('newQuery', 'New Query') }, - when: NodeContextKey.IsConnectable + when: ContextKeyExpr.and( + NodeContextKey.IsConnectable, + new ContextKeyRegexExpr('viewItem', /.+itemType\.database.*|^database$/i)) }); +// Note that we don't show this for Databases under Server nodes (viewItem == Database) because +// of an issue there where the connection always being master instead of the actual DB MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, { group: 'connection', order: 1, @@ -35,7 +44,9 @@ MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, { id: MANAGE_COMMAND_ID, title: localize('manage', 'Manage') }, - when: NodeContextKey.IsConnectable + when: ContextKeyExpr.and( + NodeContextKey.IsConnectable, + new ContextKeyRegexExpr('viewItem', /.+itemType\.database.*/i)) }); MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {