Skip to content

Commit e1d88b4

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 e1d88b4

4 files changed

Lines changed: 240 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+Plus">
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="AnsiConsole.command.categoryid">
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="AnsiConsole.command.categoryid">
201+
</command>
202+
</extension>
203+
204+
<extension point="org.eclipse.ui.handlers">
205+
<handler
206+
class="org.eclipse.ui.console.ConsoleZoomInHandler"
207+
commandId="org.eclipse.ui.console.command.fontZoomIn">
208+
</handler>
209+
<handler
210+
class="org.eclipse.ui.console.ConsoleZoomOutHandler"
211+
commandId="org.eclipse.ui.console.command.fontZoomOut">
212+
</handler>
160213
</extension>
161214

162215
<extension point="org.eclipse.ui.preferencePages">
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.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.Display;
24+
25+
/**
26+
* Command handler to increase the font size of the focused console StyledText.
27+
*
28+
* @since 3.17
29+
*/
30+
public class ConsoleZoomInHandler extends AbstractHandler {
31+
private static final String ZOOM_FONT_KEY = TextConsolePage.class.getName() + ".zoomFont"; //$NON-NLS-1$
32+
private static final String DEBUG_CONSOLE_FONT_REGISTRY_KEY = "org.eclipse.debug.ui.consoleFont"; //$NON-NLS-1$
33+
private static final int MIN_FONT_SIZE = 6;
34+
private static final int MAX_FONT_SIZE = 72;
35+
private static final int STEP = 1;
36+
37+
@Override
38+
public Object execute(ExecutionEvent event) throws ExecutionException {
39+
changeFocusedFont(STEP);
40+
return null;
41+
}
42+
43+
private void changeFocusedFont(int delta) {
44+
Display display = Display.getCurrent();
45+
if (display == null) {
46+
display = Display.getDefault();
47+
}
48+
Display d = display;
49+
d.asyncExec(() -> {
50+
StyledText st = d.getFocusControl() instanceof StyledText ? (StyledText) d.getFocusControl() : null;
51+
if (st == null || st.isDisposed()) {
52+
return;
53+
}
54+
Font current = st.getFont();
55+
if (current == null || current.isDisposed()) {
56+
return;
57+
}
58+
FontData[] fontData = current.getFontData();
59+
if (fontData == null || fontData.length == 0) {
60+
return;
61+
}
62+
int currentHeight = fontData[0].getHeight();
63+
int newHeight = Math.max(MIN_FONT_SIZE, Math.min(MAX_FONT_SIZE, currentHeight + delta));
64+
if (newHeight == currentHeight) {
65+
return;
66+
}
67+
FontData[] newFontData = fontData.clone();
68+
for (FontData fd : newFontData) {
69+
if (fd != null)
70+
fd.setHeight(newHeight);
71+
}
72+
73+
Font oldZoom = (Font) st.getData(ZOOM_FONT_KEY);
74+
Font newZoom = new Font(st.getDisplay(), newFontData);
75+
st.setFont(newZoom);
76+
st.setData(ZOOM_FONT_KEY, newZoom);
77+
if (oldZoom == null) {
78+
st.addDisposeListener(e -> {
79+
Font z = (Font) st.getData(ZOOM_FONT_KEY);
80+
if (z != null && !z.isDisposed())
81+
z.dispose();
82+
});
83+
}
84+
if (oldZoom != null && !oldZoom.isDisposed()) {
85+
oldZoom.dispose();
86+
}
87+
88+
// Update shared JFace registry so other listeners can observe the change
89+
JFaceResources.getFontRegistry().put(DEBUG_CONSOLE_FONT_REGISTRY_KEY, newFontData);
90+
});
91+
}
92+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.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.Display;
24+
25+
/**
26+
* Command handler to decrease the font size of the focused console StyledText.
27+
*
28+
* @since 3.17
29+
*/
30+
public class ConsoleZoomOutHandler extends AbstractHandler {
31+
private static final String ZOOM_FONT_KEY = TextConsolePage.class.getName() + ".zoomFont"; //$NON-NLS-1$
32+
private static final String DEBUG_CONSOLE_FONT_REGISTRY_KEY = "org.eclipse.debug.ui.consoleFont"; //$NON-NLS-1$
33+
private static final int MIN_FONT_SIZE = 6;
34+
private static final int MAX_FONT_SIZE = 72;
35+
private static final int STEP = 1;
36+
37+
@Override
38+
public Object execute(ExecutionEvent event) throws ExecutionException {
39+
changeFocusedFont(-STEP);
40+
return null;
41+
}
42+
43+
private void changeFocusedFont(int delta) {
44+
Display display = Display.getCurrent();
45+
if (display == null) {
46+
display = Display.getDefault();
47+
}
48+
Display d = display;
49+
d.asyncExec(() -> {
50+
StyledText st = d.getFocusControl() instanceof StyledText ? (StyledText) d.getFocusControl() : null;
51+
if (st == null || st.isDisposed()) {
52+
return;
53+
}
54+
Font current = st.getFont();
55+
if (current == null || current.isDisposed()) {
56+
return;
57+
}
58+
FontData[] fontData = current.getFontData();
59+
if (fontData == null || fontData.length == 0) {
60+
return;
61+
}
62+
int currentHeight = fontData[0].getHeight();
63+
int newHeight = Math.max(MIN_FONT_SIZE, Math.min(MAX_FONT_SIZE, currentHeight + delta));
64+
if (newHeight == currentHeight) {
65+
return;
66+
}
67+
FontData[] newFontData = fontData.clone();
68+
for (FontData fd : newFontData) {
69+
if (fd != null)
70+
fd.setHeight(newHeight);
71+
}
72+
73+
Font oldZoom = (Font) st.getData(ZOOM_FONT_KEY);
74+
Font newZoom = new Font(st.getDisplay(), newFontData);
75+
st.setFont(newZoom);
76+
st.setData(ZOOM_FONT_KEY, newZoom);
77+
if (oldZoom == null) {
78+
st.addDisposeListener(e -> {
79+
Font z = (Font) st.getData(ZOOM_FONT_KEY);
80+
if (z != null && !z.isDisposed())
81+
z.dispose();
82+
});
83+
}
84+
if (oldZoom != null && !oldZoom.isDisposed()) {
85+
oldZoom.dispose();
86+
}
87+
// Update shared JFace registry so other listeners can observe the change
88+
JFaceResources.getFontRegistry().put(DEBUG_CONSOLE_FONT_REGISTRY_KEY, newFontData);
89+
});
90+
}
91+
}

0 commit comments

Comments
 (0)