From 3c7dce57150aef64546fd84d6a2bd1ccbe9e3fd6 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 27 May 2016 07:38:51 +0200 Subject: [PATCH] polish --- .../parts/files/browser/views/explorerView.ts | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/vs/workbench/parts/files/browser/views/explorerView.ts b/src/vs/workbench/parts/files/browser/views/explorerView.ts index 73c4b170fdf..775451e5ee2 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerView.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerView.ts @@ -115,16 +115,10 @@ export class ExplorerView extends CollapsibleViewletView { public getActions(): IAction[] { const actions: Action[] = []; - // New File - actions.push(this.instantiationService.createInstance(NewFileAction, this.getViewer(), null)); - // New Folder + actions.push(this.instantiationService.createInstance(NewFileAction, this.getViewer(), null)); actions.push(this.instantiationService.createInstance(NewFolderAction, this.getViewer(), null)); - - // Refresh actions.push(this.instantiationService.createInstance(RefreshViewExplorerAction, this, 'explorer-action refresh-explorer')); - - // Collapse actions.push(this.instantiationService.createInstance(CollapseAction, this.getViewer(), true, 'explorer-action collapse-explorer')); // Set Order @@ -263,7 +257,7 @@ export class ExplorerView extends CollapsibleViewletView { if (lastActiveFileResource && root && root.find(lastActiveFileResource)) { let editorInput = this.instantiationService.createInstance(FileEditorInput, lastActiveFileResource, void 0, void 0); - this.openEditor(editorInput).done(null, errors.onUnexpectedError); + this.activateOrOpenEditor(editorInput).done(null, errors.onUnexpectedError); return refreshPromise; } @@ -281,11 +275,11 @@ export class ExplorerView extends CollapsibleViewletView { if (stat && !stat.isDirectory) { let editorInput = this.instantiationService.createInstance(FileEditorInput, stat.resource, stat.mime, void 0); - this.openEditor(editorInput, keepFocus).done(null, errors.onUnexpectedError); + this.activateOrOpenEditor(editorInput, keepFocus).done(null, errors.onUnexpectedError); } } - private openEditor(input: FileEditorInput, keepFocus?: boolean): TPromise { + private activateOrOpenEditor(input: FileEditorInput, keepFocus?: boolean): TPromise { // First try to find if input already visible let editors = this.editorService.getVisibleEditors(); @@ -355,6 +349,7 @@ export class ExplorerView extends CollapsibleViewletView { public getOptimalWidth(): number { let parentNode = this.explorerViewer.getHTMLElement(); let childNodes = [].slice.call(parentNode.querySelectorAll('.explorer-item-label > a')); + return DOM.getLargestChildWidth(parentNode, childNodes); } @@ -387,8 +382,7 @@ export class ExplorerView extends CollapsibleViewletView { // Open new file in editor (pinned) if (!childElement.isDirectory) { - let editorInput = this.instantiationService.createInstance(FileEditorInput, childElement.resource, childElement.mime, void 0); - return this.editorService.openEditor(editorInput, EditorOptions.create({ pinned: true })); + return this.editorService.openEditor({ resource: childElement.resource, options: { pinned: true } }); } }); }); @@ -497,10 +491,7 @@ export class ExplorerView extends CollapsibleViewletView { // Open it (pinned) if (parentElement) { - this.explorerViewer.refresh(parentElement).then(() => { - let editorInput = this.instantiationService.createInstance(FileEditorInput, importedElement.resource, importedElement.mime, void 0); - return this.editorService.openEditor(editorInput, EditorOptions.create({ pinned: true })); - }).done(null, errors.onUnexpectedError); + this.explorerViewer.refresh(parentElement).then(() => this.editorService.openEditor({ resource: importedElement.resource, options: { pinned: true } })).done(null, errors.onUnexpectedError); } } @@ -598,7 +589,7 @@ export class ExplorerView extends CollapsibleViewletView { } private filterToAddRemovedOnWorkspacePath(e: FileChangesEvent, fn: (change: IFileChange, workspacePathSegments: string[]) => boolean): FileChangesEvent { - return new FileChangesEvent(e.changes.filter((change) => { + return new FileChangesEvent(e.changes.filter(change => { if (change.type === FileChangeType.UPDATED) { return false; // we only want added / removed } @@ -688,7 +679,7 @@ export class ExplorerView extends CollapsibleViewletView { // Load Root Stat with given target path configured let options: IResolveFileOptions = { resolveTo: targetsToResolve }; - let promise = this.fileService.resolveFile(this.workspace.resource, options).then((stat: IFileStat) => { + let promise = this.fileService.resolveFile(this.workspace.resource, options).then(stat => { let explorerPromise: TPromise; // Convert to model @@ -779,7 +770,7 @@ export class ExplorerView extends CollapsibleViewletView { // Stat needs to be resolved first and then revealed let options: IResolveFileOptions = { resolveTo: [resource] }; - return this.fileService.resolveFile(this.workspace.resource, options).then((stat: IFileStat) => { + return this.fileService.resolveFile(this.workspace.resource, options).then(stat => { // Convert to model let modelStat = FileStat.create(stat, options.resolveTo); @@ -788,14 +779,14 @@ export class ExplorerView extends CollapsibleViewletView { FileStat.mergeLocalWithDisk(modelStat, root); // Select and Reveal - return this.explorerViewer.refresh(root).then(() => { - return this.doSelect(root.find(resource), reveal); - }); + return this.explorerViewer.refresh(root).then(() => this.doSelect(root.find(resource), reveal)); + }, (e: any) => this.messageService.show(Severity.Error, e)); } private hasSelection(resource: URI): FileStat { let currentSelection: FileStat[] = this.explorerViewer.getSelection(); + for (let i = 0; i < currentSelection.length; i++) { if (currentSelection[i].resource.toString() === resource.toString()) { return currentSelection[i]; -- GitLab