Skip to content

Commit ee59bca

Browse files
committed
Upload File Change fix #68
1 parent 9a33ccb commit ee59bca

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

src/main/java/com/shuzijun/markdown/controller/UploadFileController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.shuzijun.markdown.controller;
22

3+
import com.intellij.ide.util.PropertiesComponent;
34
import com.intellij.openapi.application.ApplicationManager;
45
import com.intellij.openapi.diagnostic.Logger;
56
import com.intellij.openapi.project.Project;
67
import com.intellij.openapi.util.io.FileUtil;
78
import com.intellij.openapi.vfs.LocalFileSystem;
89
import com.intellij.openapi.vfs.VirtualFile;
910
import com.shuzijun.markdown.model.MarkdownResponse;
11+
import com.shuzijun.markdown.model.PluginConstant;
1012
import com.shuzijun.markdown.model.UploadResponse;
1113
import com.shuzijun.markdown.ui.UploadFileDialogWrapper;
1214
import com.shuzijun.markdown.util.FileUtils;
@@ -63,6 +65,9 @@ public FullHttpResponse post(@NotNull QueryStringDecoder urlDecoder, @NotNull Fu
6365
if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.FileUpload) {
6466
FileUpload fileUpload = (FileUpload) data;
6567
String fileName = fileUpload.getFilename();
68+
if (PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsNameAutoKey,"Rename").equalsIgnoreCase("Timestamp")){
69+
fileName = System.currentTimeMillis() + "_" + fileName;
70+
}
6671
if (fileUpload.isCompleted()) {
6772
UploadFileDialogWrapper.FileSetting setting = getFileSetting(project, markdownFile, fileName);
6873
if (setting.isOk()) {
@@ -90,7 +95,7 @@ public FullHttpResponse post(@NotNull QueryStringDecoder urlDecoder, @NotNull Fu
9095
public UploadFileDialogWrapper.FileSetting getFileSetting(Project project, File markdownFile, String filename) {
9196
AtomicReference<UploadFileDialogWrapper.FileSetting> atomicReference = new AtomicReference<>();
9297
ApplicationManager.getApplication().invokeAndWait(() -> {
93-
String path = markdownFile.getParent() + File.separator + "assets";
98+
String path = markdownFile.getParent() + File.separator + PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsPathKey, "assets");
9499
UploadFileDialogWrapper fileDialogWrapper = new UploadFileDialogWrapper(project, path, filename);
95100
if (fileDialogWrapper.showAndGet()) {
96101
atomicReference.set(fileDialogWrapper.getSetting());

src/main/java/com/shuzijun/markdown/model/PluginConstant.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ public class PluginConstant {
2323
public static final String CDN = "https://cdn.jsdelivr.net/gh/shuzijun/markdown-editor@";
2424

2525
public static final String editorPolicyKey="markdown.editor.editorPolicy";
26+
27+
public static final String editorAssetsPathKey="markdown.editor.editorAssetsPath";
28+
29+
public static final String editorAssetsNameAutoKey="markdown.editor.editorAssetsName";
2630
}

src/main/java/com/shuzijun/markdown/setting/SettingUI.form

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.shuzijun.markdown.setting.SettingUI">
3-
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3+
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
66
<xy x="20" y="20" width="488" height="530"/>
@@ -18,7 +18,7 @@
1818
</component>
1919
<vspacer id="5c14c">
2020
<constraints>
21-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
21+
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
2222
</constraints>
2323
</vspacer>
2424
<component id="d183e" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="templatePathField">
@@ -55,6 +55,45 @@
5555
</constraints>
5656
<properties/>
5757
</component>
58+
<component id="44627" class="javax.swing.JLabel">
59+
<constraints>
60+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
61+
</constraints>
62+
<properties>
63+
<text value="Assets Path"/>
64+
<toolTipText value="relative location of md file"/>
65+
</properties>
66+
</component>
67+
<component id="6d192" class="javax.swing.JTextField" binding="assetsPath">
68+
<constraints>
69+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
70+
<preferred-size width="150" height="-1"/>
71+
</grid>
72+
</constraints>
73+
<properties>
74+
<text value=""/>
75+
</properties>
76+
</component>
77+
<component id="2e5bf" class="javax.swing.JLabel">
78+
<constraints>
79+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
80+
</constraints>
81+
<properties>
82+
<text value="Assets Name"/>
83+
<toolTipText value="relative position under the project"/>
84+
</properties>
85+
</component>
86+
<component id="5d5a1" class="javax.swing.JComboBox" binding="assetsName">
87+
<constraints>
88+
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
89+
</constraints>
90+
<properties>
91+
<model>
92+
<item value="Rename"/>
93+
<item value="Timestamp"/>
94+
</model>
95+
</properties>
96+
</component>
5897
</children>
5998
</grid>
6099
</form>

src/main/java/com/shuzijun/markdown/setting/SettingUI.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class SettingUI {
2828
private JButton syncButton;
2929
private TextFieldWithBrowseButton templatePathField;
3030
private JComboBox editorPolicyBox;
31+
private JTextField assetsPath;
32+
private JComboBox assetsName;
3133

3234
public SettingUI() {
3335
templatePathField.setText(PluginConstant.TEMPLATE_PATH);
@@ -53,19 +55,24 @@ public void actionPerformed(ActionEvent e) {
5355
editorPolicyBox.addItem(value.name());
5456
}
5557
editorPolicyBox.setSelectedItem(PropertiesComponent.getInstance().getValue(PluginConstant.editorPolicyKey,FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR.name()));
56-
58+
assetsPath.setText(PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsPathKey,"assets"));
59+
assetsName.setSelectedItem(PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsNameAutoKey,"Rename"));
5760
}
5861

5962
public JPanel getContentPane() {
6063
return mainPanel;
6164
}
6265

6366
public boolean isModified() {
64-
return !PropertiesComponent.getInstance().getValue(PluginConstant.editorPolicyKey,FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR.name()).equals(editorPolicyBox.getSelectedItem());
67+
return !PropertiesComponent.getInstance().getValue(PluginConstant.editorPolicyKey,FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR.name()).equals(editorPolicyBox.getSelectedItem())
68+
|| PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsPathKey,"assets").equals(assetsPath.getText())
69+
|| PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsNameAutoKey,"Rename").equals(assetsName.getSelectedItem());
6570
}
6671

6772
public void apply() {
6873
PropertiesComponent.getInstance().setValue(PluginConstant.editorPolicyKey,editorPolicyBox.getSelectedItem().toString());
74+
PropertiesComponent.getInstance().setValue(PluginConstant.editorAssetsPathKey,assetsPath.getText());
75+
PropertiesComponent.getInstance().setValue(PluginConstant.editorAssetsNameAutoKey,assetsName.getSelectedItem().toString());
6976
}
7077

7178
public void reset() {

0 commit comments

Comments
 (0)