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, {