Skip to content

Commit 8f2bf10

Browse files
mehmet-karamaniloveeclipse
authored andcommitted
"Auto pin" behavior for opening new Console view from existing Console
- Added "auto pin behavior" for the Console view. If user opens a new Console view from opened Console, it will raise the question if Consoles should be pinned or not. - Added new preference to the ConsolePreferencePage - Bu default the preference will be enabled See #2240
1 parent 24be9b0 commit 8f2bf10

File tree

11 files changed

+119
-18
lines changed

11 files changed

+119
-18
lines changed

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

Lines changed: 7 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);
@@ -324,6 +328,9 @@ protected void performDefaults() {
324328
updateBufferSizeEditor();
325329
updateInterpretCrAsControlCharacterEditor();
326330
updateElapsedTimePreferences();
331+
332+
IPreferenceStore prefStore = ConsolePlugin.getDefault().getPreferenceStore();
333+
prefStore.setValue(IConsoleConstants.REMEMBER_AUTO_PIN_DECISION_PREF_NAME, false);
327334
}
328335

329336
protected boolean canClearErrorMessage() {

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=Pin current and the new Console views 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/ConsoleMessages.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public class ConsoleMessages extends NLS {
3333
public static String PinConsoleAction_0;
3434
public static String PinConsoleAction_1;
3535

36+
public static String TurnOnAutoPinDialogMessage;
37+
public static String TurnOnAutoPinDialogTitle;
38+
public static String TurnOnAutoPinRememberDecision;
39+
3640
public static String ClearOutputAction_title;
3741
public static String ClearOutputAction_toolTipText;
3842

@@ -63,6 +67,7 @@ public class ConsoleMessages extends NLS {
6367
public static String TextConsolePage_PasteText;
6468
public static String TextConsolePage_PasteDescrip;
6569

70+
6671
static {
6772
// load message values from bundle file
6873
NLS.initializeMessages(BUNDLE_NAME, ConsoleMessages.class);

debug/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleMessages.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ TextConsolePage_PasteDescrip=Paste
5858
PatternMatchListenerExtension_3=Console Pattern Match Listener
5959
PatternMatchListenerExtension_4=contributed by
6060
PatternMatchListenerExtension_5=is missing required enablement expression and will be removed
61-
UpdatingConsoleState=Updating console state
61+
UpdatingConsoleState=Updating console state
62+
TurnOnAutoPinDialogMessage=To see updates of different console pages in parallel, both current and new Console view will be pinned now.
63+
TurnOnAutoPinDialogTitle=Pin Console views?
64+
TurnOnAutoPinRememberDecision=Remember my decision

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, true);
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ protected void createActions() {
461461
fDisplayConsoleAction = new ConsoleDropDownAction(this);
462462
ConsoleFactoryExtension[] extensions = ((ConsoleManager)ConsolePlugin.getDefault().getConsoleManager()).getConsoleFactoryExtensions();
463463
if (extensions.length > 0) {
464-
fOpenConsoleAction = new OpenConsoleAction();
464+
fOpenConsoleAction = new OpenConsoleAction(this);
465465
}
466466
}
467467

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

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
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;
21+
import org.eclipse.ui.IViewPart;
1622
import org.eclipse.ui.IWorkbenchPage;
1723
import org.eclipse.ui.IWorkbenchWindow;
1824
import org.eclipse.ui.PartInitException;
@@ -24,22 +30,70 @@
2430
public class ConsoleViewConsoleFactory implements IConsoleFactory {
2531

2632
int counter = 1;
33+
private ConsoleView currentConsoleView;
2734

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

4599
}

0 commit comments

Comments
 (0)