Implemented font size mod.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-18 20:57:15 +02:00
parent 95dfd3920c
commit 5d23cb5270
3 changed files with 56 additions and 7 deletions

View File

@ -1,10 +1,12 @@
import { inject, injectable } from 'inversify'; import { inject, injectable } from 'inversify';
import { EditorManager } from '@theia/editor/lib/browser';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; 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 { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
import { ArduinoMenus } from '../menu/arduino-menus'; 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 // 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 // Depends on https://github.com/eclipse-theia/theia/pull/7964
@ -17,6 +19,9 @@ export class EditContributions extends Contribution {
@inject(ClipboardService) @inject(ClipboardService)
protected readonly clipboardService: ClipboardService; protected readonly clipboardService: ClipboardService;
@inject(PreferenceService)
protected readonly preferences: PreferenceService;
registerCommands(registry: CommandRegistry): void { registerCommands(registry: CommandRegistry): void {
registry.registerCommand(EditContributions.Commands.GO_TO_LINE, { execute: () => this.run('editor.action.gotoLine') }); 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') }); 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_NEXT, { execute: () => this.run('actions.findWithSelection') });
registry.registerCommand(EditContributions.Commands.FIND_PREVIOUS, { execute: () => this.run('editor.action.nextMatchFindAction') }); 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.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') }); /* Tools */registry.registerCommand(EditContributions.Commands.AUTO_FORMAT, { execute: () => this.run('editor.action.formatDocument') });
registry.registerCommand(EditContributions.Commands.COPY_FOR_FORUM, { registry.registerCommand(EditContributions.Commands.COPY_FOR_FORUM, {
execute: async () => { execute: async () => {
@ -98,6 +109,17 @@ ${value}
order: '2' 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, { registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
commandId: EditContributions.Commands.FIND.id, commandId: EditContributions.Commands.FIND.id,
label: 'Find', label: 'Find',
@ -154,6 +176,15 @@ ${value}
keybinding: 'Shift+Tab' 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({ registry.registerKeybinding({
command: EditContributions.Commands.FIND.id, command: EditContributions.Commands.FIND.id,
keybinding: 'CtrlCmd+F' keybinding: 'CtrlCmd+F'
@ -231,9 +262,14 @@ export namespace EditContributions {
export const USE_FOR_FIND: Command = { export const USE_FOR_FIND: Command = {
id: 'arduino-for-find' 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 = { export const AUTO_FORMAT: Command = {
id: 'arduino-auto-format' id: 'arduino-auto-format' // `Auto Format` should belong to `Tool`.
}; };
} }
} }

View File

@ -1,9 +1,10 @@
import { injectable, inject } from 'inversify'; import { injectable, inject } from 'inversify';
import { EditorWidget } from '@theia/editor/lib/browser';
import { CommandService } from '@theia/core/lib/common/command'; 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 { ApplicationShell as TheiaApplicationShell, Widget } from '@theia/core/lib/browser';
import { EditorMode } from '../../editor-mode'; import { EditorMode } from '../../editor-mode';
import { EditorWidget } from '@theia/editor/lib/browser';
import { SaveAsSketch } from '../../contributions/save-as-sketch'; import { SaveAsSketch } from '../../contributions/save-as-sketch';
@injectable() @injectable()
@ -18,7 +19,17 @@ export class ApplicationShell extends TheiaApplicationShell {
protected track(widget: Widget): void { protected track(widget: Widget): void {
super.track(widget); super.track(widget);
if (!this.editorMode.proMode) { 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; return;
} }
widget.title.closable = false; widget.title.closable = false;

View File

@ -30,6 +30,8 @@ export class ElectronMenuContribution extends TheiaElectronMenuContribution impl
registerKeybindings(registry: KeybindingRegistry): void { registerKeybindings(registry: KeybindingRegistry): void {
super.registerKeybindings(registry); super.registerKeybindings(registry);
registry.unregisterKeybinding(ElectronCommands.CLOSE_WINDOW.id); registry.unregisterKeybinding(ElectronCommands.CLOSE_WINDOW.id);
registry.unregisterKeybinding(ElectronCommands.ZOOM_IN.id);
registry.unregisterKeybinding(ElectronCommands.ZOOM_OUT.id);
} }
} }