Skip to content

Commit 338e090

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 144d934 commit 338e090

File tree

11 files changed

+138
-13
lines changed

11 files changed

+138
-13
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 autoPinEditor = new BooleanFieldEditor(IConsoleConstants.AUTO_PIN_ENABLED_PREF_NAME,
181+
DebugPreferencesMessages.ConsolePreferencePage_ConsoleAutoPinEnable, SWT.NONE, getFieldEditorParent());
182+
autoPinEditor.setPreferenceStore(ConsolePlugin.getDefault().getPreferenceStore());
183+
addField(autoPinEditor);
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, when a new Console view 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ 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 automatically pinning current Console view when
176+
* opening a new Console view.
177+
*
178+
* @since 3.15
179+
*/
180+
String AUTO_PIN_ENABLED_PREF_NAME = ConsolePlugin.getUniqueIdentifier() + ".AUTO_PIN_ENABLED"; //$NON-NLS-1$
181+
166182
/**
167183
* The default tab size for text consoles.
168184
*

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public void initializeDefaultPreferences() {
2929
IPreferenceStore prefs = ConsolePlugin.getDefault().getPreferenceStore();
3030
prefs.setDefault(IConsoleConstants.P_CONSOLE_AUTO_SCROLL_LOCK, true);
3131
prefs.setDefault(IConsoleConstants.P_CONSOLE_WORD_WRAP, false);
32+
prefs.setDefault(IConsoleConstants.AUTO_PIN_ENABLED_PREF_NAME, false);
33+
prefs.setDefault(IConsoleConstants.REMEMBER_AUTO_PIN_DECISION_PREF_NAME, false);
3234
}
3335

3436
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ protected void createActions() {
462462
ConsoleFactoryExtension[] extensions = ((ConsoleManager)ConsolePlugin.getDefault().getConsoleManager()).getConsoleFactoryExtensions();
463463
if (extensions.length > 0) {
464464
fOpenConsoleAction = new OpenConsoleAction();
465+
fOpenConsoleAction.setOwnerView(this);
465466
}
466467
}
467468

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

Lines changed: 60 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;
@@ -24,22 +29,66 @@
2429
public class ConsoleViewConsoleFactory implements IConsoleFactory {
2530

2631
int counter = 1;
32+
private ConsoleView currentConsoleView;
2733

2834
@Override
2935
public void openConsole() {
3036
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-
}
37+
if (window == null) {
38+
return;
4239
}
40+
IWorkbenchPage page = window.getActivePage();
41+
if (page == null) {
42+
return;
43+
}
44+
handleAutoPin();
45+
try {
46+
String secondaryId = "Console View #" + counter; //$NON-NLS-1$
47+
page.showView(IConsoleConstants.ID_CONSOLE_VIEW, secondaryId, 1);
48+
counter++;
49+
} catch (PartInitException e) {
50+
ConsolePlugin.log(e);
51+
}
52+
}
53+
54+
/**
55+
* This handler checks if the remember auto-pin decision state <b>not true</b>
56+
* and asks the user if auto pin of the view content should be enabled.
57+
* Afterwards it checks if remember auto-pin decision was checked and sets the
58+
* preference according to that
59+
*
60+
* If the remember auto-pin decision state is <b>true</b> it gathers the auto
61+
* pin preference value and sets this to the current view.
62+
*/
63+
private void handleAutoPin() {
64+
if (currentConsoleView == null) {
65+
return;
66+
}
67+
IPreferenceStore store = ConsolePlugin.getDefault().getPreferenceStore();
68+
if (!store.getBoolean(IConsoleConstants.REMEMBER_AUTO_PIN_DECISION_PREF_NAME)) {
69+
Shell shell = Display.getDefault().getActiveShell();
70+
MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(shell,
71+
Messages.ConsoleViewConsoleFactory_TurnOnAutoPinDialogTitle,
72+
Messages.ConsoleViewConsoleFactory_TurnOnAutoPinDialogMessage,
73+
Messages.ConsoleViewConsoleFactory_TurnOnAutoPinRememberDecision, false, null, null);
74+
75+
store.setValue(IConsoleConstants.AUTO_PIN_ENABLED_PREF_NAME,
76+
toggleDialog.getReturnCode() == IDialogConstants.YES_ID);
77+
78+
store.setValue(IConsoleConstants.REMEMBER_AUTO_PIN_DECISION_PREF_NAME, toggleDialog.getToggleState());
79+
}
80+
81+
if (store.getBoolean(IConsoleConstants.AUTO_PIN_ENABLED_PREF_NAME)) {
82+
// To avoid if pinned manually and unpin due to preference..
83+
currentConsoleView.setPinned(true);
84+
}
85+
}
86+
87+
/**
88+
* Sets the console view, on which the open new console action was called.
89+
*/
90+
void setConsoleView(ConsoleView consoleView) {
91+
this.currentConsoleView = consoleView;
4392
}
4493

4594
}
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+
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class OpenConsoleAction extends Action implements IMenuCreator {
3939

4040
private ConsoleFactoryExtension[] fFactoryExtensions;
4141
private Menu fMenu;
42+
private ConsoleView consoleView;
4243

4344
public OpenConsoleAction() {
4445
super(ConsoleMessages.OpenConsoleAction_0, AS_DROP_DOWN_MENU);
@@ -64,6 +65,13 @@ private ConsoleFactoryExtension[] getSortedFactories() {
6465
return factoryExtensions;
6566
}
6667

68+
/**
69+
* @param consoleView the view which this action belongs to.
70+
*/
71+
void setOwnerView(ConsoleView consoleView) {
72+
this.consoleView = consoleView;
73+
}
74+
6775
@Override
6876
public void dispose() {
6977
fFactoryExtensions = null;
@@ -147,7 +155,9 @@ public void run() {
147155
if (fFactory == null) {
148156
fFactory = fConfig.createFactory();
149157
}
150-
158+
if (fFactory instanceof ConsoleViewConsoleFactory consViewConsFactory) {
159+
consViewConsFactory.setConsoleView(consoleView);
160+
}
151161
fFactory.openConsole();
152162
} catch (CoreException e) {
153163
ConsolePlugin.log(e);

0 commit comments

Comments
 (0)