mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
on drag out of inactive tab, restore selection to tab which was selected before drag out started (IDEA-61536)
This commit is contained in:
@@ -86,6 +86,12 @@ public final class TabInfo implements Queryable, PlaceProvider<String> {
|
||||
private Queryable myQueryable;
|
||||
private DragOutDelegate myDragOutDelegate;
|
||||
|
||||
/**
|
||||
* The tab which was selected before the mouse was pressed on this tab. Focus will be transferred to that tab if this tab is dragged
|
||||
* out of its container. (IDEA-61536)
|
||||
*/
|
||||
private WeakReference<TabInfo> myPreviousSelection = new WeakReference<TabInfo>(null);
|
||||
|
||||
public TabInfo(final JComponent component) {
|
||||
myComponent = component;
|
||||
myPreferredFocusableComponent = component;
|
||||
@@ -371,6 +377,15 @@ public final class TabInfo implements Queryable, PlaceProvider<String> {
|
||||
return myDragOutDelegate;
|
||||
}
|
||||
|
||||
public void setPreviousSelection(@Nullable TabInfo previousSelection) {
|
||||
myPreviousSelection = new WeakReference<TabInfo>(previousSelection);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TabInfo getPreviousSelection() {
|
||||
return myPreviousSelection.get();
|
||||
}
|
||||
|
||||
public interface DragOutDelegate {
|
||||
|
||||
void dragOutStarted(MouseEvent mouseEvent, TabInfo info);
|
||||
|
||||
@@ -88,6 +88,10 @@ public class TabLabel extends JPanel {
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
if (myTabs.isSelectionClick(e, false) && myInfo.isEnabled()) {
|
||||
final TabInfo selectedInfo = myTabs.getSelectedInfo();
|
||||
if (selectedInfo != myInfo) {
|
||||
myInfo.setPreviousSelection(selectedInfo);
|
||||
}
|
||||
Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
|
||||
if (c instanceof InplaceButton) return;
|
||||
myTabs.select(info, true);
|
||||
@@ -102,6 +106,7 @@ public class TabLabel extends JPanel {
|
||||
}
|
||||
|
||||
public void mouseReleased(final MouseEvent e) {
|
||||
myInfo.setPreviousSelection(null);
|
||||
handlePopup(e);
|
||||
}
|
||||
});
|
||||
|
||||
+10
-1
@@ -212,7 +212,12 @@ final class EditorTabbedContainer implements Disposable, CloseAction.CloseTarget
|
||||
|
||||
public ActionCallback removeTabAt(final int componentIndex, int indexToSelect, boolean transferFocus) {
|
||||
TabInfo toSelect = indexToSelect >= 0 && indexToSelect < myTabs.getTabCount() ? myTabs.getTabAt(indexToSelect) : null;
|
||||
final ActionCallback callback = myTabs.removeTab(myTabs.getTabAt(componentIndex), toSelect, transferFocus);
|
||||
final TabInfo info = myTabs.getTabAt(componentIndex);
|
||||
// removing hidden tab happens on end of drag-out, we've already selected the correct tab for this case in dragOutStarted
|
||||
if (info.isHidden()) {
|
||||
toSelect = null;
|
||||
}
|
||||
final ActionCallback callback = myTabs.removeTab(info, toSelect, transferFocus);
|
||||
return myProject.isOpen() ? callback : new ActionCallback.Done();
|
||||
}
|
||||
|
||||
@@ -554,8 +559,12 @@ final class EditorTabbedContainer implements Disposable, CloseAction.CloseTarget
|
||||
|
||||
@Override
|
||||
public void dragOutStarted(MouseEvent mouseEvent, TabInfo info) {
|
||||
final TabInfo previousSelection = info.getPreviousSelection();
|
||||
final Image img = myTabs.getComponentImage(info);
|
||||
info.setHidden(true);
|
||||
if (previousSelection != null) {
|
||||
myTabs.select(previousSelection, true);
|
||||
}
|
||||
|
||||
myFile = (VirtualFile)info.getObject();
|
||||
Presentation presentation = new Presentation(info.getText());
|
||||
|
||||
Reference in New Issue
Block a user