From 21c0490036b6d7dfeda74c5a8e9cd40116ace1c5 Mon Sep 17 00:00:00 2001 From: isidor Date: Wed, 18 Nov 2020 17:25:18 +0100 Subject: [PATCH] explorerService: add hasViewFocus and undoRedoSource --- .../contrib/files/browser/views/explorerView.ts | 6 ++++++ .../workbench/contrib/files/common/explorerService.ts | 10 ++++++++++ src/vs/workbench/contrib/files/common/files.ts | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/src/vs/workbench/contrib/files/browser/views/explorerView.ts b/src/vs/workbench/contrib/files/browser/views/explorerView.ts index 82439e566e7..ddd418e28f5 100644 --- a/src/vs/workbench/contrib/files/browser/views/explorerView.ts +++ b/src/vs/workbench/contrib/files/browser/views/explorerView.ts @@ -134,6 +134,7 @@ export class ExplorerView extends ViewPane { private styleElement!: HTMLStyleElement; private treeContainer!: HTMLElement; + private container!: HTMLElement; private compressedFocusContext: IContextKey; private compressedFocusFirstContext: IContextKey; private compressedFocusLastContext: IContextKey; @@ -245,6 +246,7 @@ export class ExplorerView extends ViewPane { renderBody(container: HTMLElement): void { super.renderBody(container); + this.container = container; this.treeContainer = DOM.append(container, DOM.$('.explorer-folders-view')); this.styleElement = DOM.createStyleSheet(this.treeContainer); @@ -303,6 +305,10 @@ export class ExplorerView extends ViewPane { } } + hasFocus(): boolean { + return DOM.isAncestor(document.activeElement, this.container); + } + getContext(respectMultiSelection: boolean): ExplorerItem[] { return getContext(this.tree.getFocus(), this.tree.getSelection(), respectMultiSelection, this.renderer); } diff --git a/src/vs/workbench/contrib/files/common/explorerService.ts b/src/vs/workbench/contrib/files/common/explorerService.ts index 17d2fb356a6..f3436ac27e1 100644 --- a/src/vs/workbench/contrib/files/common/explorerService.ts +++ b/src/vs/workbench/contrib/files/common/explorerService.ts @@ -16,11 +16,13 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditableData } from 'vs/workbench/common/views'; import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity'; +import { UndoRedoSource } from 'vs/platform/undoRedo/common/undoRedo'; export class ExplorerService implements IExplorerService { declare readonly _serviceBrand: undefined; private static readonly EXPLORER_FILE_CHANGES_REACT_DELAY = 500; // delay in ms to react to file changes to give our internal events a chance to react first + private static readonly UNDO_REDO_SOURCE = new UndoRedoSource(); private readonly disposables = new DisposableStore(); private editable: { stat: ExplorerItem, data: IEditableData } | undefined; @@ -84,6 +86,14 @@ export class ExplorerService implements IExplorerService { return this.view.getContext(respectMultiSelection); } + get undoRedoSource(): UndoRedoSource { + return ExplorerService.UNDO_REDO_SOURCE; + } + + hasViewFocus(): boolean { + return !!this.view && this.view.hasFocus(); + } + // IExplorerService methods findClosest(resource: URI): ExplorerItem | null { diff --git a/src/vs/workbench/contrib/files/common/files.ts b/src/vs/workbench/contrib/files/common/files.ts index fdd4e07c2e7..0933c9e8ed0 100644 --- a/src/vs/workbench/contrib/files/common/files.ts +++ b/src/vs/workbench/contrib/files/common/files.ts @@ -22,6 +22,7 @@ import { ExplorerItem } from 'vs/workbench/contrib/files/common/explorerModel'; import { once } from 'vs/base/common/functional'; import { ITextEditorOptions } from 'vs/platform/editor/common/editor'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +import { UndoRedoSource } from 'vs/platform/undoRedo/common/undoRedo'; /** * Explorer viewlet id. @@ -37,8 +38,10 @@ export interface IExplorerService { readonly _serviceBrand: undefined; readonly roots: ExplorerItem[]; readonly sortOrder: SortOrder; + undoRedoSource: UndoRedoSource; getContext(respectMultiSelection: boolean): ExplorerItem[]; + hasViewFocus(): boolean; setEditable(stat: ExplorerItem, data: IEditableData | null): Promise; getEditable(): { stat: ExplorerItem, data: IEditableData } | undefined; getEditableData(stat: ExplorerItem): IEditableData | undefined; @@ -67,6 +70,7 @@ export interface IExplorerView { setEditable(stat: ExplorerItem, isEditing: boolean): Promise; focusNeighbourIfItemFocused(item: ExplorerItem): void; isItemVisible(item: ExplorerItem): boolean; + hasFocus(): boolean; } export const IExplorerService = createDecorator('explorerService'); -- GitLab