OC-2581: Open .h and .m files side-by-side

This commit is contained in:
Alexander Kirillin
2012-03-07 16:20:08 +04:00
parent 8d615b3540
commit 2f48da2261
4 changed files with 98 additions and 1 deletions
@@ -24,6 +24,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.ScrollingModel;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.fileEditor.TextEditor;
@@ -665,6 +666,18 @@ public class EditorWindow {
*/
// open only selected file in the new splitter instead of opening all tabs
final VirtualFile file = selectedEditor.getFile();
if (virtualFile == null) {
for (FileEditorAssociateFinder finder : Extensions.getExtensions(FileEditorAssociateFinder.EP_NAME)) {
VirtualFile associatedFile = finder.getAssociatedFileToOpen(fileEditorManager.getProject(), file);
if (associatedFile != null) {
virtualFile = associatedFile;
break;
}
}
}
final VirtualFile nextFile = virtualFile == null ? file : virtualFile;
final FileEditor[] editors = fileEditorManager.openFileImpl3(res, nextFile, false, null, true).first;
syncCaretIfPossible(editors);
@@ -0,0 +1,35 @@
/*
* Copyright 2000-2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.fileEditor.impl;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created by IntelliJ IDEA.
* User: angus
* Date: 3/6/12
* Time: 1:37 PM
*/
public interface FileEditorAssociateFinder {
ExtensionPointName<FileEditorAssociateFinder> EP_NAME = ExtensionPointName.create("com.intellij.editorFileAssociateFinder");
@Nullable
VirtualFile getAssociatedFileToOpen(@NotNull Project project, @NotNull VirtualFile original);
}
@@ -122,6 +122,17 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
myDockManager = dockManager;
myListenerList =
new MessageListenerList<FileEditorManagerListener>(myProject.getMessageBus(), FileEditorManagerListener.FILE_EDITOR_MANAGER);
if (Extensions.getExtensions(FileEditorAssociateFinder.EP_NAME).length > 0) {
myListenerList.add(new FileEditorManagerAdapter() {
@Override
public void selectionChanged(FileEditorManagerEvent event) {
EditorsSplitters splitters = getSplitters();
openAssociatedFile(event.getNewFile(), splitters.getCurrentWindow(), splitters);
}
});
}
myQueue.setTrackUiActivity(true);
}
@@ -597,12 +608,39 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
else {
wndToOpenIn = getSplitters().getCurrentWindow();
}
EditorsSplitters splitters = getSplitters();
if (wndToOpenIn == null) {
wndToOpenIn = getSplitters().getOrCreateCurrentWindow(file);
wndToOpenIn = splitters.getOrCreateCurrentWindow(file);
}
openAssociatedFile(file, wndToOpenIn, splitters);
return openFileImpl2(wndToOpenIn, file, focusEditor);
}
private void openAssociatedFile(VirtualFile file, EditorWindow wndToOpenIn, EditorsSplitters splitters) {
EditorWindow[] windows = splitters.getWindows();
if (file != null && windows.length == 2) {
for (FileEditorAssociateFinder finder : Extensions.getExtensions(FileEditorAssociateFinder.EP_NAME)) {
VirtualFile associatedFile = finder.getAssociatedFileToOpen(myProject, file);
if (associatedFile != null) {
EditorWindow currentWindow = splitters.getCurrentWindow();
int idx = windows[0] == wndToOpenIn ? 1 : 0;
openFileImpl2(windows[idx], associatedFile, false);
if (currentWindow != null) {
splitters.setCurrentWindow(currentWindow, false);
}
break;
}
}
}
}
@NotNull
@Override
public Pair<FileEditor[], FileEditorProvider[]> openFileWithProviders(@NotNull VirtualFile file,
@@ -1309,6 +1347,16 @@ public class FileEditorManagerImpl extends FileEditorManagerEx implements Projec
final boolean filesEqual = oldData.first == null ? newData.first == null : oldData.first.equals(newData.first);
final boolean editorsEqual = oldData.second == null ? newData.second == null : oldData.second.equals(newData.second);
if (!filesEqual || !editorsEqual) {
if (oldData.first != null && newData.first != null) {
for (FileEditorAssociateFinder finder : Extensions.getExtensions(FileEditorAssociateFinder.EP_NAME)) {
VirtualFile associatedFile = finder.getAssociatedFileToOpen(myProject, oldData.first);
if (associatedFile == newData.first) {
return;
}
}
}
final FileEditorManagerEvent event =
new FileEditorManagerEvent(this, oldData.first, oldData.second, oldData.third, newData.first, newData.second, newData.third);
final FileEditorManagerListener publisher = getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
@@ -79,6 +79,7 @@
<extensionPoint name="editorTabTitleProvider" interface="com.intellij.openapi.fileEditor.impl.EditorTabTitleProvider"/>
<extensionPoint name="editorTabColorProvider" interface="com.intellij.openapi.fileEditor.impl.EditorTabColorProvider"/>
<extensionPoint name="editorFileSwapper" interface="com.intellij.openapi.fileEditor.impl.EditorFileSwapper"/>
<extensionPoint name="editorFileAssociateFinder" interface="com.intellij.openapi.fileEditor.impl.FileEditorAssociateFinder"/>
<extensionPoint name="http.localFileFinder" interface="com.intellij.openapi.fileEditor.impl.http.LocalFileFinder"/>
<extensionPoint name="http.fileEditorActionProvider" interface="com.intellij.openapi.fileEditor.impl.http.RemoteFileEditorActionProvider"/>