-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.6.0
- Loading branch information
Showing
14 changed files
with
339 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/shop/itbug/salvorstool/action/GenerateHookFormAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package shop.itbug.salvorstool.action | ||
|
||
import com.intellij.openapi.actionSystem.ActionUpdateThread | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.DialogWrapper | ||
import com.intellij.ui.components.JBTabbedPane | ||
import org.rust.lang.core.psi.impl.RsStructItemImpl | ||
import shop.itbug.salvorstool.tool.myManager | ||
import shop.itbug.salvorstool.tool.tryGetRsStructPsiElement | ||
import shop.itbug.salvorstool.widget.TypeJavaScriptEditor | ||
import javax.swing.JComponent | ||
|
||
class GenerateHookFormAction : AnAction() { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
Dialog(e.project!!,e.tryGetRsStructPsiElement()!!).show() | ||
} | ||
|
||
override fun update(e: AnActionEvent) { | ||
e.presentation.isVisible = e.tryGetRsStructPsiElement() != null && e.project != null | ||
e.presentation.text = "Generate React Hook Form" | ||
super.update(e) | ||
} | ||
|
||
override fun getActionUpdateThread(): ActionUpdateThread { | ||
return ActionUpdateThread.BGT | ||
} | ||
|
||
private inner class Dialog(project: Project,psi: RsStructItemImpl) : DialogWrapper(project) { | ||
private val manager = psi.myManager | ||
private val tab = JBTabbedPane() | ||
|
||
init { | ||
super.init() | ||
tab.add("Component", TypeJavaScriptEditor(project,manager.getHookForm)) | ||
} | ||
|
||
override fun createCenterPanel(): JComponent { | ||
return tab | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package shop.itbug.salvorstool.tool | ||
|
||
import org.apache.commons.io.IOUtils | ||
|
||
object FilesUtil | ||
{ | ||
|
||
val files = listOf("temps/ts_input.tsx","temps/ts_modal.tsx") | ||
|
||
/** | ||
* 加载模板文件列表 | ||
*/ | ||
fun loadTemplateFileList(path: String): String { | ||
try { | ||
println("path $path") | ||
val resource = javaClass.getResource("/$path") | ||
println(resource) | ||
resource?.let { | ||
return IOUtils.toString(it,"UTF-8") | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
return "" | ||
} | ||
return "" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/shop/itbug/salvorstool/window/TempFilesWindow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package shop.itbug.salvorstool.window | ||
|
||
import com.intellij.openapi.fileEditor.FileEditorManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.testFramework.LightVirtualFile | ||
import com.intellij.ui.ColoredListCellRenderer | ||
import com.intellij.ui.components.JBList | ||
import com.intellij.ui.components.JBScrollPane | ||
import com.intellij.util.ui.components.BorderLayoutPanel | ||
import shop.itbug.salvorstool.tool.FilesUtil | ||
import javax.swing.DefaultListModel | ||
import javax.swing.JList | ||
import javax.swing.event.ListSelectionEvent | ||
import javax.swing.event.ListSelectionListener | ||
|
||
class TempFilesWindow(val project: Project) : BorderLayoutPanel(), ListSelectionListener { | ||
|
||
private val tempFiles: List<String> = FilesUtil.files | ||
private val list = JBList<String>().apply { | ||
cellRenderer = Layout() | ||
model = Model(tempFiles) | ||
addListSelectionListener(this@TempFilesWindow) | ||
} | ||
|
||
init { | ||
addToCenter(JBScrollPane(list)) | ||
} | ||
|
||
private inner class Model(data: List<String>): DefaultListModel<String>(){ | ||
init { | ||
addAll(data) | ||
} | ||
} | ||
|
||
private inner class Layout: ColoredListCellRenderer<String>() { | ||
override fun customizeCellRenderer( | ||
list: JList<out String>, | ||
value: String?, | ||
index: Int, | ||
selected: Boolean, | ||
hasFocus: Boolean | ||
) { | ||
value?.let { append(it) } | ||
} | ||
} | ||
|
||
override fun valueChanged(e: ListSelectionEvent?) { | ||
e?.let { | ||
if(!e.valueIsAdjusting){ | ||
val text = FilesUtil.loadTemplateFileList(list.selectedValue) | ||
println(text) | ||
val lf = LightVirtualFile(list.selectedValue,text) | ||
FileEditorManager.getInstance(project).openFile(lf) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { JSX } from 'react'; | ||
import { | ||
Controller, useForm, | ||
} from 'react-hook-form'; | ||
|
||
{model} | ||
|
||
const MyDialog: React.FC<Prop> = (props) => { | ||
const { register, handleSubmit, reset, control} = useForm<Model>(); | ||
|
||
//todo!提交数据 | ||
const onFinish = async (values: Model) => { | ||
|
||
}; | ||
|
||
return ( | ||
<Dialog id={'my-dialog'} onClose={() => reset()}> | ||
<DialogBody> | ||
<DialogTitle title={'表单'} /> | ||
<form onSubmit={handleSubmit(onFinish)}> | ||
{fields} | ||
</form> | ||
</DialogBody> | ||
<DialogCloseBtn /> | ||
</Dialog> | ||
); | ||
}; | ||
export { MyDialog }; |
Oops, something went wrong.