Skip to content

Commit 8c76e12

Browse files
committed
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 #2578
1 parent 3f8585f commit 8c76e12

4 files changed

Lines changed: 196 additions & 0 deletions

File tree

debug/org.eclipse.ui.console/plugin.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ command.copy_without_escapes.name = Copy Text Without ANSI Escapes
3737
command.copy_without_escapes.description = Copy the console content to clipboard, removing the escape sequences
3838
command.enable_disable.name = Enable / Disable ANSI Support
3939
command.enable_disable.description = Enable / disable ANSI Support
40+
command.console.fontZoomIn.name = Zoom In Console Font
41+
command.console.fontZoomIn.description = Increase the console font size
42+
command.console.fontZoomOut.name = Zoom Out Console Font
43+
command.console.fontZoomOut.description = Decrease the console font size

debug/org.eclipse.ui.console/plugin.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,36 @@ M4 = Platform-specific fourth key
9191
sequence="M1+M2+Insert">
9292
</key>
9393
-->
94+
<key
95+
commandId="org.eclipse.ui.console.command.fontZoomIn"
96+
contextId="org.eclipse.ui.console.ConsoleView"
97+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
98+
sequence="M1+=">
99+
</key>
100+
<key
101+
commandId="org.eclipse.ui.console.command.fontZoomIn"
102+
contextId="org.eclipse.ui.console.ConsoleView"
103+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
104+
sequence="M1++">
105+
</key>
106+
<key
107+
commandId="org.eclipse.ui.console.command.fontZoomIn"
108+
contextId="org.eclipse.ui.console.ConsoleView"
109+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
110+
sequence="M1+NUMPAD_ADD">
111+
</key>
112+
<key
113+
commandId="org.eclipse.ui.console.command.fontZoomOut"
114+
contextId="org.eclipse.ui.console.ConsoleView"
115+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
116+
sequence="M1+-">
117+
</key>
118+
<key
119+
commandId="org.eclipse.ui.console.command.fontZoomOut"
120+
contextId="org.eclipse.ui.console.ConsoleView"
121+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
122+
sequence="M1+NUMPAD_SUBTRACT">
123+
</key>
94124
</extension>
95125

96126
<extension
@@ -157,6 +187,29 @@ M4 = Platform-specific fourth key
157187
id="org.eclipse.ui.commands.toggleState">
158188
</state>
159189
</command>
190+
<command
191+
id="org.eclipse.ui.console.command.fontZoomIn"
192+
name="%command.console.fontZoomIn.name"
193+
description="%command.console.fontZoomIn.description"
194+
categoryId="org.eclipse.ui.category.edit">
195+
</command>
196+
<command
197+
id="org.eclipse.ui.console.command.fontZoomOut"
198+
name="%command.console.fontZoomOut.name"
199+
description="%command.console.fontZoomOut.description"
200+
categoryId="org.eclipse.ui.category.edit">
201+
</command>
202+
</extension>
203+
204+
<extension point="org.eclipse.ui.handlers">
205+
<handler
206+
class="org.eclipse.ui.internal.console.ConsoleZoomInHandler"
207+
commandId="org.eclipse.ui.console.command.fontZoomIn">
208+
</handler>
209+
<handler
210+
class="org.eclipse.ui.internal.console.ConsoleZoomOutHandler"
211+
commandId="org.eclipse.ui.console.command.fontZoomOut">
212+
</handler>
160213
</extension>
161214

