mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
selection history
This commit is contained in:
@@ -31,6 +31,7 @@ import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.openapi.vcs.FileStatusManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -252,12 +253,15 @@ public class Switcher extends AnAction implements DumbAware {
|
||||
final FileEditorManagerImpl editorManager = (FileEditorManagerImpl)FileEditorManager.getInstance(project);
|
||||
final ArrayList<FileEditorInfo> filesData = new ArrayList<FileEditorInfo>();
|
||||
final ArrayList<FileEditorInfo> editors = new ArrayList<FileEditorInfo>();
|
||||
for (EditorsSplitters splitters : editorManager.getAllSplitters()) {
|
||||
for (EditorWindow window : splitters.getWindows()) {
|
||||
for (VirtualFile file : window.getFiles()) {
|
||||
editors.add(new FileEditorInfo(file, window));
|
||||
}
|
||||
}
|
||||
//for (EditorsSplitters splitters : editorManager.getAllSplitters()) {
|
||||
// for (EditorWindow window : splitters.getWindows()) {
|
||||
// for (VirtualFile file : window.getFiles()) {
|
||||
// editors.add(new FileEditorInfo(file, window));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
for (Pair<VirtualFile, EditorWindow> pair : editorManager.getSelectionHistory()) {
|
||||
editors.add(new FileEditorInfo(pair.first, pair.second));
|
||||
}
|
||||
if (editors.size() < 2) {
|
||||
final VirtualFile[] recentFiles = ArrayUtil.reverseArray(EditorHistoryManager.getInstance(project).getFiles());
|
||||
@@ -266,10 +270,10 @@ public class Switcher extends AnAction implements DumbAware {
|
||||
filesData.add(new FileEditorInfo(recentFiles[i], null));
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
ContainerUtil.sort(editors, new RecentFilesComparator(project));
|
||||
} catch (Exception e) {// IndexNotReadyException
|
||||
}
|
||||
//try {
|
||||
// ContainerUtil.sort(editors, new RecentFilesComparator(project));
|
||||
//} catch (Exception e) {// IndexNotReadyException
|
||||
//}
|
||||
for (int i = 0; i < Math.min(MAX_FILES, editors.size()); i++) {
|
||||
filesData.add(editors.get(i));
|
||||
}
|
||||
@@ -602,25 +606,25 @@ public class Switcher extends AnAction implements DumbAware {
|
||||
}
|
||||
}
|
||||
|
||||
private class RecentFilesComparator implements Comparator<FileEditorInfo> {
|
||||
private Map<FileEditorInfo, Integer> tabs = new HashMap<FileEditorInfo, Integer>();
|
||||
|
||||
public RecentFilesComparator(Project project) {
|
||||
final List<TabInfo> history = ((FileEditorManagerImpl)FileEditorManager.getInstance(project)).getTabsHistory();
|
||||
for (int i = 0; i < history.size(); i++) {
|
||||
final TabInfo info = history.get(i);
|
||||
if (info.getObject() instanceof VirtualFile && info.getComponent() instanceof EditorWindowHolder) {
|
||||
tabs.put(new FileEditorInfo((VirtualFile)info.getObject(), ((EditorWindowHolder)info.getComponent()).getEditorWindow()), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int compare(FileEditorInfo vf1, FileEditorInfo vf2) {
|
||||
final Integer index1 = tabs.get(vf1);
|
||||
final Integer index2 = tabs.get(vf2);
|
||||
return index1 == null && index2 == null ? 0 : index1 == null ? 1 : index2 == null ? -1 : index1 - index2;
|
||||
}
|
||||
}
|
||||
//private class RecentFilesComparator implements Comparator<FileEditorInfo> {
|
||||
// private Map<FileEditorInfo, Integer> tabs = new HashMap<FileEditorInfo, Integer>();
|
||||
//
|
||||
// public RecentFilesComparator(Project project) {
|
||||
// final List<TabInfo> history = ((FileEditorManagerImpl)FileEditorManager.getInstance(project)).getTabsHistory();
|
||||
// for (int i = 0; i < history.size(); i++) {
|
||||
// final TabInfo info = history.get(i);
|
||||
// if (info.getObject() instanceof VirtualFile && info.getComponent() instanceof EditorWindowHolder) {
|
||||
// tabs.put(new FileEditorInfo((VirtualFile)info.getObject(), ((EditorWindowHolder)info.getComponent()).getEditorWindow()), i);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public int compare(FileEditorInfo vf1, FileEditorInfo vf2) {
|
||||
// final Integer index1 = tabs.get(vf1);
|
||||
// final Integer index2 = tabs.get(vf2);
|
||||
// return index1 == null && index2 == null ? 0 : index1 == null ? 1 : index2 == null ? -1 : index1 - index2;
|
||||
// }
|
||||
//}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
final Object source = e.getSource();
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.intellij.ui.PrevNextActionsDescriptor;
|
||||
import com.intellij.ui.SideBorder;
|
||||
import com.intellij.ui.TabbedPaneWrapper;
|
||||
import com.intellij.ui.tabs.UiDecorator;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -236,6 +237,11 @@ public abstract class EditorComposite implements Disposable {
|
||||
publisher.selectionChanged(event);
|
||||
}
|
||||
});
|
||||
final JComponent component = newSelectedEditor.getComponent();
|
||||
final EditorWindowHolder holder = UIUtil.getParentOfType(EditorWindowHolder.class, component);
|
||||
if (holder != null) {
|
||||
((FileEditorManagerImpl)myFileEditorManager).addSelectionRecord(myFile, holder.getEditorWindow());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ public class EditorWindow {
|
||||
|
||||
beforePublisher.beforeFileClosed(editorManager, file);
|
||||
|
||||
if (myTabbedPane != null) {
|
||||
if (myTabbedPane != null && editor != null) {
|
||||
final int componentIndex = findComponentIndex(editor.getComponent());
|
||||
if (componentIndex >= 0) { // editor could close itself on decomposition
|
||||
final int indexToSelect = calcIndexToSelect(file, componentIndex);
|
||||
@@ -167,6 +167,7 @@ public class EditorWindow {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
editorManager.getSelectionHistory().remove(new Pair<VirtualFile, EditorWindow>(file, EditorWindow.this));
|
||||
final FileEditorManagerListener afterPublisher =
|
||||
editorManager.getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
|
||||
|
||||
|
||||
+35
-26
@@ -61,10 +61,10 @@ import com.intellij.openapi.wm.ex.StatusBarEx;
|
||||
import com.intellij.ui.docking.DockContainer;
|
||||
import com.intellij.ui.docking.DockManager;
|
||||
import com.intellij.ui.tabs.TabInfo;
|
||||
import com.intellij.ui.tabs.TabsListener;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.messages.impl.MessageListenerList;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue;
|
||||
import com.intellij.util.ui.update.Update;
|
||||
import org.jdom.Element;
|
||||
@@ -84,7 +84,7 @@ import java.util.List;
|
||||
* @author Eugene Belyaev
|
||||
* @author Vladimir Kondratyev
|
||||
*/
|
||||
public class FileEditorManagerImpl extends FileEditorManagerEx implements ProjectComponent, JDOMExternalizable, TabsListener {
|
||||
public class FileEditorManagerImpl extends FileEditorManagerEx implements ProjectComponent, JDOMExternalizable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl");
|
||||
private static final Key<LocalFileSystem.WatchRequest> WATCH_REQUEST_KEY = Key.create("WATCH_REQUEST_KEY");
|
||||
private static final Key<Boolean> DUMB_AWARE = Key.create("DUMB_AWARE");
|
||||
@@ -96,6 +96,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
|
||||
private EditorsSplitters mySplitters;
|
||||
private final Project myProject;
|
||||
private final List<TabInfo> myTabsHistory = new ArrayList<TabInfo>();
|
||||
private final List<Pair<VirtualFile, EditorWindow>> mySelectionHistory = new ArrayList<Pair<VirtualFile, EditorWindow>>();
|
||||
|
||||
|
||||
private final MergingUpdateQueue myQueue = new MergingUpdateQueue("FileEditorManagerUpdateQueue", 50, true, null);
|
||||
@@ -106,7 +107,6 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
|
||||
private final MyEditorPropertyChangeListener myEditorPropertyChangeListener = new MyEditorPropertyChangeListener();
|
||||
private DockManager myDockManager;
|
||||
private DockableEditorContainerFactory myContentFactory;
|
||||
private MessageBusConnection myBusConnection;
|
||||
|
||||
public FileEditorManagerImpl(final Project project, DockManager dockManager) {
|
||||
/* ApplicationManager.getApplication().assertIsDispatchThread(); */
|
||||
@@ -114,8 +114,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
|
||||
myDockManager = dockManager;
|
||||
myListenerList =
|
||||
new MessageListenerList<FileEditorManagerListener>(myProject.getMessageBus(), FileEditorManagerListener.FILE_EDITOR_MANAGER);
|
||||
myBusConnection = project.getMessageBus().connect(project);
|
||||
myBusConnection.subscribe(TabsListener.TOPIC, this);
|
||||
//myListenerList.add(new EditorSelectionListener());
|
||||
}
|
||||
|
||||
private void initDockableContentFactory() {
|
||||
@@ -501,7 +500,9 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
|
||||
}
|
||||
|
||||
private void removeHistory(VirtualFile file, EditorWindow window) {
|
||||
for (Iterator<TabInfo> i = myTabsHistory.iterator(); i.hasNext();) {
|
||||
mySelectionHistory.remove(new Pair<VirtualFile, EditorWindow>(file, window));
|
||||
|
||||
for (Iterator<TabInfo> i = myTabsHistory.iterator(); i.hasNext(); ) {
|
||||
final TabInfo info = i.next();
|
||||
final JComponent c = info.getComponent();
|
||||
if (info.getObject() == file && c instanceof EditorWindowHolder && ((EditorWindowHolder)c).getEditorWindow() == window) {
|
||||
@@ -1205,7 +1206,6 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
|
||||
// Dispose created editors. We do not use use closeEditor method because
|
||||
// it fires event and changes history.
|
||||
closeAllFiles();
|
||||
myBusConnection.disconnect();
|
||||
}
|
||||
|
||||
// BaseCompomemnt methods
|
||||
@@ -1274,6 +1274,14 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
|
||||
final FileEditorManagerEvent event =
|
||||
new FileEditorManagerEvent(this, oldSelectedFile, oldSelectedEditor, newSelectedFile, newSelectedEditor);
|
||||
final FileEditorManagerListener publisher = getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
|
||||
|
||||
if (newSelectedEditor != null) {
|
||||
final JComponent component = newSelectedEditor.getComponent();
|
||||
final EditorWindowHolder holder = UIUtil.getParentOfType(EditorWindowHolder.class, component);
|
||||
if (holder != null) {
|
||||
addSelectionRecord(newSelectedFile, holder.getEditorWindow());
|
||||
}
|
||||
}
|
||||
IdeFocusManager.getInstance(myProject).doWhenFocusSettlesDown(new ExpirableRunnable.ForProject(myProject) {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -1624,25 +1632,26 @@ private final class MyVirtualFileListener extends VirtualFileAdapter {
|
||||
return splitters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
|
||||
final JComponent selected = newSelection.getComponent();
|
||||
final Iterator<TabInfo> i = myTabsHistory.iterator();
|
||||
while (i.hasNext()) {
|
||||
final TabInfo info = i.next();
|
||||
if (info.getComponent() == selected) {
|
||||
i.remove();
|
||||
break;
|
||||
}
|
||||
public void selectionChanged(VirtualFile file, EditorWindow window) {
|
||||
final Pair<VirtualFile, EditorWindow> selection = new Pair<VirtualFile, EditorWindow>(file, window);
|
||||
mySelectionHistory.remove(selection);
|
||||
mySelectionHistory.add(0, selection);
|
||||
}
|
||||
|
||||
public List<Pair<VirtualFile, EditorWindow>> getSelectionHistory() {
|
||||
return mySelectionHistory;
|
||||
}
|
||||
|
||||
public void addSelectionRecord(VirtualFile file, EditorWindow window) {
|
||||
final Pair<VirtualFile, EditorWindow> record = new Pair<VirtualFile, EditorWindow>(file, window);
|
||||
mySelectionHistory.remove(record);
|
||||
mySelectionHistory.add(0, record);
|
||||
}
|
||||
|
||||
private class EditorSelectionListener extends FileEditorManagerAdapter {
|
||||
@Override
|
||||
public void selectionChanged(FileEditorManagerEvent event) {
|
||||
System.out.println(event.getNewFile().getName());
|
||||
}
|
||||
myTabsHistory.add(0, newSelection);
|
||||
}
|
||||
|
||||
public List<TabInfo> getTabsHistory() {
|
||||
return myTabsHistory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeSelectionChanged(TabInfo oldSelection, TabInfo newSelection) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user