mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 01:25:36 -05:00
move code from parts to contrib (#8319)
This commit is contained in:
@@ -0,0 +1,302 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import * as commands from 'sql/workbench/contrib/scripting/browser/scriptingActions';
|
||||
import { MssqlNodeContext } from 'sql/workbench/contrib/dataExplorer/browser/mssqlNodeContext';
|
||||
import { localize } from 'vs/nls';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { TreeNodeContextKey } from 'sql/workbench/contrib/objectExplorer/common/treeNodeContextKey';
|
||||
import { ConnectionContextKey } from 'sql/workbench/contrib/connection/common/connectionContextKey';
|
||||
import { NodeType } from 'sql/workbench/contrib/objectExplorer/common/nodeType';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ItemContextKey } from 'sql/workbench/contrib/dashboard/browser/widgets/explorer/explorerTreeContext';
|
||||
import { EditDataAction } from 'sql/workbench/browser/scriptingActions';
|
||||
import { DatabaseEngineEdition } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
|
||||
//#region -- Data Explorer
|
||||
// Script as Create
|
||||
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
|
||||
group: 'connection',
|
||||
order: 3,
|
||||
command: {
|
||||
id: commands.SCRIPT_AS_CREATE_COMMAND_ID,
|
||||
title: localize('scriptAsCreate', "Script as Create")
|
||||
},
|
||||
when: ContextKeyExpr.and(MssqlNodeContext.CanScriptAsCreateOrDelete, MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString()))
|
||||
});
|
||||
|
||||
// Script as Delete
|
||||
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
|
||||
group: 'connection',
|
||||
order: 4,
|
||||
command: {
|
||||
id: commands.SCRIPT_AS_DELETE_COMMAND_ID,
|
||||
title: localize('scriptAsDelete', "Script as Drop")
|
||||
},
|
||||
when: MssqlNodeContext.CanScriptAsCreateOrDelete
|
||||
});
|
||||
|
||||
// Script as Select
|
||||
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
|
||||
group: 'connection',
|
||||
order: 1,
|
||||
command: {
|
||||
id: commands.SCRIPT_AS_SELECT_COMMAND_ID,
|
||||
title: localize('scriptAsSelect', "Select Top 1000")
|
||||
},
|
||||
when: MssqlNodeContext.CanScriptAsSelect
|
||||
});
|
||||
|
||||
// Script as Execute
|
||||
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
|
||||
group: 'connection',
|
||||
order: 5,
|
||||
command: {
|
||||
id: commands.SCRIPT_AS_EXECUTE_COMMAND_ID,
|
||||
title: localize('scriptAsExecute', "Script as Execute")
|
||||
},
|
||||
when: MssqlNodeContext.CanScriptAsExecute
|
||||
});
|
||||
|
||||
// Script as Alter
|
||||
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
|
||||
group: 'connection',
|
||||
order: 5,
|
||||
command: {
|
||||
id: commands.SCRIPT_AS_ALTER_COMMAND_ID,
|
||||
title: localize('scriptAsAlter', "Script as Alter")
|
||||
},
|
||||
when: MssqlNodeContext.CanScriptAsAlter
|
||||
});
|
||||
|
||||
// Edit Data
|
||||
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
|
||||
group: 'connection',
|
||||
order: 2,
|
||||
command: {
|
||||
id: commands.EDIT_DATA_COMMAND_ID,
|
||||
title: localize('editData', "Edit Data")
|
||||
},
|
||||
when: ContextKeyExpr.and(MssqlNodeContext.CanEditData, MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString()))
|
||||
});
|
||||
//#endregion
|
||||
|
||||
//#region -- Object Explorer
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: '0_query',
|
||||
order: 1,
|
||||
command: {
|
||||
id: commands.OE_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: '0_query',
|
||||
order: 2,
|
||||
command: {
|
||||
id: commands.OE_EDIT_DATA_COMMAND_ID,
|
||||
title: localize('editData', "Edit Data")
|
||||
},
|
||||
when: ContextKeyExpr.and(TreeNodeContextKey.NodeType.isEqualTo('Table'), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString()))
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
|
||||
group: '0_query',
|
||||
order: 3,
|
||||
command: {
|
||||
id: commands.OE_SCRIPT_AS_CREATE_COMMAND_ID,
|
||||
title: localize('scriptCreate', "Script as Create")
|
||||
},
|
||||
when: ContextKeyExpr.or(
|
||||
ContextKeyExpr.and(TreeNodeContextKey.NodeType.isEqualTo('Table'), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString())),
|
||||
ContextKeyExpr.and(TreeNodeContextKey.NodeType.isEqualTo('View'), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString())),
|
||||
ContextKeyExpr.and(TreeNodeContextKey.NodeType.isEqualTo('Schema'), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString())),
|
||||
ContextKeyExpr.and(TreeNodeContextKey.NodeType.isEqualTo('User'), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString())),
|
||||
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: '0_query',
|
||||
order: 6,
|
||||
command: {
|
||||
id: commands.OE_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: '0_query',
|
||||
order: 5,
|
||||
command: {
|
||||
id: commands.OE_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: '0_query',
|
||||
order: 4,
|
||||
command: {
|
||||
id: commands.OE_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: '0_query',
|
||||
order: 7,
|
||||
command: {
|
||||
id: commands.OE_REFRESH_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))
|
||||
});
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region -- explorer widget
|
||||
|
||||
CommandsRegistry.registerCommand(commands.ExplorerScriptSelectAction.ID, (accessor, context) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
instantiationService.createInstance(commands.ExplorerScriptSelectAction, commands.ExplorerScriptSelectAction.ID, commands.ExplorerScriptSelectAction.LABEL).run(context);
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, {
|
||||
command: {
|
||||
id: commands.ExplorerScriptSelectAction.ID,
|
||||
title: commands.ExplorerScriptSelectAction.LABEL
|
||||
},
|
||||
when: ContextKeyExpr.or(ItemContextKey.ItemType.isEqualTo('view'), ItemContextKey.ItemType.isEqualTo('table')),
|
||||
order: 2
|
||||
});
|
||||
|
||||
const ExplorerEditDataActionID = 'explorer.editData';
|
||||
CommandsRegistry.registerCommand(ExplorerEditDataActionID, (accessor, context) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
instantiationService.createInstance(EditDataAction, EditDataAction.ID, EditDataAction.LABEL).run(context);
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, {
|
||||
command: {
|
||||
id: ExplorerEditDataActionID,
|
||||
title: EditDataAction.LABEL
|
||||
},
|
||||
when: ContextKeyExpr.and(ItemContextKey.ItemType.isEqualTo('table'), MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString())),
|
||||
order: 2
|
||||
});
|
||||
|
||||
CommandsRegistry.registerCommand(commands.ExplorerScriptExecuteAction.ID, (accessor, context) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
instantiationService.createInstance(commands.ExplorerScriptExecuteAction, commands.ExplorerScriptExecuteAction.ID, commands.ExplorerScriptExecuteAction.LABEL).run(context);
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, {
|
||||
command: {
|
||||
id: commands.ExplorerScriptExecuteAction.ID,
|
||||
title: commands.ExplorerScriptExecuteAction.LABEL
|
||||
},
|
||||
when: ItemContextKey.ItemType.isEqualTo('sproc'),
|
||||
order: 2
|
||||
});
|
||||
|
||||
CommandsRegistry.registerCommand(commands.ExplorerScriptAlterAction.ID, (accessor, context) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
instantiationService.createInstance(commands.ExplorerScriptAlterAction, commands.ExplorerScriptAlterAction.ID, commands.ExplorerScriptAlterAction.LABEL).run(context);
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, {
|
||||
command: {
|
||||
id: commands.ExplorerScriptAlterAction.ID,
|
||||
title: commands.ExplorerScriptAlterAction.LABEL
|
||||
},
|
||||
when: ContextKeyExpr.and(ItemContextKey.ItemType.isEqualTo('sproc'), ItemContextKey.ConnectionProvider.isEqualTo('mssql')),
|
||||
order: 2
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, {
|
||||
command: {
|
||||
id: commands.ExplorerScriptAlterAction.ID,
|
||||
title: commands.ExplorerScriptAlterAction.LABEL
|
||||
},
|
||||
when: ContextKeyExpr.and(ItemContextKey.ItemType.isEqualTo('function'), ItemContextKey.ConnectionProvider.isEqualTo('mssql')),
|
||||
order: 2
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, {
|
||||
command: {
|
||||
id: commands.ExplorerScriptAlterAction.ID,
|
||||
title: commands.ExplorerScriptAlterAction.LABEL
|
||||
},
|
||||
when: ContextKeyExpr.and(ItemContextKey.ItemType.isEqualTo('view'), ItemContextKey.ConnectionProvider.isEqualTo('mssql')),
|
||||
order: 2
|
||||
});
|
||||
|
||||
CommandsRegistry.registerCommand(commands.ExplorerScriptCreateAction.ID, (accessor, context) => {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
instantiationService.createInstance(commands.ExplorerScriptCreateAction, commands.ExplorerScriptCreateAction.ID, commands.ExplorerScriptCreateAction.LABEL).run(context);
|
||||
});
|
||||
|
||||
MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, {
|
||||
command: {
|
||||
id: commands.ExplorerScriptCreateAction.ID,
|
||||
title: commands.ExplorerScriptCreateAction.LABEL
|
||||
},
|
||||
when: MssqlNodeContext.EngineEdition.notEqualsTo(DatabaseEngineEdition.SqlOnDemand.toString()),
|
||||
order: 2
|
||||
});
|
||||
//#endregion
|
||||
415
src/sql/workbench/contrib/scripting/browser/scriptingActions.ts
Normal file
415
src/sql/workbench/contrib/scripting/browser/scriptingActions.ts
Normal file
@@ -0,0 +1,415 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IScriptingService } from 'sql/platform/scripting/common/scriptingService';
|
||||
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { TreeViewItemHandleArg } from 'sql/workbench/common/views';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { IOEShimService } from 'sql/workbench/contrib/objectExplorer/browser/objectExplorerViewTreeShim';
|
||||
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
|
||||
import { BaseActionContext } from 'sql/workbench/browser/actions';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ScriptCreateAction, ScriptDeleteAction, ScriptSelectAction, ScriptExecuteAction, ScriptAlterAction, EditDataAction } from 'sql/workbench/browser/scriptingActions';
|
||||
import { ObjectExplorerActionsContext, getTreeNode } from 'sql/workbench/contrib/objectExplorer/browser/objectExplorerActions';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
|
||||
import { TreeSelectionHandler } from 'sql/workbench/contrib/objectExplorer/browser/treeSelectionHandler';
|
||||
import { TreeUpdateUtils } from 'sql/workbench/contrib/objectExplorer/browser/treeUpdateUtils';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { TreeNode } from 'sql/workbench/contrib/objectExplorer/common/treeNode';
|
||||
import { VIEWLET_ID } from 'sql/workbench/contrib/dataExplorer/browser/dataExplorerViewlet';
|
||||
|
||||
//#region -- Data Explorer
|
||||
export const SCRIPT_AS_CREATE_COMMAND_ID = 'dataExplorer.scriptAsCreate';
|
||||
export const SCRIPT_AS_DELETE_COMMAND_ID = 'dataExplorer.scriptAsDelete';
|
||||
export const SCRIPT_AS_SELECT_COMMAND_ID = 'dataExplorer.scriptAsSelect';
|
||||
export const SCRIPT_AS_EXECUTE_COMMAND_ID = 'dataExplorer.scriptAsExecute';
|
||||
export const SCRIPT_AS_ALTER_COMMAND_ID = 'dataExplorer.scriptAsAlter';
|
||||
export const EDIT_DATA_COMMAND_ID = 'dataExplorer.scriptAsEdit';
|
||||
|
||||
// Script as Create
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_CREATE_COMMAND_ID,
|
||||
handler: async (accessor, args: TreeViewItemHandleArg) => {
|
||||
const capabilitiesService = accessor.get(ICapabilitiesService);
|
||||
const oeShimService = accessor.get(IOEShimService);
|
||||
const queryEditorService = accessor.get(IQueryEditorService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const scriptingService = accessor.get(IScriptingService);
|
||||
const errorMessageService = accessor.get(IErrorMessageService);
|
||||
const progressService = accessor.get(IProgressService);
|
||||
const profile = new ConnectionProfile(capabilitiesService, args.$treeItem.payload);
|
||||
const baseContext: BaseActionContext = {
|
||||
profile: profile,
|
||||
object: oeShimService.getNodeInfoForTreeItem(args.$treeItem).metadata
|
||||
};
|
||||
const scriptCreateAction = new ScriptCreateAction(ScriptCreateAction.ID, ScriptCreateAction.LABEL,
|
||||
queryEditorService, connectionManagementService, scriptingService, errorMessageService);
|
||||
return progressService.withProgress({ location: VIEWLET_ID }, () => scriptCreateAction.run(baseContext));
|
||||
}
|
||||
});
|
||||
|
||||
// Script as Delete
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_DELETE_COMMAND_ID,
|
||||
handler: async (accessor, args: TreeViewItemHandleArg) => {
|
||||
const capabilitiesService = accessor.get(ICapabilitiesService);
|
||||
const oeShimService = accessor.get(IOEShimService);
|
||||
const queryEditorService = accessor.get(IQueryEditorService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const scriptingService = accessor.get(IScriptingService);
|
||||
const errorMessageService = accessor.get(IErrorMessageService);
|
||||
const progressService = accessor.get(IProgressService);
|
||||
const profile = new ConnectionProfile(capabilitiesService, args.$treeItem.payload);
|
||||
const baseContext: BaseActionContext = {
|
||||
profile: profile,
|
||||
object: oeShimService.getNodeInfoForTreeItem(args.$treeItem).metadata
|
||||
};
|
||||
const scriptDeleteAction = new ScriptDeleteAction(ScriptDeleteAction.ID, ScriptDeleteAction.LABEL,
|
||||
queryEditorService, connectionManagementService, scriptingService, errorMessageService);
|
||||
return progressService.withProgress({ location: VIEWLET_ID }, () => scriptDeleteAction.run(baseContext));
|
||||
}
|
||||
});
|
||||
|
||||
// Script as Select
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_SELECT_COMMAND_ID,
|
||||
handler: async (accessor, args: TreeViewItemHandleArg) => {
|
||||
const capabilitiesService = accessor.get(ICapabilitiesService);
|
||||
const oeShimService = accessor.get(IOEShimService);
|
||||
const queryEditorService = accessor.get(IQueryEditorService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const scriptingService = accessor.get(IScriptingService);
|
||||
const progressService = accessor.get(IProgressService);
|
||||
const profile = new ConnectionProfile(capabilitiesService, args.$treeItem.payload);
|
||||
const baseContext: BaseActionContext = {
|
||||
profile: profile,
|
||||
object: oeShimService.getNodeInfoForTreeItem(args.$treeItem).metadata
|
||||
};
|
||||
const scriptSelectAction = new ScriptSelectAction(ScriptSelectAction.ID, ScriptSelectAction.LABEL,
|
||||
queryEditorService, connectionManagementService, scriptingService);
|
||||
return progressService.withProgress({ location: VIEWLET_ID }, () => scriptSelectAction.run(baseContext));
|
||||
}
|
||||
});
|
||||
|
||||
// Script as Execute
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_EXECUTE_COMMAND_ID,
|
||||
handler: async (accessor, args: TreeViewItemHandleArg) => {
|
||||
const capabilitiesService = accessor.get(ICapabilitiesService);
|
||||
const oeShimService = accessor.get(IOEShimService);
|
||||
const queryEditorService = accessor.get(IQueryEditorService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const scriptingService = accessor.get(IScriptingService);
|
||||
const progressService = accessor.get(IProgressService);
|
||||
const errorMessageService = accessor.get(IErrorMessageService);
|
||||
const profile = new ConnectionProfile(capabilitiesService, args.$treeItem.payload);
|
||||
const baseContext: BaseActionContext = {
|
||||
profile: profile,
|
||||
object: oeShimService.getNodeInfoForTreeItem(args.$treeItem).metadata
|
||||
};
|
||||
const scriptExecuteAction = new ScriptExecuteAction(ScriptExecuteAction.ID, ScriptExecuteAction.LABEL,
|
||||
queryEditorService, connectionManagementService, scriptingService, errorMessageService);
|
||||
return progressService.withProgress({ location: VIEWLET_ID }, () => scriptExecuteAction.run(baseContext));
|
||||
}
|
||||
});
|
||||
|
||||
// Script as Alter
|
||||
CommandsRegistry.registerCommand({
|
||||
id: SCRIPT_AS_ALTER_COMMAND_ID,
|
||||
handler: async (accessor, args: TreeViewItemHandleArg) => {
|
||||
const capabilitiesService = accessor.get(ICapabilitiesService);
|
||||
const oeShimService = accessor.get(IOEShimService);
|
||||
const queryEditorService = accessor.get(IQueryEditorService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const scriptingService = accessor.get(IScriptingService);
|
||||
const progressService = accessor.get(IProgressService);
|
||||
const errorMessageService = accessor.get(IErrorMessageService);
|
||||
const profile = new ConnectionProfile(capabilitiesService, args.$treeItem.payload);
|
||||
const baseContext: BaseActionContext = {
|
||||
profile: profile,
|
||||
object: oeShimService.getNodeInfoForTreeItem(args.$treeItem).metadata
|
||||
};
|
||||
const scriptAlterAction = new ScriptAlterAction(ScriptAlterAction.ID, ScriptAlterAction.LABEL,
|
||||
queryEditorService, connectionManagementService, scriptingService, errorMessageService);
|
||||
return progressService.withProgress({ location: VIEWLET_ID }, () => scriptAlterAction.run(baseContext));
|
||||
}
|
||||
});
|
||||
|
||||
// Edit Data
|
||||
CommandsRegistry.registerCommand({
|
||||
id: EDIT_DATA_COMMAND_ID,
|
||||
handler: async (accessor, args: TreeViewItemHandleArg) => {
|
||||
const capabilitiesService = accessor.get(ICapabilitiesService);
|
||||
const oeShimService = accessor.get(IOEShimService);
|
||||
const queryEditorService = accessor.get(IQueryEditorService);
|
||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
||||
const scriptingService = accessor.get(IScriptingService);
|
||||
const progressService = accessor.get(IProgressService);
|
||||
const profile = new ConnectionProfile(capabilitiesService, args.$treeItem.payload);
|
||||
const baseContext: BaseActionContext = {
|
||||
profile: profile,
|
||||
object: oeShimService.getNodeInfoForTreeItem(args.$treeItem).metadata
|
||||
};
|
||||
const editDataAction = new EditDataAction(EditDataAction.ID, EditDataAction.LABEL,
|
||||
queryEditorService, connectionManagementService, scriptingService);
|
||||
return progressService.withProgress({ location: VIEWLET_ID }, () => editDataAction.run(baseContext));
|
||||
}
|
||||
});
|
||||
//#endregion
|
||||
|
||||
//#region -- Object Explorer
|
||||
|
||||
export const OE_SCRIPT_AS_CREATE_COMMAND_ID = 'objectExplorer.scriptAsCreate';
|
||||
export const OE_SCRIPT_AS_DELETE_COMMAND_ID = 'objectExplorer.scriptAsDelete';
|
||||
export const OE_SCRIPT_AS_SELECT_COMMAND_ID = 'objectExplorer.scriptAsSelect';
|
||||
export const OE_SCRIPT_AS_EXECUTE_COMMAND_ID = 'objectExplorer.scriptAsExecute';
|
||||
export const OE_SCRIPT_AS_ALTER_COMMAND_ID = 'objectExplorer.scriptAsAlter';
|
||||
export const OE_EDIT_DATA_COMMAND_ID = 'objectExplorer.scriptAsEdit';
|
||||
export const OE_REFRESH_COMMAND_ID = 'objectExplorer.refreshNode';
|
||||
|
||||
// Script as Select
|
||||
CommandsRegistry.registerCommand({
|
||||
id: OE_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: OE_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: OE_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: OE_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: OE_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: OE_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: OE_REFRESH_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);
|
||||
}
|
||||
});
|
||||
//#endregion
|
||||
|
||||
//#region -- explorer widget
|
||||
|
||||
export class ExplorerScriptSelectAction extends ScriptSelectAction {
|
||||
constructor(
|
||||
id: string, label: string,
|
||||
@IQueryEditorService queryEditorService: IQueryEditorService,
|
||||
@IConnectionManagementService connectionManagementService: IConnectionManagementService,
|
||||
@IScriptingService scriptingService: IScriptingService,
|
||||
@IProgressService private readonly progressService: IProgressService
|
||||
) {
|
||||
super(id, label, queryEditorService, connectionManagementService, scriptingService);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return this.progressService.withProgress({ location: ProgressLocation.Window }, () => super.run(actionContext));
|
||||
}
|
||||
}
|
||||
|
||||
export class ExplorerScriptCreateAction extends ScriptCreateAction {
|
||||
constructor(
|
||||
id: string, label: string,
|
||||
@IQueryEditorService queryEditorService: IQueryEditorService,
|
||||
@IConnectionManagementService connectionManagementService: IConnectionManagementService,
|
||||
@IScriptingService scriptingService: IScriptingService,
|
||||
@IErrorMessageService errorMessageService: IErrorMessageService,
|
||||
@IProgressService private readonly progressService: IProgressService
|
||||
) {
|
||||
super(id, label, queryEditorService, connectionManagementService, scriptingService, errorMessageService);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return this.progressService.withProgress({ location: ProgressLocation.Window }, () => super.run(actionContext));
|
||||
}
|
||||
}
|
||||
|
||||
export class ExplorerScriptAlterAction extends ScriptAlterAction {
|
||||
constructor(
|
||||
id: string, label: string,
|
||||
@IQueryEditorService queryEditorService: IQueryEditorService,
|
||||
@IConnectionManagementService connectionManagementService: IConnectionManagementService,
|
||||
@IScriptingService scriptingService: IScriptingService,
|
||||
@IErrorMessageService errorMessageService: IErrorMessageService,
|
||||
@IProgressService private readonly progressService: IProgressService
|
||||
) {
|
||||
super(id, label, queryEditorService, connectionManagementService, scriptingService, errorMessageService);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return this.progressService.withProgress({ location: ProgressLocation.Window }, () => super.run(actionContext));
|
||||
}
|
||||
}
|
||||
|
||||
export class ExplorerScriptExecuteAction extends ScriptExecuteAction {
|
||||
constructor(
|
||||
id: string, label: string,
|
||||
@IQueryEditorService queryEditorService: IQueryEditorService,
|
||||
@IConnectionManagementService connectionManagementService: IConnectionManagementService,
|
||||
@IScriptingService scriptingService: IScriptingService,
|
||||
@IErrorMessageService errorMessageService: IErrorMessageService,
|
||||
@IProgressService private readonly progressService: IProgressService
|
||||
) {
|
||||
super(id, label, queryEditorService, connectionManagementService, scriptingService, errorMessageService);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return this.progressService.withProgress({ location: ProgressLocation.Window }, () => super.run(actionContext));
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
Reference in New Issue
Block a user