Skip to content

Commit

Permalink
优化设置界面,输入文本绝对路径改为选择文件
Browse files Browse the repository at this point in the history
  • Loading branch information
130046422@qq.com authored and 130046422@qq.com committed Jan 13, 2020
1 parent 65f5915 commit 0be3529
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 52 deletions.
Binary file modified files/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>cn.luojunhui.touchfish</id><!--插件id,不能和其他插件项目重复,推荐com.xxx.xxx的格式 -->
<name>Touch Fish</name><!--插件名称 -->
<version>2.2</version><!--插件版本号 -->
<version>2.3</version><!--插件版本号 -->
<vendor email="130046422@qq.com" url="https://github.com/luojunhui">luojunhui</vendor>

<!--插件描述信息,在这里可以介绍你的插件内容,支持HTML标签 -->
Expand All @@ -10,7 +10,7 @@
<p>If you have nothing to do, why don't you try reading with this plugin?</p>
<ol>
<li>Find the "Touch Fish" settings interface under ide settings.</li>
<li>Enter the absolute path of the text file.</li>
<li>Choose the text file.</li>
<li>Enter page number and number of rows per page.</li>
<li>Shortcut key &uarr; read content up</li>
<li>Shortcut &darr; read content down</li>
Expand All @@ -20,7 +20,7 @@
<p>如果你无事可作,为何不试试用此插件看书呢?</p>
<ol>
<li>在ide设置下找到“Touch Fish”设置界面。</li>
<li>输入文本的绝对路径</li>
<li>选择你想要阅读的txt文件</li>
<li>输入页码和每次阅读多少行</li>
<li>快捷键&uarr;向上读取内容</li>
<li>快捷键&darr;向下读取内容</li>
Expand All @@ -34,6 +34,7 @@
<change-notes>
<![CDATA[
<ul>
<li>v2.3 change input file path to select file on settings form</li>
<li>v2.2 add change notes description in English</li>
<li>V2.1 add plugin description in English and modify the text of the settings interface.</li>
<li>V2.0 change the way to turn pages.</li>
Expand Down
2 changes: 1 addition & 1 deletion src/config/BookConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public JComponent createComponent() {
if (this.form == null) {
this.form = new PluginSettingForm();
}
return this.form.getPluginSettingPanel();
return this.form.getSettingPanel();
}

/**
Expand Down
71 changes: 33 additions & 38 deletions src/config/PluginSettingForm.form
Original file line number Diff line number Diff line change
@@ -1,76 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="config.PluginSettingForm">
<grid id="27dc6" binding="pluginSettingPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<grid id="27dc6" binding="settingPanel" layout-manager="FormLayout">
<rowspec value="center:d:noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
<rowspec value="center:max(d;4px):noGrow"/>
<colspec value="fill:d:noGrow"/>
<colspec value="fill:d:grow"/>
<constraints>
<xy x="20" y="20" width="867" height="219"/>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<clientProperties>
<html.disable class="java.lang.Boolean" value="false"/>
</clientProperties>
<properties/>
<border type="none"/>
<children>
<component id="1747c" class="javax.swing.JLabel">
<component id="98d44" class="javax.swing.JLabel" binding="filePath">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
<forms defaultalign-horz="false"/>
</constraints>
<properties>
<text value="文件路径(Text file path):"/>
<text value="文件路径:"/>
</properties>
</component>
<component id="49ebe" class="javax.swing.JTextField" binding="pathField">
<component id="3476d" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="chooseFileBtn">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<forms top="0" left="0" bottom="0" right="50" defaultalign-horz="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
<properties/>
</component>
<component id="a8d81" class="javax.swing.JLabel">
<component id="ef9ff" class="javax.swing.JLabel" binding="pageSize">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
<forms defaultalign-horz="false"/>
</constraints>
<properties>
<text value="当前页(page):"/>
<text value="每页行数:"/>
</properties>
</component>
<component id="2139f" class="javax.swing.JTextField" binding="pageTextField">
<component id="4c011" class="javax.swing.JTextField" binding="pageSizeTextField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="272" height="30"/>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<forms defaultalign-horz="false"/>
</constraints>
<properties/>
</component>
<component id="3125c" class="javax.swing.JLabel">
<component id="2d104" class="javax.swing.JLabel" binding="curPage">
<constraints>
<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"/>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
<forms defaultalign-horz="false"/>
</constraints>
<properties>
<text value="每页加载行数(rows):"/>
<text value="当前页码::"/>
</properties>
</component>
<component id="9bf13" class="javax.swing.JTextField" binding="pageSizeTextField">
<component id="bd51b" class="javax.swing.JTextField" binding="pageTextField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<forms defaultalign-horz="false"/>
</constraints>
<properties/>
</component>
<component id="8fc10" class="javax.swing.JLabel">
<constraints>
<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"/>
</constraints>
<properties>
<text value="页码计算方式:将要读取行数/每页加载行数=当前要读取的页码"/>
</properties>
</component>
</children>
</grid>
</form>
49 changes: 39 additions & 10 deletions src/config/PluginSettingForm.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package config;

import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.text.StringUtil;

import javax.swing.*;
import java.io.File;

/**
* PluginSettingForm.class
Expand All @@ -11,30 +14,55 @@
* @author junhui
*/
public class PluginSettingForm {
private JPanel pluginSettingPanel;
private JTextField pathField;
private JTextField pageTextField;
private JPanel settingPanel;
private TextFieldWithBrowseButton chooseFileBtn;
private JTextField pageSizeTextField;
private JTextField pageTextField;
private JLabel filePath;
private JLabel pageSize;
private JLabel curPage;

public PluginSettingForm() {
this.init();
}

public JPanel getPluginSettingPanel() {
return this.pluginSettingPanel;
public JPanel getSettingPanel() {
return this.settingPanel;
}

/**
* 读取xml获取历史配置
*/
private void createUIComponents() {
private void init() {
//按钮绑定事件
this.chooseFileBtn.addBrowseFolderListener("选择文件", null, null,
FileChooserDescriptorFactory.createSingleFileDescriptor("txt"));


Config config = ConfigService.getInstance().getState();
String bookPath = config.getBookPath().trim();
if (StringUtil.isNotEmpty(bookPath)) {
this.pathField.setText(bookPath);
this.pageTextField.setText(String.valueOf(config.getPage()));
this.chooseFileBtn.getTextField().setText(bookPath);
this.pageSizeTextField.setText(String.valueOf(config.getPageSize()));
this.pageTextField.setText(String.valueOf(config.getPage()));
}
}

private void openFileAndSetPath(int selectedMode, Boolean isSupportMultiSelect) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(selectedMode);
fileChooser.setMultiSelectionEnabled(isSupportMultiSelect);
fileChooser.showOpenDialog(null);

File chooseFile = fileChooser.getSelectedFile();
String bookPath = chooseFile.getAbsolutePath();
this.chooseFileBtn.getTextField().setText(bookPath);

}


public String getBookPath() {
return this.pathField.getText();
return this.chooseFileBtn.getTextField().getText();
}

/**
Expand All @@ -52,7 +80,7 @@ public int getPage() {
}

public void setBookPath(String s) {
this.pathField.setText(s);
this.chooseFileBtn.getTextField().setText(s);
}

public void setPage(int line) {
Expand All @@ -76,4 +104,5 @@ public int getPageSize() {
public void setPageSize(int rowCount) {
this.pageSizeTextField.setText(String.valueOf(rowCount));
}

}

0 comments on commit 0be3529

Please sign in to comment.