From 64d3f611baa42d03377e269d72ff99121ba44d29 Mon Sep 17 00:00:00 2001 From: "Praveen S.K" Date: Tue, 27 Aug 2024 10:16:06 +0530 Subject: [PATCH 1/3] Added dynamic tab alignment support in MultiPageEditorPart - Added a new preference for multi-page editor tab alignment. - Added a preference change listener to MultiPageEditorPart. - Updated tab style based on the user's preference. --- .../ide/dialogs/IDEEditorsPreferencePage.java | 1 + .../ui/IWorkbenchPreferenceConstants.java | 15 +++++ .../ui/internal/WorkbenchMessages.java | 1 + .../dialogs/EditorsPreferencePage.java | 15 +++++ .../eclipse/ui/internal/messages.properties | 5 +- .../eclipse/ui/part/MultiPageEditorPart.java | 64 ++++++++++++++++++- 6 files changed, 97 insertions(+), 4 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 3283f29d763..cfa0ff1cb5f 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,6 +62,7 @@ protected Control createContents(Composite parent) { createUseIPersistablePref(composite); createPromptWhenStillOpenPref(composite); createEditorReuseGroup(composite); + createAlignMultiPageEditorTabsOnTop(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 2df7267e907..da6e03f528b 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 @@ -624,6 +624,21 @@ 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. + * + * Boolean-valued: true show the tabs on the top, and + * false if shown at the bottom. + *

+ * The default value for this preference is: false + *

+ * + * @since 3.133 + */ + String ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP = "ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP"; //$NON-NLS-1$ + /** * Workbench preference id for indicating the size of the list of most recently * used working sets. 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 dbddbbb6b6b..a07e38ef4ba 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 @@ -452,6 +452,7 @@ 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; // --- Appearance --- public static String ViewsPreferencePage_Theme; 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 401b1fc62e0..c1ead32ece9 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 @@ -72,6 +72,8 @@ public class EditorsPreferencePage extends PreferencePage implements IWorkbenchP private Button allowInplaceEditor; + private Button alignMultiPageEditorTabsOnTop; + @Override protected Control createContents(Composite parent) { Composite composite = createComposite(parent); @@ -130,6 +132,15 @@ 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 Composite createComposite(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); @@ -150,6 +161,8 @@ 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)); @@ -163,6 +176,8 @@ protected void performDefaults() { @Override public boolean performOk() { IPreferenceStore store = getPreferenceStore(); + getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP, + alignMultiPageEditorTabsOnTop.getSelection()); 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 62751910b19..c78d341fd5c 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,6 +419,7 @@ 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 # --- Appearance --- @@ -493,10 +494,10 @@ OpenPerspectiveDialogAction_tooltip=Open Perspective #---- General Preferences---- PreferencePage_noDescription = (No description available) -PreferencePageParameterValues_pageLabelSeparator = \ >\ +PreferencePageParameterValues_pageLabelSeparator = \ >\ ThemingEnabled = E&nable theming ThemeChangeWarningText = Restart for the theme changes to take full effect -ThemeChangeWarningTitle = Theme Changed +ThemeChangeWarningTitle = Theme Changed # --- Workbench ----- WorkbenchPreference_openMode=Open mode WorkbenchPreference_doubleClick=D&ouble click 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 68508e010ae..fe41eee7cf8 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 @@ -17,6 +17,7 @@ import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter; +import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; import org.eclipse.core.commands.AbstractHandler; @@ -32,7 +33,9 @@ import org.eclipse.jface.dialogs.IPageChangeProvider; import org.eclipse.jface.dialogs.IPageChangedListener; import org.eclipse.jface.dialogs.PageChangedEvent; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.util.SafeRunnable; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; @@ -56,6 +59,7 @@ import org.eclipse.ui.IPartService; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchPreferenceConstants; import org.eclipse.ui.PartInitException; import org.eclipse.ui.handlers.IHandlerService; import org.eclipse.ui.internal.PartSite; @@ -63,6 +67,7 @@ import org.eclipse.ui.internal.misc.Policy; import org.eclipse.ui.internal.services.INestable; import org.eclipse.ui.internal.services.IServiceLocatorCreator; +import org.eclipse.ui.internal.util.PrefUtil; import org.eclipse.ui.services.IDisposable; import org.eclipse.ui.services.IServiceLocator; @@ -149,10 +154,31 @@ public abstract class MultiPageEditorPart extends EditorPart implements IPageCha private ListenerList pageChangeListeners = new ListenerList<>(ListenerList.IDENTITY); /** - * Creates an empty multi-page editor with no pages. + * Creates an empty multi-page editor with no pages and registers a + * {@link PropertyChangeListener} to listen for changes to the editor's + * preference.. */ protected MultiPageEditorPart() { super(); + getAPIPreferenceStore().addPropertyChangeListener(event -> { + handlePropertyChange(event); + }); + } + + /** + * Handles property change events related to editor preferences. + * + *

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

