mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-127739 Navigation Tab
Stage 2
This commit is contained in:
+7
-6
@@ -181,7 +181,7 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
|
||||
HashSet<EditorsSplitters> all = new LinkedHashSet<EditorsSplitters>();
|
||||
if (Registry.is("editor.use.preview")) {
|
||||
initUI();
|
||||
all.add(myPreviewPanel.getSplitters());
|
||||
all.add(myPreviewPanel.getWindow().getOwner());
|
||||
}
|
||||
all.add(getMainSplitters());
|
||||
Set<DockContainer> dockContainers = myDockManager.getContainers();
|
||||
@@ -639,11 +639,12 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
|
||||
}
|
||||
else {
|
||||
wndToOpenIn = getSplitters().getCurrentWindow();
|
||||
if (wndToOpenIn == null || !wndToOpenIn.isFileOpen(file)) {
|
||||
EditorWindow previewWindow = getPreviewWindow(file, focusEditor, searchForSplitter);
|
||||
if (previewWindow != null) {
|
||||
wndToOpenIn = previewWindow;
|
||||
}
|
||||
}
|
||||
|
||||
if (wndToOpenIn == null || !wndToOpenIn.isFileOpen(file)) {
|
||||
EditorWindow previewWindow = getPreviewWindow(file, focusEditor, searchForSplitter);
|
||||
if (previewWindow != null) {
|
||||
wndToOpenIn = previewWindow;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,14 @@ import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.editor.event.DocumentListener;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FileStatus;
|
||||
import com.intellij.openapi.vcs.FileStatusManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
@@ -30,13 +34,14 @@ import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.impl.ToolWindowImpl;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.docking.DockManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class PreviewPanel extends JPanel {
|
||||
class PreviewPanel extends JPanel implements DocumentListener, FileEditorManagerListener.Before {
|
||||
private static final int HISTORY_LIMIT = 10;
|
||||
|
||||
private final Project myProject;
|
||||
@@ -46,6 +51,9 @@ class PreviewPanel extends JPanel {
|
||||
private boolean myInitialized = false;
|
||||
private EditorsSplitters myEditorsSplitters;
|
||||
private ArrayList<VirtualFile> myHistory = new ArrayList<VirtualFile>();
|
||||
private VirtualFile myModifiedFile = null;
|
||||
private ToolWindowImpl myToolWindow;
|
||||
private VirtualFile myAwaitingForOpen = null;
|
||||
|
||||
public PreviewPanel(Project project, FileEditorManagerImpl manager, DockManager dockManager) {
|
||||
myProject = project;
|
||||
@@ -58,21 +66,30 @@ class PreviewPanel extends JPanel {
|
||||
private void initToolWindowIfNeed() {
|
||||
if (myInitialized) return;
|
||||
|
||||
final ToolWindowImpl window = (ToolWindowImpl)ToolWindowManager.getInstance(myProject)
|
||||
myToolWindow = (ToolWindowImpl)ToolWindowManager.getInstance(myProject)
|
||||
.registerToolWindow(ToolWindowId.PREVIEW, this, ToolWindowAnchor.RIGHT, myProject, false);
|
||||
window.setIcon(AllIcons.Actions.PreviewDetails);
|
||||
myToolWindow.setIcon(AllIcons.Actions.PreviewDetails);
|
||||
|
||||
myEditorsSplitters = new EditorsSplitters(myManager, myDockManager, false) {
|
||||
@Override
|
||||
protected void afterFileClosed(VirtualFile file) {
|
||||
window.setTitle(": (empty)");
|
||||
public void updateFileName(VirtualFile updatedFile) {
|
||||
super.updateFileName(updatedFile);
|
||||
if (updatedFile != null && updatedFile.equals(getCurrentFile())) {
|
||||
updateWindowTitle(updatedFile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterFileOpen(VirtualFile file) {
|
||||
window.setTitle(": " +
|
||||
StringUtil.getShortened(EditorTabbedContainer.calcTabTitle(myProject, file),
|
||||
UISettings.getInstance().EDITOR_TAB_TITLE_LIMIT));
|
||||
if (file.equals(myAwaitingForOpen)) {
|
||||
updateWindowTitle(file);
|
||||
Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
if (document != null) {
|
||||
myModifiedFile = null;
|
||||
document.addDocumentListener(PreviewPanel.this, myProject);
|
||||
}
|
||||
}
|
||||
myAwaitingForOpen = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,25 +102,66 @@ class PreviewPanel extends JPanel {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
myProject.getMessageBus().connect().subscribe(FileEditorManagerListener.Before.FILE_EDITOR_MANAGER, this);
|
||||
myEditorsSplitters.createCurrentWindow();
|
||||
|
||||
myWindow = myEditorsSplitters.getCurrentWindow();
|
||||
myWindow.setTabsPlacement(UISettings.TABS_NONE);
|
||||
|
||||
setLayout(new GridLayout(1, 1));
|
||||
add(myEditorsSplitters);
|
||||
|
||||
window.setTitleActions(new MoveToEditorTabsAction(), new CloseFileAction());
|
||||
myToolWindow.setTitleActions(new MoveToEditorTabsAction(), new CloseFileAction());
|
||||
|
||||
myInitialized = true;
|
||||
}
|
||||
|
||||
EditorWindow getWindow() {
|
||||
return myWindow;
|
||||
private void updateWindowTitle(VirtualFile file) {
|
||||
if (myToolWindow == null) return;
|
||||
if (file == null) {
|
||||
myToolWindow.setTitle(": (empty)");
|
||||
}
|
||||
else {
|
||||
myToolWindow.setTitle(": " +
|
||||
StringUtil.getShortened(EditorTabbedContainer.calcTabTitle(myProject, file),
|
||||
UISettings.getInstance().EDITOR_TAB_TITLE_LIMIT));
|
||||
}
|
||||
}
|
||||
|
||||
EditorsSplitters getSplitters() {
|
||||
@Override
|
||||
public void beforeFileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
|
||||
myAwaitingForOpen = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeFileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
|
||||
if (file.equals(getCurrentFile())) {
|
||||
updateWindowTitle(null);
|
||||
Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
if (document != null) {
|
||||
document.removeDocumentListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeDocumentChange(DocumentEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void documentChanged(DocumentEvent event) {
|
||||
VirtualFile file = FileDocumentManager.getInstance().getFile(event.getDocument());
|
||||
if (file != null) {
|
||||
myModifiedFile = file;
|
||||
}
|
||||
}
|
||||
|
||||
EditorWindow getWindow() {
|
||||
initToolWindowIfNeed();
|
||||
return myEditorsSplitters;
|
||||
return myWindow;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -144,8 +202,8 @@ class PreviewPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isModified(VirtualFile currentFile) {
|
||||
return FileStatus.MODIFIED == FileStatusManager.getInstance(myProject).getStatus(currentFile);
|
||||
private boolean isModified(@NotNull VirtualFile file) {
|
||||
return file.equals(myModifiedFile);
|
||||
}
|
||||
|
||||
//returns last open file if it has "modified" status
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
|
||||
import com.intellij.openapi.actionSystem.impl.ActionManagerImpl;
|
||||
import com.intellij.openapi.actionSystem.impl.MenuItemPresentationFactory;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
@@ -54,7 +53,7 @@ import java.beans.PropertyChangeListener;
|
||||
/**
|
||||
* @author pegov
|
||||
*/
|
||||
public abstract class ToolWindowHeader extends JPanel implements Disposable, UISettingsListener, TimerListener {
|
||||
public abstract class ToolWindowHeader extends JPanel implements Disposable, UISettingsListener {
|
||||
@NonNls private static final String HIDE_ACTIVE_WINDOW_ACTION_ID = "HideActiveWindow";
|
||||
@NonNls private static final String HIDE_ACTIVE_SIDE_WINDOW_ACTION_ID = "HideSideWindows";
|
||||
|
||||
@@ -191,7 +190,6 @@ public abstract class ToolWindowHeader extends JPanel implements Disposable, UIS
|
||||
setBorder(BorderFactory.createEmptyBorder(TabsUtil.TABS_BORDER, 1, TabsUtil.TABS_BORDER, 1));
|
||||
|
||||
UISettings.getInstance().addUISettingsListener(this, toolWindow.getContentUI());
|
||||
ActionManager.getInstance().addTimerListener(500, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,41 +204,6 @@ public abstract class ToolWindowHeader extends JPanel implements Disposable, UIS
|
||||
eastPanel.add(Box.createHorizontalStrut(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
ActionManager.getInstance().addTimerListener(500, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNotify() {
|
||||
super.removeNotify();
|
||||
ActionManager.getInstance().removeTimerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModalityState getModalityState() {
|
||||
if (myToolWindow == null) return null;
|
||||
return ModalityState.stateForComponent(myToolWindow.getComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Component c : myButtonPanel.getComponents()) {
|
||||
if (c instanceof ActionButton) {
|
||||
ActionButton actionButton = (ActionButton) c;
|
||||
Presentation presentation = actionButton.myAction.getTemplatePresentation().clone();
|
||||
DataContext context = DataManager.getInstance().getDataContext(actionButton);
|
||||
AnActionEvent event = new AnActionEvent(null, context, ActionPlaces.UNKNOWN, presentation, ActionManager.getInstance(), 0);
|
||||
actionButton.myAction.update(event);
|
||||
actionButton.setEnabled(event.getPresentation().isEnabled());
|
||||
actionButton.setIcon(event.getPresentation().getIcon(), event.getPresentation().getDisabledIcon(), event.getPresentation().getHoveredIcon());
|
||||
}
|
||||
}
|
||||
myButtonPanel.revalidate();
|
||||
myButtonPanel.repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
removeAll();
|
||||
@@ -529,6 +492,7 @@ public abstract class ToolWindowHeader extends JPanel implements Disposable, UIS
|
||||
if (component != null && !component.isShowing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
action.actionPerformed(event);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user