Skip to content

Commit 5e9497d

Browse files
committed
Add "Update" action to PythonBytecodeToolWindow toolbar and refactor header UI
1 parent 0ce7319 commit 5e9497d

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

src/main/kotlin/dev/meanmail/tools/PythonBytecodeTool.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.meanmail.tools
22

3+
import com.intellij.openapi.actionSystem.ActionManager
4+
import com.intellij.openapi.actionSystem.DefaultActionGroup
35
import com.intellij.openapi.project.Project
46
import com.intellij.openapi.util.Disposer
57
import com.intellij.openapi.wm.ToolWindow
@@ -27,6 +29,13 @@ class PythonBytecodeTool : ToolWindowFactory {
2729
)
2830
toolWindow.contentManager.addContent(content)
2931

32+
// Add the update action to the tool window toolbar
33+
val actionManager = ActionManager.getInstance()
34+
val updateAction = actionManager.getAction("PythonBytecode.UpdateAction")
35+
val actionGroup = DefaultActionGroup()
36+
actionGroup.add(updateAction)
37+
toolWindow.setTitleActions(listOf(updateAction))
38+
3039
// Store the tool window component for later use
3140
toolWindowComponents[project] = pluginDevToolWindow
3241

src/main/kotlin/dev/meanmail/tools/PythonBytecodeToolWindow.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.intellij.openapi.fileEditor.FileEditorManager
1919
import com.intellij.openapi.project.Project
2020
import com.intellij.openapi.projectRoots.Sdk
2121
import com.intellij.openapi.roots.ProjectRootManager
22-
import com.intellij.ui.dsl.builder.panel
2322
import com.jetbrains.python.sdk.PythonSdkType
2423
import java.awt.Color
2524
import java.io.File
@@ -50,18 +49,10 @@ class PythonBytecodeToolWindow(private val project: Project) : Disposable, Pytho
5049

5150
private fun createEditor(): EditorEx {
5251
val editorFactory = EditorFactory.getInstance()
53-
val document = editorFactory.createDocument("Click Update button")
52+
val document = editorFactory.createDocument("Click the Update button in the toolbar")
5453
val editor: EditorEx = editorFactory.createViewer(
5554
document, project, EditorKind.MAIN_EDITOR
5655
) as EditorEx
57-
editor.permanentHeaderComponent = panel {
58-
row {
59-
button("Update") {
60-
updateBytecode()
61-
}
62-
}
63-
}
64-
editor.headerComponent = editor.permanentHeaderComponent
6556

6657
return editor
6758
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package dev.meanmail.tools
2+
3+
import com.intellij.openapi.actionSystem.AnAction
4+
import com.intellij.openapi.actionSystem.AnActionEvent
5+
import com.intellij.openapi.project.DumbAware
6+
7+
/**
8+
* Action to update the Python bytecode display.
9+
* This action is available in the Python bytecode tool window.
10+
*/
11+
class UpdateBytecodeAction : AnAction(), DumbAware {
12+
override fun actionPerformed(e: AnActionEvent) {
13+
val project = e.project ?: return
14+
val toolWindowComponent = PythonBytecodeTool.getToolWindowComponent(project) ?: return
15+
toolWindowComponent.updateBytecode()
16+
}
17+
18+
override fun update(e: AnActionEvent) {
19+
// Enable the action only if a project is available
20+
e.presentation.isEnabled = e.project != null
21+
}
22+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ First release
4242
topic="com.intellij.openapi.fileEditor.FileEditorManagerListener"/>
4343
</projectListeners>
4444

45+
<actions>
46+
<action id="PythonBytecode.UpdateAction"
47+
class="dev.meanmail.tools.UpdateBytecodeAction"
48+
text="Update Bytecode"
49+
description="Update the Python bytecode display"
50+
icon="AllIcons.Actions.Refresh">
51+
</action>
52+
</actions>
53+
4554
</idea-plugin>

0 commit comments

Comments
 (0)