-
Notifications
You must be signed in to change notification settings - Fork 157
Add font zoom functionality to console view #2579
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -91,6 +91,36 @@ M4 = Platform-specific fourth key | |||||||||||||||||||||||||||||
| sequence="M1+M2+Insert"> | ||||||||||||||||||||||||||||||
| </key> | ||||||||||||||||||||||||||||||
| --> | ||||||||||||||||||||||||||||||
| <key | ||||||||||||||||||||||||||||||
| commandId="org.eclipse.ui.console.command.fontZoomIn" | ||||||||||||||||||||||||||||||
| contextId="org.eclipse.ui.console.ConsoleView" | ||||||||||||||||||||||||||||||
| schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" | ||||||||||||||||||||||||||||||
| sequence="M1+="> | ||||||||||||||||||||||||||||||
| </key> | ||||||||||||||||||||||||||||||
| <key | ||||||||||||||||||||||||||||||
| commandId="org.eclipse.ui.console.command.fontZoomIn" | ||||||||||||||||||||||||||||||
| contextId="org.eclipse.ui.console.ConsoleView" | ||||||||||||||||||||||||||||||
| schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" | ||||||||||||||||||||||||||||||
| sequence="M1+Plus"> | ||||||||||||||||||||||||||||||
| </key> | ||||||||||||||||||||||||||||||
| <key | ||||||||||||||||||||||||||||||
| commandId="org.eclipse.ui.console.command.fontZoomIn" | ||||||||||||||||||||||||||||||
| contextId="org.eclipse.ui.console.ConsoleView" | ||||||||||||||||||||||||||||||
| schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" | ||||||||||||||||||||||||||||||
| sequence="M1+NUMPAD_ADD"> | ||||||||||||||||||||||||||||||
| </key> | ||||||||||||||||||||||||||||||
| <key | ||||||||||||||||||||||||||||||
| commandId="org.eclipse.ui.console.command.fontZoomOut" | ||||||||||||||||||||||||||||||
| contextId="org.eclipse.ui.console.ConsoleView" | ||||||||||||||||||||||||||||||
| schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" | ||||||||||||||||||||||||||||||
| sequence="M1+-"> | ||||||||||||||||||||||||||||||
| </key> | ||||||||||||||||||||||||||||||
| <key | ||||||||||||||||||||||||||||||
| commandId="org.eclipse.ui.console.command.fontZoomOut" | ||||||||||||||||||||||||||||||
| contextId="org.eclipse.ui.console.ConsoleView" | ||||||||||||||||||||||||||||||
| schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" | ||||||||||||||||||||||||||||||
| sequence="M1+NUMPAD_SUBTRACT"> | ||||||||||||||||||||||||||||||
| </key> | ||||||||||||||||||||||||||||||
| </extension> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <extension | ||||||||||||||||||||||||||||||
|
|
@@ -157,6 +187,29 @@ M4 = Platform-specific fourth key | |||||||||||||||||||||||||||||
| id="org.eclipse.ui.commands.toggleState"> | ||||||||||||||||||||||||||||||
| </state> | ||||||||||||||||||||||||||||||
| </command> | ||||||||||||||||||||||||||||||
| <command | ||||||||||||||||||||||||||||||
| id="org.eclipse.ui.console.command.fontZoomIn" | ||||||||||||||||||||||||||||||
| name="%command.console.fontZoomIn.name" | ||||||||||||||||||||||||||||||
| description="%command.console.fontZoomIn.description" | ||||||||||||||||||||||||||||||
| categoryId="AnsiConsole.command.categoryid"> | ||||||||||||||||||||||||||||||
| </command> | ||||||||||||||||||||||||||||||
| <command | ||||||||||||||||||||||||||||||
| id="org.eclipse.ui.console.command.fontZoomOut" | ||||||||||||||||||||||||||||||
| name="%command.console.fontZoomOut.name" | ||||||||||||||||||||||||||||||
| description="%command.console.fontZoomOut.description" | ||||||||||||||||||||||||||||||
| categoryId="AnsiConsole.command.categoryid"> | ||||||||||||||||||||||||||||||
|
Comment on lines
+194
to
+200
|
||||||||||||||||||||||||||||||
| categoryId="AnsiConsole.command.categoryid"> | |
| </command> | |
| <command | |
| id="org.eclipse.ui.console.command.fontZoomOut" | |
| name="%command.console.fontZoomOut.name" | |
| description="%command.console.fontZoomOut.description" | |
| categoryId="AnsiConsole.command.categoryid"> | |
| categoryId="org.eclipse.ui.category.edit"> | |
| </command> | |
| <command | |
| id="org.eclipse.ui.console.command.fontZoomOut" | |
| name="%command.console.fontZoomOut.name" | |
| description="%command.console.fontZoomOut.description" | |
| categoryId="org.eclipse.ui.category.edit"> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Advantest Europe GmbH and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Raghunandana Murthappa | ||
| *******************************************************************************/ | ||
| package org.eclipse.ui.console; | ||
|
|
||
| import org.eclipse.core.commands.AbstractHandler; | ||
|
Comment on lines
+14
to
+16
|
||
| import org.eclipse.core.commands.ExecutionEvent; | ||
| import org.eclipse.core.commands.ExecutionException; | ||
| import org.eclipse.jface.resource.JFaceResources; | ||
| import org.eclipse.swt.custom.StyledText; | ||
| import org.eclipse.swt.graphics.Font; | ||
| import org.eclipse.swt.graphics.FontData; | ||
| import org.eclipse.swt.widgets.Display; | ||
|
|
||
| /** | ||
| * Command handler to increase the font size of the focused console StyledText. | ||
| * | ||
| * @since 3.17 | ||
| */ | ||
| public class ConsoleZoomInHandler extends AbstractHandler { | ||
| private static final String ZOOM_FONT_KEY = TextConsolePage.class.getName() + ".zoomFont"; //$NON-NLS-1$ | ||
| private static final String DEBUG_CONSOLE_FONT_REGISTRY_KEY = "org.eclipse.debug.ui.consoleFont"; //$NON-NLS-1$ | ||
| private static final int MIN_FONT_SIZE = 6; | ||
| private static final int MAX_FONT_SIZE = 72; | ||
| private static final int STEP = 1; | ||
|
|
||
| @Override | ||
| public Object execute(ExecutionEvent event) throws ExecutionException { | ||
| changeFocusedFont(STEP); | ||
| return null; | ||
| } | ||
|
|
||
| private void changeFocusedFont(int delta) { | ||
|
Comment on lines
+37
to
+43
|
||
| Display display = Display.getCurrent(); | ||
| if (display == null) { | ||
| display = Display.getDefault(); | ||
| } | ||
| Display d = display; | ||
| d.asyncExec(() -> { | ||
|
Comment on lines
+44
to
+49
|
||
| StyledText st = d.getFocusControl() instanceof StyledText ? (StyledText) d.getFocusControl() : null; | ||
| if (st == null || st.isDisposed()) { | ||
| return; | ||
| } | ||
| Font current = st.getFont(); | ||
| if (current == null || current.isDisposed()) { | ||
| return; | ||
| } | ||
| FontData[] fontData = current.getFontData(); | ||
| if (fontData == null || fontData.length == 0) { | ||
| return; | ||
| } | ||
| int currentHeight = fontData[0].getHeight(); | ||
| int newHeight = Math.max(MIN_FONT_SIZE, Math.min(MAX_FONT_SIZE, currentHeight + delta)); | ||
| if (newHeight == currentHeight) { | ||
| return; | ||
| } | ||
| FontData[] newFontData = fontData.clone(); | ||
| for (FontData fd : newFontData) { | ||
| if (fd != null) | ||
| fd.setHeight(newHeight); | ||
| } | ||
|
|
||
| Font oldZoom = (Font) st.getData(ZOOM_FONT_KEY); | ||
| Font newZoom = new Font(st.getDisplay(), newFontData); | ||
| st.setFont(newZoom); | ||
| st.setData(ZOOM_FONT_KEY, newZoom); | ||
| if (oldZoom == null) { | ||
| st.addDisposeListener(e -> { | ||
| Font z = (Font) st.getData(ZOOM_FONT_KEY); | ||
| if (z != null && !z.isDisposed()) | ||
| z.dispose(); | ||
| }); | ||
| } | ||
| if (oldZoom != null && !oldZoom.isDisposed()) { | ||
| oldZoom.dispose(); | ||
| } | ||
|
|
||
| // Update shared JFace registry so other listeners can observe the change | ||
| JFaceResources.getFontRegistry().put(DEBUG_CONSOLE_FONT_REGISTRY_KEY, newFontData); | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Advantest Europe GmbH and others. | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Raghunandana Murthappa | ||
| *******************************************************************************/ | ||
| package org.eclipse.ui.console; | ||
|
|
||
| import org.eclipse.core.commands.AbstractHandler; | ||
|
Comment on lines
+14
to
+16
|
||
| import org.eclipse.core.commands.ExecutionEvent; | ||
| import org.eclipse.core.commands.ExecutionException; | ||
| import org.eclipse.jface.resource.JFaceResources; | ||
| import org.eclipse.swt.custom.StyledText; | ||
| import org.eclipse.swt.graphics.Font; | ||
| import org.eclipse.swt.graphics.FontData; | ||
| import org.eclipse.swt.widgets.Display; | ||
|
|
||
| /** | ||
| * Command handler to decrease the font size of the focused console StyledText. | ||
| * | ||
| * @since 3.17 | ||
| */ | ||
| public class ConsoleZoomOutHandler extends AbstractHandler { | ||
| private static final String ZOOM_FONT_KEY = TextConsolePage.class.getName() + ".zoomFont"; //$NON-NLS-1$ | ||
| private static final String DEBUG_CONSOLE_FONT_REGISTRY_KEY = "org.eclipse.debug.ui.consoleFont"; //$NON-NLS-1$ | ||
| private static final int MIN_FONT_SIZE = 6; | ||
| private static final int MAX_FONT_SIZE = 72; | ||
| private static final int STEP = 1; | ||
|
|
||
| @Override | ||
| public Object execute(ExecutionEvent event) throws ExecutionException { | ||
| changeFocusedFont(-STEP); | ||
| return null; | ||
| } | ||
|
|
||
| private void changeFocusedFont(int delta) { | ||
| Display display = Display.getCurrent(); | ||
| if (display == null) { | ||
| display = Display.getDefault(); | ||
| } | ||
| Display d = display; | ||
| d.asyncExec(() -> { | ||
| StyledText st = d.getFocusControl() instanceof StyledText ? (StyledText) d.getFocusControl() : null; | ||
|
Comment on lines
+44
to
+50
|
||
| if (st == null || st.isDisposed()) { | ||
| return; | ||
| } | ||
| Font current = st.getFont(); | ||
| if (current == null || current.isDisposed()) { | ||
| return; | ||
| } | ||
| FontData[] fontData = current.getFontData(); | ||
| if (fontData == null || fontData.length == 0) { | ||
| return; | ||
| } | ||
| int currentHeight = fontData[0].getHeight(); | ||
| int newHeight = Math.max(MIN_FONT_SIZE, Math.min(MAX_FONT_SIZE, currentHeight + delta)); | ||
| if (newHeight == currentHeight) { | ||
| return; | ||
| } | ||
| FontData[] newFontData = fontData.clone(); | ||
| for (FontData fd : newFontData) { | ||
| if (fd != null) | ||
| fd.setHeight(newHeight); | ||
| } | ||
|
|
||
| Font oldZoom = (Font) st.getData(ZOOM_FONT_KEY); | ||
| Font newZoom = new Font(st.getDisplay(), newFontData); | ||
| st.setFont(newZoom); | ||
| st.setData(ZOOM_FONT_KEY, newZoom); | ||
| if (oldZoom == null) { | ||
| st.addDisposeListener(e -> { | ||
| Font z = (Font) st.getData(ZOOM_FONT_KEY); | ||
| if (z != null && !z.isDisposed()) | ||
| z.dispose(); | ||
| }); | ||
| } | ||
| if (oldZoom != null && !oldZoom.isDisposed()) { | ||
| oldZoom.dispose(); | ||
| } | ||
| // Update shared JFace registry so other listeners can observe the change | ||
| JFaceResources.getFontRegistry().put(DEBUG_CONSOLE_FONT_REGISTRY_KEY, newFontData); | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key sequence token
Plusis not used anywhere else in this repository’s key bindings, andM1+=already covers the common Ctrl+'+' (shift+'=') case whileM1+NUMPAD_ADDcovers the keypad. IfPlusis not a recognized key name, this binding will be ignored at runtime. Consider removing this binding or replacing it with a verified/standard key token.