Skip to content

Commit eda1f2c

Browse files
committed
add class chooser support
1 parent 14bf9d0 commit eda1f2c

File tree

7 files changed

+46
-26
lines changed

7 files changed

+46
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Change Log
22

33

4+
## [v1.0-beat2](https://plugins.jetbrains.com/plugin/10907-mvpautocodeplus)(2018-7-9)
5+
6+
- 添加配置界面的Class选择支持
7+
48
## [v1.0-beat1](https://plugins.jetbrains.com/plugin/10907-mvpautocodeplus)(2018-7-5)
59

610
- 结合新版的mvp接口做出调整

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,21 @@ MvpAutoCodePlus
3939

4040
1. 配置父接口:
4141

42-
- <kbd>File</kbd> > <kbd>Preferences(Settings)</kbd> > <kbd>Other Settings</kbd> > <kbd>MvpAutoCodePlus</kbd> >
42+
- <kbd>File</kbd> > <kbd>Preferences(Settings)</kbd> > <kbd>Other Settings</kbd> > <kbd>MvpAutoCodePlus</kbd> >
4343

4444
![settings](./images/settings.png)
45-
45+
4646
基于[`这一套Java接口`][my_interface_java]的配置示例:
4747
![settings1](./images/settings1.png)
4848

49+
项目内的Class已经在V1.0beta2支持选择,但是如果有泛型限定的话,泛型还是需要手动添加,比如选择的类签名为:**com.longforus.base.java.BasePresenterJv<V extends IView,M extends IModel>**
50+
51+
![use3](./images/use3.png)
52+
53+
需要手动添加后面的泛型限定<V,M>:
54+
55+
![use4](./images/use4.png)
56+
4957
2. 生成:
5058

5159
![use1](./images/use1.png)
@@ -68,7 +76,7 @@ MvpAutoCodePlus
6876

6977
## 存在问题
7078

71-
- 父接口和父类的输入比较麻烦,还没有找到能在设置界面选择项目中的class的方法,好在只用设置一次就可保存了,项目中也不会经常变动.
79+
- 父接口和父类如果有泛型限定在选择后还需要手动输入泛型,好在只用设置一次就可保存了,项目中也不会经常变动.
7280
- 其他未知问题,此插件是作者首次开发插件,完全从0开始,官方的文档不是很详细,英语水平更是不堪,国内的参考资料也不多,做这个纯粹是忽然想到了,就开始做了.难免有未尽之处,欢迎各位star,issue.
7381

7482

build.gradle

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515
}
1616

1717
group 'com.longforus'
18-
version '1.0-beta1'
18+
version '1.0-beta2'
1919

2020
apply plugin: 'java'
2121
apply plugin: 'kotlin'
@@ -58,12 +58,7 @@ publishPlugin {
5858
password publishPassword
5959
}
6060

61-
//
62-
//patchPluginXml {
63-
// changeNotes """第一版盛大发布<br>
64-
//init first version.
65-
// """
66-
//}
61+
6762

6863

6964
//指定编译的编码

images/use3.png

41.6 KB
Loading

images/use4.png

20.1 KB
Loading

src/main/java/com/longforus/mvpautocodeplus/ui/ConfigForm.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
244244
</constraints>
245245
<properties>
246-
<text value=" 实现类支持指定多个,用 ; 隔开. class的直接选择功能还未实现,望大佬指点."/>
246+
<text value=" 实现类支持指定多个,用 ; 隔开. 如果需要泛型限定,选择Class后需要手动添加."/>
247247
</properties>
248248
</component>
249249
<component id="8eb09" class="com.intellij.ui.components.labels.LinkLabel" binding="lk_look_detail">

src/main/kotlin/com/longforus/mvpautocodeplus/config/ConfigComponent.kt

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.longforus.mvpautocodeplus.config
22

3-
import com.intellij.icons.AllIcons
43
import com.intellij.ide.BrowserUtil
4+
import com.intellij.ide.util.TreeClassChooserFactory
55
import com.intellij.openapi.components.ServiceManager
6-
import com.intellij.openapi.fileChooser.FileChooserDescriptor
76
import com.intellij.openapi.options.SearchableConfigurable
87
import com.intellij.openapi.project.Project
98
import com.intellij.openapi.project.ProjectManager
10-
import com.intellij.openapi.ui.Messages
119
import com.longforus.mvpautocodeplus.*
1210
import com.longforus.mvpautocodeplus.ui.ConfigForm
11+
import javax.swing.JButton
1312
import javax.swing.JComponent
13+
import javax.swing.JTextField
1414