162215
<extension point="org.eclipse.ui.preferencePages">
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Advantest Europe GmbH and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Raghunandana Murthappa
13+
*******************************************************************************/
14+
package org.eclipse.ui.internal.console;
15+
16+
import org.eclipse.core.commands.AbstractHandler;
17+
import org.eclipse.core.commands.ExecutionEvent;
18+
import org.eclipse.core.commands.ExecutionException;
19+
import org.eclipse.jface.resource.JFaceResources;
20+
import org.eclipse.swt.custom.StyledText;
21+
import org.eclipse.swt.graphics.Font;
22+
import org.eclipse.swt.graphics.FontData;
23+
import org.eclipse.swt.widgets.Control;
24+
import org.eclipse.swt.widgets.Display;
25+
import org.eclipse.ui.console.TextConsolePage;
26+
27+
/**
28+
* Command handler to increase the font size of the focused console StyledText.
29+
*
30+
* @since 3.17
31+
*/
32+
public class ConsoleZoomInHandler extends AbstractHandler {
33+
private static final String ZOOM_FONT_KEY = TextConsolePage.class.getName() + ".zoomFont"; //$NON-NLS-1$
34+
private static final String DEBUG_CONSOLE_FONT_REGISTRY_KEY = "org.eclipse.debug.ui.consoleFont"; //$NON-NLS-1$
35+
private static final int MIN_FONT_SIZE = 6;
36+
private static final int MAX_FONT_SIZE = 72;
37+
private static final int STEP = 1;
38+
39+
@Override
40+
public Object execute(ExecutionEvent event) throws ExecutionException {
41+
changeFocusedFont(STEP);
42+
return null;
43+
}
44+
45+
private void changeFocusedFont(int delta) {
46+
Display display = Display.getCurrent();
47+
if (display == null) {
48+
return;
49+
}
50+
display.syncExec(() -> applyZoom(display, delta));
51+
}
52+
53+
public static void applyZoom(Display display, int delta) {
54+
// Capture the focused control.
55+
Control focus = display.getFocusControl();
56+
StyledText st = focus instanceof StyledText ? (StyledText) focus : null;
57+
if (st == null || st.isDisposed()) {
58+
return;
59+
}
60+
Font current = st.getFont();
61+
if (current == null || current.isDisposed()) {
62+
return;
63+
}
64+
FontData[] fontData = current.getFontData();
65+
if (fontData == null || fontData.length == 0) {
66+
return;
67+
}
68+
int currentHeight = fontData[0].getHeight();
69+
int newHeight = Math.max(MIN_FONT_SIZE, Math.min(MAX_FONT_SIZE, currentHeight + delta));
70+
if (newHeight == currentHeight) {
71+
return;
72+
}
73+
FontData[] newFontData = fontData.clone();
74+
for (FontData fd : newFontData) {
75+
if (fd != null)
76+
fd.setHeight(newHeight);
77+
}
78+
79+
Font oldZoom = (Font) st.getData(ZOOM_FONT_KEY);
80+
Font newZoom = new Font(st.getDisplay(), newFontData);
81+
st.setFont(newZoom);
82+
st.setData(ZOOM_FONT_KEY, newZoom);
83+
if (oldZoom == null) {
84+
st.addDisposeListener(e -> {
85+
Font z = (Font) st.getData(ZOOM_FONT_KEY);
86+
if (z != null && !z.isDisposed())
87+
z.dispose();
88+
});
89+
}
90+
if (oldZoom != null && !oldZoom.isDisposed()) {
91+
oldZoom.dispose();
92+
}
93+
94+
// Update shared JFace registry so other listeners can observe the change
95+
JFaceResources.getFontRegistry().put(DEBUG_CONSOLE_FONT_REGISTRY_KEY, newFontData);
96+
}
97+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Advantest Europe GmbH and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Raghunandana Murthappa
13+
*******************************************************************************/
14+
package org.eclipse.ui.internal.console;
15+
16+
import org.eclipse.core.commands.AbstractHandler;
17+
import org.eclipse.core.commands.ExecutionEvent;
18+
import org.eclipse.core.commands.ExecutionException;
19+
import org.eclipse.swt.widgets.Display;
20+
21+
/**
22+
* Command handler to decrease the font size of the focused console StyledText.
23+
*
24+
* @since 3.17
25+
*/
26+
public class ConsoleZoomOutHandler extends AbstractHandler {
27+
private static final int STEP = 1;
28+
29+
@Override
30+
public Object execute(ExecutionEvent event) throws ExecutionException {
31+
changeFocusedFont(-STEP);
32+
return null;
33+
}
34+
35+
private void changeFocusedFont(int delta) {
36+
Display display = Display.getCurrent();
37+
if (display == null) {
38+
return;
39+
}
40+
display.syncExec(() -> ConsoleZoomInHandler.applyZoom(display, delta));
41+
}
42+
}

0 commit comments

Comments
 (0)