Skip to content

Commit

Permalink
Close #84 ; Optimal selection
Browse files Browse the repository at this point in the history
  • Loading branch information
shuzijun committed Jan 29, 2023
1 parent 6cd4a9e commit 96bea16
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public FullHttpResponse post(@NotNull QueryStringDecoder urlDecoder, @NotNull Fu
public UploadFileDialogWrapper.FileSetting getFileSetting(Project project, File markdownFile, String filename) {
AtomicReference<UploadFileDialogWrapper.FileSetting> atomicReference = new AtomicReference<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
String path = markdownFile.getParent() + File.separator + PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsPathKey, "assets");
String path = getFilePath(markdownFile);
UploadFileDialogWrapper fileDialogWrapper = new UploadFileDialogWrapper(project, path, filename);
if (fileDialogWrapper.showAndGet()) {
atomicReference.set(fileDialogWrapper.getSetting());
Expand All @@ -105,4 +105,12 @@ public UploadFileDialogWrapper.FileSetting getFileSetting(Project project, File
});
return atomicReference.get();
}

private String getFilePath(File markdownFile){
if (PropertiesComponent.getInstance().getBoolean(PluginConstant.editorAbsolutePathKey,false)){
return PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsPathKey, "assets");
} else {
return markdownFile.getParent() + File.separator + PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsPathKey, "assets");
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/shuzijun/markdown/model/PluginConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class PluginConstant {
public static final String editorFixToolbarKey="markdown.editor.editorFixToolbar";

public static final String editorTextOperationKey="markdown.editor.editorTextOperation";

public static final String editorAbsolutePathKey="markdown.editor.editorAbsolutePath";
}
10 changes: 9 additions & 1 deletion src/main/java/com/shuzijun/markdown/setting/SettingUI.form
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</component>
<component id="6d192" class="javax.swing.JTextField" binding="assetsPath">
<constraints>
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
Expand Down Expand Up @@ -123,6 +123,14 @@
<toolTipText value="Text Operation"/>
</properties>
</component>
<component id="2f86a" class="javax.swing.JCheckBox" binding="absolutePathCheckBox" default-binding="true">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Absolute Path"/>
</properties>
</component>
</children>
</grid>
</form>
6 changes: 5 additions & 1 deletion src/main/java/com/shuzijun/markdown/setting/SettingUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SettingUI {
private JComboBox assetsName;
private JCheckBox fixToolbar;
private JCheckBox textOperationCheckBox;
private JCheckBox absolutePathCheckBox;

public SettingUI() {
templatePathField.setText(PluginConstant.TEMPLATE_PATH);
Expand All @@ -58,6 +59,7 @@ public void actionPerformed(ActionEvent e) {
}
editorPolicyBox.setSelectedItem(PropertiesComponent.getInstance().getValue(PluginConstant.editorPolicyKey,FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR.name()));
assetsPath.setText(PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsPathKey,"assets"));
absolutePathCheckBox.setSelected(PropertiesComponent.getInstance().getBoolean(PluginConstant.editorAbsolutePathKey,false));
assetsName.setSelectedItem(PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsNameAutoKey,"Rename"));
fixToolbar.setSelected(PropertiesComponent.getInstance().getBoolean(PluginConstant.editorFixToolbarKey,true));
textOperationCheckBox.setSelected(PropertiesComponent.getInstance().getBoolean(PluginConstant.editorTextOperationKey,true));
Expand All @@ -72,7 +74,8 @@ public boolean isModified() {
|| !PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsPathKey,"assets").equals(assetsPath.getText())
|| !PropertiesComponent.getInstance().getValue(PluginConstant.editorAssetsNameAutoKey,"Rename").equals(assetsName.getSelectedItem())
|| !(PropertiesComponent.getInstance().getBoolean(PluginConstant.editorFixToolbarKey,true) == fixToolbar.isSelected())
|| !(PropertiesComponent.getInstance().getBoolean(PluginConstant.editorTextOperationKey,true) == textOperationCheckBox.isSelected());
|| !(PropertiesComponent.getInstance().getBoolean(PluginConstant.editorTextOperationKey,true) == textOperationCheckBox.isSelected())
|| !(PropertiesComponent.getInstance().getBoolean(PluginConstant.editorAbsolutePathKey,false) == absolutePathCheckBox.isSelected());
}

public void apply() {
Expand All @@ -81,6 +84,7 @@ public void apply() {
PropertiesComponent.getInstance().setValue(PluginConstant.editorAssetsNameAutoKey,assetsName.getSelectedItem().toString());
PropertiesComponent.getInstance().setValue(PluginConstant.editorFixToolbarKey,fixToolbar.isSelected(),true);
PropertiesComponent.getInstance().setValue(PluginConstant.editorTextOperationKey,textOperationCheckBox.isSelected(),true);
PropertiesComponent.getInstance().setValue(PluginConstant.editorAbsolutePathKey,absolutePathCheckBox.isSelected(),false);
}

public void reset() {
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/template/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@
vditor.vditor.toolbar.elements.info.querySelectorAll('button')[0].onclick = function () {
vditor.vditor.tip.show(document.getElementById("editorInfo").innerHTML, 0);
};
document.addEventListener('mousedown', (event) => {
if (event.button === 2) {
if (window.getSelection().isCollapsed) {
document.onselectstart =function(){
return false;
}
setTimeout(() => {
document.onselectstart =function(){
return true;
}
}, 0);
}
}
});
/*const contentMenuStyle = document.getElementById("contentMenu").style;
const notepad = document.getElementsByClassName("vditor-content")[0];
notepad.addEventListener('contextmenu', function(e) {
Expand Down

0 comments on commit 96bea16

Please sign in to comment.