Skip to content

Commit 9515721

Browse files
committed
Incorporated the review comments
- Changed the check box to drop down with Top and Bottom options - Made the private methods protected - Converted the preference store value from boolean to int and storing the SWT value of the selection directly
1 parent 64d3f61 commit 9515721

File tree

7 files changed

+51
-39
lines changed

7 files changed

+51
-39
lines changed

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected Control createContents(Composite parent) {
6262
createUseIPersistablePref(composite);
6363
createPromptWhenStillOpenPref(composite);
6464
createEditorReuseGroup(composite);
65-
createAlignMultiPageEditorTabsOnTop(composite);
65+
createAlignMultiPageEditorTabs(composite);
6666

6767
applyDialogFont(composite);
6868

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,19 +625,18 @@ public interface IWorkbenchPreferenceConstants {
625625
String DISABLE_OPEN_EDITOR_IN_PLACE = "DISABLE_OPEN_EDITOR_IN_PLACE"; //$NON-NLS-1$
626626

627627
/**
628-
* Workbench preference id for whether the tabs in the multi-page editor is
629-
* displayed on top. Note that tabs will be shown in the top only if this
630-
* preference is <code>true</code>.
628+
* Workbench preference id for the position of the tabs in the multi-page
629+
* editor.
631630
*
632-
* Boolean-valued: <code>true</code> show the tabs on the top, and
633-
* <code>false</code> if shown at the bottom.
631+
* Integer-valued: {@link SWT#TOP} for tabs on the top, and {@link SWT#BOTTOM}
632+
* for tabs at the bottom.
634633
* <p>
635-
* The default value for this preference is: <code>false</code>
634+
* The default value for this preference is: {@link SWT#BOTTOM}
636635
* </p>
637636
*
638637
* @since 3.133
639638
*/
640-
String ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP = "ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP"; //$NON-NLS-1$
639+
String ALIGN_MULTI_PAGE_EDITOR_TABS = "ALIGN_MULTI_PAGE_EDITOR_TABS"; //$NON-NLS-1$
641640

642641
/**
643642
* Workbench preference id for indicating the size of the list of most recently

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ public class WorkbenchMessages extends NLS {
452452
public static String WorkbenchPreference_stickyCycleButton;
453453
public static String WorkbenchPreference_RunInBackgroundButton;
454454
public static String WorkbenchPreference_RunInBackgroundToolTip;
455-
public static String WorkbenchPreference_AlignMultiPageEditorTabsOnTopButton;
455+
public static String WorkbenchPreference_AlignMultiPageEditorTabs;
456+
public static String WorkbenchPreference_AlignMultiPageEditorTabs_Top;
457+
public static String WorkbenchPreference_AlignMultiPageEditorTabs_Bottom;
456458

457459
// --- Appearance ---
458460
public static String ViewsPreferencePage_Theme;

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPreferenceInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public void initializeDefaultPreferences() {
102102
// Heap status preferences is stored in different node
103103
IEclipsePreferences heapNode = context.getNode("org.eclipse.ui"); //$NON-NLS-1$
104104
heapNode.putBoolean(IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR, false);
105+
heapNode.putInt(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS, SWT.BOTTOM);
105106
node.putInt(IHeapStatusConstants.PREF_UPDATE_INTERVAL, 500);
106107
node.putBoolean(IHeapStatusConstants.PREF_SHOW_MAX, false);
107108
node.putBoolean(IPreferenceConstants.OVERRIDE_PRESENTATION, false);

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
2020

21+
import org.eclipse.jface.action.Action;
22+
import org.eclipse.jface.layout.GridDataFactory;
23+
import org.eclipse.jface.layout.GridLayoutFactory;
24+
import org.eclipse.jface.preference.ComboFieldEditor;
2125
import org.eclipse.jface.preference.FieldEditor;
2226
import org.eclipse.jface.preference.IPreferenceStore;
2327
import org.eclipse.jface.preference.IntegerFieldEditor;
@@ -72,7 +76,7 @@ public class EditorsPreferencePage extends PreferencePage implements IWorkbenchP
7276

7377
private Button allowInplaceEditor;
7478

75-
private Button alignMultiPageEditorTabsOnTop;
79+
private ComboFieldEditor multiPageEditorTabPositionComboField;
7680

7781
@Override
7882
protected Control createContents(Composite parent) {
@@ -132,13 +136,21 @@ protected void createPromptWhenStillOpenPref(Composite composite) {
132136
setButtonLayoutData(promptWhenStillOpenEditor);
133137
}
134138

135-
protected void createAlignMultiPageEditorTabsOnTop(Composite composite) {
136-
alignMultiPageEditorTabsOnTop = new Button(composite, SWT.CHECK);
137-
alignMultiPageEditorTabsOnTop
138-
.setText(WorkbenchMessages.WorkbenchPreference_AlignMultiPageEditorTabsOnTopButton);
139-
alignMultiPageEditorTabsOnTop.setSelection(
140-
getAPIPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP));
141-
setButtonLayoutData(alignMultiPageEditorTabsOnTop);
139+
protected void createAlignMultiPageEditorTabs(Composite parent) {
140+
Composite comboComposite = new Composite(parent, SWT.NONE);
141+
comboComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
142+
comboComposite.setLayoutData(GridDataFactory.fillDefaults().create());
143+
String name = IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS;
144+
String label = WorkbenchMessages.WorkbenchPreference_AlignMultiPageEditorTabs;
145+
String[][] namesAndValues = {
146+
{ Action.removeMnemonics(WorkbenchMessages.WorkbenchPreference_AlignMultiPageEditorTabs_Top),
147+
String.valueOf(SWT.TOP) },
148+
{ Action.removeMnemonics(WorkbenchMessages.WorkbenchPreference_AlignMultiPageEditorTabs_Bottom),
149+
String.valueOf(SWT.BOTTOM) } };
150+
multiPageEditorTabPositionComboField = new ComboFieldEditor(name, label, namesAndValues, comboComposite);
151+
multiPageEditorTabPositionComboField.setPreferenceStore(getAPIPreferenceStore());
152+
multiPageEditorTabPositionComboField.setPage(this);
153+
multiPageEditorTabPositionComboField.load();
142154
}
143155

144156
protected Composite createComposite(Composite parent) {
@@ -161,8 +173,6 @@ protected void performDefaults() {
161173
IPreferenceStore store = getPreferenceStore();
162174
allowInplaceEditor.setSelection(
163175
!getAPIPreferenceStore().getDefaultBoolean(IWorkbenchPreferenceConstants.DISABLE_OPEN_EDITOR_IN_PLACE));
164-
alignMultiPageEditorTabsOnTop.setSelection(getAPIPreferenceStore()
165-
.getDefaultBoolean(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP));
166176
useIPersistableEditor.setSelection(store.getDefaultBoolean(IPreferenceConstants.USE_IPERSISTABLE_EDITORS));
167177
promptWhenStillOpenEditor.setSelection(getAPIPreferenceStore()
168178
.getDefaultBoolean(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN));
@@ -171,13 +181,13 @@ protected void performDefaults() {
171181
reuseEditorsThreshold.getLabelControl(editorReuseThresholdGroup).setEnabled(reuseEditors.getSelection());
172182
reuseEditorsThreshold.getTextControl(editorReuseThresholdGroup).setEnabled(reuseEditors.getSelection());
173183
recentFilesEditor.loadDefault();
184+
multiPageEditorTabPositionComboField.loadDefault();
174185
}
175186

176187
@Override
177188
public boolean performOk() {
178189
IPreferenceStore store = getPreferenceStore();
179-
getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP,
180-
alignMultiPageEditorTabsOnTop.getSelection());
190+
multiPageEditorTabPositionComboField.store();
181191
getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.DISABLE_OPEN_EDITOR_IN_PLACE,
182192
!allowInplaceEditor.getSelection());
183193
store.setValue(IPreferenceConstants.USE_IPERSISTABLE_EDITORS, useIPersistableEditor.getSelection());

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,9 @@ WorkbenchPreference_RunInBackgroundButton=Always r&un in background
419419
WorkbenchPreference_RunInBackgroundToolTip=Run long operations in the background where possible
420420
WorkbenchPreference_HeapStatusButton = Sho&w heap status
421421
WorkbenchPreference_HeapStatusButtonToolTip = Show the heap status area on the bottom of the window
422-
WorkbenchPreference_AlignMultiPageEditorTabsOnTopButton= &Align multi-page editor tabs on top
422+
WorkbenchPreference_AlignMultiPageEditorTabs= &Align multi-page editor tabs:
423+
WorkbenchPreference_AlignMultiPageEditorTabs_Top= &Top
424+
WorkbenchPreference_AlignMultiPageEditorTabs_Bottom= &Bottom
423425

424426

425427
# --- Appearance ---

bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,24 @@ public abstract class MultiPageEditorPart extends EditorPart implements IPageCha
161161
protected MultiPageEditorPart() {
162162
super();
163163
getAPIPreferenceStore().addPropertyChangeListener(event -> {
164-
handlePropertyChange(event);
164+
if (isUpdateRequired(event)) {
165+
updateContainer();
166+
}
165167
});
166168
}
167169

168170
/**
169-
* Handles property change events related to editor preferences.
170-
*
171-
* <p>
172-
* This method is invoked when a property change occurs in the preference store.
173-
* </p>
171+
* Determines whether an update is required based on a property change event.
174172
*
175173
* @param event the {@link PropertyChangeEvent} triggered by a change in the
176174
* preference store
175+
* @since 3.133
177176
*/
178-
private void handlePropertyChange(PropertyChangeEvent event) {
179-
if (event.getProperty().equals(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP)) {
180-
updateContainer();
177+
protected boolean isUpdateRequired(PropertyChangeEvent event) {
178+
if (event.getProperty().equals(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS)) {
179+
return true;
181180
}
181+
return false;
182182
}
183183

184184
/**
@@ -290,7 +290,7 @@ protected CTabFolder createContainer(Composite parent) {
290290
// use SWT.FLAT style so that an extra 1 pixel border is not reserved
291291
// inside the folder
292292
parent.setLayout(new FillLayout());
293-
final CTabFolder newContainer = new CTabFolder(parent, getPreferredTabStyle());
293+
final CTabFolder newContainer = new CTabFolder(parent, getTabStyle() | SWT.FLAT);
294294
newContainer.addSelectionListener(widgetSelectedAdapter(e -> {
295295
int newPageIndex = newContainer.indexOf((CTabItem) e.item);
296296
pageChange(newPageIndex);
@@ -318,7 +318,7 @@ protected CTabFolder createContainer(Composite parent) {
318318
}
319319

320320
/**
321-
* Determines the preferred tab style based on user preferences.
321+
* Determines the tab style based on user preferences.
322322
* <p>
323323
* This method retrieves the user preference for aligning multi-page editor tabs
324324
* on top or bottom, and returns the corresponding SWT style constant.
@@ -327,12 +327,10 @@ protected CTabFolder createContainer(Composite parent) {
327327
* @return {@code SWT.TOP} if the user prefers tabs to be aligned on top,
328328
* {@code SWT.BOTTOM} if the user prefers tabs to be aligned on the
329329
* bottom.
330+
* @since 3.133
330331
*/
331-
private int getPreferredTabStyle() {
332-
boolean alignTabsOnTop = getAPIPreferenceStore()
333-
.getBoolean(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP);
334-
int style = alignTabsOnTop ? SWT.TOP : SWT.BOTTOM;
335-
return style;
332+
protected int getTabStyle() {
333+
return getAPIPreferenceStore().getInt(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS);
336334
}
337335

338336
/**
@@ -1285,7 +1283,7 @@ public void run() {
12851283
private void updateContainer() {
12861284
Composite container = getContainer();
12871285
if (container instanceof CTabFolder tabFolder) {
1288-
tabFolder.setTabPosition(getPreferredTabStyle());
1286+
tabFolder.setTabPosition(getTabStyle());
12891287
tabFolder.requestLayout();
12901288
}
12911289
}

0 commit comments

Comments
 (0)