Skip to content
Open
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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -122,10 +122,15 @@ public BasicPartList(Shell parent, int shellStyle, int treeStyler,
this.renderer = renderer;
// this.saveHandler = saveHandler;
if (mru && getTableViewer() != null) {
boolean pinnedFirst = shouldShowPinnedEditorsFirst();
getTableViewer().setComparator(new ViewerComparator() {
@Override
public int category(Object element) {
if (element instanceof MPart part) {
if (pinnedFirst && PinnedEditorsOrder.isPinned(part)) {
// pinned editors form one block above all others
return -2;
}
CTabItem item = BasicPartList.this.renderer.findItemForPart(part);
if (item != null && !item.isShowing()) {
return -1;
Expand Down Expand Up @@ -170,9 +175,17 @@ private List<Object> getInput() {
list.add(element);
}
}
if (PartStackUtil.isEditorStack(input)) {
return PinnedEditorsOrder.pinnedFirst(list,
element -> element instanceof MPart part && PinnedEditorsOrder.isPinned(part));
}
return list;
}

private boolean shouldShowPinnedEditorsFirst() {
return PartStackUtil.isEditorStack(input) && PinnedEditorsOrder.isEnabled();
}

public void setInput() {
getTableViewer().setInput(getInput());
selectFirstMatch();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright (c) 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

package org.eclipse.e4.ui.internal.workbench.renderers.swt;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.IPresentationEngine;
import org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering;

/**
* Single place for the "show pinned editors first" behavior of the editor
* drop-down lists (chevron list and Ctrl+E). The preference only affects the
* order of these lists, tabs are never moved.
*/
public final class PinnedEditorsOrder {

private PinnedEditorsOrder() {
// utility class
}

/**
* @return whether pinned editors should be listed before the other editors
*/
public static boolean isEnabled() {
return Platform.getPreferencesService().getBoolean(
CTabRendering.PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT,
CTabRendering.SHOW_PINNED_EDITORS_FIRST,
CTabRendering.SHOW_PINNED_EDITORS_FIRST_DEFAULT,
null);
}

/**
* @return whether the given part is pinned
*/
public static boolean isPinned(MPart part) {
return part.getTags().contains(IPresentationEngine.ADORNMENT_PIN);
}

/**
* Returns the given elements with the pinned ones first. The relative order
* inside the pinned and inside the other elements is preserved. If the
* preference is disabled, the elements are returned unchanged.
*
* @param elements the elements in their regular order
* @param isPinned tells whether an element is pinned
* @return a list with the pinned elements first
*/
public static <T> List<T> pinnedFirst(List<T> elements, Predicate<? super T> isPinned) {
if (!isEnabled()) {
return elements;
}
List<T> result = new ArrayList<>(elements.size());
for (T element : elements) {
if (isPinned.test(element)) {
result.add(element);
}
}
for (T element : elements) {
if (!isPinned.test(element)) {
result.add(element);
}
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2020 IBM Corporation and others.
* Copyright (c) 2010, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -91,6 +91,17 @@ public class CTabRendering extends CTabFolderRenderer implements ICTabRendering,
*/
public static final boolean SHOW_DIRTY_INDICATOR_ON_TABS_DEFAULT = true;

/**
* A named preference for whether pinned editors are listed first in the editor
* chevron list and in the editor quick switch list (Ctrl+E).
*/
public static final String SHOW_PINNED_EDITORS_FIRST = "SHOW_PINNED_EDITORS_FIRST"; //$NON-NLS-1$

/**
* Default value for "show pinned editors first" preference
*/
public static final boolean SHOW_PINNED_EDITORS_FIRST_DEFAULT = false;

private static int MIN_VIEW_CHARS = 1;
private static int MAX_VIEW_CHARS = Integer.MAX_VALUE;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -61,6 +61,7 @@ protected Control createContents(Composite parent) {
createAllowInplaceEditorPref(composite);
createUseIPersistablePref(composite);
createPromptWhenStillOpenPref(composite);
createShowPinnedEditorsFirstPref(composite);
createEditorReuseGroup(composite);
createAlignMultiPageEditorTabs(composite);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2020 IBM Corporation and others.
* Copyright (c) 2005, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -472,6 +472,8 @@ public class WorkbenchMessages extends NLS {
public static String WorkbenchPreference_allowInplaceEditingButton;
public static String WorkbenchPreference_useIPersistableEditorButton;
public static String WorkbenchPreference_promptWhenStillOpenButton;
public static String WorkbenchPreference_showPinnedEditorsFirstButton;
public static String WorkbenchPreference_showPinnedEditorsFirstStoreError;
public static String WorkbenchPreference_stickyCycleButton;
public static String WorkbenchPreference_RunInBackgroundButton;
public static String WorkbenchPreference_RunInBackgroundToolTip;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2019 IBM Corporation and others.
* Copyright (c) 2007, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -33,6 +33,7 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.DirtyIndicatorPainter;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.PinnedEditorsOrder;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering;
import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer;
Expand Down Expand Up @@ -117,7 +118,7 @@ private List<EditorReference> getParts(WorkbenchPage page) {
refs.add((EditorReference) ier);
}
}
return refs;
return PinnedEditorsOrder.pinnedFirst(refs, EditorReference::isPinned);
}

/**
Expand Down Expand Up @@ -483,12 +484,12 @@ protected ParameterizedCommand getForwardCommand() {

@Override
protected int getCurrentItemIndex() {
if (isMruEnabled()) {
if (isMruEnabled() && !PinnedEditorsOrder.isEnabled()) {
return 0;
}
// We need to find previously selected part and return the index of the
// part before this part in our list, which ordered not by use but by
// position
// part before this part in our list, which is not ordered purely by use
// (positional order, or pinned editors moved to the top)

WorkbenchPage page = (WorkbenchPage) window.getActivePage();
List<EditorReference> sortedByUse = page.getSortedEditorReferences();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -18,6 +18,11 @@

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

import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.PinnedEditorsOrder;
import org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
Expand Down Expand Up @@ -46,6 +51,7 @@
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.util.PrefUtil;
import org.osgi.service.prefs.BackingStoreException;

/**
* The Editors preference page of the workbench.
Expand Down Expand Up @@ -74,6 +80,8 @@ public class EditorsPreferencePage extends PreferencePage implements IWorkbenchP

private Button promptWhenStillOpenEditor;

private Button showPinnedEditorsFirst;

private Button allowInplaceEditor;

private ComboFieldEditor multiPageEditorTabPositionComboField;
Expand All @@ -88,6 +96,7 @@ protected Control createContents(Composite parent) {
createAllowInplaceEditorPref(composite);
createUseIPersistablePref(composite);
createPromptWhenStillOpenPref(composite);
createShowPinnedEditorsFirstPref(composite);
createEditorReuseGroup(composite);
// ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).setPreferenceVisibility(editorReuseGroup,
// showMultipleEditorTabs);
Expand Down Expand Up @@ -136,6 +145,13 @@ protected void createPromptWhenStillOpenPref(Composite composite) {
setButtonLayoutData(promptWhenStillOpenEditor);
}

protected void createShowPinnedEditorsFirstPref(Composite composite) {
showPinnedEditorsFirst = new Button(composite, SWT.CHECK);
showPinnedEditorsFirst.setText(WorkbenchMessages.WorkbenchPreference_showPinnedEditorsFirstButton);
showPinnedEditorsFirst.setSelection(PinnedEditorsOrder.isEnabled());
setButtonLayoutData(showPinnedEditorsFirst);
}

protected void createAlignMultiPageEditorTabs(Composite parent) {
Composite comboComposite = new Composite(parent, SWT.NONE);
comboComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
Expand Down Expand Up @@ -176,6 +192,9 @@ protected void performDefaults() {
useIPersistableEditor.setSelection(store.getDefaultBoolean(IPreferenceConstants.USE_IPERSISTABLE_EDITORS));
promptWhenStillOpenEditor.setSelection(getAPIPreferenceStore()
.getDefaultBoolean(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN));
showPinnedEditorsFirst.setSelection(DefaultScope.INSTANCE
.getNode(CTabRendering.PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT)
.getBoolean(CTabRendering.SHOW_PINNED_EDITORS_FIRST, CTabRendering.SHOW_PINNED_EDITORS_FIRST_DEFAULT));
reuseEditors.setSelection(store.getDefaultBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN));
reuseEditorsThreshold.loadDefault();
reuseEditorsThreshold.getLabelControl(editorReuseThresholdGroup).setEnabled(reuseEditors.getSelection());
Expand All @@ -194,6 +213,15 @@ public boolean performOk() {
getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN,
promptWhenStillOpenEditor.getSelection());

IEclipsePreferences renderersPrefs = InstanceScope.INSTANCE
.getNode(CTabRendering.PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT);
renderersPrefs.putBoolean(CTabRendering.SHOW_PINNED_EDITORS_FIRST, showPinnedEditorsFirst.getSelection());
try {
renderersPrefs.flush();
} catch (BackingStoreException e) {
WorkbenchPlugin.log(WorkbenchMessages.WorkbenchPreference_showPinnedEditorsFirstStoreError, e);
}

// store the reuse editors setting
store.setValue(IPreferenceConstants.REUSE_EDITORS_BOOLEAN, reuseEditors.getSelection());
reuseEditorsThreshold.store();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2000, 2020 IBM Corporation and others.
# Copyright (c) 2000, 2026 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -414,6 +414,8 @@ PreferenceExportWarning_applyAndContinue = &Apply and Continue
WorkbenchPreference_allowInplaceEditingButton = Allow in-place &system editors
WorkbenchPreference_useIPersistableEditorButton = Restore &editor state on startup
WorkbenchPreference_promptWhenStillOpenButton = Pr&ompt to save on close even if still open elsewhere
WorkbenchPreference_showPinnedEditorsFirstButton = Show &pinned editors first in editor lists (chevron and Ctrl+E)
WorkbenchPreference_showPinnedEditorsFirstStoreError = Failed to store the preference to show pinned editors first.
WorkbenchPreference_stickyCycleButton = Keep &next/previous editor, view and perspectives dialog open
WorkbenchPreference_RunInBackgroundButton=Always r&un in background
WorkbenchPreference_RunInBackgroundToolTip=Run long operations in the background where possible
Expand Down
Loading
Loading