Skip to content

Commit

Permalink
core: added appearance and editor layout sub-menus
Browse files Browse the repository at this point in the history
This commit adds an `appearance` and `editor` sub-menus into the `view` menu.
Adding multiple options within each sub-menu, mainly to alter the
appearance of the editor.
  • Loading branch information
Archie27376 committed Dec 15, 2021
1 parent 6ab451e commit 0bd86b2
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 23 deletions.
57 changes: 43 additions & 14 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ export namespace CommonMenus {

export const VIEW = [...MAIN_MENU_BAR, '4_view'];
export const VIEW_PRIMARY = [...VIEW, '0_primary'];
export const VIEW_VIEWS = [...VIEW, '1_views'];
export const VIEW_LAYOUT = [...VIEW, '2_layout'];
export const VIEW_TOGGLE = [...VIEW, '3_toggle'];
export const VIEW_APPEARANCE = [...VIEW, '1_appearance'];
export const VIEW_APPEARANCE_SUBMENU = [...VIEW_APPEARANCE, '1_appearance_submenu'];
export const VIEW_APPEARANCE_SUBMENU_SCREEN = [...VIEW_APPEARANCE_SUBMENU, '2_appearance_submenu_screen'];
export const VIEW_APPEARANCE_SUBMENU_BAR = [...VIEW_APPEARANCE_SUBMENU, '3_appearance_submenu_bar'];
export const VIEW_EDITOR_SUBMENU = [...VIEW_APPEARANCE, '2_editor_submenu'];
export const VIEW_EDITOR_SUBMENU_SPLIT = [...VIEW_EDITOR_SUBMENU, '1_editor_submenu_split'];
export const VIEW_EDITOR_SUBMENU_ORTHO = [...VIEW_EDITOR_SUBMENU, '2_editor_submenu_ortho'];
export const VIEW_VIEWS = [...VIEW, '2_views'];
export const VIEW_LAYOUT = [...VIEW, '3_layout'];
export const VIEW_TOGGLE = [...VIEW, '4_toggle'];

export const SETTINGS_OPEN = [...SETTINGS_MENU, '1_settings_open'];
export const SETTINGS__THEME = [...SETTINGS_MENU, '2_settings_theme'];

// last menu item
export const HELP = [...MAIN_MENU_BAR, '9_help'];

Expand Down Expand Up @@ -244,6 +250,11 @@ export namespace CommonCommands {
category: VIEW_CATEGORY,
label: 'Open View...'
});
export const SHOW_MENU_BAR = Command.toDefaultLocalizedCommand({
id: 'window.menuBarVisibility',
category: VIEW_CATEGORY,
label: 'Show Menu Bar'
});

export const SAVE = Command.toDefaultLocalizedCommand({
id: 'core.save',
Expand Down Expand Up @@ -293,7 +304,6 @@ export namespace CommonCommands {
id: 'workbench.action.configureLanguage',
label: 'Configure Display Language'
});

}

export const supportCut = browser.isNative || document.queryCommandSupported('cut');
Expand Down Expand Up @@ -543,18 +553,18 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
order: '3'
});

