More data explorer actions (#4307)

* 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

* add new Query action

* fix various errors with how the context menus work

* add manage and new query

* add refresh command

* formatting
This commit is contained in:
Anthony Dresser
2019-03-14 17:19:37 -07:00
committed by GitHub
parent 0bc3716f74
commit 0bf0e795ca
6 changed files with 115 additions and 22 deletions

View File

@@ -323,7 +323,7 @@ export class CustomTreeView extends Disposable implements ITreeView {
const menus = this.instantiationService.createInstance(TreeMenus, this.id);
const dataSource = this.instantiationService.createInstance(TreeDataSource, this, this.container, this.id);
const renderer = this.instantiationService.createInstance(TreeRenderer, this.id, menus, actionItemProvider);
const controller = this.instantiationService.createInstance(TreeController, this.id, menus);
const controller = this.instantiationService.createInstance(TreeController, this.id, this.container.id, menus);
this.tree = this.instantiationService.createInstance(FileIconThemableWorkbenchTree, this.treeContainer, { dataSource, renderer, controller }, {});
this.tree.contextKeyService.createKey<boolean>(this.id, true);
this._register(this.tree);
@@ -738,6 +738,7 @@ class TreeController extends WorkbenchTreeController {
constructor(
private treeViewId: string,
private containerId: string,
private menus: TreeMenus,
@IContextMenuService private contextMenuService: IContextMenuService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@@ -779,7 +780,7 @@ class TreeController extends WorkbenchTreeController {
}
},
getActionsContext: () => (<TreeViewItemHandleArg>{ $treeViewId: this.treeViewId, $treeItemHandle: node.handle, $treeItem: node }),
getActionsContext: () => (<TreeViewItemHandleArg>{ $treeViewId: this.treeViewId, $treeItemHandle: node.handle, $treeItem: node, $treeContainerId: this.containerId }),
actionRunner: new MultipleSelectionActionRunner(() => tree.getSelection())
});

View File

@@ -32,7 +32,8 @@ export interface ITreeView extends vsITreeView {
export type TreeViewItemHandleArg = {
$treeViewId: string,
$treeItemHandle: string,
$treeItem?: ITreeItem
$treeItem?: ITreeItem,
$treeContainerId?: string
};
export interface ICustomViewDescriptor extends IViewDescriptor {

View File

@@ -6,7 +6,7 @@
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 } from './nodeCommands';
import { DISCONNECT_COMMAND_ID, MANAGE_COMMAND_ID, NEW_QUERY_COMMAND_ID, REFRESH_COMMAND_ID } from './nodeCommands';
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
group: 'connection',
@@ -17,3 +17,31 @@ MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
},
when: NodeContextKey.IsConnected
});
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
group: 'connection',
command: {
id: NEW_QUERY_COMMAND_ID,
title: localize('newQuery', 'New Query')
},
when: NodeContextKey.IsConnectable
});
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
group: 'connection',
order: 4,
command: {
id: MANAGE_COMMAND_ID,
title: localize('manage', 'Manage')
},
when: NodeContextKey.IsConnectable
});
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
group: 'connection',
order: 4,
command: {
id: REFRESH_COMMAND_ID,
title: localize('refresh', 'Refresh')
}
});

View File

@@ -4,11 +4,20 @@
*--------------------------------------------------------------------------------------------*/
import { IOEShimService } from 'sql/parts/objectExplorer/common/objectExplorerViewTreeShim';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { ConnectionType, IConnectableInput, IConnectionCompletionOptions, IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { generateUri } from 'sql/platform/connection/common/utils';
import { ICustomViewDescriptor, TreeViewItemHandleArg } from 'sql/workbench/common/views';
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ViewsRegistry } from 'vs/workbench/common/views';
import { IProgressService2 } from 'vs/platform/progress/common/progress';
export const DISCONNECT_COMMAND_ID = 'dataExplorer.disconnect';
export const MANAGE_COMMAND_ID = 'dataExplorer.manage';
export const NEW_QUERY_COMMAND_ID = 'dataExplorer.newQuery';
export const REFRESH_COMMAND_ID = 'dataExplorer.refresh';
CommandsRegistry.registerCommand({
id: DISCONNECT_COMMAND_ID,
@@ -24,3 +33,64 @@ CommandsRegistry.registerCommand({
return Promise.resolve(true);
}
});
CommandsRegistry.registerCommand({
id: NEW_QUERY_COMMAND_ID,
handler: (accessor, args: TreeViewItemHandleArg) => {
if (args.$treeItem) {
const queryEditorService = accessor.get(IQueryEditorService);
const connectionService = accessor.get(IConnectionManagementService);
const capabilitiesService = accessor.get(ICapabilitiesService);
return queryEditorService.newSqlEditor().then((owner: IConnectableInput) => {
// Connect our editor to the input connection
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, input: owner },
saveTheConnection: false,
showDashboard: false,
showConnectionDialogOnError: true,
showFirewallRuleOnError: true
};
return connectionService.connect(new ConnectionProfile(capabilitiesService, args.$treeItem.payload), owner.uri, options);
});
}
return Promise.resolve(true);
}
});
CommandsRegistry.registerCommand({
id: MANAGE_COMMAND_ID,
handler: (accessor, args: TreeViewItemHandleArg) => {
if (args.$treeItem) {
const connectionService = accessor.get(IConnectionManagementService);
const capabilitiesService = accessor.get(ICapabilitiesService);
let options = {
showDashboard: true,
saveTheConnection: false,
params: undefined,
showConnectionDialogOnError: true,
showFirewallRuleOnError: true
};
let profile = new ConnectionProfile(capabilitiesService, args.$treeItem.payload);
let uri = generateUri(profile, 'dashboard');
return connectionService.connect(new ConnectionProfile(capabilitiesService, args.$treeItem.payload), uri, options);
}
return Promise.resolve(true);
}
});
CommandsRegistry.registerCommand({
id: REFRESH_COMMAND_ID,
handler: (accessor, args: TreeViewItemHandleArg) => {
const progressSerivce = accessor.get(IProgressService2);
if (args.$treeItem) {
const { treeView } = (<ICustomViewDescriptor>ViewsRegistry.getView(args.$treeViewId));
if (args.$treeContainerId) {
return progressSerivce.withProgress({ location: args.$treeContainerId }, () => treeView.refresh([args.$treeItem]).then(() => true));
} else {
return treeView.refresh([args.$treeItem]).then(() => true);
}
}
return Promise.resolve(true);
}
});