Skip to content

Commit f4fa542

Browse files
committed
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.
1 parent 88774cd commit f4fa542

File tree

5 files changed

+251
-8
lines changed

5 files changed

+251
-8
lines changed
Lines changed: 172 additions & 0 deletions
Loading

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/AbstractTableInformationControl.java

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2003, 2018 IBM Corporation and others.
2+
* Copyright (c) 2003, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.e4.ui.internal.workbench.renderers.swt;
1515

16+
import java.util.List;
17+
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
1618
import org.eclipse.e4.ui.workbench.swt.internal.copy.SearchPattern;
1719
import org.eclipse.e4.ui.workbench.swt.internal.copy.WorkbenchSWTMessages;
1820
import org.eclipse.jface.preference.JFacePreferences;
@@ -23,6 +25,7 @@
2325
import org.eclipse.jface.viewers.StructuredSelection;
2426
import org.eclipse.jface.viewers.TableViewer;
2527
import org.eclipse.jface.viewers.Viewer;
28+
import org.eclipse.jface.viewers.ViewerComparator;
2629
import org.eclipse.jface.viewers.ViewerFilter;
2730
import org.eclipse.swt.SWT;
2831
import org.eclipse.swt.events.KeyListener;
@@ -33,13 +36,15 @@
3336
import org.eclipse.swt.graphics.Color;
3437
import org.eclipse.swt.graphics.FontMetrics;
3538
import org.eclipse.swt.graphics.GC;
39+
import org.eclipse.swt.graphics.Image;
3640
import org.eclipse.swt.graphics.Point;
3741
import org.eclipse.swt.graphics.Rectangle;
3842
import org.eclipse.swt.layout.FillLayout;
3943
import org.eclipse.swt.layout.GridData;
4044
import org.eclipse.swt.layout.GridLayout;
4145
import org.eclipse.swt.widgets.Composite;
4246
import org.eclipse.swt.widgets.Control;
47+
import org.eclipse.swt.widgets.Display;
4348
import org.eclipse.swt.widgets.Item;
4449
import org.eclipse.swt.widgets.Label;
4550
import org.eclipse.swt.widgets.Menu;
@@ -48,11 +53,16 @@
4853
import org.eclipse.swt.widgets.Table;
4954
import org.eclipse.swt.widgets.TableItem;
5055
import org.eclipse.swt.widgets.Text;
56+
import org.eclipse.swt.widgets.ToolBar;
57+
import org.eclipse.swt.widgets.ToolItem;
5158

