Skip to content

Commit b33c733

Browse files
committed
Fixes
1 parent 42f0f20 commit b33c733

File tree

7 files changed

+293
-298
lines changed

7 files changed

+293
-298
lines changed

src/ServiceStackIDEA/.idea/workspace.xml

Lines changed: 217 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddServiceStackRefHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,17 @@ private static String getDtoPath(Module module, String qualifiedPackageName, Str
180180
errorMessage.append("Unable to determine path for DTO file.");
181181
throw new FileNotFoundException();
182182
}
183-
fullDtoPath = rootPackageDir.getVirtualFile().getPath() + "/" + getDtoFileName(fileName);
183+
fullDtoPath = rootPackageDir.getVirtualFile().getPath() +
184+
File.separator +
185+
getDtoFileName(fileName);
184186
} else {
185187
String moduleSourcePath;
186188
if(moduleFile.getParent() == null) {
187189
moduleSourcePath = moduleFile.getPath() + "/main/java";
188190
} else {
189191
moduleSourcePath = moduleFile.getParent().getPath() + "/src/main/java";
190192
}
191-
fullDtoPath = moduleSourcePath + "/" + getDtoFileName(fileName);
193+
fullDtoPath = moduleSourcePath + File.separator + getDtoFileName(fileName);
192194
}
193195
return fullDtoPath;
194196
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddTypeScriptAction.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.intellij.psi.PsiElement;
1111
import com.intellij.util.PlatformUtils;
1212

13+
import java.io.File;
14+
1315
/**
1416
* Created by Layoric on 28/05/2016.
1517
*/
@@ -24,11 +26,12 @@ public void actionPerformed(AnActionEvent anActionEvent) {
2426
dialog.setResizable(true);
2527
dialog.setTitle("Add TypeScript ServiceStack Reference");
2628
PsiElement element = LangDataKeys.PSI_ELEMENT.getData(anActionEvent.getDataContext());
27-
29+
INativeTypesHandler defaultTsNativeTypesHandler = new TypeScriptDefinitionNativeTypesHandler();
2830
if (element != null && element instanceof PsiDirectory) {
2931
PsiDirectory selectedDir = (PsiDirectory)element;
3032
dialog.setSelectedDirectory(selectedDir.getVirtualFile().getPath());
31-
dialog.setInitialDtoName("ServiceReference1.dtos.d.ts");
33+
String initialName = getInitialFileName(selectedDir.getVirtualFile().getPath(),defaultTsNativeTypesHandler);
34+
dialog.setInitialDtoName(initialName);
3235
}
3336
showDialog(dialog);
3437
}
@@ -37,6 +40,21 @@ private void showDialog(AddTypeScriptRef dialog) {
3740
dialog.setVisible(true);
3841
}
3942

