Skip to content

Commit

Permalink
menu: update go main-menu
Browse files Browse the repository at this point in the history
The commit updates the `go` main-menu to add missing items used for
navigation, location, language-features and problems.

Signed-off-by: vince-fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Oct 22, 2021
1 parent c12d1ef commit 5c57057
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 16 deletions.
5 changes: 5 additions & 0 deletions packages/editor/src/browser/editor-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export namespace EditorCommands {
const EDITOR_CATEGORY_KEY = 'vscode/textEditor/editor';
const EDITOR_CATEGORY = 'Editor';

export const GOTO_LINE_COLUMN = Command.toLocalizedCommand({
id: 'editor.action.gotoLine',
label: 'Go to Line/Column'
}, 'vscode/gotoLineQuickAccess/gotoLineQuickAccess');

/**
* Show editor references
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/browser/editor-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export class EditorContribution implements FrontendApplicationContribution, Comm
text: nls.localize('vscode/editorStatus/singleSelection', 'Ln {0}, Col {1}', (cursor.line + 1).toString(), editor.getVisibleColumn(cursor).toString()),
alignment: StatusBarAlignment.RIGHT,
priority: 100,
tooltip: nls.localize('vscode/editorStatus/gotoLine', 'Go To Line'),
command: 'editor.action.gotoLine'
tooltip: nls.localize('vscode/editorStatus/gotoLine', 'Go to Line/Column'),
command: EditorCommands.GOTO_LINE_COLUMN.id
});
}

Expand Down
30 changes: 26 additions & 4 deletions packages/editor/src/browser/editor-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,24 @@ export namespace EditorMainMenu {
export const GO = [...MAIN_MENU_BAR, '5_go'];

/**
* Navigation menu group in the `Go` menu.
* Navigation menu group in the `Go` main-menu.
*/
export const NAVIGATION_GROUP = [...GO, '1_navigation_group'];

/**
* Workspace menu group in the `Go` main-menu.
*/
export const WORKSPACE_GROUP = [...GO, '2_workspace_group'];

/**
* Language features menu group in the `Go` main-menu.
*/
export const LANGUAGE_FEATURES_GROUP = [...GO, '3_language_features_group'];

/**
* Location menu group in the `Go` main-menu.
*/
export const LOCATION_GROUP = [...GO, '4_locations'];
}

