-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preferences: Support window.zoomLevel Preference
Fixes #8751 What it does - Allows end-user to specify window zoom level as a preference - Adds support for the addition of other window preferences How to test 1. Open `Preferences` view and locate the `window.zoomLevel` preference 2. Enter in a custom value or change the zoom level using zoom commands (`ctrl +, ctrl -, ctrl 0`) 3. Observe that the window zoom level changes and the preference is updated in the `settings.json` file 4. Reload the window and observe that the preferred zoom level is restored Signed-off-by: seantan22 <[email protected]>
- Loading branch information
seantan22
committed
Mar 2, 2021
1 parent
a20b26d
commit d15635e
Showing
4 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/core/src/electron-browser/window/electron-window-preferences.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { interfaces } from 'inversify'; | ||
import { createPreferenceProxy, PreferenceContribution, PreferenceProxy, PreferenceSchema, PreferenceService } from '../../browser/preferences'; | ||
|
||
export namespace ZoomLevel { | ||
export const DEFAULT = 0; | ||
// copied from https://github.com/microsoft/vscode/blob/dda96b69bfc63f309e60cfc5f98cb863c46b32ac/src/vs/workbench/electron-sandbox/actions/windowActions.ts#L47-L48 | ||
export const MIN = -8; | ||
export const MAX = 9; | ||
// amount to increment or decrement the window zoom level. | ||
export const VARIATION = 0.5; | ||
} | ||
|
||
export const electronWindowPreferencesSchema: PreferenceSchema = { | ||
type: 'object', | ||
properties: { | ||
'window.zoomLevel': { | ||
'type': 'number', | ||
'default': ZoomLevel.DEFAULT, | ||
'minimum': ZoomLevel.MIN, | ||
'maximum': ZoomLevel.MAX, | ||
'scope': 'application', | ||
// eslint-disable-next-line max-len | ||
'description': 'Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1.0) or below (e.g. -1.0) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity.' | ||
}, | ||
} | ||
}; | ||
|
||
export class ElectronWindowConfiguration { | ||
'window.zoomLevel': number; | ||
} | ||
|
||
export const ElectronWindowPreferences = Symbol('ElectronWindowPreferences'); | ||
export type ElectronWindowPreferences = PreferenceProxy<ElectronWindowConfiguration>; | ||
|
||
export function createElectronWindowPreferences(preferences: PreferenceService): ElectronWindowPreferences { | ||
return createPreferenceProxy(preferences, electronWindowPreferencesSchema); | ||
} | ||
|
||
export function bindWindowPreferences(bind: interfaces.Bind): void { | ||
bind(ElectronWindowPreferences).toDynamicValue(ctx => { | ||
const preferences = ctx.container.get<PreferenceService>(PreferenceService); | ||
return createElectronWindowPreferences(preferences); | ||
}).inSingletonScope(); | ||
|
||
bind(PreferenceContribution).toConstantValue({ schema: electronWindowPreferencesSchema }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters