mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
show progress for scripting actions (#23435)
This commit is contained in:
@@ -20,14 +20,14 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
|
|||||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
|
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
|
||||||
import { TreeSelectionHandler } from 'sql/workbench/services/objectExplorer/browser/treeSelectionHandler';
|
import { TreeSelectionHandler } from 'sql/workbench/services/objectExplorer/browser/treeSelectionHandler';
|
||||||
import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/treeUpdateUtils';
|
import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/treeUpdateUtils';
|
||||||
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
|
|
||||||
import { VIEWLET_ID } from 'sql/workbench/contrib/dataExplorer/browser/dataExplorerViewlet';
|
import { VIEWLET_ID } from 'sql/workbench/contrib/dataExplorer/browser/dataExplorerViewlet';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
import { getErrorMessage } from 'vs/base/common/errors';
|
import { getErrorMessage } from 'vs/base/common/errors';
|
||||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
|
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
|
||||||
import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
|
import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
|
||||||
|
import { Action } from 'vs/base/common/actions';
|
||||||
|
|
||||||
//#region -- Data Explorer
|
//#region -- Data Explorer
|
||||||
export const SCRIPT_AS_CREATE_COMMAND_ID = 'dataExplorer.scriptAsCreate';
|
export const SCRIPT_AS_CREATE_COMMAND_ID = 'dataExplorer.scriptAsCreate';
|
||||||
@@ -204,24 +204,42 @@ export const OE_SCRIPT_AS_ALTER_COMMAND_ID = 'objectExplorer.scriptAsAlter';
|
|||||||
export const OE_EDIT_DATA_COMMAND_ID = 'objectExplorer.scriptAsEdit';
|
export const OE_EDIT_DATA_COMMAND_ID = 'objectExplorer.scriptAsEdit';
|
||||||
export const OE_REFRESH_COMMAND_ID = 'objectExplorer.refreshNode';
|
export const OE_REFRESH_COMMAND_ID = 'objectExplorer.refreshNode';
|
||||||
|
|
||||||
|
async function runScriptingAction(accessor: ServicesAccessor, args: ObjectExplorerActionsContext, createAction: (instantiationService: IInstantiationService) => Action): Promise<void> {
|
||||||
|
const instantiationService = accessor.get(IInstantiationService);
|
||||||
|
const objectExplorerService = accessor.get(IObjectExplorerService);
|
||||||
|
const notificationService = accessor.get(INotificationService);
|
||||||
|
const logService = accessor.get(ILogService);
|
||||||
|
const selectionHandler = instantiationService.createInstance(TreeSelectionHandler);
|
||||||
|
const notificationHandle = notificationService.notify({
|
||||||
|
message: localize('scriptActionError.inProgress', "Generating script..."),
|
||||||
|
severity: Severity.Info,
|
||||||
|
progress: {
|
||||||
|
infinite: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const node = (await getTreeNode(args, objectExplorerService))!;
|
||||||
|
selectionHandler.onTreeActionStateChange(true);
|
||||||
|
let connectionProfile = TreeUpdateUtils.getConnectionProfile(node)!;
|
||||||
|
let metadata = node.metadata;
|
||||||
|
const action = createAction(instantiationService);
|
||||||
|
await action.run({ profile: connectionProfile, object: metadata })
|
||||||
|
selectionHandler.onTreeActionStateChange(false);
|
||||||
|
notificationHandle.close();
|
||||||
|
} catch (error) {
|
||||||
|
notificationHandle.updateSeverity(Severity.Error);
|
||||||
|
const msg = localize('scriptActionError', "An error occurred while executing the action: {0}.", getErrorMessage(error));
|
||||||
|
logService.error(msg);
|
||||||
|
notificationHandle.updateMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Script as Select
|
// Script as Select
|
||||||
CommandsRegistry.registerCommand({
|
CommandsRegistry.registerCommand({
|
||||||
id: OE_SCRIPT_AS_SELECT_COMMAND_ID,
|
id: OE_SCRIPT_AS_SELECT_COMMAND_ID,
|
||||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||||
const instantiationService = accessor.get(IInstantiationService);
|
return runScriptingAction(accessor, args, (instantiationService) => {
|
||||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
return instantiationService.createInstance(ScriptSelectAction, ScriptSelectAction.ID, ScriptSelectAction.LABEL);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -230,17 +248,8 @@ CommandsRegistry.registerCommand({
|
|||||||
CommandsRegistry.registerCommand({
|
CommandsRegistry.registerCommand({
|
||||||
id: OE_EDIT_DATA_COMMAND_ID,
|
id: OE_EDIT_DATA_COMMAND_ID,
|
||||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||||
const instantiationService = accessor.get(IInstantiationService);
|
return runScriptingAction(accessor, args, (instantiationService) => {
|
||||||
const objectExplorerService = accessor.get(IObjectExplorerService);
|
return instantiationService.createInstance(EditDataAction, EditDataAction.ID, EditDataAction.LABEL);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -249,20 +258,8 @@ CommandsRegistry.registerCommand({
|
|||||||
CommandsRegistry.registerCommand({
|
CommandsRegistry.registerCommand({
|
||||||
id: OE_SCRIPT_AS_CREATE_COMMAND_ID,
|
id: OE_SCRIPT_AS_CREATE_COMMAND_ID,
|
||||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||||
const instantiationService = accessor.get(IInstantiationService);
|
return runScriptingAction(accessor, args, (instantiationService) => {
|
||||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
return instantiationService.createInstance(ScriptCreateAction, ScriptCreateAction.ID, ScriptCreateAction.LABEL);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -271,20 +268,8 @@ CommandsRegistry.registerCommand({
|
|||||||
CommandsRegistry.registerCommand({
|
CommandsRegistry.registerCommand({
|
||||||
id: OE_SCRIPT_AS_EXECUTE_COMMAND_ID,
|
id: OE_SCRIPT_AS_EXECUTE_COMMAND_ID,
|
||||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||||
const instantiationService = accessor.get(IInstantiationService);
|
return runScriptingAction(accessor, args, (instantiationService) => {
|
||||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
return instantiationService.createInstance(ScriptExecuteAction, ScriptExecuteAction.ID, ScriptExecuteAction.LABEL);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -293,20 +278,8 @@ CommandsRegistry.registerCommand({
|
|||||||
CommandsRegistry.registerCommand({
|
CommandsRegistry.registerCommand({
|
||||||
id: OE_SCRIPT_AS_ALTER_COMMAND_ID,
|
id: OE_SCRIPT_AS_ALTER_COMMAND_ID,
|
||||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||||
const instantiationService = accessor.get(IInstantiationService);
|
return runScriptingAction(accessor, args, (instantiationService) => {
|
||||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
return instantiationService.createInstance(ScriptAlterAction, ScriptAlterAction.ID, ScriptAlterAction.LABEL);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -316,21 +289,8 @@ CommandsRegistry.registerCommand({
|
|||||||
CommandsRegistry.registerCommand({
|
CommandsRegistry.registerCommand({
|
||||||
id: OE_SCRIPT_AS_DELETE_COMMAND_ID,
|
id: OE_SCRIPT_AS_DELETE_COMMAND_ID,
|
||||||
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
handler: async (accessor, args: ObjectExplorerActionsContext) => {
|
||||||
const instantiationService = accessor.get(IInstantiationService);
|
return runScriptingAction(accessor, args, (instantiationService) => {
|
||||||
const connectionManagementService = accessor.get(IConnectionManagementService);
|
return instantiationService.createInstance(ScriptDeleteAction, ScriptDeleteAction.ID, ScriptDeleteAction.LABEL);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user