mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 09:35:39 -05:00
support default action for OE node (#22455)
* support default action for OE node * fix floating promise
This commit is contained in:
@@ -18,7 +18,7 @@ import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectio
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/treeUpdateUtils';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { MenuId, IMenuService } from 'vs/platform/actions/common/actions';
|
||||
import { MenuId, IMenuService, MenuItemAction } from 'vs/platform/actions/common/actions';
|
||||
import { ConnectionContextKey } from 'sql/workbench/services/connection/common/connectionContextKey';
|
||||
import { TreeNodeContextKey } from 'sql/workbench/services/objectExplorer/common/treeNodeContextKey';
|
||||
import { IQueryManagementService } from 'sql/workbench/services/query/common/queryManagement';
|
||||
@@ -26,6 +26,7 @@ import { ServerInfoContextKey } from 'sql/workbench/services/connection/common/s
|
||||
import { fillInActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
|
||||
import { AsyncServerTree, ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
/**
|
||||
* Provides actions for the server tree elements
|
||||
@@ -38,7 +39,8 @@ export class ServerTreeActionProvider {
|
||||
@IQueryManagementService private _queryManagementService: IQueryManagementService,
|
||||
@IMenuService private menuService: IMenuService,
|
||||
@IContextKeyService private _contextKeyService: IContextKeyService,
|
||||
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService
|
||||
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
|
||||
@ILogService private _logService: ILogService
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -65,6 +67,29 @@ export class ServerTreeActionProvider {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default action for the given element.
|
||||
*/
|
||||
public getDefaultAction(tree: AsyncServerTree | ITree, element: ServerTreeElement): IAction | undefined {
|
||||
const actions = this.getActions(tree, element).filter(a => {
|
||||
return a instanceof MenuItemAction && a.isDefault;
|
||||
});
|
||||
if (actions.length === 1) {
|
||||
return actions[0];
|
||||
} else if (actions.length > 1) {
|
||||
let nodeName: string;
|
||||
if (element instanceof ConnectionProfile) {
|
||||
nodeName = element.serverName;
|
||||
} else if (element instanceof ConnectionProfileGroup) {
|
||||
nodeName = element.name;
|
||||
} else {
|
||||
nodeName = element.label;
|
||||
}
|
||||
this._logService.error(`Multiple default actions defined for node: ${nodeName}, actions: ${actions.map(a => a.id).join(', ')}`);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return actions for connection elements
|
||||
*/
|
||||
|
||||
@@ -11,9 +11,10 @@ import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/br
|
||||
// import { IProgressRunner, IProgressService } from 'vs/platform/progress/common/progress';
|
||||
import { TreeNode } from 'sql/workbench/services/objectExplorer/common/treeNode';
|
||||
import { TreeUpdateUtils } from 'sql/workbench/services/objectExplorer/browser/treeUpdateUtils';
|
||||
import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
|
||||
import { AsyncServerTree, ServerTreeElement } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
|
||||
export interface ObjectExplorerRequestStatus {
|
||||
inProgress: boolean;
|
||||
@@ -54,14 +55,14 @@ export class TreeSelectionHandler {
|
||||
/**
|
||||
* Handle selection of tree element
|
||||
*/
|
||||
public onTreeSelect(event: any, tree: AsyncServerTree | ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, capabilitiesService: ICapabilitiesService, connectionCompleteCallback: () => void) {
|
||||
public onTreeSelect(event: any, tree: AsyncServerTree | ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, capabilitiesService: ICapabilitiesService, connectionCompleteCallback: () => void, doubleClickHandler: (node: ServerTreeElement) => void) {
|
||||
let sendSelectionEvent = ((event: any, selection: any, isDoubleClick: boolean, userInteraction: boolean, requestStatus: ObjectExplorerRequestStatus | undefined = undefined) => {
|
||||
// userInteraction: defensive - don't touch this something else is handling it.
|
||||
if (userInteraction === true && this._lastClicked && this._lastClicked[0] === selection[0]) {
|
||||
this._lastClicked = undefined;
|
||||
}
|
||||
if (!TreeUpdateUtils.isInDragAndDrop) {
|
||||
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, capabilitiesService, isDoubleClick, this.isKeyboardEvent(event), selection, tree, connectionCompleteCallback, requestStatus);
|
||||
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, capabilitiesService, isDoubleClick, this.isKeyboardEvent(event), selection, tree, connectionCompleteCallback, requestStatus, doubleClickHandler).catch(onUnexpectedError);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -110,63 +111,65 @@ export class TreeSelectionHandler {
|
||||
* @param tree
|
||||
* @param connectionCompleteCallback A function that gets called after a connection is established due to the selection, if needed
|
||||
* @param requestStatus Used to identify if a new session should be created or not to avoid creating back to back sessions
|
||||
* @param doubleClickHandler
|
||||
*/
|
||||
private handleTreeItemSelected(connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, capabilitiesService: ICapabilitiesService, isDoubleClick: boolean, isKeyboard: boolean, selection: any[], tree: AsyncServerTree | ITree, connectionCompleteCallback: () => void, requestStatus: ObjectExplorerRequestStatus | undefined): void {
|
||||
private async handleTreeItemSelected(connectionManagementService: IConnectionManagementService,
|
||||
objectExplorerService: IObjectExplorerService,
|
||||
capabilitiesService: ICapabilitiesService,
|
||||
isDoubleClick: boolean,
|
||||
isKeyboard: boolean,
|
||||
selection: any[],
|
||||
tree: AsyncServerTree | ITree,
|
||||
connectionCompleteCallback: () => void,
|
||||
requestStatus: ObjectExplorerRequestStatus | undefined,
|
||||
doubleClickHandler: (node: ServerTreeElement) => void): Promise<void> {
|
||||
if (!selection || selection.length === 0) {
|
||||
return;
|
||||
}
|
||||
const selectedNode = selection[0];
|
||||
if (selectedNode instanceof ConnectionProfile && !capabilitiesService.getCapabilities(selectedNode.providerName)) {
|
||||
connectionManagementService.handleUnsupportedProvider(selectedNode.providerName).catch(onUnexpectedError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tree instanceof AsyncServerTree) {
|
||||
if (selection && selection.length > 0 && (selection[0] instanceof ConnectionProfile)) {
|
||||
if (!capabilitiesService.getCapabilities(selection[0].providerName)) {
|
||||
connectionManagementService.handleUnsupportedProvider(selection[0].providerName).catch(onUnexpectedError);
|
||||
return;
|
||||
}
|
||||
if (selectedNode instanceof ConnectionProfile) {
|
||||
this.onTreeActionStateChange(true);
|
||||
}
|
||||
} else {
|
||||
let connectionProfile: ConnectionProfile | undefined = undefined;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: true,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true,
|
||||
showDashboard: isDoubleClick // only show the dashboard if the action is double click
|
||||
};
|
||||
if (selection && selection.length > 0 && (selection[0] instanceof ConnectionProfile)) {
|
||||
connectionProfile = <ConnectionProfile>selection[0];
|
||||
if (!capabilitiesService.getCapabilities(connectionProfile.providerName)) {
|
||||
connectionManagementService.handleUnsupportedProvider(connectionProfile.providerName).catch(onUnexpectedError);
|
||||
return;
|
||||
}
|
||||
|
||||
if (connectionProfile) {
|
||||
if (selectedNode instanceof TreeNode || selectedNode instanceof ConnectionProfile || selectedNode instanceof ConnectionProfileGroup) {
|
||||
if (isDoubleClick) {
|
||||
doubleClickHandler(selectedNode);
|
||||
} else if (selectedNode instanceof ConnectionProfile) {
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: true,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true,
|
||||
showDashboard: false
|
||||
};
|
||||
this.onTreeActionStateChange(true);
|
||||
|
||||
TreeUpdateUtils.connectAndCreateOeSession(connectionProfile, options, connectionManagementService, objectExplorerService, tree, requestStatus).then(sessionCreated => {
|
||||
try {
|
||||
const sessionCreated = await TreeUpdateUtils.connectAndCreateOeSession(selectedNode, options, connectionManagementService, objectExplorerService, tree, requestStatus);
|
||||
// Clears request status object that was created when the first timeout callback is executed.
|
||||
if (this._requestStatus) {
|
||||
this._requestStatus = undefined;
|
||||
}
|
||||
|
||||
if (!sessionCreated) {
|
||||
this.onTreeActionStateChange(false);
|
||||
}
|
||||
if (connectionCompleteCallback) {
|
||||
connectionCompleteCallback();
|
||||
}
|
||||
}, error => {
|
||||
} catch (error) {
|
||||
this.onTreeActionStateChange(false);
|
||||
});
|
||||
}
|
||||
} else if (isDoubleClick && selection && selection.length > 0 && (selection[0] instanceof TreeNode)) {
|
||||
let treeNode = selection[0];
|
||||
if (TreeUpdateUtils.isAvailableDatabaseNode(treeNode)) {
|
||||
connectionProfile = TreeUpdateUtils.getConnectionProfile(treeNode);
|
||||
if (connectionProfile) {
|
||||
connectionManagementService.showDashboard(connectionProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isKeyboard) {
|
||||
tree.toggleExpansion(selection[0]);
|
||||
tree.toggleExpansion(selectedNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user