Skip to content

Commit 2c9769e

Browse files
committed
feat(core): add save file action to AutoDev tool window
- Add AutoDevSaveFileAction class to handle save file functionality - Update AutoDevIcons to include new SaveFile icon - Add save-file.svg icon to project resources - Update AutoDevBundle properties to include new save action text - Modify autodev-core.xml to add save file action to tool window
1 parent 5a11e72 commit 2c9769e

File tree

7 files changed

+53
-0
lines changed

7 files changed

+53
-0
lines changed

core/src/223/main/resources/META-INF/autodev-core.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@
371371
<action id="AutoDev.ToolWindow.Snippet.RunDevIns"
372372
icon="cc.unitmesh.devti.AutoDevIcons.Run"
373373
class="cc.unitmesh.devti.gui.snippet.AutoDevRunAction"/>
374+
<action id="AutoDev.ToolWindow.Snippet.SaveFile"
375+
icon="cc.unitmesh.devti.AutoDevIcons.SaveFile"
376+
class="cc.unitmesh.devti.gui.snippet.AutoDevSaveFileAction"/>
374377
</group>
375378

376379
<group id="AutoDev.ToolWindow.Chat.TitleActions">

core/src/233/main/resources/META-INF/autodev-core.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@
375375
<action id="AutoDev.ToolWindow.Snippet.RunDevIns"
376376
icon="cc.unitmesh.devti.AutoDevIcons.Run"
377377
class="cc.unitmesh.devti.gui.snippet.AutoDevRunAction"/>
378+
<action id="AutoDev.ToolWindow.Snippet.SaveFile"
379+
icon="cc.unitmesh.devti.AutoDevIcons.SaveFile"
380+
class="cc.unitmesh.devti.gui.snippet.AutoDevSaveFileAction"/>
378381
</group>
379382

380383
<group id="AutoDev.ToolWindow.Chat.TitleActions">

core/src/main/kotlin/cc/unitmesh/devti/AutoDevIcons.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ object AutoDevIcons {
4141
@JvmField
4242
val Terminal: Icon = IconLoader.getIcon("/icons/terminal.svg", AutoDevIcons::class.java)
4343

44+
@JvmField
45+
val SaveFile: Icon = IconLoader.getIcon("/icons/save-file.svg", AutoDevIcons::class.java)
46+
4447
@JvmField
4548
val Stop: Icon = IconLoader.getIcon("/icons/stop.svg", AutoDevIcons::class.java)
4649

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cc.unitmesh.devti.gui.snippet
2+
3+
import cc.unitmesh.devti.AutoDevBundle
4+
import com.intellij.openapi.actionSystem.ActionUpdateThread
5+
import com.intellij.openapi.actionSystem.AnAction
6+
import com.intellij.openapi.actionSystem.AnActionEvent
7+
import com.intellij.openapi.actionSystem.CommonDataKeys
8+
import com.intellij.psi.PsiElement
9+
import com.intellij.psi.PsiManager
10+
import com.intellij.refactoring.copy.CopyHandler
11+
12+
class AutoDevSaveFileAction : AnAction(AutoDevBundle.message("autodev.save.action")) {
13+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
14+
15+
override fun update(e: AnActionEvent) {
16+
val project = e.project
17+
val virtualFile = project?.let { e.getData(CommonDataKeys.VIRTUAL_FILE) }
18+
e.presentation.isEnabled = virtualFile != null
19+
}
20+
21+
override fun actionPerformed(e: AnActionEvent) {
22+
val project = e.project ?: return
23+
var virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE) ?: return
24+
val element: PsiElement? = PsiManager.getInstance(project).findFile(virtualFile)
25+
if (element == null) return
26+
CopyHandler.doCopy(arrayOf<PsiElement?>(element.containingFile), null)
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Loading

core/src/main/resources/messages/AutoDevBundle_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,4 @@ sketch.terminal.send.chat=Send to chat
175175
sketch.terminal.popup=Popup Terminal
176176
autodev.insert.action=Insert to Editor
177177
autodev.copy.action=Copy
178+
autodev.save.action=Save File

core/src/main/resources/messages/AutoDevBundle_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,4 @@ sketch.terminal.send.chat=Send to chat
175175
sketch.terminal.popup=Popup Terminal
176176
autodev.insert.action=Insert to Editor
177177
autodev.copy.action=Copy
178+
autodev.save.action=Save File

0 commit comments

Comments
 (0)