1515
/**
1616
* Created by XQ Yang on 2018/6/25 14:12.
@@ -25,15 +25,15 @@ class ConfigComponent : SearchableConfigurable {
2525

2626
private val mCp: ConfigForm by lazy { ConfigForm() }
2727
private val state: PersistentState by lazy { ServiceManager.getService(PersistentState::class.java) }
28-
private val fcd = FileChooserDescriptor(true, false, false, false, false, false)
2928

30-
private val project: Project by lazy {
29+
private val mProject: Project by lazy {
3130
if (ProjectManager.getInstance().openProjects.isNotEmpty()) {
3231
ProjectManager.getInstance().openProjects[0]
3332
} else {
3433
ProjectManager.getInstance().defaultProject
3534
}
3635
}
36+
private val classChooserFactory by lazy { TreeClassChooserFactory.getInstance(mProject) }
3737

3838
override fun isModified(): Boolean {
3939
return mCp.tv_v_name.text != state.getValue(SUPER_VIEW) ||
@@ -61,28 +61,41 @@ class ConfigComponent : SearchableConfigurable {
6161
state.setValue(COMMENT_AUTHOR, mCp.et_comment_author.text)
6262
}
6363

64+
6465
override fun createComponent(): JComponent? {
65-
val value = state.getValue(SUPER_VIEW)
66-
mCp.tv_v_name.text = value
67-
// TODO: 2018/7/2 实现class选择 http://www.jetbrains.org/intellij/sdk/docs/user_interface_components/file_and_class_choosers.html?search=File
68-
// val dialogImpl = FileChooserDialogImpl(fcd, project)
69-
// val split = value?.split(";")
70-
// project.projectFile.findChild()
71-
mCp.btn_view_select.addActionListener {
72-
// val choose = dialogImpl.choose(project, null)
73-
Messages.showMessageDialog("还没有找到合适的方法来实现class的选择", "待开发", AllIcons.General.ErrorDialog)
74-
}
66+
mCp.tv_v_name.text = state.getValue(SUPER_VIEW)
67+
setClassChooser(mCp.btn_view_select, "Select Super View Interface", mCp.tv_v_name)
7568
mCp.tv_p_name.text = state.getValue(SUPER_PRESENTER)
69+
setClassChooser(mCp.btn_p_select, "Select Super Presenter Interface", mCp.tv_p_name)
7670
mCp.tv_m_name.text = state.getValue(SUPER_MODEL)
71+
setClassChooser(mCp.btn_m_select, "Select Super Model Interface", mCp.tv_m_name)
7772
mCp.tv_view_activity.text = state.getValue(SUPER_VIEW_ACTIVITY)
73+
setClassChooser(mCp.btn_view_a_select, "Select View extends super Activity", mCp.tv_view_activity, true)
7874
mCp.tv_view_fragment.text = state.getValue(SUPER_VIEW_FRAGMENT)
75+
setClassChooser(mCp.btn_view_f_select, "Select View extends super Fragment", mCp.tv_view_fragment, true)
7976
mCp.tv_presenter_impl.text = state.getValue(SUPER_PRESENTER_IMPL)
77+
setClassChooser(mCp.btn_pi_select, "Select Presenter extends super Class", mCp.tv_presenter_impl, true)
8078
mCp.tv_model_impl.text = state.getValue(SUPER_MODEL_IMPL)
79+
setClassChooser(mCp.btn_mi_select, "Select Model extends super Class", mCp.tv_model_impl, true)
8180
mCp.et_comment_author.text = state.getValue(COMMENT_AUTHOR)
8281
mCp.lk_look_detail.setListener({ _, _ ->
8382
BrowserUtil.browse("https://github.com/longforus/MvpAutoCodePlus/blob/master/README.md")
8483
}, "https://github.com/longforus")
8584
return mCp.mPanel
8685
}
8786

87+
private fun setClassChooser(jButton: JButton?, title: String, tv: JTextField?, append: Boolean = false) {
88+
jButton?.addActionListener {
89+
val projectScopeChooser = classChooserFactory.createProjectScopeChooser(title)
90+
projectScopeChooser.showDialog()
91+
if (projectScopeChooser.selected != null) {
92+
if (append && !tv?.text.isNullOrEmpty()) {
93+
tv?.text = "${tv?.text};${projectScopeChooser.selected.qualifiedName}"
94+
} else {
95+
tv?.text = projectScopeChooser.selected.qualifiedName
96+
}
97+
}
98+
}
99+
}
100+
88101
}

0 commit comments

Comments
 (0)