-
Notifications
You must be signed in to change notification settings - Fork 165
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++"> | ||
| </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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These commands can be executed via "Ctrl+3", and guess what ... They change current editor font, if editor is currently active, or "Debug Shell" view font etc. We need
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These commands can be executed via "Ctrl+3", and guess what ... They change current editor font, if editor is currently active, or "Debug Shell" view font etc. We need
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These commands can be executed via "Ctrl+3", and guess what ... They change current editor font, if editor is currently active, or "Debug Shell" view font etc. We need |
||
| id="org.eclipse.ui.console.command.fontZoomIn" | ||
| name="%command.console.fontZoomIn.name" | ||
| description="%command.console.fontZoomIn.description" | ||
| 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"> | ||
| </command> | ||
| </extension> | ||
|
|
||
| <extension point="org.eclipse.ui.handlers"> | ||
| <handler | ||
| class="org.eclipse.ui.internal.console.ConsoleZoomInHandler" | ||
| commandId="org.eclipse.ui.console.command.fontZoomIn"> | ||
| </handler> | ||
| <handler | ||
| class="org.eclipse.ui.internal.console.ConsoleZoomOutHandler" | ||
| commandId="org.eclipse.ui.console.command.fontZoomOut"> | ||
| </handler> | ||
| </extension> | ||
|
|
||
| <extension point="org.eclipse.ui.preferencePages"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /******************************************************************************* | ||
| * 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.internal.console; | ||
|
|
||
| import org.eclipse.core.commands.AbstractHandler; | ||
| 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.Control; | ||
| import org.eclipse.swt.widgets.Display; | ||
| import org.eclipse.ui.console.TextConsolePage; | ||
|
|
||
| /** | ||
| * 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) { | ||
|
raghucssit marked this conversation as resolved.
|
||
| Display display = Display.getCurrent(); | ||
| if (display == null) { | ||
| return; | ||
| } | ||
| display.syncExec(() -> applyZoom(display, delta)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
| } | ||
|
|
||
| public static void applyZoom(Display display, int delta) { | ||
| // Capture the focused control. | ||
| Control focus = display.getFocusControl(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if Try to play with 3 diffeent consoles:
Now open a text editor (Java code or just any plain txt file).
My expectations are:
|
||
| StyledText st = focus instanceof StyledText ? (StyledText) focus : 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please always use blocks for if/for/while statements, independently how many lines are inside.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please always use blocks for if/for/while statements, independently how many lines are inside. |
||
| 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is responsible for really awkward behavior of different consoles I've observed. I've tested few consoles and they all behave differently. Looks like consoles from Platform are OK and consistent (process console & ant), but JDT is different (it reads the font set for Console but it also changes the font for the editor) and the Host OSGI Console (PDE) doesn't care at all about default console font, same as SpotBugs (not from eclipse.org). On one side it makes sense, every contributed console can have their own font defined, on the other side, they could derive their font from the base one. So ideally we should fix JDT console (which propagates font changes to the editor), and the PDE (which should derive the font from Console preferences). It would make sense to check if CDT build console need some fix and fix that too, but first let fix the platform. All other 3rd party plugins should fix their code by themselves. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /******************************************************************************* | ||
| * 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.internal.console; | ||
|
|
||
| import org.eclipse.core.commands.AbstractHandler; | ||
| import org.eclipse.core.commands.ExecutionEvent; | ||
| import org.eclipse.core.commands.ExecutionException; | ||
| 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 int STEP = 1; | ||
|
|
||
| @Override | ||
| public Object execute(ExecutionEvent event) throws ExecutionException { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of overriding two methods, you can specify Also I wonder if the code similar to code in |
||
| changeFocusedFont(-STEP); | ||
| return null; | ||
| } | ||
|
|
||
| private void changeFocusedFont(int delta) { | ||
| Display display = Display.getCurrent(); | ||
| if (display == null) { | ||
| return; | ||
| } | ||
| display.syncExec(() -> ConsoleZoomInHandler.applyZoom(display, delta)); | ||
| } | ||
| } | ||
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.
These commands can be executed via "Ctrl+3", and guess what ... They change editor font, if it is currently active, or "Debug Shell" view font etc.
We need
<enabledWhen>on the handler to restrict it to Console view only.