@injectable()
Expand Down Expand Up @@ -76,15 +90,23 @@ export class EditorMenuContribution implements MenuContribution {
registry.registerSubmenu(EditorMainMenu.GO, nls.localize('vscode/menubar/mGoto', 'Go'));
registry.registerMenuAction(EditorMainMenu.NAVIGATION_GROUP, {
commandId: EditorCommands.GO_BACK.id,
label: EditorCommands.GO_BACK.label
label: EditorCommands.GO_BACK.label,
order: '1'
});
registry.registerMenuAction(EditorMainMenu.NAVIGATION_GROUP, {
commandId: EditorCommands.GO_FORWARD.id,
label: EditorCommands.GO_FORWARD.label
label: EditorCommands.GO_FORWARD.label,
order: '2'
});
registry.registerMenuAction(EditorMainMenu.NAVIGATION_GROUP, {
commandId: EditorCommands.GO_LAST_EDIT.id,
label: EditorCommands.GO_LAST_EDIT.label
label: nls.localize('vscode/editor.contribution/miLastEditLocation', 'Last Edit Location'),
order: '3'
});

registry.registerMenuAction(EditorMainMenu.LOCATION_GROUP, {
commandId: EditorCommands.GOTO_LINE_COLUMN.id,
order: '1'
});

// Toggle Commands.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
import { CommandContribution } from '@theia/core/lib/common';
import { CommandContribution, MenuContribution } from '@theia/core/lib/common';
import { WebSocketConnectionProvider, KeybindingContribution } from '@theia/core/lib/browser';
import { QuickFileOpenFrontendContribution } from './quick-file-open-contribution';
import { QuickFileOpenService } from './quick-file-open';
Expand All @@ -29,7 +29,7 @@ export default new ContainerModule((bind: interfaces.Bind) => {
}).inSingletonScope();

bind(QuickFileOpenFrontendContribution).toSelf().inSingletonScope();
[CommandContribution, KeybindingContribution, QuickAccessContribution].forEach(serviceIdentifier =>
[CommandContribution, KeybindingContribution, MenuContribution, QuickAccessContribution].forEach(serviceIdentifier =>
bind(serviceIdentifier).toService(QuickFileOpenFrontendContribution)
);

Expand Down
14 changes: 12 additions & 2 deletions packages/file-search/src/browser/quick-file-open-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import { injectable, inject } from '@theia/core/shared/inversify';
import URI from '@theia/core/lib/common/uri';
import { QuickFileOpenService, quickFileOpen } from './quick-file-open';
import { CommandRegistry, CommandContribution } from '@theia/core/lib/common';
import { CommandRegistry, CommandContribution, MenuContribution, MenuModelRegistry } from '@theia/core/lib/common';
import { KeybindingRegistry, KeybindingContribution, QuickAccessContribution } from '@theia/core/lib/browser';
import { EditorMainMenu } from '@theia/editor/lib/browser';
import { nls } from '@theia/core/lib/common/nls';

@injectable()
export class QuickFileOpenFrontendContribution implements QuickAccessContribution, CommandContribution, KeybindingContribution {
export class QuickFileOpenFrontendContribution implements QuickAccessContribution, CommandContribution, KeybindingContribution, MenuContribution {

@inject(QuickFileOpenService)
protected readonly quickFileOpenService: QuickFileOpenService;
Expand Down Expand Up @@ -50,6 +52,14 @@ export class QuickFileOpenFrontendContribution implements QuickAccessContributio
});
}

registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction(EditorMainMenu.WORKSPACE_GROUP, {
commandId: quickFileOpen.id,
label: nls.localize('vscode/quickAccessAction/quickOpen', 'Go to File...'),
order: '1',
});
}

registerQuickAccessProvider(): void {
this.quickFileOpenService.registerQuickAccessProvider();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco/src/browser/monaco-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(MonacoLanguages).toSelf().inSingletonScope();
rebind(LanguageService).toService(MonacoLanguages);
bind(WorkspaceSymbolCommand).toSelf().inSingletonScope();
for (const identifier of [CommandContribution, KeybindingContribution, QuickAccessContribution]) {
for (const identifier of [CommandContribution, KeybindingContribution, MenuContribution, QuickAccessContribution]) {
bind(identifier).toService(WorkspaceSymbolCommand);
}

Expand Down
47 changes: 46 additions & 1 deletion packages/monaco/src/browser/monaco-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { injectable, inject } from '@theia/core/shared/inversify';
import { MenuContribution, MenuModelRegistry, MAIN_MENU_BAR, MenuPath } from '@theia/core/lib/common';
import { EDITOR_CONTEXT_MENU } from '@theia/editor/lib/browser';
import { EditorMainMenu, EDITOR_CONTEXT_MENU } from '@theia/editor/lib/browser';
import { MonacoCommandRegistry } from './monaco-command-registry';
import { nls } from '@theia/core/lib/common/nls';
import MenuRegistry = monaco.actions.MenuRegistry;
Expand All @@ -28,6 +28,7 @@ export interface MonacoActionGroup {
export namespace MonacoMenus {
export const SELECTION = [...MAIN_MENU_BAR, '3_selection'];
export const PEEK_CONTEXT_SUBMENU: MenuPath = [...EDITOR_CONTEXT_MENU, 'navigation', 'peek_submenu'];
export const MARKERS_GROUP = [...EditorMainMenu.GO, '5_markers_group'];
}

@injectable()
Expand Down Expand Up @@ -65,6 +66,50 @@ export class MonacoEditorMenuContribution implements MenuContribution {
registry.registerMenuAction(menuPath, { commandId, order, label });
}
}

// Builtin monaco language-features commands.
registry.registerMenuAction(EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.quickOutline',
label: nls.localize('vscode/gotoSymbolQuickAccess/gotoSymbol', 'Go to Symbol in Editor...'),
order: '1'
});
registry.registerMenuAction(EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.revealDefinition',
order: '2'
});
registry.registerMenuAction(EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.revealDeclaration',
order: '3'
});
registry.registerMenuAction(EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.goToTypeDefinition',
order: '4'
});
registry.registerMenuAction(EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.goToImplementation',
order: '5'
});
registry.registerMenuAction(EditorMainMenu.LANGUAGE_FEATURES_GROUP, {
commandId: 'editor.action.goToReferences',
order: '6'
});

