mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Handle selection for multiple values in tree (#6569)
Handle OE clicking and double clicking with less logic and timeouts
This commit is contained in:
@@ -15,8 +15,8 @@ import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/tree
|
|||||||
export class TreeSelectionHandler {
|
export class TreeSelectionHandler {
|
||||||
// progressRunner: IProgressRunner;
|
// progressRunner: IProgressRunner;
|
||||||
|
|
||||||
private _clicks: number = 0;
|
private _lastClicked: any;
|
||||||
private _doubleClickTimeoutTimer: NodeJS.Timer = undefined;
|
private _clickTimer: NodeJS.Timer = undefined;
|
||||||
|
|
||||||
// constructor(@IProgressService private _progressService: IProgressService) {
|
// constructor(@IProgressService private _progressService: IProgressService) {
|
||||||
|
|
||||||
@@ -42,28 +42,31 @@ export class TreeSelectionHandler {
|
|||||||
* 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) {
|
||||||
if (this.isMouseEvent(event)) {
|
let sendSelectionEvent = ((event: any, selection: any, isDoubleClick: boolean) => {
|
||||||
this._clicks++;
|
let isKeyboard = event && event.payload && event.payload.origin === 'keyboard';
|
||||||
}
|
|
||||||
|
|
||||||
// clear pending click timeouts to avoid sending multiple events on double-click
|
|
||||||
if (this._doubleClickTimeoutTimer) {
|
|
||||||
clearTimeout(this._doubleClickTimeoutTimer);
|
|
||||||
}
|
|
||||||
|
|
||||||
let isKeyboard = event && event.payload && event.payload.origin === 'keyboard';
|
|
||||||
|
|
||||||
// grab the current selection for use later
|
|
||||||
let selection = tree.getSelection();
|
|
||||||
|
|
||||||
this._doubleClickTimeoutTimer = setTimeout(() => {
|
|
||||||
// don't send tree update events while dragging
|
|
||||||
if (!TreeUpdateUtils.isInDragAndDrop) {
|
if (!TreeUpdateUtils.isInDragAndDrop) {
|
||||||
let isDoubleClick = this._clicks > 1;
|
|
||||||
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, isDoubleClick, isKeyboard, selection, tree, connectionCompleteCallback);
|
this.handleTreeItemSelected(connectionManagementService, objectExplorerService, isDoubleClick, isKeyboard, selection, tree, connectionCompleteCallback);
|
||||||
}
|
}
|
||||||
this._clicks = 0;
|
});
|
||||||
this._doubleClickTimeoutTimer = undefined;
|
|
||||||
|
let selection = tree.getSelection();
|
||||||
|
|
||||||
|
if (!selection || selection.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let specificSelection = selection[0];
|
||||||
|
|
||||||
|
if (this.isMouseEvent(event)) {
|
||||||
|
if (this._lastClicked === specificSelection) {
|
||||||
|
clearTimeout(this._clickTimer);
|
||||||
|
sendSelectionEvent(event, selection, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._lastClicked = specificSelection;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._clickTimer = setTimeout(() => {
|
||||||
|
sendSelectionEvent(event, selection, false);
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user