Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dynamic tab alignment support in MultiPageEditorPart #2224

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected Control createContents(Composite parent) {
createUseIPersistablePref(composite);
createPromptWhenStillOpenPref(composite);
createEditorReuseGroup(composite);
createAlignMultiPageEditorTabs(composite);

applyDialogFont(composite);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,20 @@ public interface IWorkbenchPreferenceConstants {
*/
String DISABLE_OPEN_EDITOR_IN_PLACE = "DISABLE_OPEN_EDITOR_IN_PLACE"; //$NON-NLS-1$

/**
* Workbench preference id for the position of the tabs in the multi-page
* editor.
*
* 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: {@link SWT#BOTTOM}
* </p>
*
* @since 3.133
*/
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
* used working sets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +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_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,6 +76,8 @@ public class EditorsPreferencePage extends PreferencePage implements IWorkbenchP

private Button allowInplaceEditor;

private ComboFieldEditor multiPageEditorTabPositionComboField;

@Override
protected Control createContents(Composite parent) {
Composite composite = createComposite(parent);
Expand Down Expand Up @@ -132,6 +136,23 @@ protected void createPromptWhenStillOpenPref(Composite composite) {
setButtonLayoutData(promptWhenStillOpenEditor);
}

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) {
Composite composite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
Expand Down Expand Up @@ -160,11 +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();
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,6 +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_AlignMultiPageEditorTabs= &Align multi-page editor tabs:
WorkbenchPreference_AlignMultiPageEditorTabs_Top= &Top
WorkbenchPreference_AlignMultiPageEditorTabs_Bottom= &Bottom


# --- Appearance ---
Expand Down Expand Up @@ -493,7 +496,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -56,13 +59,15 @@
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;
import org.eclipse.ui.internal.WorkbenchPlugin;
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;

Expand Down Expand Up @@ -149,10 +154,31 @@
private ListenerList<IPageChangedListener> 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 -> {
if (isUpdateRequired(event)) {
updateContainer();
}
});
}

/**
* 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
*/
protected boolean isUpdateRequired(PropertyChangeEvent event) {
if (event.getProperty().equals(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS)) {
return true;
}
return false;
}

/**
Expand Down Expand Up @@ -264,7 +290,7 @@
// 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, getTabStyle() | SWT.FLAT);
newContainer.addSelectionListener(widgetSelectedAdapter(e -> {
int newPageIndex = newContainer.indexOf((CTabItem) e.item);
pageChange(newPageIndex);
Expand All @@ -291,6 +317,29 @@
return newContainer;
}

/**
* 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.
* </p>
*
* @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
*/
protected int getTabStyle() {
return getAPIPreferenceStore().getInt(IWorkbenchPreferenceConstants.ALIGN_MULTI_PAGE_EDITOR_TABS);
}

/**
* @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.
Expand Down Expand Up @@ -915,8 +964,8 @@

if (editor != null) {
// active the service for this inner editor
if (service instanceof INestableKeyBindingService) {

Check warning on line 967 in bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler and API Tools

Deprecation

NORMAL: The type INestableKeyBindingService is deprecated
final INestableKeyBindingService nestableService = (INestableKeyBindingService) service;

Check warning on line 968 in bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler and API Tools

Deprecation

NORMAL: The type INestableKeyBindingService is deprecated

Check warning on line 968 in bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorPart.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler and API Tools

Deprecation

NORMAL: The type INestableKeyBindingService is deprecated
nestableService.activateKeyBindingService(editor.getEditorSite());

} else {
Expand Down Expand Up @@ -1230,4 +1279,23 @@
});
}
}

/**
* Updates the tab position of the container in the multi-page editor.
*
* <p>
* This method retrieves the current container and sets the tab position based
* on the user preference.
* </p>
*
* @since 3.133
*/
protected void updateContainer() {
Composite container = getContainer();
if (container instanceof CTabFolder tabFolder) {
tabFolder.setTabPosition(getTabStyle());
tabFolder.requestLayout();
}
}

}
Loading