|
|
@@ -1,30 +1,65 @@
|
|
|
-import com.intellij.openapi.actionSystem.*
|
|
|
+import com.intellij.openapi.actionSystem.AnAction
|
|
|
+import com.intellij.openapi.actionSystem.AnActionEvent
|
|
|
import com.intellij.openapi.actionSystem.LangDataKeys
|
|
|
+import com.intellij.openapi.actionSystem.PlatformDataKeys
|
|
|
+import com.intellij.psi.PsiDirectory
|
|
|
import com.intellij.psi.PsiElement
|
|
|
-
|
|
|
import constant.Constants
|
|
|
-import util.NotifierType
|
|
|
-import util.NotifierUtil
|
|
|
-import util.FlutterUtil
|
|
|
+import template.CodeTemplate
|
|
|
+import ui.ConfirmAction
|
|
|
+import ui.PageCreateDialog
|
|
|
+import util.*
|
|
|
|
|
|
|
|
|
class PageCreateAction : AnAction() {
|
|
|
override fun actionPerformed(e: AnActionEvent) {
|
|
|
val project = e.getData(PlatformDataKeys.PROJECT)!!
|
|
|
val psiElement: PsiElement? = e.getData(LangDataKeys.PSI_ELEMENT)
|
|
|
- val isValidAction = FlutterUtil.isValidAction(project, psiElement)
|
|
|
+ val rootPath: String = PathUtil.getRootPath(project)
|
|
|
+ val isValidAction = FlutterUtil.isValidAction(project, psiElement, rootPath)
|
|
|
|
|
|
if (isValidAction) {
|
|
|
- NotifierUtil.showNotifier(
|
|
|
- project, "you did a correction action congratulations!",
|
|
|
- type = NotifierType.INFO,
|
|
|
- )
|
|
|
-// val directory = PsiDirectoryFactory.getInstance(project).createDirectory(project.projectFile!!)
|
|
|
+ PageCreateDialog(project, object : ConfirmAction {
|
|
|
+ override fun onConFirm(pageName: String, stateful: Boolean, router: Boolean) {
|
|
|
+ if (pageName.isEmpty()) {
|
|
|
+ NotifierUtil.showNotifier(
|
|
|
+ project, Constants.emptyPageNameHint, type = NotifierType.ERROR,
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ // 生成ViewModel路径
|
|
|
+ // 读取lib下目录 /pages/mine/collection
|
|
|
+ val selectFullPath = (psiElement as PsiDirectory).virtualFile.path
|
|
|
+ var pathDir = selectFullPath.replace("$rootPath/lib", "")
|
|
|
+ pathDir = pathDir.replace("/${Constants.pageDirectory}", "")
|
|
|
+
|
|
|
+ // 生成view model文件
|
|
|
+ FlutterUtil.writePage(
|
|
|
+ project,
|
|
|
+ "$rootPath/lib/view_model$pathDir",
|
|
|
+ "${CodeUtil.toFileName(pageName)}_view_model.dart",
|
|
|
+ CodeTemplate.getViewModel(
|
|
|
+ pageName,
|
|
|
+ )
|
|
|
+ )
|
|
|
+ // 生成page文件
|
|
|
+ FlutterUtil.writePage(
|
|
|
+ project,
|
|
|
+ selectFullPath,
|
|
|
+ "${CodeUtil.toFileName(pageName)}_page.dart",
|
|
|
+ CodeTemplate.getStatefulRouter(
|
|
|
+ stateful,
|
|
|
+ pageName,
|
|
|
+ if (router) CodeUtil.toCamelCase(pageName) else null,
|
|
|
+ pathDir
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).show()
|
|
|
} else {
|
|
|
NotifierUtil.showNotifier(
|
|
|
- project,
|
|
|
- Constants.validFailedHint,
|
|
|
- type = NotifierType.ERROR
|
|
|
+ project, Constants.validFailedHint, type = NotifierType.ERROR
|
|
|
)
|
|
|
}
|
|
|
}
|