5259
/**
5360
* @since 3.0
5461
*/
5562
public abstract class AbstractTableInformationControl {
63+
private ViewerComparator originalComparatorOrder;
64+
private Object originalInputOrder;
65+
private boolean reversed = false;
5666

5767
/**
5868
* The NamePatternFilter selects the elements which match the given string
@@ -311,18 +321,25 @@ public TableViewer getTableViewer() {
311321
}
312322

313323
protected Text createFilterText(Composite parent) {
314-
fFilterText = new Text(parent, SWT.NONE);
324+
Composite c = new Composite(parent, SWT.NONE);
325+
GridLayout layout = new GridLayout(2, false);
326+
layout.marginHeight = 0;
327+
layout.marginWidth = 0;
328+
c.setLayout(layout);
329+
c.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
315330

316-
GridData data = new GridData();
331+
fFilterText = new Text(c, SWT.NONE);
332+
333+
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
317334
GC gc = new GC(parent);
318335
gc.setFont(parent.getFont());
319336
FontMetrics fontMetrics = gc.getFontMetrics();
320337
gc.dispose();
321338

322339
data.heightHint = org.eclipse.jface.dialogs.Dialog
323-
.convertHeightInCharsToPixels(fontMetrics, 1);
340+
.convertHeightInCharsToPixels(fontMetrics, 1);
324341
data.horizontalAlignment = GridData.FILL;
325-
data.verticalAlignment = GridData.BEGINNING;
342+
data.verticalAlignment = GridData.CENTER;
326343
fFilterText.setLayoutData(data);
327344

328345
fFilterText.addKeyListener(KeyListener.keyPressedAdapter(e -> {
@@ -345,6 +362,43 @@ protected Text createFilterText(Composite parent) {
345362
}
346363
}));
347364

365+
ToolBar toolBar = new ToolBar(c, SWT.FLAT | SWT.NO_FOCUS);
366+
GridData tbData = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
367+
toolBar.setLayoutData(tbData);
368+
369+
ToolItem reverseItem = new ToolItem(toolBar, SWT.CHECK);
370+
Image image = new Image(Display.getCurrent(),
371+
getClass().getClassLoader().getResourceAsStream("icons/full/elcl16/moveupdown.svg"));//$NON-NLS-1$
372+
reverseItem.setImage(image);
373+
reverseItem.setToolTipText(SWTRenderersMessages.mostRecentActiveEditor);
374+
reverseItem.addDisposeListener(e -> {
375+
if (image != null && !image.isDisposed()) {
376+
image.dispose();
377+
}
378+
});
379+
380+
reverseItem.addListener(SWT.Selection, e -> {
381+
if (this instanceof BasicPartList bpl) {
382+
383+
if (!reversed) {
384+
if (originalComparatorOrder == null) {
385+
originalComparatorOrder = fTableViewer.getComparator();
386+
originalInputOrder = fTableViewer.getInput();
387+
}
388+
List<MPart> showEditors = bpl.getEditorsReversed();
389+
fTableViewer.setComparator(null);
390+
fTableViewer.setInput(showEditors);
391+
reversed = true;
392+
393+
} else {
394+
fTableViewer.setComparator(originalComparatorOrder);
395+
fTableViewer.setInput(originalInputOrder);
396+
reversed = false;
397+
}
398+
fTableViewer.refresh();
399+
}
400+
});
401+
348402
// Horizontal separator line
349403
Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
350404
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/BasicPartList.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,6 +16,7 @@
1616
package org.eclipse.e4.ui.internal.workbench.renderers.swt;
1717

1818
import java.util.ArrayList;
19+
import java.util.Collections;
1920
import java.util.List;
2021
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
2122
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
@@ -164,6 +165,20 @@ private List<Object> getInput() {
164165
return list;
165166
}
166167

168+
public List<MPart> getEditorsReversed() {
169+
List<MPart> showEditors = new ArrayList<>();
170+
for (Object obj : getInput()) {
171+
if (obj instanceof MPart part) {
172+
CTabItem item = renderer.findItemForPart(part);
173+
if (item != null && !item.isShowing()) {
174+
showEditors.add(part);
175+
}
176+
}
177+
}
178+
Collections.reverse(showEditors);
179+
return showEditors;
180+
}
181+
167182
public void setInput() {
168183
getTableViewer().setInput(getInput());
169184
selectFirstMatch();

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/SWTRenderersMessages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2010, 2015 IBM Corporation and others.
2+
* Copyright (c) 2010, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -35,6 +35,7 @@ public class SWTRenderersMessages extends NLS {
3535
public static String menuCloseRight;
3636
public static String menuCloseLeft;
3737
public static String menuDetach;
38+
public static String mostRecentActiveEditor;
3839

3940
public static String viewMenu;
4041

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2010, 2015 IBM Corporation and others.
2+
# Copyright (c) 2010, 2025 IBM Corporation and others.
33
#
44
# This program and the accompanying materials
55
# are made available under the terms of the Eclipse Public License 2.0
@@ -26,4 +26,5 @@ menuCloseAll = Close &All
2626
menuCloseRight = Close Tabs to the &Right
2727
menuCloseLeft = Close Tabs to the &Left
2828
menuDetach= &Detach
29+
mostRecentActiveEditor=Show most recently active editor at the top
2930
viewMenu = View Menu

0 commit comments

Comments
 (0)