rework listbox to not require platform (#5192)

This commit is contained in:
Anthony Dresser
2019-04-26 15:02:03 -07:00
committed by GitHub
parent 64377000c6
commit 91b946bf3d
3 changed files with 47 additions and 28 deletions

View File

@@ -18,6 +18,7 @@ import { attachListBoxStyler } from 'sql/platform/theme/common/styler';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { KeyCode } from 'vs/base/common/keyCodes';
@Component({
selector: 'modelview-listBox',
@@ -48,7 +49,25 @@ export default class ListBoxComponent extends ComponentBase implements IComponen
ngAfterViewInit(): void {
if (this._inputContainer) {
this._input = new ListBox([], this.contextViewService, this.clipboardService);
this._input = new ListBox([], this.contextViewService);
this._input.onKeyDown(e => {
if (this._input.selectedOptions.length > 0) {
const key = e.keyCode;
const ctrlOrCmd = e.ctrlKey || e.metaKey;
if (ctrlOrCmd && key === KeyCode.KEY_C) {
let textToCopy = this._input.selectedOptions[0];
for (let i = 1; i < this._input.selectedOptions.length; i++) {
textToCopy = textToCopy + ', ' + this._input.selectedOptions[i];
}
// Copy to clipboard
this.clipboardService.writeText(textToCopy);
e.stopPropagation();
}
}
});
this._input.render(this._inputContainer.nativeElement);
this._register(this._input);

View File

@@ -31,6 +31,7 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ISelectOptionItem } from 'vs/base/browser/ui/selectBox/selectBox';
import { KeyCode } from 'vs/base/common/keyCodes';
export const BACKUP_SELECTOR: string = 'backup-component';
@@ -268,7 +269,25 @@ export class BackupComponent {
});
// Set backup path list
this.pathListBox = new ListBox([], this.contextViewService, this.clipboardService);
this.pathListBox = new ListBox([], this.contextViewService);
this.pathListBox.onKeyDown(e => {
if (this.pathListBox.selectedOptions.length > 0) {
const key = e.keyCode;
const ctrlOrCmd = e.ctrlKey || e.metaKey;
if (ctrlOrCmd && key === KeyCode.KEY_C) {
let textToCopy = this.pathListBox.selectedOptions[0];
for (let i = 1; i < this.pathListBox.selectedOptions.length; i++) {
textToCopy = textToCopy + ', ' + this.pathListBox.selectedOptions[i];
}
// Copy to clipboard
this.clipboardService.writeText(textToCopy);
e.stopPropagation();
}
}
});
this.pathListBox.render(this.pathElement.nativeElement);
// Set backup path add/remove buttons