Provide an action to reveal the currently active file in the explorer (fixes #4858)

This commit is contained in:
Benjamin Pasero
2016-04-01 16:08:59 +02:00
parent 7d3f69febb
commit 71e424f8a7
2 changed files with 44 additions and 2 deletions
@@ -10,7 +10,7 @@ import {Action, IAction} from 'vs/base/common/actions';
import {ActionItem, BaseActionItem, Separator} from 'vs/base/browser/ui/actionbar/actionbar';
import {Scope, IActionBarRegistry, Extensions as ActionBarExtensions, ActionBarContributor} from 'vs/workbench/browser/actionBarRegistry';
import {IEditorInputActionContext, IEditorInputAction, EditorInputActionContributor} from 'vs/workbench/browser/parts/editor/baseEditor';
import {AddToWorkingFiles, FocusWorkingFiles, FocusFilesExplorer, OpenPreviousWorkingFile, OpenNextWorkingFile, CloseAllFilesAction, CloseFileAction, CloseOtherFilesAction, GlobalCompareResourcesAction, GlobalNewFolderAction, RevertFileAction, SaveFilesAction, SaveAllAction, SaveFileAction, keybindingForAction, MoveFileToTrashAction, TriggerRenameFileAction, PasteFileAction, CopyFileAction, SelectResourceForCompareAction, CompareResourcesAction, NewFolderAction, NewFileAction, OpenToSideAction} from 'vs/workbench/parts/files/browser/fileActions';
import {AddToWorkingFiles, FocusWorkingFiles, FocusFilesExplorer, OpenPreviousWorkingFile, OpenNextWorkingFile, CloseAllFilesAction, CloseFileAction, CloseOtherFilesAction, GlobalCompareResourcesAction, GlobalNewFolderAction, RevertFileAction, SaveFilesAction, SaveAllAction, SaveFileAction, keybindingForAction, MoveFileToTrashAction, TriggerRenameFileAction, PasteFileAction, CopyFileAction, SelectResourceForCompareAction, CompareResourcesAction, NewFolderAction, NewFileAction, OpenToSideAction, ShowActiveFileInExplorer} from 'vs/workbench/parts/files/browser/fileActions';
import {RevertLocalChangesAction, AcceptLocalChangesAction, ConflictResolutionDiffEditorInput} from 'vs/workbench/parts/files/browser/saveErrorHandler';
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {IWorkbenchActionRegistry, Extensions as ActionExtensions} from 'vs/workbench/common/actionRegistry';
@@ -175,4 +175,5 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(OpenNextWorkingFile, O
registry.registerWorkbenchAction(new SyncActionDescriptor(OpenPreviousWorkingFile, OpenPreviousWorkingFile.ID, OpenPreviousWorkingFile.LABEL, { primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.UpArrow) }), category);
registry.registerWorkbenchAction(new SyncActionDescriptor(AddToWorkingFiles, AddToWorkingFiles.ID, AddToWorkingFiles.LABEL, { primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.Enter) }), category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusWorkingFiles, FocusWorkingFiles.ID, FocusWorkingFiles.LABEL, { primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_E) }), category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusFilesExplorer, FocusFilesExplorer.ID, FocusFilesExplorer.LABEL), category);
registry.registerWorkbenchAction(new SyncActionDescriptor(FocusFilesExplorer, FocusFilesExplorer.ID, FocusFilesExplorer.LABEL), category);
registry.registerWorkbenchAction(new SyncActionDescriptor(ShowActiveFileInExplorer, ShowActiveFileInExplorer.ID, ShowActiveFileInExplorer.LABEL), category);
@@ -17,6 +17,7 @@ import errors = require('vs/base/common/errors');
import strings = require('vs/base/common/strings');
import {Event, EventType as CommonEventType} from 'vs/base/common/events';
import {getPathLabel} from 'vs/base/common/labels';
import severity from 'vs/base/common/severity';
import diagnostics = require('vs/base/common/diagnostics');
import {Action, IAction} from 'vs/base/common/actions';
import {MessageType, IInputValidator} from 'vs/base/browser/ui/inputbox/inputBox';
@@ -2316,6 +2317,46 @@ export class FocusFilesExplorer extends Action {
}
}
export class ShowActiveFileInExplorer extends Action {
public static ID = 'workbench.files.action.showActiveFileInExplorer';
public static LABEL = nls.localize('showInExplorer', "Show Active File in Explorer");
constructor(
id: string,
label: string,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IViewletService private viewletService: IViewletService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IMessageService private messageService: IMessageService
) {
super(id, label);
}
public run(): TPromise<any> {
let fileInput = asFileEditorInput(this.editorService.getActiveEditorInput(), true);
if (fileInput) {
return this.viewletService.openViewlet(Files.VIEWLET_ID, false).then((viewlet: ExplorerViewlet) => {
const isInsideWorkspace = this.contextService.isInsideWorkspace(fileInput.getResource());
if (isInsideWorkspace) {
const explorerView = viewlet.getExplorerView();
if (explorerView) {
explorerView.expand();
explorerView.select(fileInput.getResource(), true);
}
} else {
const workingFilesView = viewlet.getWorkingFilesView();
workingFilesView.expand();
}
});
} else {
this.messageService.show(severity.Info, nls.localize('openFileToShow', "Open a file first to show it in the explorer"));
}
return TPromise.as(true);
}
}
export function keybindingForAction(id: string): Keybinding {
switch (id) {
case GlobalNewFileAction.ID: