Skip to content

Commit 9670aa7

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 1848058 commit 9670aa7

File tree

5 files changed

+189
-8
lines changed

5 files changed

+189
-8
lines changed
Lines changed: 98 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: 71 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
@@ -313,18 +323,25 @@ public TableViewer getTableViewer() {
313323
}
314324

315325
protected Text createFilterText(Composite parent) {
316-
fFilterText = new Text(parent, SWT.NONE);
326+
Composite c = new Composite(parent, SWT.NONE);
327+
GridLayout layout = new GridLayout(2, false);
328+
layout.marginHeight = 0;
329+
layout.marginWidth = 0;
330+
c.setLayout(layout);
331+
c.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
317332

318-
GridData data = new GridData();
333+
fFilterText = new Text(c, SWT.NONE);
334+
335+
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
319336
GC gc = new GC(parent);
320337
gc.setFont(parent.getFont());
321338
FontMetrics fontMetrics = gc.getFontMetrics();
322339
gc.dispose();
323340

324341
data.heightHint = org.eclipse.jface.dialogs.Dialog
325-
.convertHeightInCharsToPixels(fontMetrics, 1);
342+
.convertHeightInCharsToPixels(fontMetrics, 1);
326343
data.horizontalAlignment = GridData.FILL;
327-
data.verticalAlignment = GridData.BEGINNING;
344+
data.verticalAlignment = GridData.CENTER;
328345
fFilterText.setLayoutData(data);
329346

330347
fFilterText.addKeyListener(KeyListener.keyPressedAdapter(e -> {
@@ -347,6 +364,48 @@ protected Text createFilterText(Composite parent) {
347364
}
348365
}));
349366

367+
ToolBar toolBar = new ToolBar(c, SWT.FLAT | SWT.NO_FOCUS);
368+
GridData tbData = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
369+
toolBar.setLayoutData(tbData);
370+
371+
ToolItem reverseItem = new ToolItem(toolBar, SWT.CHECK);
372+
Image image = new Image(Display.getCurrent(),
373+
getClass().getClassLoader().getResourceAsStream("icons/full/elcl16/view_recent_editor.svg"));//$NON-NLS-1$
374+
reverseItem.setImage(image);
375+
reverseItem.setToolTipText(SWTRenderersMessages.mostRecentHiddenEditor);
376+
reverseItem.addDisposeListener(e -> {
377+
if (image != null && !image.isDisposed()) {
378+
image.dispose();
379+
}
380+
});
381+
382+
reverseItem.addListener(SWT.Selection, e -> {
383+
if (this instanceof BasicPartList bpl) {
384+
385+
if (!reversed) {
386+
if (originalComparatorOrder == null) {
387+
originalComparatorOrder = fTableViewer.getComparator();
388+
originalInputOrder = fTableViewer.getInput();
389+
}
390+
List<MPart> showEditors = bpl.getEditorsReversed();
391+
fTableViewer.setComparator(null);
392+
fTableViewer.setInput(showEditors);
393+
reversed = true;
394+
395+
} else {
396+
fTableViewer.setComparator(originalComparatorOrder);
397+
fTableViewer.setInput(originalInputOrder);
398+
reversed = false;
399+
}
400+
if (fFilterText.getText().isEmpty()) {
401+
computeSizeHint();
402+
fComposite.layout(true, true);
403+
fComposite.getShell().pack(true);
404+
fTableViewer.refresh();
405+
}
406+
}
407+
});
408+
350409
// Horizontal separator line
351410
Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
352411
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
@@ -378,7 +437,14 @@ private void installFilter() {
378437
fFilterText.addModifyListener(e -> {
379438
String text = ((Text) e.widget).getText();
380439
setMatcherString(text);
440+
fTableViewer.refresh();
441+
if (text.isEmpty()) {
442+
computeSizeHint();
443+
fComposite.layout(true, true);
444+
fComposite.getShell().pack(true);
445+
}
381446
});
447+
computeSizeHint();
382448
}
383449

384450
/**

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;
@@ -162,6 +163,20 @@ private List<Object> getInput() {
162163
return list;
163164
}
164165

166+
public List<MPart> getEditorsReversed() {
167+
List<MPart> showEditors = new ArrayList<>();
168+
for (Object obj : getInput()) {
169+
if (obj instanceof MPart part) {
170+
CTabItem item = renderer.findItemForPart(part);
171+
if (item != null && !item.isShowing()) {
172+
showEditors.add(part);
173+
}
174+
}
175+
}
176+
Collections.reverse(showEditors);
177+
return showEditors;
178+
}
179+
165180
public void setInput() {
166181
getTableViewer().setInput(getInput());
167182
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 mostRecentHiddenEditor;
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+
mostRecentHiddenEditor=Show editors by most recently moved to the chevron
2930
viewMenu = View Menu

0 commit comments

Comments
 (0)