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 19, 2021
1 parent 8bf1697 commit 9eafe03
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 15 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 @@ -30,6 +30,11 @@ export namespace EditorCommands {
const EDITOR_CATEGORY = 'Editor';
const VIEW_CATEGORY = 'View';

export const GOTO_LINE_COLUMN: Command = {
id: 'editor.action.gotoLine',
label: 'Go to line/column'
};

/**
* 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 @@ -122,8 +122,8 @@ export class EditorContribution implements FrontendApplicationContribution, Comm
text: `Ln ${cursor.line + 1}, Col ${editor.getVisibleColumn(cursor)}`,
alignment: StatusBarAlignment.RIGHT,
priority: 100,
tooltip: 'Go To Line',
command: 'editor.action.gotoLine'
tooltip: EditorCommands.GOTO_LINE_COLUMN.label,
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 @@ -41,10 +41,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 @@ -75,15 +89,23 @@ export class EditorMenuContribution implements MenuContribution {
registry.registerSubmenu(EditorMainMenu.GO, 'Go');
registry.registerMenuAction(EditorMainMenu.NAVIGATION_GROUP, {
commandId: EditorCommands.GO_BACK.id,
label: 'Back'
label: 'Back',
order: '1'
});
registry.registerMenuAction(EditorMainMenu.NAVIGATION_GROUP, {
commandId: EditorCommands.GO_FORWARD.id,
label: 'Forward'
label: 'Forward',
order: '2'
});
registry.registerMenuAction(EditorMainMenu.NAVIGATION_GROUP, {
commandId: EditorCommands.GO_LAST_EDIT.id,
label: 'Last Edit Location'
label: '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
13 changes: 11 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,12 @@
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';

@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 +51,14 @@ export class QuickFileOpenFrontendContribution implements QuickAccessContributio
});
}

registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction(EditorMainMenu.WORKSPACE_GROUP, {
commandId: quickFileOpen.id,
label: '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 MenuRegistry = monaco.actions.MenuRegistry;

Expand All @@ -27,6 +27,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 @@ -64,6 +65,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: '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: 'Next Problem',
order: '1'
});
registry.registerMenuAction(MonacoMenus.MARKERS_GROUP, {
commandId: 'editor.action.marker.prevInFiles',
label: 'Previous Problem',
order: '2'
});
}

protected registerPeekSubmenu(registry: MenuModelRegistry): void {
Expand Down
12 changes: 10 additions & 2 deletions packages/monaco/src/browser/workspace-symbol-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import { environment } from '@theia/core/shared/@theia/application-package/lib/e
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 } from '@theia/core/lib/common';
import { CommandRegistry, CommandHandler, Command, SelectionService, CancellationToken, CommandContribution, MenuContribution, MenuModelRegistry } 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 = {
Expand All @@ -53,6 +54,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 @@ -289,7 +289,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 9eafe03

Please sign in to comment.