提交 090d29b3 编写于 作者: B Benjamin Pasero

💄 list service consumers

上级 6adbd5b2
......@@ -641,8 +641,7 @@ export class ReferenceWidget extends PeekViewWidget {
var options: tree.ITreeOptions = {
twistiePixels: 20,
ariaLabel: nls.localize('treeAriaLabel', "References"),
keyboardSupport: false
ariaLabel: nls.localize('treeAriaLabel', "References")
};
this._tree = this._instantiationService.createInstance(WorkbenchTree, div.getHTMLElement(), config, options);
......
......@@ -117,11 +117,22 @@ class MultipleSelectionController<T> implements IMultipleSelectionController<T>
}
}
function handleMultiSelectSupport<T>(options: IListOptions<T>, configurationService: IConfigurationService): IListOptions<T> {
if (options.multipleSelectionSupport === true && !options.multipleSelectionController) {
options.multipleSelectionController = new MultipleSelectionController(configurationService);
}
return options;
}
export class WorkbenchList<T> extends List<T> {
readonly contextKeyService: IContextKeyService;
private listDoubleSelection: IContextKey<boolean>;
private _useAltAsMultipleSelectionModifier: boolean;
constructor(
container: HTMLElement,
delegate: IDelegate<T>,
......@@ -130,31 +141,45 @@ export class WorkbenchList<T> extends List<T> {
@IContextKeyService contextKeyService: IContextKeyService,
@IListService listService: IListService,
@IThemeService themeService: IThemeService,
@IConfigurationService configurationService: IConfigurationService
@IConfigurationService private configurationService: IConfigurationService
) {
const multipleSelectionSupport = !(options.multipleSelectionSupport === false);
super(container, delegate, renderers, mixin(handleMultiSelectSupport(options, configurationService), { keyboardSupport: false } as IListOptions<any>, false));
if (multipleSelectionSupport && !options.multipleSelectionController) {
options.multipleSelectionController = new MultipleSelectionController(configurationService);
}
super(container, delegate, renderers, mixin(options, useAltAsMultipleSelectionModifier(configurationService)));
this.contextKeyService = createScopedContextKeyService(contextKeyService, this);
this.listDoubleSelection = WorkbenchListDoubleSelection.bindTo(this.contextKeyService);
this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(configurationService);
this.disposables.push(combinedDisposable([
this.contextKeyService,
(listService as ListService).register(this),
attachListStyler(this, themeService),
this.onSelectionChange(() => this.listDoubleSelection.set(this.getSelection().length === 2))
]));
this.registerListeners();
}
public get useAltAsMultipleSelectionModifier(): boolean {
return this._useAltAsMultipleSelectionModifier;
}
private registerListeners(): void {
this.disposables.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(multiSelectModifierSettingKey)) {
this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(this.configurationService);
}
}));
}
}
export class WorkbenchPagedList<T> extends PagedList<T> {
readonly contextKeyService: IContextKeyService;
private disposable: IDisposable;
private disposables: IDisposable[] = [];
private _useAltAsMultipleSelectionModifier: boolean;
constructor(
container: HTMLElement,
......@@ -164,57 +189,90 @@ export class WorkbenchPagedList<T> extends PagedList<T> {
@IContextKeyService contextKeyService: IContextKeyService,
@IListService listService: IListService,
@IThemeService themeService: IThemeService,
@IConfigurationService configurationService: IConfigurationService
@IConfigurationService private configurationService: IConfigurationService
) {
const multipleSelectionSupport = !(options.multipleSelectionSupport === false);
if (multipleSelectionSupport && !options.multipleSelectionController) {
options.multipleSelectionController = new MultipleSelectionController(configurationService);
}
super(container, delegate, renderers, mixin(handleMultiSelectSupport(options, configurationService), { keyboardSupport: false } as IListOptions<any>, false));
super(container, delegate, renderers, mixin(options, useAltAsMultipleSelectionModifier(configurationService)));
this.contextKeyService = createScopedContextKeyService(contextKeyService, this);
this.disposable = combinedDisposable([
this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(configurationService);
this.disposables.push(combinedDisposable([
this.contextKeyService,
(listService as ListService).register(this),
attachListStyler(this, themeService)
]);
]));
this.registerListeners();
}
public get useAltAsMultipleSelectionModifier(): boolean {
return this._useAltAsMultipleSelectionModifier;
}
private registerListeners(): void {
this.disposables.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(multiSelectModifierSettingKey)) {
this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(this.configurationService);
}
}));
}
dispose(): void {
this.disposable.dispose();
this.disposables = dispose(this.disposables);
}
}
export class WorkbenchTree extends Tree {
readonly contextKeyService: IContextKeyService;
protected disposables: IDisposable[] = [];
private listDoubleSelection: IContextKey<boolean>;
private _useAltAsMultipleSelectionModifier: boolean;
constructor(
container: HTMLElement,
configuration: ITreeConfiguration,
options: ITreeOptions,
@IContextKeyService contextKeyService: IContextKeyService,
@IListService listService: IListService,
@IThemeService themeService: IThemeService
@IThemeService themeService: IThemeService,
@IConfigurationService private configurationService: IConfigurationService
) {
super(container, configuration, options);
super(container, configuration, mixin(options, { keyboardSupport: false } as ITreeOptions, false));
this.contextKeyService = createScopedContextKeyService(contextKeyService, this);
this.listDoubleSelection = WorkbenchListDoubleSelection.bindTo(this.contextKeyService);
this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(configurationService);
this.disposables.push(
this.contextKeyService,
(listService as ListService).register(this),
attachListStyler(this, themeService)
);
this.registerListeners();
}
public get useAltAsMultipleSelectionModifier(): boolean {
return this._useAltAsMultipleSelectionModifier;
}
private registerListeners(): void {
this.disposables.push(this.onDidChangeSelection(() => {
const selection = this.getSelection();
this.listDoubleSelection.set(selection && selection.length === 2);
}));
this.disposables.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(multiSelectModifierSettingKey)) {
this._useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier(this.configurationService);
}
}));
}
dispose(): void {
......
......@@ -92,7 +92,7 @@ export class TreeView extends TreeViewsViewletPanel {
const tree = this.instantiationService.createInstance(FileIconThemableWorkbenchTree,
container.getHTMLElement(),
{ dataSource, renderer, controller },
{ keyboardSupport: false }
{}
);
tree.contextKeyService.createKey<boolean>(this.id, true);
......
......@@ -31,6 +31,7 @@ import { WorkbenchTree, IListService } from 'vs/platform/list/browser/listServic
import { IWorkbenchThemeService, IFileIconTheme } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { ITreeConfiguration, ITreeOptions } from 'vs/base/parts/tree/browser/tree';
import Event, { Emitter } from 'vs/base/common/event';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
export interface IViewOptions extends IPanelOptions {
id: string;
......@@ -771,9 +772,10 @@ export class FileIconThemableWorkbenchTree extends WorkbenchTree {
options: ITreeOptions,
@IContextKeyService contextKeyService: IContextKeyService,
@IListService listService: IListService,
@IThemeService themeService: IWorkbenchThemeService
@IThemeService themeService: IWorkbenchThemeService,
@IConfigurationService configurationService: IConfigurationService
) {
super(container, configuration, { ...options, ...{ showTwistie: false, twistiePixels: 12 } }, contextKeyService, listService, themeService);
super(container, configuration, { ...options, ...{ showTwistie: false, twistiePixels: 12 } }, contextKeyService, listService, themeService, configurationService);
DOM.addClass(container, 'file-icon-themable-tree');
DOM.addClass(container, 'show-file-icons');
......
......@@ -380,9 +380,9 @@ export class StackFrame implements IStackFrame {
return `${this.name} (${this.source.inMemory ? this.source.name : this.source.uri.fsPath}:${this.range.startLineNumber})`;
}
public openInEditor(editorService: IWorkbenchEditorService, preserveFocus?: boolean, sideBySide?: boolean): TPromise<any> {
public openInEditor(editorService: IWorkbenchEditorService, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
return !this.source.available ? TPromise.as(null) :
this.source.openInEditor(editorService, this.range, preserveFocus, sideBySide);
this.source.openInEditor(editorService, this.range, preserveFocus, sideBySide, pinned);
}
}
......
......@@ -56,7 +56,7 @@ export class Source {
return this.uri.scheme === DEBUG_SCHEME;
}
public openInEditor(editorService: IWorkbenchEditorService, selection: IRange, preserveFocus?: boolean, sideBySide?: boolean): TPromise<any> {
public openInEditor(editorService: IWorkbenchEditorService, selection: IRange, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
return !this.available ? TPromise.as(null) : editorService.openEditor({
resource: this.uri,
description: this.origin,
......@@ -65,7 +65,7 @@ export class Source {
selection,
revealIfVisible: true,
revealInCenterIfOutsideViewport: true,
pinned: !preserveFocus && !this.inMemory
pinned: pinned || (!preserveFocus && !this.inMemory)
}
}, sideBySide);
}
......
......@@ -102,8 +102,7 @@ export class CallStackView extends TreeViewsViewletPanel {
controller
}, {
ariaLabel: nls.localize({ comment: ['Debug is a noun in this context, not a verb.'], key: 'callStackAriaLabel' }, "Debug Call Stack"),
twistiePixels,
keyboardSupport: false
twistiePixels
});
const fileResultsNavigation = new FileResultsNavigation(this.tree);
......@@ -116,7 +115,7 @@ export class CallStackView extends TreeViewsViewletPanel {
const element = e.element;
if (element instanceof StackFrame) {
this.debugService.focusStackFrame(element, element.thread, element.thread.process, true);
element.openInEditor(this.editorService, e.editorOptions.preserveFocus, e.sideBySide).done(undefined, errors.onUnexpectedError);
element.openInEditor(this.editorService, e.editorOptions.preserveFocus, e.sideBySide, e.editorOptions.pinned).done(undefined, errors.onUnexpectedError);
}
if (element instanceof Thread) {
this.debugService.focusStackFrame(undefined, element, element.process, true);
......
......@@ -75,8 +75,7 @@ export class DebugHoverWidget implements IContentWidget {
}, {
indentPixels: 6,
twistiePixels: 15,
ariaLabel: nls.localize('treeAriaLabel', "Debug Hover"),
keyboardSupport: false
ariaLabel: nls.localize('treeAriaLabel', "Debug Hover")
});
this.valueContainer = $('.value');
......
......@@ -49,8 +49,7 @@ const $ = dom.$;
const replTreeOptions: ITreeOptions = {
twistiePixels: 20,
ariaLabel: nls.localize('replAriaLabel', "Read Eval Print Loop Panel"),
keyboardSupport: false
ariaLabel: nls.localize('replAriaLabel', "Read Eval Print Loop Panel")
};
const HISTORY_STORAGE_KEY = 'debug.repl.history';
......
......@@ -90,8 +90,7 @@ export class VariablesView extends TreeViewsViewletPanel {
controller: this.instantiationService.createInstance(VariablesController, new VariablesActionProvider(this.debugService, this.keybindingService), MenuId.DebugVariablesContext)
}, {
ariaLabel: nls.localize('variablesAriaTreeLabel', "Debug Variables"),
twistiePixels,
keyboardSupport: false
twistiePixels
});
CONTEXT_VARIABLES_FOCUSED.bindTo(this.tree.contextKeyService);
......
......@@ -69,8 +69,7 @@ export class WatchExpressionsView extends TreeViewsViewletPanel {
dnd: new WatchExpressionsDragAndDrop(this.debugService)
}, {
ariaLabel: nls.localize({ comment: ['Debug is a noun in this context, not a verb.'], key: 'watchAriaTreeLabel' }, "Debug Watch Expressions"),
twistiePixels,
keyboardSupport: false
twistiePixels
});
CONTEXT_WATCH_EXPRESSIONS_FOCUSED.bindTo(this.tree.contextKeyService);
......
......@@ -526,8 +526,7 @@ export class ExtensionEditor extends BaseEditor {
controller
}, {
indentPixels: 40,
twistiePixels: 20,
keyboardSupport: false
twistiePixels: 20
});
tree.setInput(extensionDependencies);
......
......@@ -78,8 +78,7 @@ export class ExtensionsListView extends ViewsViewletPanel {
const delegate = new Delegate();
const renderer = this.instantiationService.createInstance(Renderer);
this.list = this.instantiationService.createInstance(WorkbenchPagedList, this.extensionsList, delegate, [renderer], {
ariaLabel: localize('extensions', "Extensions"),
keyboardSupport: false
ariaLabel: localize('extensions', "Extensions")
});
chain(this.list.onSelectionChange)
......@@ -443,6 +442,7 @@ export class ExtensionsListView extends ViewsViewletPanel {
const activeEditorInput = this.editorService.getActiveEditorInput();
this.editorInputService.pinEditor(activeEditor.position, activeEditorInput);
activeEditor.focus();
}
......
......@@ -403,8 +403,7 @@ export class ExplorerView extends TreeViewsViewletPanel implements IExplorerView
accessibilityProvider
}, {
autoExpandSingleChildren: true,
ariaLabel: nls.localize('treeAriaLabel', "Files Explorer"),
keyboardSupport: false
ariaLabel: nls.localize('treeAriaLabel', "Files Explorer")
});
// Bind context keys
......
......@@ -56,7 +56,7 @@ import { extractResources } from 'vs/workbench/browser/editor';
import { relative } from 'path';
import { DataTransfers } from 'vs/base/browser/dnd';
import { distinctParents } from 'vs/base/common/resources';
import { WorkbenchTree, multiSelectModifierSettingKey } from 'vs/platform/list/browser/listService';
import { WorkbenchTree } from 'vs/platform/list/browser/listService';
export class FileDataSource implements IDataSource {
constructor(
......@@ -330,33 +330,20 @@ export class FileController extends DefaultController implements IDisposable {
private contributedContextMenu: IMenu;
private toDispose: IDisposable[];
private previousSelectionRangeStop: FileStat;
private useAltAsMultiSelectModifier: boolean;
constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IContextMenuService private contextMenuService: IContextMenuService,
@ITelemetryService private telemetryService: ITelemetryService,
@IMenuService private menuService: IMenuService,
@IContextKeyService contextKeyService: IContextKeyService,
@IConfigurationService private configurationService: IConfigurationService
@IContextKeyService contextKeyService: IContextKeyService
) {
super({ clickBehavior: ClickBehavior.ON_MOUSE_UP /* do not change to not break DND */, keyboardSupport: false /* handled via IListService */ });
this.useAltAsMultiSelectModifier = configurationService.getValue(multiSelectModifierSettingKey) === 'alt';
this.toDispose = [];
this.registerListeners();
}
private registerListeners(): void {
this.toDispose.push(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(multiSelectModifierSettingKey)) {
this.useAltAsMultiSelectModifier = this.configurationService.getValue(multiSelectModifierSettingKey) === 'alt';
}
}));
}
public onLeftClick(tree: ITree, stat: FileStat | Model, event: IMouseEvent, origin: string = 'mouse'): boolean {
public onLeftClick(tree: WorkbenchTree, stat: FileStat | Model, event: IMouseEvent, origin: string = 'mouse'): boolean {
const payload = { origin: origin };
const isDoubleClick = (origin === 'mouse' && event.detail === 2);
......@@ -394,7 +381,7 @@ export class FileController extends DefaultController implements IDisposable {
}
// Allow to multiselect
if ((this.useAltAsMultiSelectModifier && event.altKey) || !this.useAltAsMultiSelectModifier && (event.ctrlKey || event.metaKey)) {
if ((tree.useAltAsMultipleSelectionModifier && event.altKey) || !tree.useAltAsMultipleSelectionModifier && (event.ctrlKey || event.metaKey)) {
const selection = tree.getSelection();
this.previousSelectionRangeStop = undefined;
if (selection.indexOf(stat) >= 0) {
......@@ -435,7 +422,7 @@ export class FileController extends DefaultController implements IDisposable {
if (!stat.isDirectory) {
let sideBySide = false;
if (event) {
sideBySide = this.useAltAsMultiSelectModifier ? (event.ctrlKey || event.metaKey) : event.altKey;
sideBySide = tree.useAltAsMultipleSelectionModifier ? (event.ctrlKey || event.metaKey) : event.altKey;
}
this.openEditor(stat, { preserveFocus, sideBySide, pinned: isDoubleClick });
......
......@@ -28,7 +28,7 @@ import { EditorGroup } from 'vs/workbench/common/editor/editorStacksModel';
import { attachStylerCallback } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { badgeBackground, badgeForeground, contrastBorder } from 'vs/platform/theme/common/colorRegistry';
import { WorkbenchList, useAltAsMultipleSelectionModifier } from 'vs/platform/list/browser/listService';
import { WorkbenchList } from 'vs/platform/list/browser/listService';
import { IDelegate, IRenderer, IListContextMenuEvent, IListMouseEvent } from 'vs/base/browser/ui/list/list';
import { EditorLabel } from 'vs/workbench/browser/labels';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
......@@ -153,7 +153,6 @@ export class OpenEditorsView extends ViewsViewletPanel {
new EditorGroupRenderer(this.keybindingService, this.instantiationService, this.editorGroupService),
new OpenEditorRenderer(getSelectedElements, this.instantiationService, this.keybindingService, this.configurationService, this.editorGroupService)
], {
keyboardSupport: false,
identityProvider: element => element instanceof OpenEditor ? element.getId() : element.id.toString()
});
......@@ -278,7 +277,7 @@ export class OpenEditorsView extends ViewsViewletPanel {
const position = this.model.positionOfGroup(element.group);
this.editorService.closeEditor(position, element.editor).done(null, errors.onUnexpectedError);
} else {
const sideBySide = useAltAsMultipleSelectionModifier(this.configurationService) ? event.browserEvent.altKey : (event.browserEvent.ctrlKey || event.browserEvent.metaKey);
const sideBySide = this.list.useAltAsMultipleSelectionModifier ? (event.browserEvent.ctrlKey || event.browserEvent.metaKey) : event.browserEvent.altKey;
this.openEditor(element, { preserveFocus: !isDoubleClick, pinned: isDoubleClick, sideBySide });
}
}
......
......@@ -206,8 +206,7 @@ export class MarkersPanel extends Panel {
}, {
indentPixels: 0,
twistiePixels: 20,
ariaLabel: Messages.MARKERS_PANEL_ARIA_LABEL_PROBLEMS_TREE,
keyboardSupport: false
ariaLabel: Messages.MARKERS_PANEL_ARIA_LABEL_PROBLEMS_TREE
});
Constants.MarkerFocusContextKey.bindTo(this.tree.contextKeyService);
......
......@@ -333,7 +333,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
this.keybindingsListContainer = DOM.append(parent, $('.keybindings-list-container'));
this.keybindingsList = this._register(this.instantiationService.createInstance(WorkbenchList, this.keybindingsListContainer, new Delegate(), [new KeybindingHeaderRenderer(), new KeybindingItemRenderer(this, this.keybindingsService)],
{ identityProvider: e => e.id, keyboardSupport: false, mouseSupport: true, ariaLabel: localize('keybindingsLabel', "Keybindings") }));
{ identityProvider: e => e.id, mouseSupport: true, ariaLabel: localize('keybindingsLabel', "Keybindings") }));
this._register(this.keybindingsList.onContextMenu(e => this.onContextMenu(e)));
this._register(this.keybindingsList.onFocusChange(e => this.onFocusChange(e)));
this._register(this.keybindingsList.onDidFocus(() => {
......
......@@ -854,8 +854,7 @@ export class RepositoryPanel extends ViewletPanel {
];
this.list = this.instantiationService.createInstance(WorkbenchList, this.listContainer, delegate, renderers, {
identityProvider: scmResourceIdentityProvider,
keyboardSupport: false
identityProvider: scmResourceIdentityProvider
});
chain(this.list.onOpen)
......@@ -941,6 +940,7 @@ export class RepositoryPanel extends ViewletPanel {
}
this.editorGroupService.pinEditor(activeEditor.position, activeEditorInput);
activeEditor.focus();
}
private onListContextMenu(e: IListContextMenuEvent<ISCMResourceGroup | ISCMResource>): void {
......
......@@ -505,8 +505,7 @@ export class SearchViewlet extends Viewlet {
accessibilityProvider: this.instantiationService.createInstance(SearchAccessibilityProvider),
dnd
}, {
ariaLabel: nls.localize('treeAriaLabel', "Search Results"),
keyboardSupport: false
ariaLabel: nls.localize('treeAriaLabel', "Search Results")
});
this.tree.setInput(this.viewModel.searchResult);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册