mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 09:42:34 -05:00
Isolate features (#6792)
* working; new query and scripting * working; removing manage from menus and combining data explorer contributions * consolidate dashboard contributions; move manage action to dashboard contributions; make groupings the same * fix notebook actions * fix tests
This commit is contained in:
@@ -304,40 +304,6 @@ export class RecentConnectionsFilterAction extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
export class NewQueryAction extends Action {
|
||||
public static ID = 'registeredServers.newQuery';
|
||||
public static LABEL = localize('registeredServers.newQuery', "New Query");
|
||||
private _connectionProfile: IConnectionProfile;
|
||||
get connectionProfile(): IConnectionProfile {
|
||||
return this._connectionProfile;
|
||||
}
|
||||
set connectionProfile(profile: IConnectionProfile) {
|
||||
this._connectionProfile = profile;
|
||||
}
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@IQueryEditorService private queryEditorService: IQueryEditorService,
|
||||
@IConnectionManagementService private connectionManagementService: IConnectionManagementService,
|
||||
@IObjectExplorerService protected _objectExplorerService: IObjectExplorerService,
|
||||
@IEditorService protected _workbenchEditorService: IEditorService,
|
||||
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService
|
||||
) {
|
||||
super(id, label);
|
||||
this.class = 'extension-action update';
|
||||
}
|
||||
|
||||
public run(actionContext: ObjectExplorerActionsContext): Promise<boolean> {
|
||||
if (actionContext instanceof ObjectExplorerActionsContext) {
|
||||
this._connectionProfile = new ConnectionProfile(this._capabilitiesService, actionContext.connectionProfile);
|
||||
}
|
||||
|
||||
TaskUtilities.newQuery(this._connectionProfile, this.connectionManagementService, this.queryEditorService, this._objectExplorerService, this._workbenchEditorService);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions to delete a server/group
|
||||
*/
|
||||
|
||||
@@ -3,14 +3,11 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { localize } from 'vs/nls';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
||||
import { ExecuteCommandAction } from 'vs/platform/actions/common/actions';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { IConnectionManagementService, IConnectionCompletionOptions } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { TreeNode } from 'sql/workbench/parts/objectExplorer/common/treeNode';
|
||||
import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/treeUpdateUtils';
|
||||
import { TreeSelectionHandler } from 'sql/workbench/parts/objectExplorer/browser/treeSelectionHandler';
|
||||
@@ -68,83 +65,3 @@ export class OEAction extends ExecuteCommandAction {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class ManageConnectionAction extends Action {
|
||||
public static ID = 'objectExplorer.manage';
|
||||
public static LABEL = localize('ManageAction', "Manage");
|
||||
|
||||
private _treeSelectionHandler: TreeSelectionHandler;
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
private _tree: ITree,
|
||||
@IConnectionManagementService protected _connectionManagementService: IConnectionManagementService,
|
||||
@ICapabilitiesService protected _capabilitiesService: ICapabilitiesService,
|
||||
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService
|
||||
) {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
run(actionContext: ObjectExplorerActionsContext): Promise<any> {
|
||||
this._treeSelectionHandler = this._instantiationService.createInstance(TreeSelectionHandler);
|
||||
this._treeSelectionHandler.onTreeActionStateChange(true);
|
||||
let self = this;
|
||||
let promise = new Promise<boolean>((resolve, reject) => {
|
||||
self.doManage(actionContext).then((success) => {
|
||||
self.done();
|
||||
resolve(success);
|
||||
}, error => {
|
||||
self.done();
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
private async doManage(actionContext: ObjectExplorerActionsContext): Promise<boolean> {
|
||||
let treeNode: TreeNode = undefined;
|
||||
let connectionProfile: IConnectionProfile = undefined;
|
||||
if (actionContext instanceof ObjectExplorerActionsContext) {
|
||||
// Must use a real connection profile for this action due to lookup
|
||||
connectionProfile = ConnectionProfile.fromIConnectionProfile(this._capabilitiesService, actionContext.connectionProfile);
|
||||
if (!actionContext.isConnectionNode) {
|
||||
treeNode = await getTreeNode(actionContext, this._objectExplorerService);
|
||||
if (TreeUpdateUtils.isDatabaseNode(treeNode)) {
|
||||
connectionProfile = TreeUpdateUtils.getConnectionProfile(treeNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!connectionProfile) {
|
||||
// This should never happen. There should be always a valid connection if the manage action is called for
|
||||
// an OE node or a database node
|
||||
return true;
|
||||
}
|
||||
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showDashboard: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
// If it's a database node just open a database connection and open dashboard,
|
||||
// the node is already from an open OE session we don't need to create new session
|
||||
if (TreeUpdateUtils.isAvailableDatabaseNode(treeNode)) {
|
||||
return this._connectionManagementService.showDashboard(connectionProfile);
|
||||
} else {
|
||||
return TreeUpdateUtils.connectAndCreateOeSession(connectionProfile, options, this._connectionManagementService, this._objectExplorerService, this._tree);
|
||||
}
|
||||
}
|
||||
|
||||
private done() {
|
||||
this._treeSelectionHandler.onTreeActionStateChange(false);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
DeleteConnectionAction, RefreshAction, EditServerGroupAction
|
||||
} from 'sql/workbench/parts/objectExplorer/browser/connectionTreeAction';
|
||||
import {
|
||||
ManageConnectionAction, OEAction
|
||||
OEAction
|
||||
} from 'sql/workbench/parts/objectExplorer/browser/objectExplorerActions';
|
||||
import { TreeNode } from 'sql/workbench/parts/objectExplorer/common/treeNode';
|
||||
import { NodeType } from 'sql/workbench/parts/objectExplorer/common/nodeType';
|
||||
@@ -23,12 +23,10 @@ import { ConnectionProfile } from 'sql/platform/connection/common/connectionProf
|
||||
import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/treeUpdateUtils';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { MenuId, IMenuService } from 'vs/platform/actions/common/actions';
|
||||
import { NewQueryAction, BackupAction, RestoreAction } from 'sql/workbench/common/actions';
|
||||
import { BackupAction, RestoreAction } from 'sql/workbench/common/actions';
|
||||
import { ConnectionContextKey } from 'sql/workbench/parts/connection/common/connectionContextKey';
|
||||
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
|
||||
import { TreeNodeContextKey } from 'sql/workbench/parts/objectExplorer/common/treeNodeContextKey';
|
||||
import { IQueryManagementService } from 'sql/platform/query/common/queryManagement';
|
||||
import { IScriptingService } from 'sql/platform/scripting/common/scriptingService';
|
||||
import { ServerInfoContextKey } from 'sql/workbench/parts/connection/common/serverInfoContextKey';
|
||||
import { fillInActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
|
||||
import { NewNotebookAction } from 'sql/workbench/parts/notebook/browser/notebookActions';
|
||||
@@ -42,8 +40,6 @@ export class ServerTreeActionProvider extends ContributableActionProvider {
|
||||
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||
@IQueryManagementService private _queryManagementService: IQueryManagementService,
|
||||
@IScriptingService private _scriptingService: IScriptingService,
|
||||
@IContextMenuService private contextMenuService: IContextMenuService,
|
||||
@IMenuService private menuService: IMenuService,
|
||||
@IContextKeyService private _contextKeyService: IContextKeyService
|
||||
) {
|
||||
@@ -111,7 +107,6 @@ export class ServerTreeActionProvider extends ContributableActionProvider {
|
||||
|
||||
private getBuiltinConnectionActions(context: ObjectExplorerContext): IAction[] {
|
||||
let actions: IAction[] = [];
|
||||
actions.push(this._instantiationService.createInstance(ManageConnectionAction, ManageConnectionAction.ID, ManageConnectionAction.LABEL, context.tree));
|
||||
this.addNewQueryNotebookActions(context, actions);
|
||||
|
||||
if (this._connectionManagementService.isProfileConnected(context.profile)) {
|
||||
@@ -168,7 +163,6 @@ export class ServerTreeActionProvider extends ContributableActionProvider {
|
||||
if (TreeUpdateUtils.isDatabaseNode(treeNode)) {
|
||||
if (TreeUpdateUtils.isAvailableDatabaseNode(treeNode)) {
|
||||
isAvailableDatabaseNode = true;
|
||||
actions.push(this._instantiationService.createInstance(ManageConnectionAction, ManageConnectionAction.ID, ManageConnectionAction.LABEL, context.tree));
|
||||
this.addNewQueryNotebookActions(context, actions);
|
||||
} else {
|
||||
return actions;
|
||||
@@ -193,7 +187,6 @@ export class ServerTreeActionProvider extends ContributableActionProvider {
|
||||
|
||||
private addNewQueryNotebookActions(context: ObjectExplorerContext, actions: IAction[]): void {
|
||||
if (this._queryManagementService.isProviderRegistered(context.profile.providerName)) {
|
||||
actions.push(this._instantiationService.createInstance(OEAction, NewQueryAction.ID, NewQueryAction.LABEL));
|
||||
// Workaround for #6397 right-click and run New Notebook connects to wrong server. Use notebook action instead of generic command action
|
||||
let notebookAction = this._instantiationService.createInstance(NewNotebookAction, NewNotebookAction.ID, NewNotebookAction.LABEL);
|
||||
actions.push(notebookAction);
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import {
|
||||
SCRIPT_AS_SELECT_COMMAND_ID, EDIT_DATA_COMMAND_ID, SCRIPT_AS_CREATE_COMMAND_ID,
|
||||
SCRIPT_AS_EXECUTE_COMMAND_ID, SCRIPT_AS_ALTER_COMMAND_ID, SCRIPT_AS_DELETE_COMMAND_ID,
|
||||
REFRESH_OE_COMMAND_ID
|
||||
} from 'sql/workbench/parts/objectExplorer/electron-browser/objectExplorerScriptingActions';
|
||||
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
|
||||
import { localize } from 'vs/nls';
|
||||
import { ConnectionContextKey } from 'sql/workbench/parts/connection/common/connectionContextKey';
|
||||
import { TreeNodeContextKey } from 'sql/workbench/parts/objectExplorer/common/treeNodeContextKey';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { NodeType } from 'sql/workbench/parts/objectExplorer/common/nodeType';
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: 'scripting',
|
||||
order: 1,
|
||||
command: {
|
||||
id: SCRIPT_AS_SELECT_COMMAND_ID,
|
||||
title: localize('scriptSelect', "Select Top 1000")
|
||||
},
|
||||
when: ContextKeyExpr.or(TreeNodeContextKey.NodeType.isEqualTo('Table'), TreeNodeContextKey.NodeType.isEqualTo('View'))
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: 'scripting',
|
||||
order: 2,
|
||||
command: {
|
||||
id: EDIT_DATA_COMMAND_ID,
|
||||
title: localize('editData', "Edit Data")
|
||||
},
|
||||
when: TreeNodeContextKey.NodeType.isEqualTo('Table')
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: 'scripting',
|
||||
order: 3,
|
||||
command: {
|
||||
id: SCRIPT_AS_CREATE_COMMAND_ID,
|
||||
title: localize('scriptCreate', "Script as Create")
|
||||
},
|
||||
when: ContextKeyExpr.or(
|
||||
TreeNodeContextKey.NodeType.isEqualTo('Table'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('View'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('Schema'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('User'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('UserDefinedTableType'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('StoredProcedure'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('AggregateFunction'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('PartitionFunction'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('ScalarValuedFunction'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo('TableValuedFunction'))
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: 'scripting',
|
||||
order: 6,
|
||||
command: {
|
||||
id: SCRIPT_AS_EXECUTE_COMMAND_ID,
|
||||
title: localize('scriptExecute', "Script as Execute")
|
||||
},
|
||||
when: ContextKeyExpr.and(ConnectionContextKey.Provider.isEqualTo('MSSQL'), TreeNodeContextKey.NodeType.isEqualTo('StoredProcedure'))
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: 'scripting',
|
||||
order: 5,
|
||||
command: {
|
||||
id: SCRIPT_AS_ALTER_COMMAND_ID,
|
||||
title: localize('scriptAlter', "Script as Alter")
|
||||
},
|
||||
when:
|
||||
ContextKeyExpr.or(
|
||||
ContextKeyExpr.and(
|
||||
ConnectionContextKey.Provider.isEqualTo('MSSQL'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.StoredProcedure)),
|
||||
ContextKeyExpr.and(
|
||||
ConnectionContextKey.Provider.isEqualTo('MSSQL'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.View)),
|
||||
ContextKeyExpr.and(
|
||||
ConnectionContextKey.Provider.isEqualTo('MSSQL'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.AggregateFunction)),
|
||||
ContextKeyExpr.and(
|
||||
ConnectionContextKey.Provider.isEqualTo('MSSQL'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.PartitionFunction)),
|
||||
ContextKeyExpr.and(
|
||||
ConnectionContextKey.Provider.isEqualTo('MSSQL'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.ScalarValuedFunction)),
|
||||
ContextKeyExpr.and(
|
||||
ConnectionContextKey.Provider.isEqualTo('MSSQL'),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.TableValuedFunction)),
|
||||
)
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: 'scripting',
|
||||
order: 4,
|
||||
command: {
|
||||
id: SCRIPT_AS_DELETE_COMMAND_ID,
|
||||
title: localize('scriptDelete', "Script as Drop")
|
||||
},
|
||||
when: ContextKeyExpr.or(
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Table),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.View),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Schema),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.User),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.UserDefinedTableType),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.StoredProcedure),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.AggregateFunction),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.PartitionFunction),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.ScalarValuedFunction),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.TableValuedFunction))
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: 'scripting',
|
||||
order: 7,
|
||||
command: {
|
||||
id: REFRESH_OE_COMMAND_ID,
|
||||
title: localize('refreshNode', "Refresh")
|
||||
},
|
||||
when: ContextKeyExpr.or(
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Table),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.View),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.Schema),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.User),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.UserDefinedTableType),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.StoredProcedure),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.AggregateFunction),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.PartitionFunction),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.ScalarValuedFunction),
|
||||
TreeNodeContextKey.NodeType.isEqualTo(NodeType.TableValuedFunction))
|
||||
});
|
||||
@@ -1,196 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ScriptSelectAction, EditDataAction, ScriptCreateAction, ScriptExecuteAction, ScriptAlterAction, ScriptDeleteAction } from 'sql/workbench/electron-browser/scriptingActions';
|
||||
import { TreeSelectionHandler } from 'sql/workbench/parts/objectExplorer/browser/treeSelectionHandler';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/common/objectExplorerService';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ObjectExplorerActionsContext, getTreeNode } from 'sql/workbench/parts/objectExplorer/browser/objectExplorerActions';
|
||||
import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/treeUpdateUtils';
|
||||
import { TreeNode } from 'sql/workbench/parts/objectExplorer/common/treeNode';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
|
||||
export const SCRIPT_AS_CREATE_COMMAND_ID = 'objectExplorer.scriptAsCreate';
|
||||
export const SCRIPT_AS_DELETE_COMMAND_ID = 'objectExplorer.scriptAsDelete';
|
||||
export const SCRIPT_AS_SELECT_COMMAND_ID = 'objectExplorer.scriptAsSelect';
|
||||
export const SCRIPT_AS_EXECUTE_COMMAND_ID = 'objectExplorer.scriptAsExecute';
|
||||
export const SCRIPT_AS_ALTER_COMMAND_ID = 'objectExplorer.scriptAsAlter';
|
||||
export const EDIT_DATA_COMMAND_ID = 'objectExplorer.scriptAsEdit';
|
||||
export const REFRESH_OE_COMMAND_ID = 'objectExplorer.refreshNode';
|
||||
|
||||
// Script as Select
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_SELECT_COMMAND_ID,
|
||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const objectExplorerService = accessor.get(IObjectExplorerService);
|
||||
const selectionHandler = instantiationService.createInstance(TreeSelectionHandler);
|
||||
const node = await getTreeNode(args, objectExplorerService);
|
||||
selectionHandler.onTreeActionStateChange(true);
|
||||
let connectionProfile = TreeUpdateUtils.getConnectionProfile(node);
|
||||
let ownerUri = connectionManagementService.getConnectionUri(connectionProfile);
|
||||
ownerUri = connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||
let metadata = node.metadata;
|
||||
|
||||
return instantiationService.createInstance(ScriptSelectAction, ScriptSelectAction.ID, ScriptSelectAction.LABEL).run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||
selectionHandler.onTreeActionStateChange(false);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Edit Data
|
||||
CommandsRegistry.registerCommand({
|
||||
id: EDIT_DATA_COMMAND_ID,
|
||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const objectExplorerService = accessor.get(IObjectExplorerService);
|
||||
const selectionHandler = instantiationService.createInstance(TreeSelectionHandler);
|
||||
const node = await getTreeNode(args, objectExplorerService);
|
||||
selectionHandler.onTreeActionStateChange(true);
|
||||
let connectionProfile = TreeUpdateUtils.getConnectionProfile(node);
|
||||
let metadata = node.metadata;
|
||||
|
||||
return instantiationService.createInstance(EditDataAction, EditDataAction.ID, EditDataAction.LABEL).run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||
selectionHandler.onTreeActionStateChange(false);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Script as Create
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_CREATE_COMMAND_ID,
|
||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const objectExplorerService = accessor.get(IObjectExplorerService);
|
||||
const selectionHandler = instantiationService.createInstance(TreeSelectionHandler);
|
||||
const node = await getTreeNode(args, objectExplorerService);
|
||||
selectionHandler.onTreeActionStateChange(true);
|
||||
let connectionProfile = TreeUpdateUtils.getConnectionProfile(node);
|
||||
let metadata = node.metadata;
|
||||
let ownerUri = connectionManagementService.getConnectionUri(connectionProfile);
|
||||
ownerUri = connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||
|
||||
return instantiationService.createInstance(ScriptCreateAction, ScriptCreateAction.ID, ScriptCreateAction.LABEL).run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||
selectionHandler.onTreeActionStateChange(false);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Script as Execute
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_EXECUTE_COMMAND_ID,
|
||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const objectExplorerService = accessor.get(IObjectExplorerService);
|
||||
const selectionHandler = instantiationService.createInstance(TreeSelectionHandler);
|
||||
const node = await getTreeNode(args, objectExplorerService);
|
||||
selectionHandler.onTreeActionStateChange(true);
|
||||
let connectionProfile = TreeUpdateUtils.getConnectionProfile(node);
|
||||
let metadata = node.metadata;
|
||||
let ownerUri = connectionManagementService.getConnectionUri(connectionProfile);
|
||||
ownerUri = connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||
|
||||
return instantiationService.createInstance(ScriptExecuteAction, ScriptExecuteAction.ID, ScriptExecuteAction.LABEL).run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||
selectionHandler.onTreeActionStateChange(false);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Script as Alter
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_ALTER_COMMAND_ID,
|
||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const objectExplorerService = accessor.get(IObjectExplorerService);
|
||||
const selectionHandler = instantiationService.createInstance(TreeSelectionHandler);
|
||||
const node = await getTreeNode(args, objectExplorerService);
|
||||
selectionHandler.onTreeActionStateChange(true);
|
||||
let connectionProfile = TreeUpdateUtils.getConnectionProfile(node);
|
||||
let metadata = node.metadata;
|
||||
let ownerUri = connectionManagementService.getConnectionUri(connectionProfile);
|
||||
ownerUri = connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||
|
||||
return instantiationService.createInstance(ScriptAlterAction, ScriptAlterAction.ID, ScriptAlterAction.LABEL).run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||
selectionHandler.onTreeActionStateChange(false);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Script as Delete
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_DELETE_COMMAND_ID,
|
||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const objectExplorerService = accessor.get(IObjectExplorerService);
|
||||
const selectionHandler = instantiationService.createInstance(TreeSelectionHandler);
|
||||
//set objectExplorerTreeNode for context menu clicks
|
||||
const node = await getTreeNode(args, objectExplorerService);
|
||||
selectionHandler.onTreeActionStateChange(true);
|
||||
const connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>node);
|
||||
const metadata = node.metadata;
|
||||
let ownerUri = connectionManagementService.getConnectionUri(connectionProfile);
|
||||
ownerUri = connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||
|
||||
return instantiationService.createInstance(ScriptDeleteAction, ScriptDeleteAction.ID, ScriptDeleteAction.LABEL).run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||
selectionHandler.onTreeActionStateChange(false);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Refresh Action for Scriptable objects
|
||||
CommandsRegistry.registerCommand({
|
||||
id: REFRESH_OE_COMMAND_ID,
|
||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const capabilitiesService = accessor.get(ICapabilitiesService);
|
||||
const objectExplorerService = accessor.get(IObjectExplorerService);
|
||||
const errorMessageService = accessor.get(IErrorMessageService);
|
||||
const connection = new ConnectionProfile(capabilitiesService, args.connectionProfile);
|
||||
let treeNode: TreeNode;
|
||||
if (connectionManagementService.isConnected(undefined, connection)) {
|
||||
treeNode = await getTreeNode(args, objectExplorerService);
|
||||
if (treeNode === undefined) {
|
||||
objectExplorerService.updateObjectExplorerNodes(connection.toIConnectionProfile()).then(() => {
|
||||
treeNode = objectExplorerService.getObjectExplorerNode(connection);
|
||||
});
|
||||
}
|
||||
}
|
||||
const tree = objectExplorerService.getServerTreeView().tree;
|
||||
if (treeNode) {
|
||||
return tree.collapse(treeNode).then(() => {
|
||||
return objectExplorerService.refreshTreeNode(treeNode.getSession(), treeNode).then(() => {
|
||||
return tree.refresh(treeNode).then(() => {
|
||||
return tree.expand(treeNode);
|
||||
}, refreshError => {
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
}, error => {
|
||||
errorMessageService.showDialog(Severity.Error, '', error);
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
}, collapseError => {
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
});
|
||||
@@ -24,12 +24,15 @@ import { Tree } from 'vs/base/parts/tree/browser/treeImpl';
|
||||
import { ServerTreeDataSource } from 'sql/workbench/parts/objectExplorer/browser/serverTreeDataSource';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { ObjectExplorerActionsContext, ManageConnectionAction } from 'sql/workbench/parts/objectExplorer/browser/objectExplorerActions';
|
||||
import { ObjectExplorerActionsContext } from 'sql/workbench/parts/objectExplorer/browser/objectExplorerActions';
|
||||
import { IConnectionResult, IConnectionParams } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { TreeSelectionHandler } from 'sql/workbench/parts/objectExplorer/browser/treeSelectionHandler';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { UNSAVED_GROUP_ID, mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { $ } from 'vs/base/browser/dom';
|
||||
import { OEManageConnectionAction } from 'sql/workbench/parts/dashboard/browser/dashboardActions';
|
||||
import { IViewsService, IView, ViewContainer, IViewDescriptorCollection } from 'vs/workbench/common/views';
|
||||
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
suite('SQL Connection Tree Action tests', () => {
|
||||
let errorMessageService: TypeMoq.Mock<TestErrorMessageService>;
|
||||
@@ -103,8 +106,21 @@ suite('SQL Connection Tree Action tests', () => {
|
||||
return treeSelectionMock.object;
|
||||
});
|
||||
|
||||
let manageConnectionAction: ManageConnectionAction = new ManageConnectionAction(ManageConnectionAction.ID,
|
||||
ManageConnectionAction.LABEL, undefined, connectionManagementService.object, capabilitiesService, instantiationService.object, objectExplorerService.object);
|
||||
const viewsService = new class implements IViewsService {
|
||||
_serviceBrand: ServiceIdentifier<any>;
|
||||
openView(id: string, focus?: boolean): Promise<IView> {
|
||||
return Promise.resolve({
|
||||
id: '',
|
||||
serversTree: undefined
|
||||
});
|
||||
}
|
||||
getViewDescriptors(container: ViewContainer): IViewDescriptorCollection {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
};
|
||||
|
||||
let manageConnectionAction: OEManageConnectionAction = new OEManageConnectionAction(OEManageConnectionAction.ID,
|
||||
OEManageConnectionAction.LABEL, connectionManagementService.object, capabilitiesService, instantiationService.object, objectExplorerService.object, viewsService);
|
||||
|
||||
let actionContext = new ObjectExplorerActionsContext();
|
||||
actionContext.connectionProfile = connection.toIConnectionProfile();
|
||||
@@ -141,8 +157,8 @@ suite('SQL Connection Tree Action tests', () => {
|
||||
return treeSelectionMock.object;
|
||||
});
|
||||
|
||||
let manageConnectionAction: ManageConnectionAction = new ManageConnectionAction(ManageConnectionAction.ID,
|
||||
ManageConnectionAction.LABEL, undefined, connectionManagementService.object, capabilitiesService, instantiationService.object, objectExplorerService.object);
|
||||
let manageConnectionAction: OEManageConnectionAction = new OEManageConnectionAction(OEManageConnectionAction.ID,
|
||||
OEManageConnectionAction.LABEL, connectionManagementService.object, capabilitiesService, instantiationService.object, objectExplorerService.object, undefined);
|
||||
|
||||
let actionContext = new ObjectExplorerActionsContext();
|
||||
actionContext.connectionProfile = connection.toIConnectionProfile();
|
||||
|
||||
Reference in New Issue
Block a user