Revert "Revert "OE clicking and awaiting the expansion calls"" (#6923)

* Revert "Revert "OE clicking and awaiting the expansion calls" (#6921)"

This reverts commit b9e3a468ae.

* Handle edge cases better

* Polling for OE load time
This commit is contained in:
Amir Omidi
2019-09-03 10:31:29 -07:00
committed by GitHub
parent a5c824a318
commit 33a7fe38e1
7 changed files with 82 additions and 36 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.
this._objectExplorerService.resolveTreeNodeChildren(node.getSession(), node).then(() => {
resolve(node.children);
}, expandError => {
node.setExpandedState(TreeItemCollapsibleState.Collapsed);
}, async expandError => {
await node.setExpandedState(TreeItemCollapsibleState.Collapsed);
node.errorStateMessage = expandError;
this.showError(expandError);
// 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();
const root = <ConnectionProfileGroup>this._tree.getInput();
const expandGroups: boolean = this._configurationService.getValue(SERVER_GROUP_CONFIG)[SERVER_GROUP_AUTOEXPAND_CONFIG];
if (expandGroups) {
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(root));
await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(root));
}
if (root && !root.hasValidConnections) {
@@ -270,9 +270,9 @@ export class ServerTreeView extends Disposable {
if (connection) {
const conn = this.getConnectionInTreeInput(connection.id);
if (conn) {
return this._objectExplorerService.deleteObjectExplorerNode(conn).then(() => {
this._tree.collapse(conn);
this._tree.refresh(conn);
return this._objectExplorerService.deleteObjectExplorerNode(conn).then(async () => {
await this._tree.collapse(conn);
return this._tree.refresh(conn);
});
}
}
@@ -342,10 +342,10 @@ export class ServerTreeView extends Disposable {
} else {
treeInput = filteredResults[0];
}
this._tree.setInput(treeInput).then(() => {
this._tree.setInput(treeInput).then(async () => {
if (isHidden(this.messages)) {
this._tree.getFocus();
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput));
await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput));
} else {
this._tree.clearFocus();
}
@@ -374,10 +374,10 @@ export class ServerTreeView extends Disposable {
// Add all connections to tree root and set tree input
const treeInput = new ConnectionProfileGroup('searchroot', undefined, 'searchroot', undefined, undefined);
treeInput.addConnections(filteredResults);
this._tree.setInput(treeInput).then(() => {
this._tree.setInput(treeInput).then(async () => {
if (isHidden(this.messages)) {
this._tree.getFocus();
this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput));
await this._tree.expandAll(ConnectionProfileGroup.getSubgroups(treeInput));
} else {
this._tree.clearFocus();
}

View File

@@ -15,8 +15,9 @@ import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/tree
export class TreeSelectionHandler {
// progressRunner: IProgressRunner;
private _lastClicked: any;
private _lastClicked: any[];
private _clickTimer: any = undefined;
private _otherTimer: any = undefined;
// constructor(@IProgressService private _progressService: IProgressService) {
@@ -38,14 +39,21 @@ export class TreeSelectionHandler {
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 select ion of tree element
*/
public onTreeSelect(event: any, tree: ITree, connectionManagementService: IConnectionManagementService, objectExplorerService: IObjectExplorerService, connectionCompleteCallback: () => void) {
let sendSelectionEvent = ((event: any, selection: any, isDoubleClick: boolean) => {
let isKeyboard = event && event.payload && event.payload.origin === 'keyboard';
let sendSelectionEvent = ((event: any, selection: any, isDoubleClick: boolean, userInteraction: boolean) => {
// 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, isDoubleClick, isKeyboard, selection, tree, connectionCompleteCallback);
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, isDoubleClick, this.isKeyboardEvent(event), selection, tree, connectionCompleteCallback);
}
});
@@ -56,18 +64,29 @@ export class TreeSelectionHandler {
}
let specificSelection = selection[0];
if (this.isMouseEvent(event)) {
if (this._lastClicked === specificSelection) {
if (this.isMouseEvent(event) || this.isKeyboardEvent(event)) {
if (this._lastClicked !== undefined) {
clearTimeout(this._clickTimer);
sendSelectionEvent(event, selection, true);
return;
}
this._lastClicked = specificSelection;
}
let lastSpecificClick = this._lastClicked[0];
this._clickTimer = setTimeout(() => {
sendSelectionEvent(event, selection, false);
}, 300);
if (lastSpecificClick === specificSelection) {
sendSelectionEvent(event, selection, true, true);
return;
} else {
sendSelectionEvent(event, this._lastClicked, false, true);
}
}
this._lastClicked = selection;
this._clickTimer = setTimeout(() => {
sendSelectionEvent(event, selection, false, true);
}, 400);
} else {
clearTimeout(this._otherTimer);
this._otherTimer = setTimeout(() => {
sendSelectionEvent(event, selection, false, false);
}, 400);
}
}
/**

View File

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

View File

@@ -120,10 +120,10 @@ export class TaskHistoryView {
//Get the tree Input
let treeInput = this._taskService.getAllTasks();
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
if (targetsToExpand) {
this._tree.expandAll(targetsToExpand);
await this._tree.expandAll(targetsToExpand);
}
if (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, {
getChildren: treeNode => this.getChildren(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)
});
node.childProvider = nodeInfo.childProvider;