43+
private String getInitialFileName(String path, INativeTypesHandler defaultTsNativeTypesHandler) {
44+
String initName = "ServiceReference";
45+
Integer count = 1;
46+
while(true) {
47+
File existingFile = new File(path + "/" + initName + count.toString() +
48+
defaultTsNativeTypesHandler.getFileExtension());
49+
if(existingFile.exists()) {
50+
count++;
51+
} else {
52+
break;
53+
}
54+
}
55+
return initName + count.toString();
56+
}
57+
4058
@Override
4159
public void update(AnActionEvent e) {
4260
Module module = getModule(e);

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddTypeScriptRef.form

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</properties>
1414
<border type="none"/>
1515
<children>
16-
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
16+
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1717
<margin top="0" left="0" bottom="0" right="0"/>
1818
<constraints>
1919
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -23,13 +23,13 @@
2323
<children>
2424
<hspacer id="98af6">
2525
<constraints>
26-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
26+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
2727
</constraints>
2828
</hspacer>
2929
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
3030
<margin top="0" left="0" bottom="0" right="0"/>
3131
<constraints>
32-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
32+
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
3333
</constraints>
3434
<properties/>
3535
<border type="none"/>
@@ -52,6 +52,15 @@
5252
</component>
5353
</children>
5454
</grid>
55+
<component id="ada23" class="javax.swing.JCheckBox" binding="onlyTypeScriptDefinitionsCheckBox" default-binding="true">
56+
<constraints>
57+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
58+
</constraints>
59+
<properties>
60+
<selected value="true"/>
61+
<text value="Only TypeScript definitions"/>
62+
</properties>
63+
</component>
5564
</children>
5665
</grid>
5766
<grid id="141f5" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -97,7 +106,7 @@
97106
</grid>
98107
</constraints>
99108
<properties>
100-
<text value="dtos.java"/>
109+
<text value=""/>
101110
</properties>
102111
</component>
103112
</children>

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddTypeScriptRef.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ public class AddTypeScriptRef extends JDialog {
2222
private JTextField nameTextField;
2323
private JTextPane errorTextPane;
2424
private JTextPane infoTextPane;
25+
private JCheckBox onlyTypeScriptDefinitionsCheckBox;
2526

2627
private String selectedDirectory;
27-
private StringBuilder errorMessageBuilder = new StringBuilder();
2828
private String errorMessage;
2929

30-
private String initialDtoName;
3130
private Module module;
3231

3332
public AddTypeScriptRef(Module module) {
@@ -169,14 +168,21 @@ public void actionPerformed(ActionEvent e) {
169168
}
170169

171170
private void onOK() {
171+
StringBuilder errorMessageBuilder = new StringBuilder();
172172
AddTypeScriptRefHandler.handleOk(
173173
this.module,
174174
this.addressUrlTextField.getText(),
175175
this.nameTextField.getText(),
176176
this.selectedDirectory,
177-
this.errorMessageBuilder
177+
this.onlyTypeScriptDefinitionsCheckBox.isSelected(),
178+
errorMessageBuilder
178179
);
179-
dispose();
180+
if (errorMessageBuilder.toString().length() > 0) {
181+
errorTextPane.setText(errorMessageBuilder.toString());
182+
errorTextPane.setVisible(true);
183+
} else {
184+
dispose();
185+
}
180186
}
181187

182188
private void onCancel() {
@@ -190,6 +196,7 @@ public static void main(String[] args) {
190196
dialog.setVisible(true);
191197
System.exit(0);
192198
}
199+
193200
private ImageIcon createImageIcon(String path, String description) {
194201
URL imgURL = getClass().getResource(path);
195202
if (imgURL != null) {
@@ -210,11 +217,11 @@ public void setSelectedDirectory(String selectedDirectory) {
210217
}
211218

212219
public String getInitialDtoName() {
213-
return initialDtoName;
220+
return this.nameTextField.getText();
214221
}
215222

216223
public void setInitialDtoName(String initialDtoName) {
217-
this.initialDtoName = initialDtoName;
224+
this.nameTextField.setText(initialDtoName);
218225
}
219226

220227
{
@@ -239,19 +246,23 @@ public void setInitialDtoName(String initialDtoName) {
239246
contentPane.setPreferredSize(new Dimension(550, 220));
240247
contentPane.setRequestFocusEnabled(false);
241248
final JPanel panel1 = new JPanel();
242-
panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
249+
panel1.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0, 0), -1, -1));
243250
contentPane.add(panel1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, 1, null, null, null, 0, false));
244251
final Spacer spacer1 = new Spacer();
245-
panel1.add(spacer1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
252+
panel1.add(spacer1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
246253
final JPanel panel2 = new JPanel();
247254
panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, true, false));
248-
panel1.add(panel2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
255+
panel1.add(panel2, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
249256
buttonOK = new JButton();
250257
buttonOK.setText("OK");
251258
panel2.add(buttonOK, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
252259
buttonCancel = new JButton();
253260
buttonCancel.setText("Cancel");
254261
panel2.add(buttonCancel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
262+
onlyTypeScriptDefinitionsCheckBox = new JCheckBox();
263+
onlyTypeScriptDefinitionsCheckBox.setSelected(true);
264+
onlyTypeScriptDefinitionsCheckBox.setText("Only TypeScript definitions");
265+
panel1.add(onlyTypeScriptDefinitionsCheckBox, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
255266
final JPanel panel3 = new JPanel();
256267
panel3.setLayout(new GridLayoutManager(2, 3, new Insets(0, 0, 0, 0), -1, -1));
257268
contentPane.add(panel3, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
@@ -265,7 +276,7 @@ public void setInitialDtoName(String initialDtoName) {
265276
label2.setText("Name");
266277
panel3.add(label2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
267278
nameTextField = new JTextField();
268-
nameTextField.setText("dtos.java");
279+
nameTextField.setText("");
269280
panel3.add(nameTextField, new GridConstraints(1, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
270281
final JPanel panel4 = new JPanel();
271282
panel4.setLayout(new GridLayoutManager(2, 1, new Insets(0, 0, 0, 0), -1, -1));

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddTypeScriptRefHandler.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,29 @@ static void handleOk(Module module,
1919
String addressUrl,
2020
String fileName,
2121
String selectedDirectory,
22+
Boolean definitionsOnly,
2223
StringBuilder errorMessage) {
24+
File file = new File(selectedDirectory);
25+
INativeTypesHandler nativeTypesHandler =
26+
definitionsOnly ?
27+
new TypeScriptDefinitionNativeTypesHandler() :
28+
new TypeScriptNativeTypesHandler();
29+
30+
String dtoPath = file.getAbsolutePath() + File.separator
31+
+ getDtoFileName(fileName,nativeTypesHandler);
32+
List<String> codeLines = getDtoLines(addressUrl,nativeTypesHandler,errorMessage);
2333

24-
List<String> codeLines = getDtoLines(addressUrl,fileName,errorMessage);
25-
if (!IDEAUtils.writeDtoFile(codeLines, selectedDirectory, errorMessage)) {
34+
if (!IDEAUtils.writeDtoFile(codeLines, dtoPath, errorMessage)) {
2635
return;
2736
}
28-
File file = new File(selectedDirectory);
29-
String dtoPath = file.getAbsolutePath() + "/" + getDtoFileName(fileName);
30-
Analytics.SubmitAnonymousAddReferenceUsage(getNativeTypesHandler(fileName));
37+
38+
Analytics.SubmitAnonymousAddReferenceUsage(nativeTypesHandler);
3139
refreshFile(module,dtoPath, true);
3240
VirtualFileManager.getInstance().syncRefresh();
3341
}
3442

35-
private static List<String> getDtoLines(String addressUrl, String fileName,
43+
private static List<String> getDtoLines(String addressUrl, INativeTypesHandler nativeTypesHandler,
3644
StringBuilder errorMessage) {
37-
INativeTypesHandler nativeTypesHandler = getNativeTypesHandler(fileName);
3845
try {
3946
return nativeTypesHandler.getUpdatedCode(addressUrl, null);
4047
} catch (URISyntaxException e) {
@@ -52,15 +59,12 @@ private static List<String> getDtoLines(String addressUrl, String fileName,
5259
}
5360
}
5461

55-
public static String getDtoFileName(String name) {
56-
INativeTypesHandler nativeTypesHandler = getNativeTypesHandler(name);
57-
int p = name.lastIndexOf(".");
58-
String e = name.substring(p);
59-
if (p == -1 || !e.equals(nativeTypesHandler.getFileExtension())) {
62+
public static String getDtoFileName(String name, INativeTypesHandler nativeTypesHandler) {
63+
if (!name.endsWith(nativeTypesHandler.getFileExtension())) {
6064
/* file has no extension */
6165
return name + nativeTypesHandler.getFileExtension();
6266
} else {
63-
/* file has extension e */
67+
/* file has extension */
6468
return name;
6569
}
6670
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/TypeScriptDefinitionNativeTypesHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class TypeScriptDefinitionNativeTypesHandler extends BaseNativeTypesHandler {
77
@Override
88
public String getFileExtension() {
9-
return "dtos.d.ts";
9+
return ".dtos.d.ts";
1010
}
1111

1212
@Override

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy