From 27730bd40f220af3c185f2e77b2b8356b7c920c1 Mon Sep 17 00:00:00 2001 From: Elsa Zacharia Date: Mon, 15 Sep 2025 16:48:07 +0530 Subject: [PATCH] Add toggle button in chevron drop down to prioritize recently overflowed editors In the workbench, the chevron drop down shows all editors, including those that cannot fit in the main editor area. By default, these editors are ordered using a comparator, which makes it harder to quickly navigate to editors that recently moved into the chevron due to overflow. This change introduces a toggle button near the filter text in the chevron drop down that allows users to switch the order to a new one. This new view displays the editors that most recently moved into the chevron drop down at the top. Activating the toggle displays these recently overflowed editors first, providing quick access, while clicking it again restores the normal display order. This feature improves visibility when there are so many editors that are open in the workbench window and editors overflow into the chevron at the same time. --- .../icons/full/elcl16/view_recent_editor.svg | 98 +++++++++++++++++++ .../swt/AbstractTableInformationControl.java | 67 ++++++++++++- .../renderers/swt/BasicPartList.java | 17 +++- .../renderers/swt/SWTRenderersMessages.java | 3 +- .../renderers/swt/messages.properties | 3 +- 5 files changed, 180 insertions(+), 8 deletions(-) create mode 100644 bundles/org.eclipse.e4.ui.workbench.renderers.swt/icons/full/elcl16/view_recent_editor.svg diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/icons/full/elcl16/view_recent_editor.svg b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/icons/full/elcl16/view_recent_editor.svg new file mode 100644 index 00000000000..1015f7096b4 --- /dev/null +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/icons/full/elcl16/view_recent_editor.svg @@ -0,0 +1,98 @@ + + + +image/svg+xml diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java index f4333185d8f..c8739e26825 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2018 IBM Corporation and others. + * Copyright (c) 2003, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.e4.ui.internal.workbench.renderers.swt; +import java.util.List; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.workbench.swt.internal.copy.SearchPattern; import org.eclipse.e4.ui.workbench.swt.internal.copy.WorkbenchSWTMessages; import org.eclipse.jface.preference.JFacePreferences; @@ -23,6 +25,7 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyListener; @@ -33,6 +36,7 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.FontMetrics; import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; @@ -40,6 +44,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Item; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Menu; @@ -48,11 +53,16 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; /** * @since 3.0 */ public abstract class AbstractTableInformationControl { + private ViewerComparator originalComparatorOrder; + private Object originalInputOrder; + private boolean reversed = false; /** * The NamePatternFilter selects the elements which match the given string @@ -313,18 +323,25 @@ public TableViewer getTableViewer() { } protected Text createFilterText(Composite parent) { - fFilterText = new Text(parent, SWT.NONE); + Composite c = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + c.setLayout(layout); + c.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - GridData data = new GridData(); + fFilterText = new Text(c, SWT.NONE); + + GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false); GC gc = new GC(parent); gc.setFont(parent.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); data.heightHint = org.eclipse.jface.dialogs.Dialog - .convertHeightInCharsToPixels(fontMetrics, 1); + .convertHeightInCharsToPixels(fontMetrics, 1); data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.BEGINNING; + data.verticalAlignment = GridData.CENTER; fFilterText.setLayoutData(data); fFilterText.addKeyListener(KeyListener.keyPressedAdapter(e -> { @@ -347,6 +364,46 @@ protected Text createFilterText(Composite parent) { } })); + ToolBar toolBar = new ToolBar(c, SWT.FLAT | SWT.NO_FOCUS); + GridData tbData = new GridData(SWT.RIGHT, SWT.CENTER, false, false); + toolBar.setLayoutData(tbData); + + ToolItem reverseItem = new ToolItem(toolBar, SWT.CHECK); + Image image = new Image(Display.getCurrent(), + getClass().getClassLoader().getResourceAsStream("icons/full/elcl16/view_recent_editor.svg"));//$NON-NLS-1$ + reverseItem.setImage(image); + reverseItem.setToolTipText(SWTRenderersMessages.mostRecentHiddenEditor); + reverseItem.addDisposeListener(e -> { + if (image != null && !image.isDisposed()) { + image.dispose(); + } + }); + + reverseItem.addListener(SWT.Selection, e -> { + if (this instanceof BasicPartList bpl) { + + if (!reversed) { + if (originalComparatorOrder == null) { + originalComparatorOrder = fTableViewer.getComparator(); + originalInputOrder = fTableViewer.getInput(); + } + List showEditors = bpl.getEditorsReversed(); + fTableViewer.setComparator(null); + fTableViewer.setInput(showEditors); + reversed = true; + + } else { + fTableViewer.setComparator(originalComparatorOrder); + fTableViewer.setInput(originalInputOrder); + reversed = false; + } + computeSizeHint(); + fComposite.layout(true, true); + fComposite.getShell().pack(true); + fTableViewer.refresh(); + } + }); + // Horizontal separator line Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/BasicPartList.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/BasicPartList.java index 1da73e31ce6..babcb8366f3 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/BasicPartList.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/BasicPartList.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -16,6 +16,7 @@ package org.eclipse.e4.ui.internal.workbench.renderers.swt; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.eclipse.e4.ui.model.application.ui.MDirtyable; import org.eclipse.e4.ui.model.application.ui.MElementContainer; @@ -162,6 +163,20 @@ private List getInput() { return list; } + public List getEditorsReversed() { + List showEditors = new ArrayList<>(); + for (Object obj : getInput()) { + if (obj instanceof MPart part) { + CTabItem item = renderer.findItemForPart(part); + if (item != null && !item.isShowing()) { + showEditors.add(part); + } + } + } + Collections.reverse(showEditors); + return showEditors; + } + public void setInput() { getTableViewer().setInput(getInput()); selectFirstMatch(); diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/SWTRenderersMessages.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/SWTRenderersMessages.java index 306c14c140e..2ed88f43533 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/SWTRenderersMessages.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/SWTRenderersMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 IBM Corporation and others. + * Copyright (c) 2010, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -35,6 +35,7 @@ public class SWTRenderersMessages extends NLS { public static String menuCloseRight; public static String menuCloseLeft; public static String menuDetach; + public static String mostRecentHiddenEditor; public static String viewMenu; diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/messages.properties b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/messages.properties index 1d92d34976a..520c58cc903 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/messages.properties +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2010, 2015 IBM Corporation and others. +# Copyright (c) 2010, 2025 IBM Corporation and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -26,4 +26,5 @@ menuCloseAll = Close &All menuCloseRight = Close Tabs to the &Right menuCloseLeft = Close Tabs to the &Left menuDetach= &Detach +mostRecentHiddenEditor=Show editors by most recently moved to the chevron viewMenu = View Menu \ No newline at end of file