提交 605b95d3 编写于 作者: B Benjamin Pasero

convert diff actions to commands (for #59346)

上级 a5580c3d
...@@ -12,7 +12,7 @@ import { IEditorQuickOpenEntry, IQuickOpenRegistry, Extensions as QuickOpenExten ...@@ -12,7 +12,7 @@ import { IEditorQuickOpenEntry, IQuickOpenRegistry, Extensions as QuickOpenExten
import { StatusbarItemDescriptor, IStatusbarRegistry, Extensions as StatusExtensions } from 'vs/workbench/browser/parts/statusbar/statusbar'; import { StatusbarItemDescriptor, IStatusbarRegistry, Extensions as StatusExtensions } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar'; import { StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { IEditorRegistry, EditorDescriptor, Extensions as EditorExtensions } from 'vs/workbench/browser/editor'; import { IEditorRegistry, EditorDescriptor, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { EditorInput, IEditorInputFactory, SideBySideEditorInput, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions } from 'vs/workbench/common/editor'; import { EditorInput, IEditorInputFactory, SideBySideEditorInput, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions, TextCompareEditorActiveContext } from 'vs/workbench/common/editor';
import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResourceEditor'; import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResourceEditor';
import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor'; import { SideBySideEditor } from 'vs/workbench/browser/parts/editor/sideBySideEditor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
...@@ -25,7 +25,7 @@ import { BinaryResourceDiffEditor } from 'vs/workbench/browser/parts/editor/bina ...@@ -25,7 +25,7 @@ import { BinaryResourceDiffEditor } from 'vs/workbench/browser/parts/editor/bina
import { ChangeEncodingAction, ChangeEOLAction, ChangeModeAction, EditorStatus } from 'vs/workbench/browser/parts/editor/editorStatus'; import { ChangeEncodingAction, ChangeEOLAction, ChangeModeAction, EditorStatus } from 'vs/workbench/browser/parts/editor/editorStatus';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions'; import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { Scope, IActionBarRegistry, Extensions as ActionBarExtensions, ActionBarContributor } from 'vs/workbench/browser/actions'; import { Scope, IActionBarRegistry, Extensions as ActionBarExtensions, ActionBarContributor } from 'vs/workbench/browser/actions';
import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions'; import { SyncActionDescriptor, MenuRegistry, MenuId, IMenuItem } from 'vs/platform/actions/common/actions';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes'; import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
import { import {
...@@ -443,8 +443,8 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: editorCommands. ...@@ -443,8 +443,8 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, { command: { id: editorCommands.
interface IEditorToolItem { id: string; title: string; iconDark: string; iconLight: string; } interface IEditorToolItem { id: string; title: string; iconDark: string; iconLight: string; }
function appendEditorToolItem(primary: IEditorToolItem, alternative: IEditorToolItem, when: ContextKeyExpr, order: number): void { function appendEditorToolItem(primary: IEditorToolItem, when: ContextKeyExpr, order: number, alternative?: IEditorToolItem): void {
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { const item: IMenuItem = {
command: { command: {
id: primary.id, id: primary.id,
title: primary.title, title: primary.title,
...@@ -453,18 +453,23 @@ function appendEditorToolItem(primary: IEditorToolItem, alternative: IEditorTool ...@@ -453,18 +453,23 @@ function appendEditorToolItem(primary: IEditorToolItem, alternative: IEditorTool
light: URI.parse(require.toUrl(`vs/workbench/browser/parts/editor/media/${primary.iconLight}`)) light: URI.parse(require.toUrl(`vs/workbench/browser/parts/editor/media/${primary.iconLight}`))
} }
}, },
alt: { group: 'navigation',
when,
order
};
if (alternative) {
item.alt = {
id: alternative.id, id: alternative.id,
title: alternative.title, title: alternative.title,
iconLocation: { iconLocation: {
dark: URI.parse(require.toUrl(`vs/workbench/browser/parts/editor/media/${alternative.iconDark}`)), dark: URI.parse(require.toUrl(`vs/workbench/browser/parts/editor/media/${alternative.iconDark}`)),
light: URI.parse(require.toUrl(`vs/workbench/browser/parts/editor/media/${alternative.iconLight}`)) light: URI.parse(require.toUrl(`vs/workbench/browser/parts/editor/media/${alternative.iconLight}`))
} }
}, };
group: 'navigation', }
when,
order MenuRegistry.appendMenuItem(MenuId.EditorTitle, item);
});
} }
// Editor Title Menu: Split Editor // Editor Title Menu: Split Editor
...@@ -474,14 +479,15 @@ appendEditorToolItem( ...@@ -474,14 +479,15 @@ appendEditorToolItem(
title: nls.localize('splitEditorRight', "Split Editor Right"), title: nls.localize('splitEditorRight', "Split Editor Right"),
iconDark: 'split-editor-horizontal-inverse.svg', iconDark: 'split-editor-horizontal-inverse.svg',
iconLight: 'split-editor-horizontal.svg' iconLight: 'split-editor-horizontal.svg'
}, { },
ContextKeyExpr.not('splitEditorsVertically'),
100000, // towards the end
{
id: editorCommands.SPLIT_EDITOR_DOWN, id: editorCommands.SPLIT_EDITOR_DOWN,
title: nls.localize('splitEditorDown', "Split Editor Down"), title: nls.localize('splitEditorDown', "Split Editor Down"),
iconDark: 'split-editor-vertical-inverse.svg', iconDark: 'split-editor-vertical-inverse.svg',
iconLight: 'split-editor-vertical.svg' iconLight: 'split-editor-vertical.svg'
}, }
ContextKeyExpr.not('splitEditorsVertically'),
100000 /* towards the end */
); );
appendEditorToolItem( appendEditorToolItem(
...@@ -490,14 +496,15 @@ appendEditorToolItem( ...@@ -490,14 +496,15 @@ appendEditorToolItem(
title: nls.localize('splitEditorDown', "Split Editor Down"), title: nls.localize('splitEditorDown', "Split Editor Down"),
iconDark: 'split-editor-vertical-inverse.svg', iconDark: 'split-editor-vertical-inverse.svg',
iconLight: 'split-editor-vertical.svg' iconLight: 'split-editor-vertical.svg'
}, { },
ContextKeyExpr.has('splitEditorsVertically'),
100000, // towards the end
{
id: editorCommands.SPLIT_EDITOR_RIGHT, id: editorCommands.SPLIT_EDITOR_RIGHT,
title: nls.localize('splitEditorRight', "Split Editor Right"), title: nls.localize('splitEditorRight', "Split Editor Right"),
iconDark: 'split-editor-horizontal-inverse.svg', iconDark: 'split-editor-horizontal-inverse.svg',
iconLight: 'split-editor-horizontal.svg' iconLight: 'split-editor-horizontal.svg'
}, }
ContextKeyExpr.has('splitEditorsVertically'),
100000 // towards the end
); );
// Editor Title Menu: Close Group (tabs disabled) // Editor Title Menu: Close Group (tabs disabled)
...@@ -507,14 +514,15 @@ appendEditorToolItem( ...@@ -507,14 +514,15 @@ appendEditorToolItem(
title: nls.localize('close', "Close"), title: nls.localize('close', "Close"),
iconDark: 'close-big-inverse-alt.svg', iconDark: 'close-big-inverse-alt.svg',
iconLight: 'close-big-alt.svg' iconLight: 'close-big-alt.svg'
}, { },
ContextKeyExpr.and(ContextKeyExpr.not('config.workbench.editor.showTabs'), ContextKeyExpr.not('groupActiveEditorDirty')),
1000000, // towards the far end
{
id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID, id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID,
title: nls.localize('closeAll', "Close All"), title: nls.localize('closeAll', "Close All"),
iconDark: 'closeall-editors-inverse.svg', iconDark: 'closeall-editors-inverse.svg',
iconLight: 'closeall-editors.svg' iconLight: 'closeall-editors.svg'
}, }
ContextKeyExpr.and(ContextKeyExpr.not('config.workbench.editor.showTabs'), ContextKeyExpr.not('groupActiveEditorDirty')),
1000000 // towards the end
); );
appendEditorToolItem( appendEditorToolItem(
...@@ -523,14 +531,39 @@ appendEditorToolItem( ...@@ -523,14 +531,39 @@ appendEditorToolItem(
title: nls.localize('close', "Close"), title: nls.localize('close', "Close"),
iconDark: 'close-dirty-inverse-alt.svg', iconDark: 'close-dirty-inverse-alt.svg',
iconLight: 'close-dirty-alt.svg' iconLight: 'close-dirty-alt.svg'
}, { },
ContextKeyExpr.and(ContextKeyExpr.not('config.workbench.editor.showTabs'), ContextKeyExpr.has('groupActiveEditorDirty')),
1000000, // towards the far end
{
id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID, id: editorCommands.CLOSE_EDITORS_IN_GROUP_COMMAND_ID,
title: nls.localize('closeAll', "Close All"), title: nls.localize('closeAll', "Close All"),
iconDark: 'closeall-editors-inverse.svg', iconDark: 'closeall-editors-inverse.svg',
iconLight: 'closeall-editors.svg' iconLight: 'closeall-editors.svg'
}
);
// Diff Editor Title Menu: Previous Change
appendEditorToolItem(
{
id: editorCommands.GOTO_PREVIOUS_CHANGE,
title: nls.localize('navigate.prev.label', "Previous Change"),
iconDark: 'previous-diff-inverse.svg',
iconLight: 'previous-diff.svg'
}, },
ContextKeyExpr.and(ContextKeyExpr.not('config.workbench.editor.showTabs'), ContextKeyExpr.has('groupActiveEditorDirty')), TextCompareEditorActiveContext,
1000000 // towards the end 10
);
// Diff Editor Title Menu: Next Change
appendEditorToolItem(
{
id: editorCommands.GOTO_NEXT_CHANGE,
title: nls.localize('navigate.next.label', "Next Change"),
iconDark: 'next-diff-inverse.svg',
iconLight: 'next-diff.svg'
},
TextCompareEditorActiveContext,
11
); );
// Editor Commands for Command Palette // Editor Commands for Command Palette
......
...@@ -37,7 +37,10 @@ export const MOVE_ACTIVE_EDITOR_COMMAND_ID = 'moveActiveEditor'; ...@@ -37,7 +37,10 @@ export const MOVE_ACTIVE_EDITOR_COMMAND_ID = 'moveActiveEditor';
export const LAYOUT_EDITOR_GROUPS_COMMAND_ID = 'layoutEditorGroups'; export const LAYOUT_EDITOR_GROUPS_COMMAND_ID = 'layoutEditorGroups';
export const KEEP_EDITOR_COMMAND_ID = 'workbench.action.keepEditor'; export const KEEP_EDITOR_COMMAND_ID = 'workbench.action.keepEditor';
export const SHOW_EDITORS_IN_GROUP = 'workbench.action.showEditorsInGroup'; export const SHOW_EDITORS_IN_GROUP = 'workbench.action.showEditorsInGroup';
export const TOGGLE_DIFF_SIDE_BY_SIDE = 'toggle.diff.renderSideBySide'; export const TOGGLE_DIFF_SIDE_BY_SIDE = 'toggle.diff.renderSideBySide';
export const GOTO_NEXT_CHANGE = 'workbench.action.compareEditor.nextChange';
export const GOTO_PREVIOUS_CHANGE = 'workbench.action.compareEditor.previousChange';
export const SPLIT_EDITOR_UP = 'workbench.action.splitEditorUp'; export const SPLIT_EDITOR_UP = 'workbench.action.splitEditorUp';
export const SPLIT_EDITOR_DOWN = 'workbench.action.splitEditorDown'; export const SPLIT_EDITOR_DOWN = 'workbench.action.splitEditorDown';
...@@ -224,7 +227,7 @@ export function mergeAllGroups(editorGroupService: IEditorGroupsService): void { ...@@ -224,7 +227,7 @@ export function mergeAllGroups(editorGroupService: IEditorGroupsService): void {
function registerDiffEditorCommands(): void { function registerDiffEditorCommands(): void {
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.compareEditor.nextChange', id: GOTO_NEXT_CHANGE,
weight: KeybindingWeight.WorkbenchContrib, weight: KeybindingWeight.WorkbenchContrib,
when: TextCompareEditorVisibleContext, when: TextCompareEditorVisibleContext,
primary: KeyMod.Alt | KeyCode.F5, primary: KeyMod.Alt | KeyCode.F5,
...@@ -232,7 +235,7 @@ function registerDiffEditorCommands(): void { ...@@ -232,7 +235,7 @@ function registerDiffEditorCommands(): void {
}); });
KeybindingsRegistry.registerCommandAndKeybindingRule({ KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'workbench.action.compareEditor.previousChange', id: GOTO_PREVIOUS_CHANGE,
weight: KeybindingWeight.WorkbenchContrib, weight: KeybindingWeight.WorkbenchContrib,
when: TextCompareEditorVisibleContext, when: TextCompareEditorVisibleContext,
primary: KeyMod.Alt | KeyMod.Shift | KeyCode.F5, primary: KeyMod.Alt | KeyMod.Shift | KeyCode.F5,
......
...@@ -3,24 +3,6 @@ ...@@ -3,24 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
.vs .monaco-workbench .textdiff-editor-action.next {
background: url('next-diff.svg') center center no-repeat;
}
.vs .monaco-workbench .textdiff-editor-action.previous {
background: url('previous-diff.svg') center center no-repeat;
}
.vs-dark .monaco-workbench .textdiff-editor-action.next,
.hc-black .monaco-workbench .textdiff-editor-action.next {
background: url('next-diff-inverse.svg') center center no-repeat;
}
.vs-dark .monaco-workbench .textdiff-editor-action.previous,
.hc-black .monaco-workbench .textdiff-editor-action.previous {
background: url('previous-diff-inverse.svg') center center no-repeat;
}
.vs .monaco-workbench .textdiff-editor-action.toggleIgnoreTrimWhitespace { .vs .monaco-workbench .textdiff-editor-action.toggleIgnoreTrimWhitespace {
opacity: 1; opacity: 1;
background: url('paragraph.svg') center center no-repeat; background: url('paragraph.svg') center center no-repeat;
......
...@@ -48,8 +48,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { ...@@ -48,8 +48,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
private diffNavigator: DiffNavigator; private diffNavigator: DiffNavigator;
private diffNavigatorDisposables: IDisposable[] = []; private diffNavigatorDisposables: IDisposable[] = [];
private nextDiffAction: NavigateAction;
private previousDiffAction: NavigateAction;
private toggleIgnoreTrimWhitespaceAction: ToggleIgnoreTrimWhitespaceAction; private toggleIgnoreTrimWhitespaceAction: ToggleIgnoreTrimWhitespaceAction;
constructor( constructor(
...@@ -88,8 +86,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { ...@@ -88,8 +86,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
createEditorControl(parent: HTMLElement, configuration: ICodeEditorOptions): IDiffEditor { createEditorControl(parent: HTMLElement, configuration: ICodeEditorOptions): IDiffEditor {
// Actions // Actions
this.nextDiffAction = new NavigateAction(this, true);
this.previousDiffAction = new NavigateAction(this, false);
this.toggleIgnoreTrimWhitespaceAction = new ToggleIgnoreTrimWhitespaceAction(this._actualConfigurationService); this.toggleIgnoreTrimWhitespaceAction = new ToggleIgnoreTrimWhitespaceAction(this._actualConfigurationService);
this.updateIgnoreTrimWhitespaceAction(); this.updateIgnoreTrimWhitespaceAction();
...@@ -141,11 +137,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { ...@@ -141,11 +137,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
}); });
this.diffNavigatorDisposables.push(this.diffNavigator); this.diffNavigatorDisposables.push(this.diffNavigator);
this.diffNavigatorDisposables.push(this.diffNavigator.onDidUpdate(() => {
this.nextDiffAction.updateEnablement();
this.previousDiffAction.updateEnablement();
}));
// Enablement of actions // Enablement of actions
this.updateIgnoreTrimWhitespaceAction(); this.updateIgnoreTrimWhitespaceAction();
...@@ -294,9 +285,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { ...@@ -294,9 +285,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
getActions(): IAction[] { getActions(): IAction[] {
return [ return [
this.toggleIgnoreTrimWhitespaceAction, this.toggleIgnoreTrimWhitespaceAction
this.previousDiffAction,
this.nextDiffAction
]; ];
} }
...@@ -384,39 +373,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { ...@@ -384,39 +373,6 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor {
} }
} }
class NavigateAction extends Action {
static ID_NEXT = 'workbench.action.compareEditor.nextChange';
static ID_PREV = 'workbench.action.compareEditor.previousChange';
private editor: TextDiffEditor;
private next: boolean;
constructor(editor: TextDiffEditor, next: boolean) {
super(next ? NavigateAction.ID_NEXT : NavigateAction.ID_PREV);
this.editor = editor;
this.next = next;
this.label = this.next ? nls.localize('navigate.next.label', "Next Change") : nls.localize('navigate.prev.label', "Previous Change");
this.class = this.next ? 'textdiff-editor-action next' : 'textdiff-editor-action previous';
this.enabled = false;
}
run(): TPromise<any> {
if (this.next) {
this.editor.getDiffNavigator().next();
} else {
this.editor.getDiffNavigator().previous();
}
return null;
}
updateEnablement(): void {
this.enabled = this.editor.getDiffNavigator().canNavigate();
}
}
class ToggleIgnoreTrimWhitespaceAction extends Action { class ToggleIgnoreTrimWhitespaceAction extends Action {
static ID = 'workbench.action.compareEditor.toggleIgnoreTrimWhitespace'; static ID = 'workbench.action.compareEditor.toggleIgnoreTrimWhitespace';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册