Skip to content

Commit

Permalink
#8594 - implement copy path context menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Apr 4, 2018
1 parent de6653a commit 1dcb420
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/vs/workbench/parts/search/browser/searchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import { OS } from 'vs/base/common/platform';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { VIEW_ID } from 'vs/platform/search/common/search';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { ICommandHandler } from 'vs/platform/commands/common/commands';
import { Schemas } from 'vs/base/common/network';
import { getPathLabel } from 'vs/base/common/labels';

export function isSearchViewFocused(viewletService: IViewletService, panelService: IPanelService): boolean {
let searchView = getSearchView(viewletService, panelService);
Expand Down Expand Up @@ -630,3 +634,11 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
return false;
}
}

export const copyPathCommand: ICommandHandler = (accessor, fileMatch: FileMatch) => {
const clipboardService = accessor.get(IClipboardService);

const resource = fileMatch.resource();
const text = resource.scheme === Schemas.file ? getPathLabel(resource) : resource.toString();
clipboardService.writeText(text);
};
4 changes: 3 additions & 1 deletion src/vs/workbench/parts/search/browser/searchResultsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,9 @@ export class SearchTreeController extends WorkbenchTreeController {
const actions: IAction[] = [];
fillInActions(this.contextMenu, { shouldForwardArgs: true }, actions, this.contextMenuService);
return TPromise.as(actions);
}
},

getActionsContext: () => element
});

return true;
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/parts/search/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const FocusSearchFromResults = 'search.action.focusSearchFromResults';
export const OpenMatchToSide = 'search.action.openResultToSide';
export const CancelActionId = 'search.action.cancel';
export const RemoveActionId = 'search.action.remove';
export const CopyPathCommandId = 'search.action.copyPath';
export const CopyMatchCommandId = 'search.action.copyMatch';
export const ReplaceActionId = 'search.action.replace';
export const ReplaceAllInFileActionId = 'search.action.replaceAllInFile';
export const ReplaceAllInFolderActionId = 'search.action.replaceAllInFolder';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ import { getMultiSelectedResources } from 'vs/workbench/parts/files/browser/file
import { Schemas } from 'vs/base/common/network';
import { PanelRegistry, Extensions as PanelExtensions, PanelDescriptor } from 'vs/workbench/browser/panel';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { openSearchView, getSearchView, ReplaceAllInFolderAction, ReplaceAllAction, CloseReplaceAction, FocusNextInputAction, FocusPreviousInputAction, FocusNextSearchResultAction, FocusPreviousSearchResultAction, ReplaceInFilesAction, FindInFilesAction, FocusActiveEditorCommand, toggleCaseSensitiveCommand, ShowNextSearchTermAction, ShowPreviousSearchTermAction, toggleRegexCommand, ShowPreviousSearchIncludeAction, ShowNextSearchIncludeAction, CollapseDeepestExpandedLevelAction, toggleWholeWordCommand, RemoveAction, ReplaceAction, ClearSearchResultsAction } from 'vs/workbench/parts/search/browser/searchActions';
import { openSearchView, getSearchView, ReplaceAllInFolderAction, ReplaceAllAction, CloseReplaceAction, FocusNextInputAction, FocusPreviousInputAction, FocusNextSearchResultAction, FocusPreviousSearchResultAction, ReplaceInFilesAction, FindInFilesAction, FocusActiveEditorCommand, toggleCaseSensitiveCommand, ShowNextSearchTermAction, ShowPreviousSearchTermAction, toggleRegexCommand, ShowPreviousSearchIncludeAction, ShowNextSearchIncludeAction, CollapseDeepestExpandedLevelAction, toggleWholeWordCommand, RemoveAction, ReplaceAction, ClearSearchResultsAction, copyPathCommand } from 'vs/workbench/parts/search/browser/searchActions';
import { VIEW_ID, ISearchConfigurationProperties } from 'vs/platform/search/common/search';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { SearchViewLocationUpdater } from 'vs/workbench/parts/search/browser/searchViewLocationUpdater';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';

registerSingleton(ISearchWorkbenchService, SearchWorkbenchService);
replaceContributions();
Expand Down Expand Up @@ -235,6 +235,27 @@ MenuRegistry.appendMenuItem(MenuId.SearchContext, {
order: 2
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
id: Constants.CopyPathCommandId,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
when: Constants.FileFocusKey,
primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_C,
win: {
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_C
},
handler: copyPathCommand
});

MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.CopyPathCommandId,
title: nls.localize('copyPathLabel', "Copy Path")
},
when: Constants.FileFocusKey,
group: 'search',
order: 3
});

CommandsRegistry.registerCommand({
id: Constants.ToggleSearchViewPositionCommandId,
handler: (accessor) => {
Expand All @@ -254,7 +275,7 @@ MenuRegistry.appendMenuItem(MenuId.SearchContext, {
},
when: Constants.SearchViewVisibleKey,
group: 'search_2',
order: 3
order: 1
});

const FIND_IN_FOLDER_ID = 'filesExplorer.findInFolder';
Expand Down

0 comments on commit 1dcb420

Please sign in to comment.