Skip to content

Commit 430909e

Browse files
committed
修改未添加p m 超类事的界面bug
1 parent 1b0b098 commit 430909e

File tree

5 files changed

+26
-56
lines changed

5 files changed

+26
-56
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ MvpAutoCodePlus
5353

5454
- 选择代码实现方式,可选Java或Kotlin
5555

56-
- 选择View的实现方式,Activity或Fragment,如果配置了多个的话,可选择其中之一,不想生成的项去掉前面的复选框.(如果使用了泛型的话,会导致其他类中该类找不到的问题,比如P的实现类中有泛型M,但是没有勾选生成M的实现类,P的实现类中就会找不到)
56+
- 选择View的实现方式,Activity或Fragment,如果配置了多个的话,可选择其中之一,不想生成的项去掉前面的复选框.如果没有输入P和M实现类的超类,那么生成的P和M的实现类只会实现对应的接口.
5757

5858
- 点击Ok,稍等一会儿,代码就生成了,生成的包结构如下:
5959

src/main/java/com/longforus/mvpautocodeplus/ui/EnterKeywordDialog.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,23 @@ public static EnterKeywordDialog getDialog(OnOkListener onOkListener) {
107107
private static void setSavedSuperClass(EnterKeywordDialog dialog, PersistentState state) {
108108
dialog.mActivityRadioButton.addChangeListener(e -> {
109109
if (dialog.mActivityRadioButton.isSelected()) {
110-
setSuperClass(dialog.cob_v, state.getValue(ConsKt.SUPER_VIEW_ACTIVITY), dialog.mViewCheckBox);
110+
setSuperClass(dialog.cob_v, state.getValue(ConsKt.SUPER_VIEW_ACTIVITY), dialog.mViewCheckBox, ConsKt.IS_NOT_SET + "," + ConsKt.GOTO_SETTING);
111111
} else {
112-
setSuperClass(dialog.cob_v, state.getValue(ConsKt.SUPER_VIEW_FRAGMENT), dialog.mViewCheckBox);
112+
setSuperClass(dialog.cob_v, state.getValue(ConsKt.SUPER_VIEW_FRAGMENT), dialog.mViewCheckBox, ConsKt.IS_NOT_SET + "," + ConsKt.GOTO_SETTING);
113113
}
114114
});
115-
setSuperClass(dialog.cob_v, state.getValue(ConsKt.SUPER_VIEW_ACTIVITY), dialog.mViewCheckBox);
116-
setSuperClass(dialog.cob_p, state.getValue(ConsKt.SUPER_PRESENTER_IMPL), dialog.mPresenterCheckBox);
117-
setSuperClass(dialog.cob_m, state.getValue(ConsKt.SUPER_MODEL_IMPL), dialog.mModelCheckBox);
115+
setSuperClass(dialog.cob_v, state.getValue(ConsKt.SUPER_VIEW_ACTIVITY), dialog.mViewCheckBox, ConsKt.IS_NOT_SET + "," + ConsKt.GOTO_SETTING);
116+
setSuperClass(dialog.cob_p, state.getValue(ConsKt.SUPER_PRESENTER_IMPL), null, ConsKt.IS_NOT_SET + "," + ConsKt.NO_SUPER_CLASS);
117+
setSuperClass(dialog.cob_m, state.getValue(ConsKt.SUPER_MODEL_IMPL), null, ConsKt.IS_NOT_SET + "," + ConsKt.NO_SUPER_CLASS);
118118
}
119119

120-
private static void setSuperClass(JComboBox<String> cob, String value, JCheckBox jcb) {
120+
private static void setSuperClass(JComboBox<String> cob, String value, JCheckBox jcb, String nullShowStr) {
121121
if (TextUtils.isEmpty(value)) {
122-
value = ConsKt.IS_NOT_SET;
123-
jcb.setSelected(false);
124-
} else {
122+
value = nullShowStr;
123+
if (jcb != null) {
124+
jcb.setSelected(false);
125+
}
126+
} else if (jcb != null) {
125127
jcb.setSelected(true);
126128
}
127129
cob.setModel(new MutableCollectionComboBoxModel<String>(Arrays.asList(value.split(";"))));

src/main/kotlin/com/longforus/mvpautocodeplus/Cons.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ fun getPresenterInfName(name: String) = "I${name}Presenter"
1212
fun getModelInfName(name: String) = "I${name}Model"
1313

1414
const val GOTO_SETTING = "Please go to File-> Settings -> OtherSettings -> MvpAutoCodePlus set."
15-
const val IS_NOT_SET = "Is not set, $GOTO_SETTING"
16-
const val NO_SUPER_CLASS = "no_super_class"
15+
const val IS_NOT_SET = "Is not set"
16+
const val NO_SUPER_CLASS = "The implementation class will have no superclass"
1717

1818
const val CONTRACT = "contract"
1919
const val VIEW = "view"

src/main/kotlin/com/longforus/mvpautocodeplus/MainAction.kt

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import com.intellij.openapi.fileEditor.FileEditorManager
1010
import com.intellij.openapi.fileEditor.TextEditor
1111
import com.intellij.openapi.project.Project
1212
import com.intellij.openapi.ui.Messages
13-
import com.intellij.openapi.vfs.VirtualFile
1413
import com.intellij.psi.PsiClass
1514
import com.intellij.psi.PsiDirectory
1615
import com.intellij.psi.PsiFile
1716
import com.intellij.psi.PsiJavaFile
1817
import com.intellij.util.PlatformIcons
19-
import com.intellij.vcsUtil.VcsFileUtil
2018
import com.longforus.mvpautocodeplus.config.PersistentState
2119
import com.longforus.mvpautocodeplus.maker.TemplateMaker
2220
import com.longforus.mvpautocodeplus.maker.TemplateParamFactory
@@ -66,79 +64,49 @@ class MainAction : AnAction("main", "auto make mvp code", PlatformIcons.CLASS_IC
6664
Messages.showErrorDialog("Super View Interface name is null ! $GOTO_SETTING", "Error")
6765
return
6866
}
69-
if (state.getValue(SUPER_PRESENTER).isNullOrEmpty()) {
70-
Messages.showErrorDialog("Super Presenter Interface name is null ! $GOTO_SETTING", "Error")
71-
return
72-
}
73-
if (state.getValue(SUPER_MODEL).isNullOrEmpty()) {
74-
Messages.showErrorDialog("Super Model Interface name is null ! $GOTO_SETTING", "Error")
75-
return
76-
}
77-
7867
val contract = getSubDir(dir, CONTRACT)
7968

8069
EnterKeywordDialog.getDialog {
81-
val fileArray = arrayListOf<VirtualFile>()
8270
runWriteAction {
8371
if (it.isJava) {
8472
val contractJ = createFile(it.name, CONTRACT_TP_NAME_JAVA, contract, "") as PsiJavaFile
85-
fileArray.add(contract.virtualFile)
86-
if (!it.vImpl.isEmpty() && it.vImpl != IS_NOT_SET) {
73+
if (!it.vImpl.isEmpty() && !it.vImpl.startsWith(IS_NOT_SET)) {
8774
val sdV = getSubDir(dir, VIEW)
8875
if (it.isActivity) {
89-
createFile(it.name, VIEW_IMPL_TP_ACTIVITY_JAVA, sdV, it.vImpl, contractJ)?.let {
90-
fileArray.add(it.virtualFile)
91-
}
76+
createFile(it.name, VIEW_IMPL_TP_ACTIVITY_JAVA, sdV, it.vImpl, contractJ)
9277
} else {
93-
createFile(it.name, VIEW_IMPL_TP_FRAGMENT_JAVA, sdV, it.vImpl, contractJ)?.let {
94-
fileArray.add(it.virtualFile)
95-
}
78+
createFile(it.name, VIEW_IMPL_TP_FRAGMENT_JAVA, sdV, it.vImpl, contractJ)
9679
}
9780
}
9881
if (!it.pImpl.isEmpty()) {
9982
val sdP = getSubDir(dir, PRESENTER)
100-
createFile(it.name, PRESENTER_IMPL_TP_JAVA, sdP, it.pImpl, contractJ)?.let {
101-
fileArray.add(it.virtualFile)
102-
}
83+
createFile(it.name, PRESENTER_IMPL_TP_JAVA, sdP, it.pImpl, contractJ)
10384
}
10485
if (!it.mImpl.isEmpty()) {
10586
val sdM = getSubDir(dir, MODEL)
106-
createFile(it.name, MODEL_IMPL_TP_JAVA, sdM, it.mImpl, contractJ)?.let {
107-
fileArray.add(it.virtualFile)
108-
}
87+
createFile(it.name, MODEL_IMPL_TP_JAVA, sdM, it.mImpl, contractJ)
10988
}
11089

11190
} else {
11291
val contractK = createFile(it.name, CONTRACT_TP_NAME_KOTLIN, contract, "", fileName = getContractName(it.name))
113-
if (contractK != null) {
114-
fileArray.add(contractK.virtualFile)
115-
}
116-
if (!it.vImpl.isEmpty() && it.vImpl != IS_NOT_SET) {
92+
93+
if (!it.vImpl.isEmpty() && !it.vImpl.startsWith(IS_NOT_SET)) {
11794
val sdV = getSubDir(dir, VIEW)
11895
if (it.isActivity) {
119-
createFile(it.name, VIEW_IMPL_TP_ACTIVITY_KOTLIN, sdV, it.vImpl, contractK, "${it.name}Activity")?.let {
120-
fileArray.add(it.virtualFile)
121-
}
96+
createFile(it.name, VIEW_IMPL_TP_ACTIVITY_KOTLIN, sdV, it.vImpl, contractK, "${it.name}Activity")
12297
} else {
123-
createFile(it.name, VIEW_IMPL_TP_FRAGMENT_KOTLIN, sdV, it.vImpl, contractK, "${it.name}Fragment")?.let {
124-
fileArray.add(it.virtualFile)
125-
}
98+
createFile(it.name, VIEW_IMPL_TP_FRAGMENT_KOTLIN, sdV, it.vImpl, contractK, "${it.name}Fragment")
12699
}
127100
}
128101
if (!it.pImpl.isEmpty()) {
129102
val sdP = getSubDir(dir, PRESENTER)
130-
createFile(it.name, PRESENTER_IMPL_TP_KOTLIN, sdP, it.pImpl, contractK, "${it.name}Presenter")?.let {
131-
fileArray.add(it.virtualFile)
132-
}
103+
createFile(it.name, PRESENTER_IMPL_TP_KOTLIN, sdP, it.pImpl, contractK, "${it.name}Presenter")
133104
}
134105
if (!it.mImpl.isEmpty()) {
135106
val sdM = getSubDir(dir, MODEL)
136-
createFile(it.name, MODEL_IMPL_TP_KOTLIN, sdM, it.mImpl, contractK, "${it.name}Model")?.let {
137-
fileArray.add(it.virtualFile)
138-
}
107+
createFile(it.name, MODEL_IMPL_TP_KOTLIN, sdM, it.mImpl, contractK, "${it.name}Model")
139108
}
140109
}
141-
VcsFileUtil.addFilesToVcsWithConfirmation(project!!, fileArray)
142110
}
143111

144112
}

src/main/kotlin/com/longforus/mvpautocodeplus/maker/TemplateParamFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ object TemplateParamFactory {
9393

9494

9595
fun getNameAndGenericType(type: String, isContract: Boolean = true, enterName: String = "", selectedValue: String = ""): Pair<String?, String> {
96-
if (selectedValue == IS_NOT_SET) {
96+
if (selectedValue.startsWith(IS_NOT_SET)) {
9797
return "" to ""
9898
}
9999
val setValue = if (selectedValue.isNotEmpty()) selectedValue else state.getValue(type)

0 commit comments

Comments
 (0)