add contribution for refresh action on scriptable objects (#6645)

This commit is contained in:
Aditya Bist
2019-08-09 10:08:24 -07:00
committed by GitHub
parent 1ff9a2ec4c
commit 1dd3277985
4 changed files with 119 additions and 25 deletions

View File

@@ -118,8 +118,11 @@ export class ServerTreeActionProvider extends ContributableActionProvider {
actions.push(this._instantiationService.createInstance(DisconnectConnectionAction, DisconnectConnectionAction.ID, DisconnectConnectionAction.LABEL, context.profile)); actions.push(this._instantiationService.createInstance(DisconnectConnectionAction, DisconnectConnectionAction.ID, DisconnectConnectionAction.LABEL, context.profile));
} }
actions.push(this._instantiationService.createInstance(DeleteConnectionAction, DeleteConnectionAction.ID, DeleteConnectionAction.DELETE_CONNECTION_LABEL, context.profile)); actions.push(this._instantiationService.createInstance(DeleteConnectionAction, DeleteConnectionAction.ID, DeleteConnectionAction.DELETE_CONNECTION_LABEL, context.profile));
actions.push(this._instantiationService.createInstance(RefreshAction, RefreshAction.ID, RefreshAction.LABEL, context.tree, context.profile));
// Contribute refresh action for scriptable objects via contribution
if (!this.isScriptableObject(context)) {
actions.push(this._instantiationService.createInstance(RefreshAction, RefreshAction.ID, RefreshAction.LABEL, context.tree, context.profile));
}
return actions; return actions;
} }
@@ -180,7 +183,10 @@ export class ServerTreeActionProvider extends ContributableActionProvider {
this.addRestoreAction(context, actions); this.addRestoreAction(context, actions);
} }
actions.push(this._instantiationService.createInstance(RefreshAction, RefreshAction.ID, RefreshAction.LABEL, context.tree, treeNode)); // Contribute refresh action for scriptable objects via contribution
if (!this.isScriptableObject(context)) {
actions.push(this._instantiationService.createInstance(RefreshAction, RefreshAction.ID, RefreshAction.LABEL, context.tree, context.profile));
}
return actions; return actions;
} }
@@ -205,6 +211,15 @@ export class ServerTreeActionProvider extends ContributableActionProvider {
actions.push(this._instantiationService.createInstance(OEAction, RestoreAction.ID, RestoreAction.LABEL)); actions.push(this._instantiationService.createInstance(OEAction, RestoreAction.ID, RestoreAction.LABEL));
} }
} }
private isScriptableObject(context: ObjectExplorerContext): boolean {
if (context.treeNode) {
if (NodeType.SCRIPTABLE_OBJECTS.includes(context.treeNode.nodeTypeId)) {
return true;
}
}
return false;
}
} }
interface ObjectExplorerContext { interface ObjectExplorerContext {

View File

@@ -93,6 +93,10 @@ export class NodeType {
public static ExternalTable = 'ExternalTable'; public static ExternalTable = 'ExternalTable';
public static ColumnMasterKey = 'ColumnMasterKey'; public static ColumnMasterKey = 'ColumnMasterKey';
public static ColumnEncryptionKey = 'ColumnEncryptionKey'; public static ColumnEncryptionKey = 'ColumnEncryptionKey';
public static readonly SCRIPTABLE_OBJECTS = [NodeType.Table, NodeType.View, NodeType.Schema, NodeType.User, NodeType.UserDefinedTableType,
NodeType.StoredProcedure, NodeType.AggregateFunction, NodeType.PartitionFunction, NodeType.ScalarValuedFunction,
NodeType.TableValuedFunction];
} }
export interface SqlThemeIcon { export interface SqlThemeIcon {

View File

@@ -3,16 +3,21 @@
* Licensed under the Source EULA. See License.txt in the project root for license information. * 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 } from 'sql/workbench/parts/objectExplorer/electron-browser/objectExplorerScriptingActions'; 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 { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { localize } from 'vs/nls'; import { localize } from 'vs/nls';
import { ConnectionContextKey } from 'sql/workbench/parts/connection/common/connectionContextKey'; import { ConnectionContextKey } from 'sql/workbench/parts/connection/common/connectionContextKey';
import { TreeNodeContextKey } from 'sql/workbench/parts/objectExplorer/common/treeNodeContextKey'; import { TreeNodeContextKey } from 'sql/workbench/parts/objectExplorer/common/treeNodeContextKey';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { NodeType } from 'sql/workbench/parts/objectExplorer/common/nodeType';
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, { MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
group: 'scripting', group: 'scripting',
order: 3, order: 1,
command: { command: {
id: SCRIPT_AS_SELECT_COMMAND_ID, id: SCRIPT_AS_SELECT_COMMAND_ID,
title: localize('scriptSelect', "Select Top 1000") title: localize('scriptSelect', "Select Top 1000")
@@ -22,7 +27,7 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, { MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
group: 'scripting', group: 'scripting',
order: 3, order: 2,
command: { command: {
id: EDIT_DATA_COMMAND_ID, id: EDIT_DATA_COMMAND_ID,
title: localize('editData', "Edit Data") title: localize('editData', "Edit Data")
@@ -52,7 +57,7 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, { MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
group: 'scripting', group: 'scripting',
order: 3, order: 6,
command: { command: {
id: SCRIPT_AS_EXECUTE_COMMAND_ID, id: SCRIPT_AS_EXECUTE_COMMAND_ID,
title: localize('scriptExecute', "Script as Execute") title: localize('scriptExecute', "Script as Execute")
@@ -62,7 +67,7 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, { MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
group: 'scripting', group: 'scripting',
order: 3, order: 5,
command: { command: {
id: SCRIPT_AS_ALTER_COMMAND_ID, id: SCRIPT_AS_ALTER_COMMAND_ID,
title: localize('scriptAlter', "Script as Alter") title: localize('scriptAlter', "Script as Alter")
@@ -71,41 +76,61 @@ MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
ContextKeyExpr.or( ContextKeyExpr.or(
ContextKeyExpr.and( ContextKeyExpr.and(
ConnectionContextKey.Provider.isEqualTo('MSSQL'), ConnectionContextKey.Provider.isEqualTo('MSSQL'),
TreeNodeContextKey.NodeType.isEqualTo('StoredProcedure')), TreeNodeContextKey.NodeType.isEqualTo(NodeType.StoredProcedure)),
ContextKeyExpr.and( ContextKeyExpr.and(
ConnectionContextKey.Provider.isEqualTo('MSSQL'), ConnectionContextKey.Provider.isEqualTo('MSSQL'),
TreeNodeContextKey.NodeType.isEqualTo('View')), TreeNodeContextKey.NodeType.isEqualTo(NodeType.View)),
ContextKeyExpr.and( ContextKeyExpr.and(
ConnectionContextKey.Provider.isEqualTo('MSSQL'), ConnectionContextKey.Provider.isEqualTo('MSSQL'),
TreeNodeContextKey.NodeType.isEqualTo('AggregateFunction')), TreeNodeContextKey.NodeType.isEqualTo(NodeType.AggregateFunction)),
ContextKeyExpr.and( ContextKeyExpr.and(
ConnectionContextKey.Provider.isEqualTo('MSSQL'), ConnectionContextKey.Provider.isEqualTo('MSSQL'),
TreeNodeContextKey.NodeType.isEqualTo('PartitionFunction')), TreeNodeContextKey.NodeType.isEqualTo(NodeType.PartitionFunction)),
ContextKeyExpr.and( ContextKeyExpr.and(
ConnectionContextKey.Provider.isEqualTo('MSSQL'), ConnectionContextKey.Provider.isEqualTo('MSSQL'),
TreeNodeContextKey.NodeType.isEqualTo('ScalarValuedFunction')), TreeNodeContextKey.NodeType.isEqualTo(NodeType.ScalarValuedFunction)),
ContextKeyExpr.and( ContextKeyExpr.and(
ConnectionContextKey.Provider.isEqualTo('MSSQL'), ConnectionContextKey.Provider.isEqualTo('MSSQL'),
TreeNodeContextKey.NodeType.isEqualTo('TableValuedFunction')), TreeNodeContextKey.NodeType.isEqualTo(NodeType.TableValuedFunction)),
) )
}); });
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, { MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
group: 'scripting', group: 'scripting',
order: 3, order: 4,
command: { command: {
id: SCRIPT_AS_DELETE_COMMAND_ID, id: SCRIPT_AS_DELETE_COMMAND_ID,
title: localize('scriptDelete', "Script as Drop") title: localize('scriptDelete', "Script as Drop")
}, },
when: ContextKeyExpr.or( when: ContextKeyExpr.or(
TreeNodeContextKey.NodeType.isEqualTo('Table'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Table),
TreeNodeContextKey.NodeType.isEqualTo('View'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.View),
TreeNodeContextKey.NodeType.isEqualTo('Schema'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.Schema),
TreeNodeContextKey.NodeType.isEqualTo('User'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.User),
TreeNodeContextKey.NodeType.isEqualTo('UserDefinedTableType'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.UserDefinedTableType),
TreeNodeContextKey.NodeType.isEqualTo('StoredProcedure'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.StoredProcedure),
TreeNodeContextKey.NodeType.isEqualTo('AggregateFunction'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.AggregateFunction),
TreeNodeContextKey.NodeType.isEqualTo('PartitionFunction'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.PartitionFunction),
TreeNodeContextKey.NodeType.isEqualTo('ScalarValuedFunction'), TreeNodeContextKey.NodeType.isEqualTo(NodeType.ScalarValuedFunction),
TreeNodeContextKey.NodeType.isEqualTo('TableValuedFunction')) 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))
}); });

View File

@@ -12,6 +12,10 @@ import { ObjectExplorerActionsContext, getTreeNode } from 'sql/workbench/parts/o
import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/treeUpdateUtils'; import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/treeUpdateUtils';
import { TreeNode } from 'sql/workbench/parts/objectExplorer/common/treeNode'; import { TreeNode } from 'sql/workbench/parts/objectExplorer/common/treeNode';
import { CommandsRegistry } from 'vs/platform/commands/common/commands'; 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_CREATE_COMMAND_ID = 'objectExplorer.scriptAsCreate';
export const SCRIPT_AS_DELETE_COMMAND_ID = 'objectExplorer.scriptAsDelete'; export const SCRIPT_AS_DELETE_COMMAND_ID = 'objectExplorer.scriptAsDelete';
@@ -19,8 +23,9 @@ export const SCRIPT_AS_SELECT_COMMAND_ID = 'objectExplorer.scriptAsSelect';
export const SCRIPT_AS_EXECUTE_COMMAND_ID = 'objectExplorer.scriptAsExecute'; export const SCRIPT_AS_EXECUTE_COMMAND_ID = 'objectExplorer.scriptAsExecute';
export const SCRIPT_AS_ALTER_COMMAND_ID = 'objectExplorer.scriptAsAlter'; export const SCRIPT_AS_ALTER_COMMAND_ID = 'objectExplorer.scriptAsAlter';
export const EDIT_DATA_COMMAND_ID = 'objectExplorer.scriptAsEdit'; export const EDIT_DATA_COMMAND_ID = 'objectExplorer.scriptAsEdit';
export const REFRESH_OE_COMMAND_ID = 'objectExplorer.refreshNode';
// Script as Create // Script as Select
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: SCRIPT_AS_SELECT_COMMAND_ID, id: SCRIPT_AS_SELECT_COMMAND_ID,
handler: async (accessor, args: ObjectExplorerActionsContext) => { handler: async (accessor, args: ObjectExplorerActionsContext) => {
@@ -42,6 +47,7 @@ CommandsRegistry.registerCommand({
} }
}); });
// Edit Data
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: EDIT_DATA_COMMAND_ID, id: EDIT_DATA_COMMAND_ID,
handler: async (accessor, args: ObjectExplorerActionsContext) => { handler: async (accessor, args: ObjectExplorerActionsContext) => {
@@ -60,6 +66,7 @@ CommandsRegistry.registerCommand({
} }
}); });
// Script as Create
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: SCRIPT_AS_CREATE_COMMAND_ID, id: SCRIPT_AS_CREATE_COMMAND_ID,
handler: async (accessor, args: ObjectExplorerActionsContext) => { handler: async (accessor, args: ObjectExplorerActionsContext) => {
@@ -81,6 +88,7 @@ CommandsRegistry.registerCommand({
} }
}); });
// Script as Execute
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: SCRIPT_AS_EXECUTE_COMMAND_ID, id: SCRIPT_AS_EXECUTE_COMMAND_ID,
handler: async (accessor, args: ObjectExplorerActionsContext) => { handler: async (accessor, args: ObjectExplorerActionsContext) => {
@@ -102,6 +110,7 @@ CommandsRegistry.registerCommand({
} }
}); });
// Script as Alter
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: SCRIPT_AS_ALTER_COMMAND_ID, id: SCRIPT_AS_ALTER_COMMAND_ID,
handler: async (accessor, args: ObjectExplorerActionsContext) => { handler: async (accessor, args: ObjectExplorerActionsContext) => {
@@ -123,6 +132,8 @@ CommandsRegistry.registerCommand({
} }
}); });
// Script as Delete
CommandsRegistry.registerCommand({ CommandsRegistry.registerCommand({
id: SCRIPT_AS_DELETE_COMMAND_ID, id: SCRIPT_AS_DELETE_COMMAND_ID,
handler: async (accessor, args: ObjectExplorerActionsContext) => { handler: async (accessor, args: ObjectExplorerActionsContext) => {
@@ -144,3 +155,42 @@ CommandsRegistry.registerCommand({
}); });
} }
}); });
// 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);
}
});