mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 01:28:26 -05:00
Add Data Explorer Context and apply to disconnect (#4265)
* adding context * apply extension changes * shimming disconnect * add data explorer context menu and add disconnect to it * clean up shim code; better handle errors * remove tpromise * simplify code * add node context on data explorer * formatting * fix various errors with how the context menus work
This commit is contained in:
@@ -4,22 +4,19 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { ITreeItem } from 'sql/workbench/common/views';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { TreeNode } from 'sql/parts/objectExplorer/common/treeNode';
|
||||
import { IConnectionManagementService, ConnectionType } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { Deferred } from 'sql/base/common/promise';
|
||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/common/objectExplorerService';
|
||||
import { TreeNode } from 'sql/parts/objectExplorer/common/treeNode';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { ConnectionType, IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ITreeItem } from 'sql/workbench/common/views';
|
||||
import { IConnectionDialogService } from 'sql/workbench/services/connection/common/connectionDialogService';
|
||||
|
||||
import { IConnectionProfile } from 'azdata';
|
||||
|
||||
import { TreeItemCollapsibleState } from 'vs/workbench/common/views';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/common/objectExplorerService';
|
||||
import { hash } from 'vs/base/common/hash';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { TreeItemCollapsibleState } from 'vs/workbench/common/views';
|
||||
|
||||
export const SERVICE_ID = 'oeShimService';
|
||||
export const IOEShimService = createDecorator<IOEShimService>(SERVICE_ID);
|
||||
@@ -29,9 +26,10 @@ export interface IOEShimService {
|
||||
getChildren(node: ITreeItem, viewId: string): Promise<ITreeItem[]>;
|
||||
disconnectNode(viewId: string, node: ITreeItem): Promise<boolean>;
|
||||
providerExists(providerId: string): boolean;
|
||||
isNodeConnected(viewId: string, node: ITreeItem): boolean;
|
||||
}
|
||||
|
||||
export class OEShimService implements IOEShimService {
|
||||
export class OEShimService extends Disposable implements IOEShimService {
|
||||
_serviceBrand: any;
|
||||
|
||||
private sessionMap = new Map<number, string>();
|
||||
@@ -43,6 +41,7 @@ export class OEShimService implements IOEShimService {
|
||||
@IConnectionDialogService private cd: IConnectionDialogService,
|
||||
@ICapabilitiesService private capabilities: ICapabilitiesService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
private async createSession(viewId: string, providerId: string, node: ITreeItem): Promise<string> {
|
||||
@@ -139,6 +138,10 @@ export class OEShimService implements IOEShimService {
|
||||
public providerExists(providerId: string): boolean {
|
||||
return this.oe.providerRegistered(providerId);
|
||||
}
|
||||
|
||||
public isNodeConnected(viewId: string, node: ITreeItem): boolean {
|
||||
return this.sessionMap.has(generateSessionMapKey(viewId, node));
|
||||
}
|
||||
}
|
||||
|
||||
function generateSessionMapKey(viewId: string, node: ITreeItem): number {
|
||||
|
||||
@@ -386,41 +386,6 @@ export class DeleteConnectionAction extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
class DisconnectProfileAction extends Action {
|
||||
|
||||
constructor(
|
||||
@IOEShimService private objectExplorerService: IOEShimService
|
||||
) {
|
||||
super(DisconnectConnectionAction.ID);
|
||||
}
|
||||
run(args: TreeViewItemHandleArg): Promise<boolean> {
|
||||
if (args.$treeItem) {
|
||||
return this.objectExplorerService.disconnectNode(args.$treeViewId, args.$treeItem).then(() => {
|
||||
const { treeView } = (<ICustomViewDescriptor>ViewsRegistry.getView(args.$treeViewId));
|
||||
// we need to collapse it then refresh it so that the tree doesn't try and use it's cache next time the user expands the node
|
||||
return treeView.collapse(args.$treeItem).then(() => treeView.refresh([args.$treeItem]).then(() => true));
|
||||
});
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
|
||||
CommandsRegistry.registerCommand({
|
||||
id: DisconnectConnectionAction.ID,
|
||||
handler: (accessor, args: TreeViewItemHandleArg) => {
|
||||
return accessor.get(IInstantiationService).createInstance(DisconnectProfileAction).run(args);
|
||||
}
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
|
||||
group: 'connection',
|
||||
order: 4,
|
||||
command: {
|
||||
id: DisconnectConnectionAction.ID,
|
||||
title: DisconnectConnectionAction.LABEL
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Action to clear search results
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user