Skip to content

Commit

Permalink
- Code Outline panel is not always rendered when open file or tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sitano committed Aug 24, 2011
1 parent 9a71b96 commit 4d274ad
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[core]
autocrlf=input
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ General usage instructions:
Known bugs:
-----------
+ (Fixed in 1.0) Plugin does not work when running on Java 6 (JDK 6.0)
+ (Fixed in 1.0) Code Outline panel is not always rendered when open file or tab
- Exceptions when pointing to not existing place in code
- Code Outline panel is not always rendered when open file or tab
- Scale outline when it's too tall to fit
- Plugin not deal well with deleting large amounts of text when file is too large
- Rotate or wrap outline when toolwindow is moved to top or bottom
Expand All @@ -50,11 +50,7 @@ IntelliJ IDEA debug note:
-Didea.plugins.path=~/.IdeaIC11/system/plugins-sandbox/plugins
-Didea.platform.prefix=Idea
-Dfile.encoding=UTF-8
-classpath /usr/java/default/lib/tools.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/idea_rt.jar:
~/idea-com/idea-IC-108.SNAPSHOT/lib/idea.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/bootstrap.jar:
~/idea-com/idea-IC-108.SNAPSHOT/lib/extensions.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/util.jar:
~/idea-com/idea-IC-108.SNAPSHOT/lib/openapi.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/trove4j.jar:
~/idea-com/idea-IC-108.SNAPSHOT/lib/jdom.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/log4j.jar
-classpath /usr/java/default/lib/tools.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/idea_rt.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/idea.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/bootstrap.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/extensions.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/util.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/openapi.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/trove4j.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/jdom.jar:~/idea-com/idea-IC-108.SNAPSHOT/lib/log4j.jar
com.intellij.idea.Main

Also com.intellij.rt.execution.application.AppMain can be used.
Expand Down
58 changes: 45 additions & 13 deletions src/main/java/net/kano/codeoutline/CodeOutlineToolWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* File created by keith @ Oct 22, 2003
*
* Modified by John.Koepi
*/

package net.kano.codeoutline;

import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
Expand Down Expand Up @@ -74,39 +75,68 @@ public class CodeOutlineToolWindow extends JPanel {
/** The panel currently being displayed. */
private CodeOutlinePanel currentPanel = null;

private Map<FileEditor, CodeOutlinePanel> editor2panel
= new IdentityHashMap<FileEditor, CodeOutlinePanel>();
private Map<VirtualFile, CodeOutlinePanel> file2panel
= new IdentityHashMap<VirtualFile, CodeOutlinePanel>();
private Map<FileEditor, CodeOutlinePanel> editor2panel = new IdentityHashMap<FileEditor, CodeOutlinePanel>();
private Map<VirtualFile, CodeOutlinePanel> file2panel = new IdentityHashMap<VirtualFile, CodeOutlinePanel>();

/**
* An editor listener for the given project, to create and destroy code
* outline panels.
*/
private FileEditorManagerListener editorListener
= new FileEditorManagerListener() {
private FileEditorManagerListener editorListener = new FileEditorManagerListener() {
@Override
public void fileOpened(FileEditorManager source, VirtualFile file) {
FileEditor fileEditor = source.getSelectedEditor(file);
if (fileEditor instanceof TextEditor) {
openPanel(fileEditor, file);
CodeOutlinePanel panel = openPanel(fileEditor, file);
/* Force panel sub-component switch, cause we have no guaranty it will come
* after we register new instance.
*/
if (checkCurrentPanel(source, file, panel))
repaint();
}
}

@Override
public void fileClosed(FileEditorManager source, VirtualFile file) {
closePanel(file);
}

/**
* Switch panel if given editor is selected
*/
private boolean checkCurrentPanel(FileEditorManager source, VirtualFile file, CodeOutlinePanel panel) {
EditorEx selectedEditorEx = ((EditorEx)source.getSelectedTextEditor());
if (selectedEditorEx.getVirtualFile() == file && !isAncestorOf(panel)) {
replacePanel(panel);
return true;
}

return false;
}

/**
* This often comes before fileOpened event (or may not)
*/
@Override
public void selectionChanged(final FileEditorManagerEvent event) {
CodeOutlinePanel panel = editor2panel.get(event.getNewEditor());
replacePanel(panel);
repaint();
}

/**
* Replaces current panel with new panel.
*/
private void replacePanel(CodeOutlinePanel panel) {
if (currentPanel != null) {
remove(currentPanel);
}
CodeOutlinePanel panel = editor2panel.get(
event.getNewEditor());

currentPanel = panel;

if (panel != null) {
add(panel, GBC_DEFAULT);
}
repaint();
}
};

Expand Down Expand Up @@ -148,12 +178,14 @@ public CodeOutlineToolWindow(CodeOutlinePlugin plugin, Project project) {
* @param fileEditor a file editor
* @param file a file
*/
private synchronized void openPanel(FileEditor fileEditor,
VirtualFile file) {
private synchronized CodeOutlinePanel openPanel(FileEditor fileEditor, VirtualFile file) {
Editor editor = ((TextEditor) fileEditor).getEditor();
CodeOutlinePanel panel = new CodeOutlinePanel(plugin, project, editor);

editor2panel.put(fileEditor, panel);
file2panel.put(file, panel);

return panel;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ private LetterThicknessManager() throws ClassNotFoundException {
FontMetrics fm = null;

try {
// static create method (JDK6, 7)
// Static fabric method (JDK6, OpenJDK7)
Method staticMethodConstructor = fdm.getMethod("getMetrics", params);
fm = (FontMetrics) staticMethodConstructor.invoke(null, font);
} catch (NoSuchMethodException e) {
// old constructor (old JDK5 impl)
// Constructor (old JDK4, 5 impl)
Constructor constructor = fdm.getConstructor(params);
fm = (FontMetrics) constructor.newInstance(args);
} finally {
Expand Down
41 changes: 21 additions & 20 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<!DOCTYPE idea-plugin PUBLIC "" "http://plugins.intellij.net/plugin.dtd">
<idea-plugin url="http://code.google.com/p/intellij-code-outline/">
<id>CodeOutline2</id>
<name>Code Outline 2</name>
<description>Shows a zoomed out "outline" of your code while you're editing it.</description>
<version>1.0</version>
<vendor email="john.koepi@gmail.com">Ivan</vendor>
<change-notes>
Since 1.0:
- Support for JDK6 (fixed bug NoClassMethodFound Exception)
</change-notes>
<idea-version since-build="93.13"/>
<application-components>
<component>
<implementation-class>net.kano.codeoutline.CodeOutlinePlugin
</implementation-class>
</component>
</application-components>
</idea-plugin>

<!DOCTYPE idea-plugin PUBLIC "" "http://plugins.intellij.net/plugin.dtd">
<idea-plugin url="http://code.google.com/p/intellij-code-outline/">
<id>CodeOutline2</id>
<name>Code Outline 2</name>
<description>Shows a zoomed out "outline" of your code while you're editing it.</description>
<version>1.0</version>
<vendor email="john.koepi@gmail.com">Ivan</vendor>
<change-notes>
Since 1.0:
- Support for JDK6 (fixed bug NoClassMethodFound Exception)
- No panel rendering when open projects and new files
</change-notes>
<idea-version since-build="93.13"/>
<application-components>
<component>
<implementation-class>net.kano.codeoutline.CodeOutlinePlugin
</implementation-class>
</component>
</application-components>
</idea-plugin>

0 comments on commit 4d274ad

Please sign in to comment.