diff --git a/src/sql/parts/connection/common/serverInfoContextKey.ts b/src/sql/parts/connection/common/serverInfoContextKey.ts new file mode 100644 index 0000000000..e0eadf6327 --- /dev/null +++ b/src/sql/parts/connection/common/serverInfoContextKey.ts @@ -0,0 +1,39 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { ServerInfo } from 'azdata'; + +export class ServerInfoContextKey implements IContextKey { + + static ServerInfo = new RawContextKey('serverInfo', undefined); + static ServerMajorVersion = new RawContextKey('serverMajorVersion', undefined); + + private _serverInfo: IContextKey; + private _serverMajorVersion: IContextKey; + + constructor( + @IContextKeyService contextKeyService: IContextKeyService + ) { + this._serverInfo = ServerInfoContextKey.ServerInfo.bindTo(contextKeyService); + this._serverMajorVersion = ServerInfoContextKey.ServerMajorVersion.bindTo(contextKeyService); + } + + set(value: ServerInfo) { + this._serverInfo.set(value); + let majorVersion = value && value.serverMajorVersion; + this._serverMajorVersion.set(majorVersion && `${majorVersion}`); + } + + reset(): void { + this._serverMajorVersion.reset(); + } + + public get(): ServerInfo { + return this._serverInfo.get(); + } +} diff --git a/src/sql/parts/objectExplorer/viewlet/serverTreeActionProvider.ts b/src/sql/parts/objectExplorer/viewlet/serverTreeActionProvider.ts index 26f0b77ada..2a091f0805 100644 --- a/src/sql/parts/objectExplorer/viewlet/serverTreeActionProvider.ts +++ b/src/sql/parts/objectExplorer/viewlet/serverTreeActionProvider.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; +import * as azdata from 'azdata'; import { TPromise } from 'vs/base/common/winjs.base'; import { ITree } from 'vs/base/parts/tree/browser/tree'; import { ContributableActionProvider } from 'vs/workbench/browser/actions'; @@ -15,8 +16,7 @@ import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem'; import { DisconnectConnectionAction, AddServerAction, DeleteConnectionAction, RefreshAction, EditServerGroupAction -} - from 'sql/parts/objectExplorer/viewlet/connectionTreeAction'; +} from 'sql/parts/objectExplorer/viewlet/connectionTreeAction'; import { ObjectExplorerActionUtilities, ManageConnectionAction, OEAction } from 'sql/parts/objectExplorer/viewlet/objectExplorerActions'; @@ -34,6 +34,7 @@ import { TreeNodeContextKey } from 'sql/parts/objectExplorer/viewlet/treeNodeCon import { IQueryManagementService } from 'sql/platform/query/common/queryManagement'; import { IScriptingService } from 'sql/platform/scripting/common/scriptingService'; import * as constants from 'sql/common/constants'; +import { ServerInfoContextKey } from 'sql/parts/connection/common/serverInfoContextKey'; /** * Provides actions for the server tree elements @@ -132,7 +133,13 @@ export class ServerTreeActionProvider extends ContributableActionProvider { private getContextKeyService(context: ObjectExplorerContext): IContextKeyService { let scopedContextService = this._contextKeyService.createScoped(); let connectionContextKey = new ConnectionContextKey(scopedContextService); - connectionContextKey.set(context.profile); + let connectionProfile = context && context.profile; + connectionContextKey.set(connectionProfile); + let serverInfoContextKey = new ServerInfoContextKey(scopedContextService); + if (connectionProfile.id) { + let serverInfo = this._connectionManagementService.getServerInfo(connectionProfile.id); + serverInfoContextKey.set(serverInfo); + } let treeNodeContextKey = new TreeNodeContextKey(scopedContextService); if (context.treeNode) { treeNodeContextKey.set(context.treeNode);