From 5dc1350eb9796007f404c5af603053d176acb23d Mon Sep 17 00:00:00 2001 From: "Praveen S.K" Date: Thu, 29 Aug 2024 09:01:27 +0530 Subject: [PATCH] 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 --- .../ide/dialogs/IDEEditorsPreferencePage.java | 2 +- .../ui/IWorkbenchPreferenceConstants.java | 13 ++++---- .../ui/internal/WorkbenchMessages.java | 4 ++- .../WorkbenchPreferenceInitializer.java | 1 + .../dialogs/EditorsPreferencePage.java | 32 ++++++++++++------- .../eclipse/ui/internal/messages.properties | 4 ++- .../eclipse/ui/part/MultiPageEditorPart.java | 32 +++++++++---------- 7 files changed, 49 insertions(+), 39 deletions(-) diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java index cfa0ff1cb5f..13d631e8276 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/IDEEditorsPreferencePage.java @@ -62,7 +62,7 @@ protected Control createContents(Composite parent) { createUseIPersistablePref(composite); createPromptWhenStillOpenPref(composite); createEditorReuseGroup(composite); - createAlignMultiPageEditorTabsOnTop(composite); + createAlignMultiPageEditorTabs(composite); applyDialogFont(composite); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java index 3118dfa6f04..708570610a7 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPreferenceConstants.java @@ -625,19 +625,18 @@ public interface IWorkbenchPreferenceConstants { String DISABLE_OPEN_EDITOR_IN_PLACE = "DISABLE_OPEN_EDITOR_IN_PLACE"; //$NON-NLS-1$ /** - * Workbench preference id for whether the tabs in the multi-page editor is - * displayed on top. Note that tabs will be shown in the top only if this - * preference is true. + * Workbench preference id for the position of the tabs in the multi-page + * editor. * - * Boolean-valued: true show the tabs on the top, and - * false if shown at the bottom. + * Integer-valued: {@link SWT#TOP} for tabs on the top, and {@link SWT#BOTTOM} + * for tabs at the bottom. *

- * The default value for this preference is: false + * The default value for this preference is: {@link SWT#BOTTOM} *

* * @since 3.133 */ - String ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP = "ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP"; //$NON-NLS-1$ + String ALIGN_MULTI_PAGE_EDITOR_TABS = "ALIGN_MULTI_PAGE_EDITOR_TABS"; //$NON-NLS-1$ /** * Workbench preference id for indicating the size of the list of most recently diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java index 449a51f0778..ec1e7cc8554 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java @@ -462,7 +462,9 @@ public class WorkbenchMessages extends NLS { public static String WorkbenchPreference_stickyCycleButton; public static String WorkbenchPreference_RunInBackgroundButton; public static String WorkbenchPreference_RunInBackgroundToolTip; - public static String WorkbenchPreference_AlignMultiPageEditorTabsOnTopButton; + public static String WorkbenchPreference_AlignMultiPageEditorTabs; + public static String WorkbenchPreference_AlignMultiPageEditorTabs_Top; + public static String WorkbenchPreference_AlignMultiPageEditorTabs_Bottom; // --- Appearance --- public static String ViewsPreferencePage_Theme; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPreferenceInitializer.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPreferenceInitializer.java index 66fff649148..349dc1e744b 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPreferenceInitializer.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPreferenceInitializer.java @@ -102,6 +102,7 @@ public void initializeDefaultPreferences() { // Heap status preferences is stored in different node IEclipsePreferences heapNode = context.getNode("org.eclipse.ui"); //$NON-NLS-1$ heapNode.putBoolean(IWorkbenchPreferenceConstants.SHOW_MEMORY_MONITOR, false); + heapNode.putInt(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS, SWT.BOTTOM); node.putInt(IHeapStatusConstants.PREF_UPDATE_INTERVAL, 500); node.putBoolean(IHeapStatusConstants.PREF_SHOW_MAX, false); node.putBoolean(IPreferenceConstants.OVERRIDE_PRESENTATION, false); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java index 26a5f2fbc46..11807871b86 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/EditorsPreferencePage.java @@ -18,8 +18,10 @@ import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; +import org.eclipse.jface.action.Action; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.preference.ComboFieldEditor; import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IntegerFieldEditor; @@ -74,7 +76,7 @@ public class EditorsPreferencePage extends PreferencePage implements IWorkbenchP private Button allowInplaceEditor; - private Button alignMultiPageEditorTabsOnTop; + private ComboFieldEditor multiPageEditorTabPositionComboField; @Override protected Control createContents(Composite parent) { @@ -134,13 +136,21 @@ protected void createPromptWhenStillOpenPref(Composite composite) { setButtonLayoutData(promptWhenStillOpenEditor); } - protected void createAlignMultiPageEditorTabsOnTop(Composite composite) { - alignMultiPageEditorTabsOnTop = new Button(composite, SWT.CHECK); - alignMultiPageEditorTabsOnTop - .setText(WorkbenchMessages.WorkbenchPreference_AlignMultiPageEditorTabsOnTopButton); - alignMultiPageEditorTabsOnTop.setSelection( - getAPIPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP)); - setButtonLayoutData(alignMultiPageEditorTabsOnTop); + protected void createAlignMultiPageEditorTabs(Composite parent) { + Composite comboComposite = new Composite(parent, SWT.NONE); + comboComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create()); + comboComposite.setLayoutData(GridDataFactory.fillDefaults().create()); + String name = IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS; + String label = WorkbenchMessages.WorkbenchPreference_AlignMultiPageEditorTabs; + String[][] namesAndValues = { + { Action.removeMnemonics(WorkbenchMessages.WorkbenchPreference_AlignMultiPageEditorTabs_Top), + String.valueOf(SWT.TOP) }, + { Action.removeMnemonics(WorkbenchMessages.WorkbenchPreference_AlignMultiPageEditorTabs_Bottom), + String.valueOf(SWT.BOTTOM) } }; + multiPageEditorTabPositionComboField = new ComboFieldEditor(name, label, namesAndValues, comboComposite); + multiPageEditorTabPositionComboField.setPreferenceStore(getAPIPreferenceStore()); + multiPageEditorTabPositionComboField.setPage(this); + multiPageEditorTabPositionComboField.load(); } protected Composite createComposite(Composite parent) { @@ -163,8 +173,6 @@ protected void performDefaults() { IPreferenceStore store = getPreferenceStore(); allowInplaceEditor.setSelection( !getAPIPreferenceStore().getDefaultBoolean(IWorkbenchPreferenceConstants.DISABLE_OPEN_EDITOR_IN_PLACE)); - alignMultiPageEditorTabsOnTop.setSelection(getAPIPreferenceStore() - .getDefaultBoolean(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP)); useIPersistableEditor.setSelection(store.getDefaultBoolean(IPreferenceConstants.USE_IPERSISTABLE_EDITORS)); promptWhenStillOpenEditor.setSelection(getAPIPreferenceStore() .getDefaultBoolean(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN)); @@ -173,13 +181,13 @@ protected void performDefaults() { reuseEditorsThreshold.getLabelControl(editorReuseThresholdGroup).setEnabled(reuseEditors.getSelection()); reuseEditorsThreshold.getTextControl(editorReuseThresholdGroup).setEnabled(reuseEditors.getSelection()); recentFilesEditor.loadDefault(); + multiPageEditorTabPositionComboField.loadDefault(); } @Override public boolean performOk() { IPreferenceStore store = getPreferenceStore(); - getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP, - alignMultiPageEditorTabsOnTop.getSelection()); + multiPageEditorTabPositionComboField.store(); getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.DISABLE_OPEN_EDITOR_IN_PLACE, !allowInplaceEditor.getSelection()); store.setValue(IPreferenceConstants.USE_IPERSISTABLE_EDITORS, useIPersistableEditor.getSelection()); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties index d31356d2a43..8e1eeb6fe7e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties @@ -419,7 +419,9 @@ WorkbenchPreference_RunInBackgroundButton=Always r&un in background WorkbenchPreference_RunInBackgroundToolTip=Run long operations in the background where possible WorkbenchPreference_HeapStatusButton = Sho&w heap status WorkbenchPreference_HeapStatusButtonToolTip = Show the heap status area on the bottom of the window -WorkbenchPreference_AlignMultiPageEditorTabsOnTopButton= &Align multi-page editor tabs on top +WorkbenchPreference_AlignMultiPageEditorTabs= &Align multi-page editor tabs: +WorkbenchPreference_AlignMultiPageEditorTabs_Top= &Top +WorkbenchPreference_AlignMultiPageEditorTabs_Bottom= &Bottom # --- Appearance --- diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java index fe41eee7cf8..0b1783bcf56 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java @@ -161,24 +161,24 @@ public abstract class MultiPageEditorPart extends EditorPart implements IPageCha protected MultiPageEditorPart() { super(); getAPIPreferenceStore().addPropertyChangeListener(event -> { - handlePropertyChange(event); + if (isUpdateRequired(event)) { + updateContainer(); + } }); } /** - * Handles property change events related to editor preferences. - * - *

- * This method is invoked when a property change occurs in the preference store. - *

+ * Determines whether an update is required based on a property change event. * * @param event the {@link PropertyChangeEvent} triggered by a change in the * preference store + * @since 3.133 */ - private void handlePropertyChange(PropertyChangeEvent event) { - if (event.getProperty().equals(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP)) { - updateContainer(); + protected boolean isUpdateRequired(PropertyChangeEvent event) { + if (event.getProperty().equals(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS)) { + return true; } + return false; } /** @@ -290,7 +290,7 @@ protected CTabFolder createContainer(Composite parent) { // use SWT.FLAT style so that an extra 1 pixel border is not reserved // inside the folder parent.setLayout(new FillLayout()); - final CTabFolder newContainer = new CTabFolder(parent, getPreferredTabStyle()); + final CTabFolder newContainer = new CTabFolder(parent, getTabStyle() | SWT.FLAT); newContainer.addSelectionListener(widgetSelectedAdapter(e -> { int newPageIndex = newContainer.indexOf((CTabItem) e.item); pageChange(newPageIndex); @@ -318,7 +318,7 @@ protected CTabFolder createContainer(Composite parent) { } /** - * Determines the preferred tab style based on user preferences. + * Determines the tab style based on user preferences. *

* This method retrieves the user preference for aligning multi-page editor tabs * on top or bottom, and returns the corresponding SWT style constant. @@ -327,12 +327,10 @@ protected CTabFolder createContainer(Composite parent) { * @return {@code SWT.TOP} if the user prefers tabs to be aligned on top, * {@code SWT.BOTTOM} if the user prefers tabs to be aligned on the * bottom. + * @since 3.133 */ - private int getPreferredTabStyle() { - boolean alignTabsOnTop = getAPIPreferenceStore() - .getBoolean(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP); - int style = alignTabsOnTop ? SWT.TOP : SWT.BOTTOM; - return style; + protected int getTabStyle() { + return getAPIPreferenceStore().getInt(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS); } /** @@ -1285,7 +1283,7 @@ public void run() { private void updateContainer() { Composite container = getContainer(); if (container instanceof CTabFolder tabFolder) { - tabFolder.setTabPosition(getPreferredTabStyle()); + tabFolder.setTabPosition(getTabStyle()); tabFolder.requestLayout(); } }