Skip to content

Commit

Permalink
select only required editor in window
Browse files Browse the repository at this point in the history
  • Loading branch information
JB-Dmitry committed May 28, 2014
1 parent 68aadaf commit 311406c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -644,6 +644,10 @@ public void run() {
}

public void setEditor(@Nullable final EditorWithProviderComposite editor, final boolean focusEditor) {
setEditor(editor, true, focusEditor);
}

public void setEditor(@Nullable final EditorWithProviderComposite editor, final boolean selectEditor, final boolean focusEditor) {
if (editor != null) {
if (myTabbedPane == null) {
myPanel.removeAll ();
Expand All @@ -654,7 +658,9 @@ public void setEditor(@Nullable final EditorWithProviderComposite editor, final

final int index = findEditorIndex(editor);
if (index != -1) {
setSelectedEditor(editor, focusEditor);
if (selectEditor) {
setSelectedEditor(editor, focusEditor);
}
}
else {
Integer initialIndex = editor.getFile().getUserData(INITIAL_INDEX_KEY);
Expand All @@ -672,7 +678,9 @@ public void setEditor(@Nullable final EditorWithProviderComposite editor, final
final Icon template = AllIcons.FileTypes.Text;
myTabbedPane.insertTab(file, new EmptyIcon(template.getIconWidth(), template.getIconHeight()), new TComp(this, editor), null, indexToInsert);
trimToSize(UISettings.getInstance().EDITOR_TAB_LIMIT, file, false);
setSelectedEditor(editor, focusEditor);
if (selectEditor) {
setSelectedEditor(editor, focusEditor);
}
myOwner.updateFileIcon(file);
myOwner.updateFileColor(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
public class EditorsSplitters extends IdePanePanel implements UISettingsListener {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.fileEditor.impl.EditorsSplitters");
private static final String PINNED = "pinned";
private static final String CURRENT_IN_TAB = "current-in-tab";

private final static EditorEmptyTextPainter ourPainter = ServiceManager.getService(EditorEmptyTextPainter.class);

Expand Down Expand Up @@ -227,8 +228,7 @@ private void writeComposite(final Element res, final VirtualFile file, final Edi
final HistoryEntry entry = composite.currentStateAsHistoryEntry();
entry.writeExternal(fileElement, getManager().getProject());
fileElement.setAttribute(PINNED, Boolean.toString(pinned));
fileElement.setAttribute("current", Boolean.toString(composite.equals (getManager ().getLastSelected ())));
fileElement.setAttribute("current-in-tab", Boolean.toString(composite.equals (selectedEditor)));
fileElement.setAttribute(CURRENT_IN_TAB, Boolean.toString(composite.equals(selectedEditor)));
res.addContent(fileElement);
}

Expand Down Expand Up @@ -281,19 +281,15 @@ private JPanel readExternalPanel(final Element element, @Nullable JPanel panel)
}
}

VirtualFile currentFile = null;
for (int i = 0; i < children.size(); i++) {
final Element file = children.get(i);
try {
final FileEditorManagerImpl fileEditorManager = getManager();
final HistoryEntry entry = new HistoryEntry(fileEditorManager.getProject(), file.getChild(HistoryEntry.TAG), true);
final boolean isCurrent = Boolean.valueOf(file.getAttributeValue("current")).booleanValue();
fileEditorManager.openFileImpl4(window, entry.myFile, false, entry, isCurrent, i);
final boolean isCurrentInTab = Boolean.valueOf(file.getAttributeValue(CURRENT_IN_TAB)).booleanValue();
fileEditorManager.openFileImpl4(window, entry.myFile, isCurrentInTab, entry, isCurrentInTab, i);
if (fileEditorManager.isFileOpen(entry.myFile)) {
window.setFilePinned(entry.myFile, Boolean.valueOf(file.getAttributeValue(PINNED)).booleanValue());
if (Boolean.valueOf(file.getAttributeValue("current-in-tab")).booleanValue()) {
currentFile = entry.myFile;
}
}

}
Expand All @@ -303,12 +299,6 @@ private JPanel readExternalPanel(final Element element, @Nullable JPanel panel)
}
}
}
if (currentFile != null) {
final EditorComposite editor = window.findFileComposite(currentFile);
if (editor != null) {
window.setSelectedEditor(editor, true);
}
}
return window.myPanel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ public boolean value(FileEditorProvider fileEditorProvider) {
LOG.assertTrue(provider != null, "Provider for file "+file+" is null. All providers: "+Arrays.asList(providers));
LOG.assertTrue(provider.accept(myProject, file), "Provider " + provider + " doesn't accept file " + file);
final FileEditor editor = provider.createEditor(myProject, file);
LOG.assertTrue(editor != null);
LOG.assertTrue(editor.isValid());
editors[i] = editor;
// Register PropertyChangeListener into editor
Expand Down Expand Up @@ -823,7 +822,7 @@ public boolean value(FileEditorProvider fileEditorProvider) {
}
}

window.setEditor(newSelectedComposite, focusEditor);
window.setEditor(newSelectedComposite, current, focusEditor);

final EditorHistoryManager editorHistoryManager = EditorHistoryManager.getInstance(myProject);
for (int i = 0; i < editors.length; i++) {
Expand Down

0 comments on commit 311406c

Please sign in to comment.