diff --git a/arduino-ide-extension/src/browser/contributions/edit-contributions.ts b/arduino-ide-extension/src/browser/contributions/edit-contributions.ts index 3b938da9..66188a56 100644 --- a/arduino-ide-extension/src/browser/contributions/edit-contributions.ts +++ b/arduino-ide-extension/src/browser/contributions/edit-contributions.ts @@ -1,10 +1,12 @@ import { inject, injectable } from 'inversify'; -import { EditorManager } from '@theia/editor/lib/browser'; import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; +import { EditorManager } from '@theia/editor/lib/browser/editor-manager'; +import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution'; +import { ClipboardService } from '@theia/core/lib/browser/clipboard-service'; +import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service'; +import { EDITOR_FONT_DEFAULTS } from '@theia/editor/lib/browser/editor-preferences'; import { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution'; import { ArduinoMenus } from '../menu/arduino-menus'; -import { ClipboardService } from '@theia/core/lib/browser/clipboard-service'; -import { CommonCommands } from '@theia/core/lib/browser'; // TODO: [macOS]: to remove `Start Dictation...` and `Emoji & Symbol` see this thread: https://github.com/electron/electron/issues/8283#issuecomment-269522072 // Depends on https://github.com/eclipse-theia/theia/pull/7964 @@ -17,6 +19,9 @@ export class EditContributions extends Contribution { @inject(ClipboardService) protected readonly clipboardService: ClipboardService; + @inject(PreferenceService) + protected readonly preferences: PreferenceService; + registerCommands(registry: CommandRegistry): void { registry.registerCommand(EditContributions.Commands.GO_TO_LINE, { execute: () => this.run('editor.action.gotoLine') }); registry.registerCommand(EditContributions.Commands.TOGGLE_COMMENT, { execute: () => this.run('editor.action.commentLine') }); @@ -26,6 +31,12 @@ export class EditContributions extends Contribution { registry.registerCommand(EditContributions.Commands.FIND_NEXT, { execute: () => this.run('actions.findWithSelection') }); registry.registerCommand(EditContributions.Commands.FIND_PREVIOUS, { execute: () => this.run('editor.action.nextMatchFindAction') }); registry.registerCommand(EditContributions.Commands.USE_FOR_FIND, { execute: () => this.run('editor.action.previousSelectionMatchFindAction') }); + registry.registerCommand(EditContributions.Commands.INCREASE_FONT_SIZE, { + execute: () => this.preferences.set('editor.fontSize', this.preferences.get('editor.fontSize', EDITOR_FONT_DEFAULTS.fontSize) + 1) + }); + registry.registerCommand(EditContributions.Commands.DECREASE_FONT_SIZE, { + execute: () => this.preferences.set('editor.fontSize', this.preferences.get('editor.fontSize', EDITOR_FONT_DEFAULTS.fontSize) - 1) + }); /* Tools */registry.registerCommand(EditContributions.Commands.AUTO_FORMAT, { execute: () => this.run('editor.action.formatDocument') }); registry.registerCommand(EditContributions.Commands.COPY_FOR_FORUM, { execute: async () => { @@ -98,6 +109,17 @@ ${value} order: '2' }); + registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, { + commandId: EditContributions.Commands.INCREASE_FONT_SIZE.id, + label: 'Increase Font Size', + order: '0' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, { + commandId: EditContributions.Commands.DECREASE_FONT_SIZE.id, + label: 'Decrease Font Size', + order: '1' + }); + registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, { commandId: EditContributions.Commands.FIND.id, label: 'Find', @@ -154,6 +176,15 @@ ${value} keybinding: 'Shift+Tab' }); + registry.registerKeybinding({ + command: EditContributions.Commands.INCREASE_FONT_SIZE.id, + keybinding: 'CtrlCmd+=' // TODO: compare with the Java IDE. It uses `⌘+`. There is no `+` on EN_US. + }); + registry.registerKeybinding({ + command: EditContributions.Commands.DECREASE_FONT_SIZE.id, + keybinding: 'CtrlCmd+-' + }); + registry.registerKeybinding({ command: EditContributions.Commands.FIND.id, keybinding: 'CtrlCmd+F' @@ -231,9 +262,14 @@ export namespace EditContributions { export const USE_FOR_FIND: Command = { id: 'arduino-for-find' }; - // `Auto Format` does not belong here. + export const INCREASE_FONT_SIZE: Command = { + id: 'arduino-increase-font-size' + }; + export const DECREASE_FONT_SIZE: Command = { + id: 'arduino-decrease-font-size' + }; export const AUTO_FORMAT: Command = { - id: 'arduino-auto-format' + id: 'arduino-auto-format' // `Auto Format` should belong to `Tool`. }; } } diff --git a/arduino-ide-extension/src/browser/customization/core/application-shell.ts b/arduino-ide-extension/src/browser/customization/core/application-shell.ts index 3da1b2ea..fb94ae5c 100644 --- a/arduino-ide-extension/src/browser/customization/core/application-shell.ts +++ b/arduino-ide-extension/src/browser/customization/core/application-shell.ts @@ -1,9 +1,10 @@ import { injectable, inject } from 'inversify'; +import { EditorWidget } from '@theia/editor/lib/browser'; import { CommandService } from '@theia/core/lib/common/command'; +import { PreferencesWidget } from '@theia/preferences/lib/browser/views/preference-widget'; import { ApplicationShell as TheiaApplicationShell, Widget } from '@theia/core/lib/browser'; import { EditorMode } from '../../editor-mode'; -import { EditorWidget } from '@theia/editor/lib/browser'; import { SaveAsSketch } from '../../contributions/save-as-sketch'; @injectable() @@ -18,7 +19,17 @@ export class ApplicationShell extends TheiaApplicationShell { protected track(widget: Widget): void { super.track(widget); if (!this.editorMode.proMode) { - if (widget instanceof EditorWidget && widget.editor.uri.toString().endsWith('arduino-cli.yaml')) { + if (widget instanceof EditorWidget) { + // Always allow closing the whitelisted files. + // TODO: It would be better to blacklist the sketch files only. + if (['tasks.json', + 'launch.json', + 'settings.json', + 'arduino-cli.yaml'].some(fileName => widget.editor.uri.toString().endsWith(fileName))) { + return; + } + } + if (widget instanceof PreferencesWidget) { return; } widget.title.closable = false; diff --git a/arduino-ide-extension/src/electron-browser/customization/core/electron-menu-contribution.ts b/arduino-ide-extension/src/electron-browser/customization/core/electron-menu-contribution.ts index 13c0f76b..c201e761 100644 --- a/arduino-ide-extension/src/electron-browser/customization/core/electron-menu-contribution.ts +++ b/arduino-ide-extension/src/electron-browser/customization/core/electron-menu-contribution.ts @@ -30,6 +30,8 @@ export class ElectronMenuContribution extends TheiaElectronMenuContribution impl registerKeybindings(registry: KeybindingRegistry): void { super.registerKeybindings(registry); registry.unregisterKeybinding(ElectronCommands.CLOSE_WINDOW.id); + registry.unregisterKeybinding(ElectronCommands.ZOOM_IN.id); + registry.unregisterKeybinding(ElectronCommands.ZOOM_OUT.id); } }