mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
handle keyboard selection (#13175)
This commit is contained in:
@@ -10,7 +10,7 @@ import { IConnectionTreeDescriptor, IConnectionTreeService } from 'sql/workbench
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { IIdentityProvider, IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
|
||||
import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
|
||||
import { IAsyncDataSource, ITreeMouseEvent, ITreeNode, ITreeRenderer } from 'vs/base/browser/ui/tree/tree';
|
||||
import { IAsyncDataSource, ITreeNode, ITreeRenderer } from 'vs/base/browser/ui/tree/tree';
|
||||
import { Iterable } from 'vs/base/common/iterator';
|
||||
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { basename, dirname } from 'vs/base/common/resources';
|
||||
@@ -46,6 +46,7 @@ import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/cont
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { IConnectionProfile } from 'azdata';
|
||||
|
||||
export type TreeElement = ConnectionDialogTreeProviderElement | ITreeItemFromProvider | SavedConnectionNode | ServerTreeElement;
|
||||
|
||||
@@ -56,6 +57,11 @@ export class ConnectionBrowseTab implements IPanelTab {
|
||||
constructor(@IInstantiationService private readonly instantiationService: IInstantiationService) { }
|
||||
}
|
||||
|
||||
export interface SelectedConnectionChangedEventArgs {
|
||||
connectionProfile: IConnectionProfile,
|
||||
connect: boolean
|
||||
}
|
||||
|
||||
export class ConnectionBrowserView extends Disposable implements IPanelView {
|
||||
private tree: WorkbenchAsyncDataTree<TreeModel, TreeElement> | undefined;
|
||||
private filterInput: InputBox | undefined;
|
||||
@@ -67,11 +73,8 @@ export class ConnectionBrowserView extends Disposable implements IPanelView {
|
||||
|
||||
public onDidChangeVisibility = Event.None;
|
||||
|
||||
private readonly _onSelect = this._register(new Emitter<ITreeMouseEvent<TreeElement>>());
|
||||
public readonly onSelect = this._onSelect.event;
|
||||
|
||||
private readonly _onDblClick = this._register(new Emitter<ITreeMouseEvent<TreeElement>>());
|
||||
public readonly onDblClick = this._onDblClick.event;
|
||||
private readonly _onSelectedConnectionChanged = this._register(new Emitter<SelectedConnectionChangedEventArgs>());
|
||||
public readonly onSelectedConnectionChanged = this._onSelectedConnectionChanged.event;
|
||||
|
||||
constructor(
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||
@@ -180,19 +183,12 @@ export class ConnectionBrowserView extends Disposable implements IPanelView {
|
||||
});
|
||||
}
|
||||
}));
|
||||
this._register(this.tree.onMouseDblClick(e => this._onDblClick.fire(e)));
|
||||
this._register(this.tree.onMouseClick(e => this._onSelect.fire(e)));
|
||||
this._register(this.tree.onMouseDblClick(e => {
|
||||
this.handleTreeElementSelection(e?.element, true);
|
||||
}));
|
||||
|
||||
this._register(this.tree.onDidOpen((e) => {
|
||||
if (!e.browserEvent) {
|
||||
return;
|
||||
}
|
||||
const selection = this.tree.getSelection();
|
||||
if (selection.length === 1) {
|
||||
const selectedNode = selection[0];
|
||||
if ('element' in selectedNode && selectedNode.element.command) {
|
||||
this.commandService.executeCommand(selectedNode.element.command.id, ...(selectedNode.element.command.arguments || []));
|
||||
}
|
||||
}
|
||||
this.handleTreeElementSelection(e?.element, false);
|
||||
}));
|
||||
|
||||
this.tree.setInput(this.model);
|
||||
@@ -221,6 +217,30 @@ export class ConnectionBrowserView extends Disposable implements IPanelView {
|
||||
}));
|
||||
}
|
||||
|
||||
private handleTreeElementSelection(selectedNode: TreeElement, connect: boolean): void {
|
||||
if (!selectedNode) {
|
||||
return;
|
||||
}
|
||||
if ('element' in selectedNode) {
|
||||
if (selectedNode.element.command) {
|
||||
this.commandService.executeCommand(selectedNode.element.command.id, ...(selectedNode.element.command.arguments || []));
|
||||
} else {
|
||||
if (selectedNode.element.payload) {
|
||||
this._onSelectedConnectionChanged.fire(
|
||||
{
|
||||
connectionProfile: selectedNode.element.payload,
|
||||
connect: connect
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (selectedNode instanceof ConnectionProfile) {
|
||||
this._onSelectedConnectionChanged.fire({
|
||||
connectionProfile: selectedNode,
|
||||
connect: connect
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private updateSavedConnectionsNode(): void {
|
||||
if (this.model.savedConnectionNode) {
|
||||
this.tree.updateChildren(this.model.savedConnectionNode);
|
||||
|
||||
@@ -43,7 +43,7 @@ import { ClearRecentConnectionsAction } from 'sql/workbench/services/connection/
|
||||
import { ITree } from 'vs/base/parts/tree/browser/tree';
|
||||
import { AsyncServerTree } from 'sql/workbench/services/objectExplorer/browser/asyncServerTree';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { ConnectionBrowseTab, ITreeItemFromProvider } from 'sql/workbench/services/connection/browser/connectionBrowseTab';
|
||||
import { ConnectionBrowseTab } from 'sql/workbench/services/connection/browser/connectionBrowseTab';
|
||||
|
||||
export interface OnShowUIResponse {
|
||||
selectedProviderDisplayName: string;
|
||||
@@ -265,21 +265,9 @@ export class ConnectionDialogWidget extends Modal {
|
||||
|
||||
this.browsePanel = new ConnectionBrowseTab(this.instantiationService);
|
||||
|
||||
this.browsePanel.view.onSelect(e => {
|
||||
if (e.element instanceof ConnectionProfile) {
|
||||
this.onConnectionClick(e.element);
|
||||
} else if ((e.element as ITreeItemFromProvider)?.element?.payload) {
|
||||
this.onConnectionClick((e.element as ITreeItemFromProvider).element.payload);
|
||||
}
|
||||
});
|
||||
|
||||
this.browsePanel.view.onDblClick(e => {
|
||||
if (e.element instanceof ConnectionProfile) {
|
||||
this.onConnectionClick(e.element, true);
|
||||
} else if ((e.element as ITreeItemFromProvider)?.element?.payload) {
|
||||
this.onConnectionClick((e.element as ITreeItemFromProvider).element.payload, true);
|
||||
}
|
||||
});
|
||||
this._register(this.browsePanel.view.onSelectedConnectionChanged(e => {
|
||||
this.onConnectionClick(e.connectionProfile, e.connect);
|
||||
}));
|
||||
|
||||
if (this._configurationService.getValue<boolean>('workbench.enablePreviewFeatures')) {
|
||||
this._panel.pushTab(this.browsePanel);
|
||||
|
||||
Reference in New Issue
Block a user