Skip to content

Commit 5cfe5c4

Browse files
committed
Support 171.3556 EAPs
Fixes #155 #156 #156
1 parent 974f0aa commit 5cfe5c4

File tree

1 file changed

+28
-44
lines changed

1 file changed

+28
-44
lines changed

src/main/java/net/vektah/codeglance/EditorPanelInjector.kt

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,18 @@ class EditorPanelInjector(private val project: Project, private val runner: Task
3232
/**
3333
* Here be dragons. No Seriously. Run!
3434
*
35-
* There is a loading pane that proxies stuff here blah blah.. We need to dig down so we can check
36-
* if we have already injected into a given component... On the plus side might be a bit closer to being able to
37-
* injecting into the editor space itself...
35+
* We are digging way down into the editor layout. This lets the codeglance panel be right next to the scroll bar.
36+
* In an ideal world it would be inside the scroll bar... maybe one day.
3837
*
3938
* vsch: added handling when the editor is even deeper, inside firstComponent of a JBSplitter, used by idea-multimarkdown
4039
* and Markdown Support to show split preview. Missed this plugin while editing markdown. These changes got it back.
4140
*
4241
* @param editor A text editor to inject into.
4342
*/
44-
private fun inject(editor: FileEditor) {
43+
private fun getPanel(editor: FileEditor): JPanel? {
4544
if (editor !is TextEditor) {
4645
logger.debug("I01: Injection failed, only text editors are supported currently.")
47-
return
46+
return null
4847
}
4948

5049
try {
@@ -59,57 +58,42 @@ class EditorPanelInjector(private val project: Project, private val runner: Task
5958
}
6059

6160
val pane = layoutComponent as JLayeredPane
62-
val panel = pane.getComponent(1) as JPanel
63-
val innerLayout = panel.layout as BorderLayout
64-
65-
// Ok we finally found the actual editor layout. Now make sure we haven't already injected into this editor.
66-
if (innerLayout.getLayoutComponent(BorderLayout.LINE_END) == null) {
67-
val glancePanel = GlancePanel(project, editor, panel, runner)
68-
panel.add(glancePanel, BorderLayout.LINE_END)
69-
panels.put(editor, glancePanel)
61+
62+
if (pane.getComponentCount() > 1) {
63+
return pane.getComponent(1) as JPanel
7064
} else {
71-
logger.warn("I07: Injection skipped. Looks like we have already injected something here.")
65+
return pane.getComponent(0) as JPanel
7266
}
7367
} catch (e: ClassCastException) {
7468
logger.warn("Injection failed")
7569
e.printStackTrace()
76-
return
70+
return null
7771
}
78-
7972
}
8073

81-
private fun uninject(editor: FileEditor) {
82-
if (editor !is TextEditor) {
83-
logger.debug("I01: Uninjection failed, only text editors are supported currently.")
84-
return
85-
}
8674

87-
try {
88-
val outerPanel = editor.component as JPanel
89-
val outerLayout = outerPanel.layout as BorderLayout
90-
var layoutComponent = outerLayout.getLayoutComponent(BorderLayout.CENTER)
91-
92-
if (layoutComponent is JBSplitter) {
93-
// editor is inside firstComponent of a JBSplitter
94-
val editorComp = layoutComponent.firstComponent as JPanel
95-
layoutComponent = (editorComp.layout as BorderLayout).getLayoutComponent(BorderLayout.CENTER)
96-
}
75+
private fun inject(editor: FileEditor) {
76+
val panel = getPanel(editor) ?: return
77+
val innerLayout = panel.layout as BorderLayout
78+
79+
if (innerLayout.getLayoutComponent(BorderLayout.LINE_END) == null) {
80+
val glancePanel = GlancePanel(project, editor, panel, runner)
81+
panel.add(glancePanel, BorderLayout.LINE_END)
82+
panels.put(editor, glancePanel)
83+
} else {
84+
logger.warn("I07: Injection skipped. Looks like we have already injected something here.")
85+
}
86+
}
9787

98-
val pane = layoutComponent as JLayeredPane
99-
val panel = pane.getComponent(1) as JPanel
100-
val innerLayout = panel.layout as BorderLayout
88+
private fun uninject(editor: FileEditor) {
89+
val panel = getPanel(editor) ?: return
90+
val innerLayout = panel.layout as BorderLayout
10191

102-
// Ok we finally found the actual editor layout. Now make sure we haven't already injected into this editor.
103-
val glancePanel = innerLayout.getLayoutComponent(BorderLayout.LINE_END)
104-
if (glancePanel != null) {
105-
panel.remove(glancePanel)
106-
}
107-
} catch (e: ClassCastException) {
108-
logger.warn("Uninjection failed")
109-
e.printStackTrace()
110-
return
92+
// Ok we finally found the actual editor layout. Now make sure we have already injected into this editor.
93+
val glancePanel = innerLayout.getLayoutComponent(BorderLayout.LINE_END)
94+
if (glancePanel != null) {
95+
panel.remove(glancePanel)
11196
}
112-
11397
}
11498

11599
override fun fileClosed(fem: FileEditorManager, virtualFile: VirtualFile) {

0 commit comments

Comments
 (0)