8000 Limit interface scale by AlbyIanna · Pull Request #1502 · arduino/arduino-ide · GitHub
[go: up one dir, main page]

Skip to content

Limit interface scale #1502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
limit interface scale
  • Loading branch information
Alberto Iannaccone committed Oct 6, 2022
commit ebe4b40e7e5415ca263a0f5624af505a89b67ec6
135 changes: 116 additions & 19 deletions arduino-ide-extension/src/browser/contributions/edit-contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import {
KeybindingRegistry,
CommandRegistry,
} from './contribution';
import { ArduinoMenus } from '../menu/arduino-menus';
import { nls } from '@theia/core/lib/common';
import { ArduinoMenus, PlaceholderMenuNode } from '../menu/arduino-menus';
import { DisposableCollection, nls } from '@theia/core/lib/common';
import type { ICodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/browser/editorBrowser';
import type { StandaloneCodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor';

import { Settings } from '../dialogs/settings/settings';
import { MainMenuManager } from '../../common/main-menu-manager';

// 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
@injectable()
Expand All @@ -24,6 +27,39 @@ export class EditContributions extends Contribution {
@inject(ClipboardService)
private readonly clipboardService: ClipboardService;

@inject(MenuModelRegistry)
private readonly menuRegistry: MenuModelRegistry;

@inject(MainMenuManager)
protected readonly mainMenuManager: MainMenuManager;

private readonly menuActionsDisposables = new DisposableCollection();
private fontScalingEnabled: EditContributions.FontScalingEnabled = {
increase: true,
decrease: true,
};

private checkInterfaceScaleMenuActions(settings: Settings): void {
let newFontScalingEnabled: EditContributions.FontScalingEnabled = {
increase: true,
decrease: true,
};
if (settings.autoScaleInterface) {
newFontScalingEnabled = {
increase: settings.interfaceScale < EditContributions.ZoomLevel.MAX,
decrease: settings.interfaceScale > EditContributions.ZoomLevel.MIN,
};
}
const isChanged = Object.keys(newFontScalingEnabled).some(
(key: keyof EditContributions.FontScalingEnabled) =>
newFontScalingEnabled[key] !== this.fontScalingEnabled[key]
);
if (isChanged) {
this.registerInterfaceScaleMenuActions(newFontScalingEnabled);
}
this.fontScalingEnabled = newFontScalingEnabled;
}

override registerCommands(registry: CommandRegistry): void {
registry.registerCommand(EditContributions.Commands.GO_TO_LINE, {
execute: () => this.run('editor.action.gotoLine'),
Expand Down Expand Up @@ -59,7 +95,9 @@ export class EditContributions extends Contribution {
}
await this.settingsService.update(settings);
await this.settingsService.save();
this.checkInterfaceScaleMenuActions(settings);
},
isEnabled: () => this.fontScalingEnabled.increase,
});
registry.registerCommand(EditContributions.Commands.DECREASE_FONT_SIZE, {
execute: async () => {
Expand All @@ -71,7 +109,9 @@ export class EditContributions extends Contribution {
}
await this.settingsService.update(settings);
await this.settingsService.save();
this.checkInterfaceScaleMenuActions(settings);
},
isEnabled: () => this.fontScalingEnabled.decrease,
});
/* Tools */ registry.registerCommand(
EditContributions.Commands.AUTO_FORMAT,
Expand Down Expand Up @@ -147,23 +187,6 @@ ${value}
order: '3',
});

registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
commandId: EditContributions.Commands.INCREASE_FONT_SIZE.id,
label: nls.localize(
'arduino/editor/increaseFontSize',
'Increase Font Size'
),
order: '0',
});
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP, {
commandId: EditContributions.Commands.DECREASE_FONT_SIZE.id,
label: nls.localize(
'arduino/editor/decreaseFontSize',
'Decrease Font Size'
),
order: '1',
});

registry.registerMenuAction(ArduinoMenus.EDIT__FIND_GROUP, {
commandId: EditContributions.Commands.FIND.id,
label: nls.localize('vscode/findController/startFindAction', 'Find'),
Expand Down Expand Up @@ -200,6 +223,70 @@ ${value}
label: nls.localize('arduino/editor/autoFormat', 'Auto Format'), // XXX: The Java IDE uses `Use Selection For Find`.
order: '0',
});

this.registerInterfaceScaleMenuActions();
}

private registerInterfaceScaleMenuActions(
newFontScalingEnabled = this.fontScalingEnabled
): void {
this.menuActionsDisposables.dispose();
const increaseFontSizeMenuAction = {
commandId: EditContributions.Commands.INCREASE_FONT_SIZE.id,
label: nls.localize(
'arduino/editor/increaseFontSize',
'Increase Font Size'
),
order: '0',
};
const decreaseFontSizeMenuAction = {
commandId: EditContributions.Commands.DECREASE_FONT_SIZE.id,
label: nls.localize(
'arduino/editor/decreaseFontSize',
'Decrease Font Size'
),
order: '1',
};

if (newFontScalingEnabled.increase) {
this.menuActionsDisposables.push(
this.menuRegistry.registerMenuAction(
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
increaseFontSizeMenuAction
)
);
} else {
this.menuActionsDisposables.push(
this.menuRegistry.registerMenuNode(
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
new PlaceholderMenuNode(
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
increaseFontSizeMenuAction.label,
{ order: increaseFontSizeMenuAction.order }
)
)
);
}
if (newFontScalingEnabled.decrease) {
this.menuActionsDisposables.push(
this.menuRegistry.registerMenuAction(
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
decreaseFontSizeMenuAction
)
);
} else {
this.menuActionsDisposables.push(
this.menuRegistry.registerMenuNode(
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
new PlaceholderMenuNode(
ArduinoMenus.EDIT__FONT_CONTROL_GROUP,
decreaseFontSizeMenuAction.label,
{ order: decreaseFontSizeMenuAction.order }
)
)
);
}
this.mainMenuManager.update();
}

override registerKeybindings(registry: KeybindingRegistry): void {
Expand Down Expand Up @@ -325,4 +412,14 @@ export namespace EditContributions {
id: 'arduino-auto-format', // `Auto Format` should belong to `Tool`.
};
}

export namespace ZoomLevel {
export const MIN = -8;
export const MAX = 9;
}

export interface FontScalingEnabled {
increase: boolean;
decrease: boolean;
}
}
0