on drag out of inactive tab, restore selection to tab which was selected before drag out started (IDEA-61536)

This commit is contained in:
Dmitry Jemerov
2012-02-20 19:29:23 +01:00
parent bde8741be2
commit 0b2318bf51
3 changed files with 30 additions and 1 deletions
@@ -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);
}
});
@@ -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());