Skip to content

Commit 4fc81ad

Browse files
author
dengzi
committed
init
1 parent 16a4cd3 commit 4fc81ad

6 files changed

Lines changed: 211 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea
2+
/.out
3+
/*.iml

resources/META-INF/plugin.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<idea-plugin>
2+
<id>com.dengzii.plugin.auc_gen</id>
3+
<name>AucFrameGenerator</name>
4+
<version>1.0</version>
5+
<vendor email="dengzii@foxmail.com" url="https://github.com/dengzii">denzi</vendor>
6+
7+
<description><![CDATA[
8+
Make easy to create auc frame directory structure
9+
]]></description>
10+
11+
<change-notes><![CDATA[
12+
1.0: release basically feature, generate feature module
13+
]]>
14+
</change-notes>
15+
16+
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
17+
<idea-version since-build="173.0"/>
18+
19+
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
20+
on how to target different products -->
21+
<!-- uncomment to enable plugin in all products
22+
<depends>com.intellij.modules.lang</depends>
23+
-->
24+
25+
<extensions defaultExtensionNs="com.intellij">
26+
<!-- Add your extensions here -->
27+
</extensions>
28+
29+
<actions>
30+
<!-- Add your actions here -->
31+
<action id="com.dengzii.plugin.auc.gen" class="com.dengzii.plugin.auc.AucFrameGen" text="AucFrameGenerator"
32+
description="AucFrameGenerator">
33+
<add-to-group group-id="ProjectViewPopupMenu" anchor="first"/>
34+
</action>
35+
</actions>
36+
37+
</idea-plugin>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.dengzii.plugin.auc
2+
3+
import com.intellij.openapi.actionSystem.AnAction
4+
import com.intellij.openapi.actionSystem.AnActionEvent
5+
import com.intellij.openapi.command.WriteCommandAction
6+
7+
/**
8+
* <pre>
9+
* author : dengzi
10+
* e-mail : denua@foxmail.com
11+
* github : https://github.com/MrDenua
12+
* time : 2019/12/31
13+
* desc :
14+
</pre> *
15+
*/
16+
class AucFrameGen : AnAction() {
17+
override fun actionPerformed(e: AnActionEvent) {
18+
val kit = PluginKit.get(e)
19+
if (!kit.isProjectValid()) {
20+
return
21+
}
22+
WriteCommandAction.writeCommandAction(kit.project).run(FileWriteAction(kit))
23+
}
24+
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.dengzii.plugin.auc
2+
3+
import com.intellij.util.ThrowableRunnable
4+
5+
/**
6+
* <pre>
7+
* author : dengzi
8+
* e-mail : denua@foxmail.com
9+
* github : https://github.com/MrDenua
10+
* time : 2019/12/31
11+
* desc :
12+
* </pre>
13+
*/
14+
class FileWriteAction(var kit: PluginKit) : ThrowableRunnable<RuntimeException> {
15+
16+
override fun run() {
17+
kit.createDir("helloworld")
18+
}
19+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.dengzii.plugin.auc
2+
3+
import com.jetbrains.rd.util.printlnError
4+
5+
/**
6+
* <pre>
7+
* author : dengzi
8+
* e-mail : denua@foxmail.com
9+
* github : https://github.com/MrDenua
10+
* time : 2019/12/31
11+
* desc :
12+
* </pre>
13+
*/
14+
object Logger {
15+
16+
var enable: Boolean = true
17+
18+
fun e(tag: String, log: String) {
19+
log("e", tag, log)
20+
}
21+
22+
fun e(tag: String, e: Throwable) {
23+
log("e", tag, e.localizedMessage)
24+
e.printStackTrace()
25+
}
26+
27+
fun i(tag: String, log: String) {
28+
log("i", tag, log)
29+
}
30+
31+
fun d(tag: String, log: String) {
32+
log("d", tag, log)
33+
}
34+
35+
private fun log(level: String, tag: String, log: String) {
36+
if (!enable) {
37+
return
38+
}
39+
val logStr = "${level.toUpperCase()}/$tag: $log"
40+
if (level == "e") {
41+
printlnError(logStr)
42+
return
43+
}
44+
println(logStr)
45+
}
46+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.dengzii.plugin.auc
2+
3+
import com.intellij.openapi.actionSystem.AnActionEvent
4+
import com.intellij.openapi.actionSystem.PlatformDataKeys
5+
import com.intellij.openapi.module.Module
6+
import com.intellij.openapi.module.ModuleManager
7+
import com.intellij.openapi.project.Project
8+
import com.intellij.openapi.vfs.VirtualFile
9+
import com.intellij.psi.PsiFile
10+
11+
/**
12+
* <pre>
13+
* author : dengzi
14+
* e-mail : denua@foxmail.com
15+
* github : https://github.com/MrDenua
16+
* time : 2019/12/31
17+
* desc :
18+
* </pre>
19+
*/
20+
class PluginKit private constructor(e: AnActionEvent) {
21+
22+
private val event = e
23+
lateinit var project: Project
24+
25+
init {
26+
if (e.project != null) {
27+
project = e.project!!
28+
}
29+
}
30+
31+
fun isProjectValid(): Boolean {
32+
return project.isOpen && project.isInitialized
33+
}
34+
35+
fun getModules(): Array<Module> {
36+
return ModuleManager.getInstance(project).modules
37+
}
38+
39+
fun getPsiFile(): PsiFile? {
40+
return event.getData(PlatformDataKeys.PSI_FILE)
41+
}
42+
43+
fun getVirtualFile(): VirtualFile? {
44+
return event.getData(PlatformDataKeys.VIRTUAL_FILE)
45+
}
46+
47+
fun createDir(name: String, vf: VirtualFile? = getVirtualFile()) {
48+
if (checkCreateFile(name, vf)) {
49+
return
50+
}
51+
vf!!.createChildDirectory(null, name)
52+
}
53+
54+
fun createFile(name: String, vf: VirtualFile? = getVirtualFile()) {
55+
if (checkCreateFile(name, vf)) {
56+
return
57+
}
58+
vf!!.createChildData(null, name)
59+
}
60+
61+
private fun checkCreateFile(name: String, vf: VirtualFile?): Boolean {
62+
if (vf == null || !vf.isDirectory) {
63+
Logger.e(TAG, "target is null or is not a directory.")
64+
return false
65+
}
66+
if (vf.findChild(name)?.exists() == true) {
67+
Logger.e(TAG, "directory already exists.")
68+
return false
69+
}
70+
return true
71+
}
72+
73+
companion object {
74+
75+
private val TAG = PluginKit::class.java.simpleName;
76+
77+
fun get(e: AnActionEvent): PluginKit {
78+
return PluginKit(e)
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)