提交 3f2c8900 编写于 作者: I isidor

explorer better expand to

上级 2d4fcf14
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import * as perf from 'vs/base/common/performance'; import * as perf from 'vs/base/common/performance';
import { sequence } from 'vs/base/common/async';
import { Action, IAction } from 'vs/base/common/actions'; import { Action, IAction } from 'vs/base/common/actions';
import { memoize } from 'vs/base/common/decorators'; import { memoize } from 'vs/base/common/decorators';
import { IFilesConfiguration, ExplorerFolderContext, FilesExplorerFocusedContext, ExplorerFocusedContext, ExplorerRootContext, ExplorerResourceReadonlyContext, IExplorerService, ExplorerResourceCut } from 'vs/workbench/contrib/files/common/files'; import { IFilesConfiguration, ExplorerFolderContext, FilesExplorerFocusedContext, ExplorerFocusedContext, ExplorerRootContext, ExplorerResourceReadonlyContext, IExplorerService, ExplorerResourceCut } from 'vs/workbench/contrib/files/common/files';
...@@ -49,6 +48,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService ...@@ -49,6 +48,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService
import { isMacintosh } from 'vs/base/common/platform'; import { isMacintosh } from 'vs/base/common/platform';
import { KeyCode } from 'vs/base/common/keyCodes'; import { KeyCode } from 'vs/base/common/keyCodes';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { isEqualOrParent } from 'vs/base/common/resources';
export class ExplorerView extends ViewletPanel { export class ExplorerView extends ViewletPanel {
static readonly ID: string = 'workbench.explorer.fileView'; static readonly ID: string = 'workbench.explorer.fileView';
...@@ -188,7 +188,7 @@ export class ExplorerView extends ViewletPanel { ...@@ -188,7 +188,7 @@ export class ExplorerView extends ViewletPanel {
this.tree.domFocus(); this.tree.domFocus();
} }
})); }));
this.disposables.push(this.explorerService.onDidSelectItem(e => this.onSelectItem(e.item, e.reveal))); this.disposables.push(this.explorerService.onDidSelectResource(e => this.onSelectResource(e.resource, e.reveal)));
this.disposables.push(this.explorerService.onDidCopyItems(e => this.onCopyItems(e.items, e.cut, e.previouslyCutItems))); this.disposables.push(this.explorerService.onDidCopyItems(e => this.onCopyItems(e.items, e.cut, e.previouslyCutItems)));
// Update configuration // Update configuration
...@@ -507,28 +507,36 @@ export class ExplorerView extends ViewletPanel { ...@@ -507,28 +507,36 @@ export class ExplorerView extends ViewletPanel {
return toResource(input, { supportSideBySide: true }); return toResource(input, { supportSideBySide: true });
} }
private onSelectItem(fileStat: ExplorerItem, reveal = this.autoReveal): Promise<void> { private onSelectResource(resource: URI, reveal = this.autoReveal): void {
if (!fileStat || !this.isBodyVisible() || this.tree.getInput() === fileStat) { if (!resource || !this.isBodyVisible()) {
return Promise.resolve(undefined); return;
} }
// Expand all stats in the parent chain // Expand all stats in the parent chain
const toExpand: ExplorerItem[] = []; const root = this.explorerService.roots.filter(r => isEqualOrParent(resource, r.resource)).pop();
let parent = fileStat.parent; if (root) {
while (parent) { const traverse = async (item: ExplorerItem) => {
toExpand.push(parent); if (item.resource.toString() === resource.toString()) {
parent = parent.parent;
}
return sequence(toExpand.reverse().map(s => () => this.tree.expand(s))).then(() => {
if (reveal) { if (reveal) {
this.tree.reveal(fileStat, 0.5); this.tree.reveal(item, 0.5);
} }
this.tree.setFocus([fileStat]); this.tree.setFocus([item]);
this.tree.setSelection([fileStat]); this.tree.setSelection([item]);
} else {
await this.tree.expand(item);
let found = false;
item.children.forEach(async child => {
if (!found && isEqualOrParent(resource, child.resource)) {
found = true;
await traverse(child);
}
}); });
} }
};
traverse(root);
}
}
private onCopyItems(stats: ExplorerItem[], cut: boolean, previousCut: ExplorerItem[]): void { private onCopyItems(stats: ExplorerItem[], cut: boolean, previousCut: ExplorerItem[]): void {
this.fileCopiedContextKey.set(stats.length > 0); this.fileCopiedContextKey.set(stats.length > 0);
......
...@@ -34,7 +34,7 @@ export class ExplorerService implements IExplorerService { ...@@ -34,7 +34,7 @@ export class ExplorerService implements IExplorerService {
private _onDidChangeRoots = new Emitter<void>(); private _onDidChangeRoots = new Emitter<void>();
private _onDidChangeItem = new Emitter<ExplorerItem | undefined>(); private _onDidChangeItem = new Emitter<ExplorerItem | undefined>();
private _onDidChangeEditable = new Emitter<ExplorerItem>(); private _onDidChangeEditable = new Emitter<ExplorerItem>();
private _onDidSelectItem = new Emitter<{ item?: ExplorerItem, reveal?: boolean }>(); private _onDidSelectResource = new Emitter<{ resource?: URI, reveal?: boolean }>();
private _onDidCopyItems = new Emitter<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>(); private _onDidCopyItems = new Emitter<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>();
private disposables: IDisposable[] = []; private disposables: IDisposable[] = [];
private editable: { stat: ExplorerItem, data: IEditableData } | undefined; private editable: { stat: ExplorerItem, data: IEditableData } | undefined;
...@@ -68,8 +68,8 @@ export class ExplorerService implements IExplorerService { ...@@ -68,8 +68,8 @@ export class ExplorerService implements IExplorerService {
return this._onDidChangeEditable.event; return this._onDidChangeEditable.event;
} }
get onDidSelectItem(): Event<{ item?: ExplorerItem, reveal?: boolean }> { get onDidSelectResource(): Event<{ resource?: URI, reveal?: boolean }> {
return this._onDidSelectItem.event; return this._onDidSelectResource.event;
} }
get onDidCopyItems(): Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }> { get onDidCopyItems(): Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }> {
...@@ -142,7 +142,7 @@ export class ExplorerService implements IExplorerService { ...@@ -142,7 +142,7 @@ export class ExplorerService implements IExplorerService {
select(resource: URI, reveal?: boolean): Promise<void> { select(resource: URI, reveal?: boolean): Promise<void> {
const fileStat = this.findClosest(resource); const fileStat = this.findClosest(resource);
if (fileStat) { if (fileStat) {
this._onDidSelectItem.fire({ item: fileStat, reveal }); this._onDidSelectResource.fire({ resource: fileStat.resource, reveal });
return Promise.resolve(undefined); return Promise.resolve(undefined);
} }
...@@ -161,7 +161,7 @@ export class ExplorerService implements IExplorerService { ...@@ -161,7 +161,7 @@ export class ExplorerService implements IExplorerService {
this._onDidChangeItem.fire(item ? item.parent : undefined); this._onDidChangeItem.fire(item ? item.parent : undefined);
// Select and Reveal // Select and Reveal
this._onDidSelectItem.fire({ item: item || undefined, reveal }); this._onDidSelectResource.fire({ resource: item ? item.resource : undefined, reveal });
}, () => { }, () => {
root.isError = true; root.isError = true;
this._onDidChangeItem.fire(root); this._onDidChangeItem.fire(root);
......
...@@ -44,7 +44,7 @@ export interface IExplorerService { ...@@ -44,7 +44,7 @@ export interface IExplorerService {
readonly onDidChangeRoots: Event<void>; readonly onDidChangeRoots: Event<void>;
readonly onDidChangeItem: Event<ExplorerItem | undefined>; readonly onDidChangeItem: Event<ExplorerItem | undefined>;
readonly onDidChangeEditable: Event<ExplorerItem>; readonly onDidChangeEditable: Event<ExplorerItem>;
readonly onDidSelectItem: Event<{ item?: ExplorerItem, reveal?: boolean }>; readonly onDidSelectResource: Event<{ resource?: URI, reveal?: boolean }>;
readonly onDidCopyItems: Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>; readonly onDidCopyItems: Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>;
setEditable(stat: ExplorerItem, data: IEditableData | null): void; setEditable(stat: ExplorerItem, data: IEditableData | null): void;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册