From e1d88b4d46efe2da206f712f62ac8154b726a4b5 Mon Sep 17 00:00:00 2001 From: raghucssit Date: Wed, 18 Mar 2026 22:39:37 +0100 Subject: [PATCH] Add font zoom functionality to console view -Add key listener on text widget of console view which listens ctrl plus and control minus(including numpad +/-) -Zoom in/out of the console view text in steps based on the keys pressed. see https://github.com/eclipse-platform/eclipse.platform/issues/2578 --- .../org.eclipse.ui.console/plugin.properties | 4 + debug/org.eclipse.ui.console/plugin.xml | 53 +++++++++++ .../ui/console/ConsoleZoomInHandler.java | 92 +++++++++++++++++++ .../ui/console/ConsoleZoomOutHandler.java | 91 ++++++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 debug/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsoleZoomInHandler.java create mode 100644 debug/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsoleZoomOutHandler.java diff --git a/debug/org.eclipse.ui.console/plugin.properties b/debug/org.eclipse.ui.console/plugin.properties index 7f084b3ff55..5dc60ccbc69 100644 --- a/debug/org.eclipse.ui.console/plugin.properties +++ b/debug/org.eclipse.ui.console/plugin.properties @@ -37,3 +37,7 @@ command.copy_without_escapes.name = Copy Text Without ANSI Escapes command.copy_without_escapes.description = Copy the console content to clipboard, removing the escape sequences command.enable_disable.name = Enable / Disable ANSI Support command.enable_disable.description = Enable / disable ANSI Support +command.console.fontZoomIn.name = Zoom In Console Font +command.console.fontZoomIn.description = Increase the console font size +command.console.fontZoomOut.name = Zoom Out Console Font +command.console.fontZoomOut.description = Decrease the console font size diff --git a/debug/org.eclipse.ui.console/plugin.xml b/debug/org.eclipse.ui.console/plugin.xml index cf75e8936ce..2760ae2750f 100644 --- a/debug/org.eclipse.ui.console/plugin.xml +++ b/debug/org.eclipse.ui.console/plugin.xml @@ -91,6 +91,36 @@ M4 = Platform-specific fourth key sequence="M1+M2+Insert"> --> + + + + + + + + + + + + + + + + + + + + + diff --git a/debug/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsoleZoomInHandler.java b/debug/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsoleZoomInHandler.java new file mode 100644 index 00000000000..9dc91099088 --- /dev/null +++ b/debug/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsoleZoomInHandler.java @@ -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; +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) { + 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; + 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); + }); + } +} diff --git a/debug/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsoleZoomOutHandler.java b/debug/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsoleZoomOutHandler.java new file mode 100644 index 00000000000..1e694eca889 --- /dev/null +++ b/debug/org.eclipse.ui.console/src/org/eclipse/ui/console/ConsoleZoomOutHandler.java @@ -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; +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; + 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); + }); + } +}