Skip to content

Commit ac36083

Browse files
- Added auto pin behavior for the console view. If user opens a new
console, it will raise the question if auto pin should be done. - Added a new preference to the ConsolePreferencePage
1 parent a97efae commit ac36083

File tree

8 files changed

+116
-12
lines changed

8 files changed

+116
-12
lines changed

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/ConsolePreferencePage.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ public void widgetSelected(SelectionEvent e) {
177177
addField(new BooleanFieldEditor(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, DebugPreferencesMessages.ConsolePreferencePage_Show__Console_View_when_there_is_program_output_3, SWT.NONE, getFieldEditorParent()));
178178
addField(new BooleanFieldEditor(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, DebugPreferencesMessages.ConsolePreferencePage_Show__Console_View_when_there_is_program_error_3, SWT.NONE, getFieldEditorParent()));
179179

180+
BooleanFieldEditor editor = new BooleanFieldEditor(IConsoleConstants.AUTO_PIN_ENABLED_PREF_NAME,
181+
DebugPreferencesMessages.ConsolePreferencePage_ConsoleAutoPinEnable, SWT.NONE, getFieldEditorParent());
182+
editor.setPreferenceStore(ConsolePlugin.getDefault().getPreferenceStore());
183+
addField(editor);
180184
Label comboLabel = new Label(getFieldEditorParent(), SWT.NONE);
181185
comboLabel.setText(DebugPreferencesMessages.ConsoleElapsedTimeLabel);
182186
fElapsedFormat = new ComboViewer(getFieldEditorParent(), SWT.DROP_DOWN | SWT.BORDER);

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class DebugPreferencesMessages extends NLS {
3131
public static String ConsolePreferencePage_Console_width;
3232
public static String ConsolePreferencePage_Limit_console_output_1;
3333
public static String ConsolePreferencePage_Console_buffer_size__characters___2;
34+
35+
public static String ConsolePreferencePage_ConsoleAutoPinEnable;
3436
public static String ConsolePreferencePage_The_console_buffer_size_must_be_at_least_1000_characters__1;
3537
public static String ConsolePreferencePage_console_width;
3638
public static String ConsolePreferencePage_12;

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ConsolePreferencePage_Wrap_text_1=Fixed &width console
2323
ConsolePreferencePage_Console_width=&Maximum character width:
2424
ConsolePreferencePage_Limit_console_output_1=&Limit console output
2525
ConsolePreferencePage_Console_buffer_size__characters___2=Console &buffer size (characters):
26+
ConsolePreferencePage_ConsoleAutoPinEnable=Auto pin current console view, if new console is opened
2627
ConsolePreferencePage_The_console_buffer_size_must_be_at_least_1000_characters__1=Buffer size must be between 1000 and {0} inclusive.
2728
ConsolePreferencePage_console_width=Character width must be between 80 and 1000 inclusive.
2829
ConsolePreferencePage_12=Displayed &tab width:

debug/org.eclipse.ui.console/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.ui.console; singleton:=true
5-
Bundle-Version: 3.14.400.qualifier
5+
Bundle-Version: 3.15.0.qualifier
66
Bundle-Activator: org.eclipse.ui.console.ConsolePlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin

debug/org.eclipse.ui.console/src/org/eclipse/ui/console/IConsoleConstants.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ public interface IConsoleConstants {
163163
*/
164164
String P_CONSOLE_WORD_WRAP = ConsolePlugin.getUniqueIdentifier() + ".P_CONSOLE_WORD_WRAP"; //$NON-NLS-1$
165165

166+
/**
167+
* The preference name for the auto pin question to avoid that opening for every
168+
* new console opening.
169+
*
170+
* @since 3.15
171+
*/
172+
String REMEMBER_AUTO_PIN_DECISION_PREF_NAME = ConsolePlugin.getUniqueIdentifier() + ".AUTO_PIN_ASKED"; //$NON-NLS-1$
173+
174+
/**
175+
* The preference name for the auto pin.
176+
*
177+
* @since 3.15
178+
*/
179+
String AUTO_PIN_ENABLED_PREF_NAME = ConsolePlugin.getUniqueIdentifier() + ".AUTO_PIN_ENABLED"; //$NON-NLS-1$
180+
166181
/**
167182
* The default tab size for text consoles.
168183
*

debug/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleViewConsoleFactory.java

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.internal.console;
1515

16+
import org.eclipse.jface.dialogs.IDialogConstants;
17+
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
18+
import org.eclipse.jface.preference.IPreferenceStore;
19+
import org.eclipse.swt.widgets.Display;
20+
import org.eclipse.swt.widgets.Shell;
1621
import org.eclipse.ui.IWorkbenchPage;
1722
import org.eclipse.ui.IWorkbenchWindow;
1823
import org.eclipse.ui.PartInitException;
@@ -28,17 +33,54 @@ public class ConsoleViewConsoleFactory implements IConsoleFactory {
2833
@Override
2934
public void openConsole() {
3035
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
31-
if (window != null) {
32-
IWorkbenchPage page = window.getActivePage();
33-
if (page != null) {
34-
try {
35-
String secondaryId = "Console View #" + counter; //$NON-NLS-1$
36-
page.showView(IConsoleConstants.ID_CONSOLE_VIEW, secondaryId, 1);
37-
counter++;
38-
} catch (PartInitException e) {
39-
ConsolePlugin.log(e);
40-
}
41-
}
36+
if (window == null) {
37+
return;
38+
}
39+
IWorkbenchPage page = window.getActivePage();
40+
if (page == null) {
41+
return;
42+
}
43+
handleAutoPin(page);
44+
try {
45+
String secondaryId = "Console View #" + counter; //$NON-NLS-1$
46+
page.showView(IConsoleConstants.ID_CONSOLE_VIEW, secondaryId, 1);
47+
counter++;
48+
} catch (PartInitException e) {
49+
ConsolePlugin.log(e);
50+
}
51+
}
52+
53+
/**
54+
* This handler checks if the remember auto-pin decision state <b>not true</b>
55+
* and asks the user if auto pin of the view content should be enabled.
56+
* Afterwards it checks if remember auto-pin decision was checked and sets the
57+
* preference according to that
58+
*
59+
* If the remember auto-pin decision state is <b>true</b> it gathers the auto
60+
* pin preference value and sets this to the current view.
61+
*
62+
* @param page the active page
63+
* @since 3.14
64+
*/
65+
private void handleAutoPin(IWorkbenchPage page) {
66+
IPreferenceStore store = ConsolePlugin.getDefault().getPreferenceStore();
67+
if (!store.getBoolean(IConsoleConstants.REMEMBER_AUTO_PIN_DECISION_PREF_NAME)) {
68+
Shell shell = Display.getDefault().getActiveShell();
69+
MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(shell,
70+
Messages.ConsoleViewConsoleFactory_TurnOnAutoPinDialogTitle,
71+
Messages.ConsoleViewConsoleFactory_TurnOnAutoPinDialogMessage,
72+
Messages.ConsoleViewConsoleFactory_TurnOnAutoPinRememberDecision, false, null, null);
73+
74+
store.setValue(IConsoleConstants.AUTO_PIN_ENABLED_PREF_NAME,
75+
toggleDialog.getReturnCode() == IDialogConstants.YES_ID);
76+
77+
store.setValue(IConsoleConstants.REMEMBER_AUTO_PIN_DECISION_PREF_NAME, toggleDialog.getToggleState());
78+
}
79+
80+
if (store.getBoolean(IConsoleConstants.AUTO_PIN_ENABLED_PREF_NAME)
81+
&& page.getActivePart() instanceof ConsoleView currentConsoleView) {
82+
// To avoid if pinned manually and unpin due to preference..
83+
currentConsoleView.setPinned(true);
4284
}
4385
}
4486

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.eclipse.ui.internal.console;
2+
3+
import org.eclipse.osgi.util.NLS;
4+
5+
/**
6+
* @since 3.14
7+
*/
8+
public class Messages extends NLS {
9+
10+
/**
11+
* @since 3.14
12+
*/
13+
private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$
14+
15+
/**
16+
* @since 3.14
17+
*/
18+
public static String ConsoleViewConsoleFactory_TurnOnAutoPinDialogMessage;
19+
20+
/**
21+
* @since 3.14
22+
*/
23+
public static String ConsoleViewConsoleFactory_TurnOnAutoPinDialogTitle;
24+
25+
/**
26+
* @since 3.14
27+
*/
28+
public static String ConsoleViewConsoleFactory_TurnOnAutoPinRememberDecision;
29+
30+
static {
31+
// initialize resource bundle
32+
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
33+
}
34+
35+
private Messages() {
36+
}
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ConsoleViewConsoleFactory_TurnOnAutoPinDialogMessage=If a new console is opened, it's possible to auto pin the old console view to keep its content. Would you like to turn on the auto pin?
2+
ConsoleViewConsoleFactory_TurnOnAutoPinDialogTitle=Enable auto pin
3+
ConsoleViewConsoleFactory_TurnOnAutoPinRememberDecision=Remember my decision

0 commit comments

Comments
 (0)