eclipse-platform / eclipse.platform.ui

Eclipse Platform
https://projects.eclipse.org/projects/eclipse.platform
Eclipse Public License 2.0
81 stars 188 forks source link

Pin editor tab #501

Open E1izabeth opened 1 year ago

E1izabeth commented 1 year ago

It would be nice if pin editor tab command moves tab to the left or to a separate toolbar for pinned tabs.

We (DBeaver) have such requests from our community dbeaver/dbeaver#17160 and tried to implement our own command for that, but eclipse platform doesn't have a way to manage editor's icon and override drag-n-drop actions.

mickaelistria commented 1 year ago

This is a good proposal. Are you willing to submit a PR that implements it?

E1izabeth commented 1 year ago

I've made some digging into CTabFolder and for me it looks pretty unobvious, what are the required modifications to introduce the functionality under consideration.

mickaelistria commented 1 year ago

In CTabFolder, around line 2080

        for (int i=0; i < items.length; i++) {
            Rectangle itemBounds = items[i].getBounds();
            if (i != selectedIndex && event.getBounds().intersects(itemBounds)) {
                renderer.draw(i, SWT.BACKGROUND | SWT.FOREGROUND | items[i].state , itemBounds, gc);
            }
        }

Is the block that instructs of drawing the tabs. Currently it seems to only care about the position to decide what to draw, but if there are extra infos like "pinned" available, those can be used to take priority when deciding here what to draw or not.

Wittmaxi commented 1 year ago

As far as I have seen, the only reference for pinned is in WorkbenchPartReference, I don't think checking for pinned is apropriate in CTabFolder. It is likely that the better solution set the priority indexes in the CTabFolder for the pinned elements. I am not yet sure how a WorkbenchPartReference could find it's own CTabFolder - I will investigate into this. @mickaelistria

Another - possibly cleaner - solution is to add an option for pinning CTabItems in a CTabFolder. I can imagine an API that looks like this (very roughly sketched):

tabFolder.allowForPinning(true);
tabFolder.pin (4);

allowForPinning could display a tooltip to the CTabFolder

grafik

mickaelistria commented 1 year ago

add an option for pinning CTabItems in a CTabFolder

yes, I think that the best place where to hook the low-level capability as it will be able to serve more cases. Although it would only be a subset of the solution: for editors, you'd also need to store somewhere (eg in the memento) which editors/parts are pinned so they remain pinned upon restart.

tabFolder.allowForPinning(true); tabFolder.pin (4);

You don't need a particular method to enable the feature, just tabFolder.pin(4) is enough. Then consumers such as the CTabFolderRenderer used by the workbench can take care of adding the pin context menu as they prefer and call tabFolder.pin(x) directly, together with related actions (such as storing the state in the workbench).