提交 6294fa20 编写于 作者: R Rob Lourens

PR feedback

上级 e42c6630
......@@ -9,7 +9,7 @@ import * as DOM from 'vs/base/browser/dom';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { IAction, IActionRunner } from 'vs/base/common/actions';
import { ActionBar, ActionItem, Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
import { FileLabel } from 'vs/workbench/browser/labels';
import { ITree, IDataSource, ISorter, IAccessibilityProvider, IFilter, IRenderer, ContextMenuEvent } from 'vs/base/parts/tree/browser/tree';
......@@ -25,9 +25,9 @@ import { getPathLabel } from 'vs/base/common/labels';
import { FileKind } from 'vs/platform/files/common/files';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
import { WorkbenchTreeController, WorkbenchTree } from 'vs/platform/list/browser/listService';
import { fillInActions } from 'vs/platform/actions/browser/menuItemActionItem';
export class SearchDataSource implements IDataSource {
......@@ -361,61 +361,35 @@ export class SearchFilter implements IFilter {
}
export class SearchTreeController extends WorkbenchTreeController {
private contextMenu: IMenu;
constructor(
@IContextMenuService private contextMenuService: IContextMenuService,
@IMenuService private menuService: IMenuService,
@IKeybindingService private readonly _keybindingService: IKeybindingService,
@IConfigurationService configurationService: IConfigurationService
) {
super({}, configurationService);
}
public onContextMenu(tree: WorkbenchTree, element: any, event: ContextMenuEvent): boolean {
tree.setFocus(element);
const actions = this._getMenuActions(tree);
if (!actions.length) {
return true;
if (!this.contextMenu) {
this.contextMenu = this.menuService.createMenu(MenuId.SearchContext, tree.contextKeyService);
}
tree.setFocus(element);
const anchor = { x: event.posx, y: event.posy };
this.contextMenuService.showContextMenu({
getAnchor: () => anchor,
getActions: () => {
const actions: IAction[] = [];
fillInActions(this.contextMenu, { shouldForwardArgs: true }, actions, this.contextMenuService);
return TPromise.as(actions);
},
getActionItem: (action) => {
const keybinding = this._keybindingService.lookupKeybinding(action.id);
if (keybinding) {
return new ActionItem(action, action, { label: true, keybinding: keybinding.getLabel() });
}
return null;
},
onHide: (wasCancelled?: boolean) => {
if (wasCancelled) {
tree.domFocus();
}
}
// getActionsContext: () => element instanceof OpenEditor ? { groupId: element.group.id, editorIndex: element.editorIndex } : { groupId: element.id }
});
return true;
}
private _getMenuActions(tree: WorkbenchTree): IAction[] {
const result: IAction[] = [];
const menu = this.menuService.createMenu(MenuId.SearchContext, tree.contextKeyService);
const groups = menu.getActions();
menu.dispose();
for (let group of groups) {
const [, actions] = group;
result.push(...actions);
result.push(new Separator());
}
result.pop(); // remove last separator
return result;
}
}
......@@ -528,7 +528,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
if (treeHasFocus) {
const focus = e.focus;
this.firstMatchFocused.set(this.tree.getNavigator().first() === focus);
this.fileMatchOrMatchFocused.set(true);
this.fileMatchOrMatchFocused.set(!!focus);
this.fileMatchFocused.set(focus instanceof FileMatch);
this.folderMatchFocused.set(focus instanceof FolderMatch);
this.matchFocused.set(focus instanceof Match);
......
......@@ -126,15 +126,6 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.RemoveActionId,
title: RemoveAction.LABEL
},
when: Constants.FileMatchOrMatchFocusKey,
group: 'search'
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: Constants.ReplaceActionId,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
......@@ -148,15 +139,6 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.ReplaceActionId,
title: ReplaceAction.LABEL
},
when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.MatchFocusKey),
group: 'search'
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: Constants.ReplaceAllInFileActionId,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
......@@ -169,15 +151,6 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.ReplaceAllInFileActionId,
title: ReplaceAllAction.LABEL
},
when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.FileFocusKey),
group: 'search'
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: Constants.ReplaceAllInFolderActionId,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
......@@ -190,15 +163,6 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.ReplaceAllInFolderActionId,
title: ReplaceAllInFolderAction.LABEL
},
when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.FolderFocusKey),
group: 'search'
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: Constants.CloseReplaceWidgetActionId,
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
......@@ -229,6 +193,46 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.ReplaceActionId,
title: ReplaceAction.LABEL
},
when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.MatchFocusKey),
group: 'search',
order: 1
});
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.ReplaceAllInFolderActionId,
title: ReplaceAllInFolderAction.LABEL
},
when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.FolderFocusKey),
group: 'search',
order: 1
});
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.ReplaceAllInFileActionId,
title: ReplaceAllAction.LABEL
},
when: ContextKeyExpr.and(Constants.ReplaceActiveKey, Constants.FileFocusKey),
group: 'search',
order: 1
});
MenuRegistry.appendMenuItem(MenuId.SearchContext, {
command: {
id: Constants.RemoveActionId,
title: RemoveAction.LABEL
},
when: Constants.FileMatchOrMatchFocusKey,
group: 'search',
order: 2
});
const FIND_IN_FOLDER_ID = 'filesExplorer.findInFolder';
CommandsRegistry.registerCommand({
id: FIND_IN_FOLDER_ID,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册