Skip to content

Commit

Permalink
Incorporated the review comments
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
praveen-skp authored and sratz committed Oct 31, 2024
1 parent 40edabf commit 5dc1350
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected Control createContents(Composite parent) {
createUseIPersistablePref(composite);
createPromptWhenStillOpenPref(composite);
createEditorReuseGroup(composite);
createAlignMultiPageEditorTabsOnTop(composite);
createAlignMultiPageEditorTabs(composite);

applyDialogFont(composite);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>true</code>.
* Workbench preference id for the position of the tabs in the multi-page
* editor.
*
* Boolean-valued: <code>true</code> show the tabs on the top, and
* <code>false</code> if shown at the bottom.
* Integer-valued: {@link SWT#TOP} for tabs on the top, and {@link SWT#BOTTOM}
* for tabs at the bottom.
* <p>
* The default value for this preference is: <code>false</code>
* The default value for this preference is: {@link SWT#BOTTOM}
* </p>
*
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>
* This method is invoked when a property change occurs in the preference store.
* </p>
* 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;
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
* <p>
* This method retrieves the user preference for aligning multi-page editor tabs
* on top or bottom, and returns the corresponding SWT style constant.
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 5dc1350

Please sign in to comment.