registry.registerMenuAction(CommonMenus.VIEW_LAYOUT, {
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, {
commandId: CommonCommands.TOGGLE_BOTTOM_PANEL.id,
order: '0'
order: '1'
});
registry.registerMenuAction(CommonMenus.VIEW_LAYOUT, {
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, {
commandId: CommonCommands.TOGGLE_STATUS_BAR.id,
order: '1',
label: 'Toggle Status Bar'
order: '2',
label: nls.localizeByDefault('Toggle Status Bar Visibility')
});
registry.registerMenuAction(CommonMenus.VIEW_LAYOUT, {
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, {
commandId: CommonCommands.COLLAPSE_ALL_PANELS.id,
order: '2'
order: '3'
});

registry.registerMenuAction(SHELL_TABBAR_CONTEXT_CLOSE, {
Expand Down Expand Up @@ -587,7 +597,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
label: CommonCommands.COLLAPSE_PANEL.label,
order: '5'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_SPLIT, {
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_SCREEN, {
commandId: CommonCommands.TOGGLE_MAXIMIZED.id,
label: CommonCommands.TOGGLE_MAXIMIZED.label,
order: '6'
Expand All @@ -597,6 +607,11 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
label: CommonCommands.COPY_PATH.label,
order: '1',
});
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_BAR, {
commandId: CommonCommands.SHOW_MENU_BAR.id,
label: nls.localizeByDefault('Toggle Menu Bar'),
order: '0'
});
registry.registerMenuAction(CommonMenus.HELP, {
commandId: CommonCommands.ABOUT_COMMAND.id,
label: CommonCommands.ABOUT_COMMAND.label,
Expand All @@ -620,6 +635,8 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
registry.registerMenuAction(CommonMenus.SETTINGS__THEME, {
commandId: CommonCommands.SELECT_ICON_THEME.id
});

registry.registerSubmenu(CommonMenus.VIEW_APPEARANCE_SUBMENU, nls.localizeByDefault('Appearance'));
}

registerCommands(commandRegistry: CommandRegistry): void {
Expand Down Expand Up @@ -799,7 +816,19 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
isVisible: title => Boolean(title?.owner && this.shell.canToggleMaximized(title?.owner)),
execute: title => title?.owner && this.shell.toggleMaximized(title?.owner),
}));

commandRegistry.registerCommand(CommonCommands.SHOW_MENU_BAR, {
isEnabled: () => !isOSX,
isVisible: () => !isOSX,
execute: () => {
const menuBarVisibility = 'window.menuBarVisibility';
const visibility = this.preferences[menuBarVisibility];
if (visibility !== 'compact') {
this.preferenceService.updateValue(menuBarVisibility, 'compact');
} else {
this.preferenceService.updateValue(menuBarVisibility, 'classic');
}
}
});
commandRegistry.registerCommand(CommonCommands.SAVE, {
execute: () => this.shell.save({ formatType: FormatType.ON })
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export namespace ElectronCommands {

export namespace ElectronMenus {
export const VIEW_WINDOW = [...CommonMenus.VIEW, 'window'];
export const VIEW_ZOOM = [...CommonMenus.VIEW, 'zoom'];
export const VIEW_ZOOM = [...CommonMenus.VIEW_APPEARANCE_SUBMENU, '4_appearance_submenu_zoom'];
}

export namespace ElectronMenus {
Expand Down Expand Up @@ -364,5 +364,10 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
registry.registerMenuAction(ElectronMenus.FILE_CLOSE, {
commandId: ElectronCommands.CLOSE_WINDOW.id,
});
registry.registerMenuAction(CommonMenus.VIEW_APPEARANCE_SUBMENU_SCREEN, {
commandId: ElectronCommands.TOGGLE_FULL_SCREEN.id,
label: nls.localizeByDefault('Full Screen'),
order: '0'
});
}
}
16 changes: 8 additions & 8 deletions packages/editor/src/browser/editor-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ export class EditorContribution implements FrontendApplicationContribution, Comm
commands.registerCommand(EditorCommands.SHOW_ALL_OPENED_EDITORS, {
execute: () => this.quickInputService?.open('edt ')
});
const splitHandlerFactory = (splitMode: DockLayout.InsertMode): CommandHandler => new CurrentWidgetCommandAdapter(this.shell, {
isEnabled: title => title?.owner instanceof EditorWidget,
isVisible: title => title?.owner instanceof EditorWidget,
execute: async title => {
if (title?.owner instanceof EditorWidget) {
const selection = title.owner.editor.selection;
const newEditor = await this.editorManager.openToSide(title.owner.editor.uri, { selection, widgetOptions: { mode: splitMode, ref: title.owner } });
const oldEditorState = title.owner.editor.storeViewState();
const splitHandlerFactory = (splitMode: DockLayout.InsertMode): CommandHandler => ({
isEnabled: () => !!this.editorManager.currentEditor,
execute: async () => {
const { currentEditor } = this.editorManager;
if (currentEditor) {
const selection = currentEditor.editor.selection;
const newEditor = await this.editorManager.openToSide(currentEditor.editor.uri, { selection, widgetOptions: { mode: splitMode } });
const oldEditorState = currentEditor.editor.storeViewState();
newEditor.editor.restoreViewState(oldEditorState);
}
}
Expand Down
37 changes: 37 additions & 0 deletions packages/editor/src/browser/editor-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,43 @@ export class EditorMenuContribution implements MenuContribution {
label: nls.localizeByDefault('Close Editor'),
order: '1'
});
registry.registerMenuAction(CommonMenus.VIEW_EDITOR_SUBMENU_SPLIT, {
commandId: EditorCommands.SPLIT_EDITOR_RIGHT.id,
label: nls.localizeByDefault('Split Editor Right'),
order: '0'
});

registry.registerMenuAction(CommonMenus.VIEW_EDITOR_SUBMENU_SPLIT, {
commandId: EditorCommands.SPLIT_EDITOR_LEFT.id,
label: nls.localizeByDefault('Split Editor Left'),
order: '1'
});

registry.registerMenuAction(CommonMenus.VIEW_EDITOR_SUBMENU_SPLIT, {
commandId: EditorCommands.SPLIT_EDITOR_UP.id,
label: nls.localizeByDefault('Split Editor Up'),
order: '2'
});

registry.registerMenuAction(CommonMenus.VIEW_EDITOR_SUBMENU_SPLIT, {
commandId: EditorCommands.SPLIT_EDITOR_DOWN.id,
label: nls.localizeByDefault('Split Editor Down'),
order: '3'
});

registry.registerMenuAction(CommonMenus.VIEW_EDITOR_SUBMENU_ORTHO, {
commandId: EditorCommands.SPLIT_EDITOR_HORIZONTAL.id,
label: nls.localize('theia/editor/splitHorizontal', 'Split Editor Horizontal'),
order: '1'
});

registry.registerMenuAction(CommonMenus.VIEW_EDITOR_SUBMENU_ORTHO, {
commandId: EditorCommands.SPLIT_EDITOR_VERTICAL.id,
label: nls.localize('theia/editor/splitVertical', 'Split Editor Vertical'),
order: '2'
});

registry.registerSubmenu(CommonMenus.VIEW_EDITOR_SUBMENU, nls.localizeByDefault('Editor Layout'));
}

}

0 comments on commit 0bd86b2

Please sign in to comment.