+ * + * @param event the {@link PropertyChangeEvent} triggered by a change in the + * preference store + */ + private void handlePropertyChange(PropertyChangeEvent event) { + if (event.getProperty().equals(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP)) { + updateContainer(); + } } /** @@ -264,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, SWT.BOTTOM | SWT.FLAT); + final CTabFolder newContainer = new CTabFolder(parent, getPreferredTabStyle()); newContainer.addSelectionListener(widgetSelectedAdapter(e -> { int newPageIndex = newContainer.indexOf((CTabItem) e.item); pageChange(newPageIndex); @@ -291,6 +317,31 @@ protected CTabFolder createContainer(Composite parent) { return newContainer; } + /** + * Determines the preferred 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. + *

+ * + * @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. + */ + private int getPreferredTabStyle() { + boolean alignTabsOnTop = getAPIPreferenceStore() + .getBoolean(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS_ON_TOP); + int style = alignTabsOnTop ? SWT.TOP : SWT.BOTTOM; + return style; + } + + /** + * @since 3.133 + */ + protected IPreferenceStore getAPIPreferenceStore() { + return PrefUtil.getAPIPreferenceStore(); + } + /** * Creates a tab item at the given index and places the given control in the new * item. The item is a CTabItem with no style bits set. @@ -1230,4 +1281,13 @@ public void run() { }); } } + + private void updateContainer() { + Composite container = getContainer(); + if (container instanceof CTabFolder tabFolder) { + tabFolder.setTabPosition(getPreferredTabStyle()); + tabFolder.requestLayout(); + } + } + } From 9515721521f1bb442bde00838c7a280191e92d30 Mon Sep 17 00:00:00 2001 From: "Praveen S.K" Date: Thu, 29 Aug 2024 09:01:27 +0530 Subject: [PATCH 2/3] 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 | 34 ++++++++++++------- .../eclipse/ui/internal/messages.properties | 4 ++- .../eclipse/ui/part/MultiPageEditorPart.java | 32 ++++++++--------- 7 files changed, 51 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 da6e03f528b..9674ff37d44 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 a07e38ef4ba..4f285064053 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 @@ -452,7 +452,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 c1ead32ece9..ce12f666602 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,6 +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; @@ -72,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) { @@ -132,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) { @@ -161,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)); @@ -171,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 c78d341fd5c..0c1c1dc2bd0 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(); } } From 2aba601f839ab1bc03983d38acc5163ba2874d57 Mon Sep 17 00:00:00 2001 From: "Praveen S.K" Date: Thu, 29 Aug 2024 09:08:16 +0530 Subject: [PATCH 3/3] Changed the updateContainer method to protected --- .../org/eclipse/ui/part/MultiPageEditorPart.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 0b1783bcf56..c08023634cd 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 @@ -1280,7 +1280,17 @@ public void run() { } } - private void updateContainer() { + /** + * Updates the tab position of the container in the multi-page editor. + * + *

+ * This method retrieves the current container and sets the tab position based + * on the user preference. + *

+ * + * @since 3.133 + */ + protected void updateContainer() { Composite container = getContainer(); if (container instanceof CTabFolder tabFolder) { tabFolder.setTabPosition(getTabStyle());