registry.registerMenuAction(EditorMainMenu.LOCATION_GROUP, {
commandId: 'editor.action.jumpToBracket',
order: '2'
});

// Builtin monaco problem commands.
registry.registerMenuAction(MonacoMenus.MARKERS_GROUP, {
commandId: 'editor.action.marker.nextInFiles',
label: nls.localize('vscode/gotoError/miGotoNextProblem', 'Next Problem'),
order: '1'
});
registry.registerMenuAction(MonacoMenus.MARKERS_GROUP, {
commandId: 'editor.action.marker.prevInFiles',
label: nls.localize('vscode/gotoError/miGotoPreviousProblem', 'Previous Problem'),
order: '2'
});
}

protected registerPeekSubmenu(registry: MenuModelRegistry): void {
Expand Down
16 changes: 13 additions & 3 deletions packages/monaco/src/browser/workspace-symbol-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
import { injectable, inject } from '@theia/core/shared/inversify';
import { environment } from '@theia/core/shared/@theia/application-package/lib/environment';
import { KeybindingContribution, KeybindingRegistry, OpenerService, LabelProvider } from '@theia/core/lib/browser';

import { QuickAccessContribution, QuickAccessProvider, QuickInputService, QuickAccessRegistry, QuickPicks, QuickPickItem, findMatches } from '@theia/core/lib/browser/quick-input';
import { CommandRegistry, CommandHandler, Command, SelectionService, CancellationToken, CommandContribution, nls } from '@theia/core/lib/common';
import {
CommandRegistry, CommandHandler, Command, SelectionService, CancellationToken,
CommandContribution, MenuContribution, MenuModelRegistry, nls
} from '@theia/core/lib/common';
import { Range, Position, SymbolInformation } from '@theia/core/shared/vscode-languageserver-types';
import { WorkspaceSymbolParams } from '@theia/core/shared/vscode-languageserver-protocol';
import { MonacoLanguages, WorkspaceSymbolProvider } from './monaco-languages';
import URI from '@theia/core/lib/common/uri';
import { EditorMainMenu } from '@theia/editor/lib/browser';

@injectable()
export class WorkspaceSymbolCommand implements QuickAccessProvider, CommandContribution, KeybindingContribution, CommandHandler, QuickAccessContribution {
export class WorkspaceSymbolCommand implements QuickAccessProvider, CommandContribution, KeybindingContribution, MenuContribution, CommandHandler, QuickAccessContribution {
public static readonly PREFIX = '#';

private command = Command.toLocalizedCommand({
Expand All @@ -53,6 +56,13 @@ export class WorkspaceSymbolCommand implements QuickAccessProvider, CommandContr
commands.registerCommand(this.command, this);
}

registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction(EditorMainMenu.WORKSPACE_GROUP, {
commandId: this.command.id,
order: '2'
});
}

private isElectron(): boolean {
return environment.electron.is();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
execute: () => commands.executeCommand(WorkspaceCommands.ADD_FOLDER.id)
});
commands.registerCommand({ id: 'workbench.action.gotoLine' }, {
execute: () => commands.executeCommand('editor.action.gotoLine')
execute: () => commands.executeCommand(EditorCommands.GOTO_LINE_COLUMN.id)
});
commands.registerCommand({ id: 'workbench.action.quickOpen' }, {
execute: (prefix?: unknown) => this.quickInput.open(typeof prefix === 'string' ? prefix : '')
Expand Down

0 comments on commit 5c57057

Please sign in to comment.