OE clicking and awaiting the expansion calls (#6761)

* Server selection with proper awaits

* Handle keyboard clicks immedietely.

* Clean up the event a little more

* Eat the event if its not mouse or keyboard
This commit is contained in:
Amir Omidi
2019-08-21 10:25:52 -07:00
committed by GitHub
parent baa482bd79
commit b731c56076
6 changed files with 48 additions and 34 deletions

View File

@@ -75,8 +75,8 @@ export class ServerTreeDataSource implements IDataSource {
// It has been tested for connecting to the server in profile itself and things work fine there. // It has been tested for connecting to the server in profile itself and things work fine there.
this._objectExplorerService.resolveTreeNodeChildren(node.getSession(), node).then(() => { this._objectExplorerService.resolveTreeNodeChildren(node.getSession(), node).then(() => {
resolve(node.children); resolve(node.children);
}, expandError => { }, async expandError => {
node.setExpandedState(TreeItemCollapsibleState.Collapsed); await node.setExpandedState(TreeItemCollapsibleState.Collapsed);
node.errorStateMessage = expandError; node.errorStateMessage = expandError;
this.showError(expandError); this.showError(expandError);
// collapse node and refresh in case of error so remove tree cache // collapse node and refresh in case of error so remove tree cache

View File

@@ -171,13 +171,13 @@ export class ServerTreeView extends Disposable {
})); }));
} }
return new Promise<void>((resolve, reject) => { return new Promise<void>(async (resolve, reject) => {
this.refreshTree(); this.refreshTree();
const root = <ConnectionProfileGroup>this._tree.getInput(); const root = <ConnectionProfileGroup>this._tree.getInput();
const expandGroups: boolean = this._configurationService.getValue(SERVER_GROUP_CONFIG)[SERVER_GROUP_AUTOEXPAND_CONFIG]; const expandGroups: boolean = this._configurationService.getValue(SERVER_GROUP_CONFIG)[SERVER_GROUP_AUTOEXPAND_CONFIG];
if (expandGroups) { if (expandGroups) {
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(root)); await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(root));
} }
if (root && !root.hasValidConnections) { if (root && !root.hasValidConnections) {
@@ -270,9 +270,9 @@ export class ServerTreeView extends Disposable {
if (connection) { if (connection) {
const conn = this.getConnectionInTreeInput(connection.id); const conn = this.getConnectionInTreeInput(connection.id);
if (conn) { if (conn) {
return this._objectExplorerService.deleteObjectExplorerNode(conn).then(() => { return this._objectExplorerService.deleteObjectExplorerNode(conn).then(async () => {
this._tree.collapse(conn); await this._tree.collapse(conn);
this._tree.refresh(conn); return this._tree.refresh(conn);
}); });
} }
} }
@@ -342,10 +342,10 @@ export class ServerTreeView extends Disposable {
} else { } else {
treeInput = filteredResults[0]; treeInput = filteredResults[0];
} }
this._tree.setInput(treeInput).then(() => { this._tree.setInput(treeInput).then(async () => {
if (isHidden(this.messages)) { if (isHidden(this.messages)) {
this._tree.getFocus(); this._tree.getFocus();
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput)); await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput));
} else { } else {
this._tree.clearFocus(); this._tree.clearFocus();
} }
@@ -374,10 +374,10 @@ export class ServerTreeView extends Disposable {
// Add all connections to tree root and set tree input // Add all connections to tree root and set tree input
const treeInput = new ConnectionProfileGroup('searchroot', undefined, 'searchroot', undefined, undefined); const treeInput = new ConnectionProfileGroup('searchroot', undefined, 'searchroot', undefined, undefined);
treeInput.addConnections(filteredResults); treeInput.addConnections(filteredResults);
this._tree.setInput(treeInput).then(() => { this._tree.setInput(treeInput).then(async () => {
if (isHidden(this.messages)) { if (isHidden(this.messages)) {
this._tree.getFocus(); this._tree.getFocus();
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput)); await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput));
} else { } else {
this._tree.clearFocus(); this._tree.clearFocus();
} }

View File

@@ -15,7 +15,7 @@ import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/tree
export class TreeSelectionHandler { export class TreeSelectionHandler {
// progressRunner: IProgressRunner; // progressRunner: IProgressRunner;
private _lastClicked: any; private _lastClicked: any[];
private _clickTimer: NodeJS.Timer = undefined; private _clickTimer: NodeJS.Timer = undefined;
// constructor(@IProgressService private _progressService: IProgressService) { // constructor(@IProgressService private _progressService: IProgressService) {
@@ -38,14 +38,20 @@ export class TreeSelectionHandler {
return event && event.payload && event.payload.origin === 'mouse'; return event && event.payload && event.payload.origin === 'mouse';
} }
private isKeyboardEvent(event: any): boolean {
return event && event.payload && event.payload.origin === 'keyboard';
}
/** /**
* Handle selection of tree element * Handle selection of tree element
*/ */
public onTreeSelect(event: any, tree: ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, connectionCompleteCallback: () => void) { public onTreeSelect(event: any, tree: ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, connectionCompleteCallback: () => void) {
let sendSelectionEvent = ((event: any, selection: any, isDoubleClick: boolean) => { let sendSelectionEvent = (async (event: any, selection: any, isDoubleClick: boolean) => {
let isKeyboard = event && event.payload && event.payload.origin === 'keyboard'; if (this._lastClicked === selection) {
this._lastClicked = undefined;
}
if (!TreeUpdateUtils.isInDragAndDrop) { if (!TreeUpdateUtils.isInDragAndDrop) {
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, isDoubleClick, isKeyboard, selection, tree, connectionCompleteCallback); await this.handleTreeItemSelected(connectionManagementService, objectExplorerService, isDoubleClick, this.isKeyboardEvent(event), selection, tree, connectionCompleteCallback);
} }
}); });
@@ -57,24 +63,32 @@ export class TreeSelectionHandler {
let specificSelection = selection[0]; let specificSelection = selection[0];
if (this.isMouseEvent(event)) { if (this.isMouseEvent(event)) {
if (this._lastClicked === specificSelection) { if (this._lastClicked !== undefined) {
clearTimeout(this._clickTimer); clearTimeout(this._clickTimer);
sendSelectionEvent(event, selection, true); let lastSpecificClick = this._lastClicked[0];
return;
}
this._lastClicked = specificSelection;
}
this._clickTimer = setTimeout(() => { if (lastSpecificClick === specificSelection) {
sendSelectionEvent(event, selection, false); sendSelectionEvent(event, selection, true);
}, 300); return;
} else {
sendSelectionEvent(event, this._lastClicked, false);
}
}
this._lastClicked = selection;
this._clickTimer = setTimeout(() => {
sendSelectionEvent(event, selection, false);
}, 300);
} else if (this.isKeyboardEvent(event)) {
sendSelectionEvent(event, selection, true);
}
} }
/** /**
* *
* @param connectionCompleteCallback A function that gets called after a connection is established due to the selection, if needed * @param connectionCompleteCallback A function that gets called after a connection is established due to the selection, if needed
*/ */
private handleTreeItemSelected(connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, isDoubleClick: boolean, isKeyboard: boolean, selection: any[], tree: ITree, connectionCompleteCallback: () => void): void { private async handleTreeItemSelected(connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, isDoubleClick: boolean, isKeyboard: boolean, selection: any[], tree: ITree, connectionCompleteCallback: () => void): Promise<void> {
let connectionProfile: ConnectionProfile = undefined; let connectionProfile: ConnectionProfile = undefined;
let options: IConnectionCompletionOptions = { let options: IConnectionCompletionOptions = {
params: undefined, params: undefined,
@@ -105,7 +119,7 @@ export class TreeSelectionHandler {
if (TreeUpdateUtils.isAvailableDatabaseNode(treeNode)) { if (TreeUpdateUtils.isAvailableDatabaseNode(treeNode)) {
connectionProfile = TreeUpdateUtils.getConnectionProfile(treeNode); connectionProfile = TreeUpdateUtils.getConnectionProfile(treeNode);
if (connectionProfile) { if (connectionProfile) {
connectionManagementService.showDashboard(connectionProfile); await connectionManagementService.showDashboard(connectionProfile);
} }
} }
} }

View File

@@ -74,13 +74,13 @@ export class TreeUpdateUtils {
treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService, providers); treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService, providers);
} }
const previousTreeInput: any = tree.getInput(); const previousTreeInput: any = tree.getInput();
return tree.setInput(treeInput).then(() => { return tree.setInput(treeInput).then(async () => {
if (previousTreeInput instanceof Disposable) { if (previousTreeInput instanceof Disposable) {
previousTreeInput.dispose(); previousTreeInput.dispose();
} }
// Make sure to expand all folders that where expanded in the previous session // Make sure to expand all folders that where expanded in the previous session
if (targetsToExpand) { if (targetsToExpand) {
tree.expandAll(targetsToExpand); await tree.expandAll(targetsToExpand);
} }
if (selectedElement) { if (selectedElement) {
tree.select(selectedElement); tree.select(selectedElement);
@@ -118,10 +118,10 @@ export class TreeUpdateUtils {
let treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService); let treeInput = TreeUpdateUtils.getTreeInput(connectionManagementService);
if (treeInput) { if (treeInput) {
if (treeInput !== tree.getInput()) { if (treeInput !== tree.getInput()) {
return tree.setInput(treeInput).then(() => { return tree.setInput(treeInput).then(async () => {
// Make sure to expand all folders that where expanded in the previous session // Make sure to expand all folders that where expanded in the previous session
if (targetsToExpand) { if (targetsToExpand) {
tree.expandAll(targetsToExpand); await tree.expandAll(targetsToExpand);
} }
if (selectedElement) { if (selectedElement) {
tree.select(selectedElement); tree.select(selectedElement);
@@ -316,4 +316,4 @@ export class TreeUpdateUtils {
} }
return connectionProfile; return connectionProfile;
} }
} }

View File

@@ -120,10 +120,10 @@ export class TaskHistoryView {
//Get the tree Input //Get the tree Input
let treeInput = this._taskService.getAllTasks(); let treeInput = this._taskService.getAllTasks();
if (treeInput) { if (treeInput) {
this._tree.setInput(treeInput).then(() => { this._tree.setInput(treeInput).then(async () => {
// Make sure to expand all folders that where expanded in the previous session // Make sure to expand all folders that where expanded in the previous session
if (targetsToExpand) { if (targetsToExpand) {
this._tree.expandAll(targetsToExpand); await this._tree.expandAll(targetsToExpand);
} }
if (selectedElement) { if (selectedElement) {
this._tree.select(selectedElement); this._tree.select(selectedElement);

View File

@@ -604,7 +604,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
nodeInfo.nodeSubType, nodeInfo.nodeStatus, parent, nodeInfo.metadata, nodeInfo.iconType, { nodeInfo.nodeSubType, nodeInfo.nodeStatus, parent, nodeInfo.metadata, nodeInfo.iconType, {
getChildren: treeNode => this.getChildren(treeNode), getChildren: treeNode => this.getChildren(treeNode),
isExpanded: treeNode => this.isExpanded(treeNode), isExpanded: treeNode => this.isExpanded(treeNode),
setNodeExpandedState: (treeNode, expandedState) => this.setNodeExpandedState(treeNode, expandedState), setNodeExpandedState: async (treeNode, expandedState) => await this.setNodeExpandedState(treeNode, expandedState),
setNodeSelected: (treeNode, selected, clearOtherSelections: boolean = undefined) => this.setNodeSelected(treeNode, selected, clearOtherSelections) setNodeSelected: (treeNode, selected, clearOtherSelections: boolean = undefined) => this.setNodeSelected(treeNode, selected, clearOtherSelections)
}); });
node.childProvider = nodeInfo.childProvider; node.childProvider = nodeInfo.childProvider;