Skip to content

Commit

Permalink
修改了读取文本方式,使用stream将文本list分页,设置页改为输入页码,修复翻页bug
Browse files Browse the repository at this point in the history
  • Loading branch information
luojunhui committed Jul 17, 2019
1 parent bff5cfd commit 8053d05
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 74 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# 使用

> 1. 打开settings下的`Touch Fish`,输入文本文件的`绝对路径`/当前记录行/加载行数后保存(如下图所示),然后重启IDEA.
> 1. 打开settings下的`Touch Fish`,输入文本文件的`绝对路径`/当前页/每页加载行数后保存(如下图所示),然后重启IDEA.
> 2. 打开`Touch Fish`窗口,如无意外就能看到文本内容了.
> 3. 快捷键↑向上读取内容,↓向下读取内容.
Expand Down
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.
6 changes: 4 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
<!--插件描述信息,在这里可以介绍你的插件内容,支持HTML标签 -->
<description>
<![CDATA[
开启一个toolWindow展示文件的文本内容.<br>
<p>一款jetbrains旗下的ide上touch fish(摸鱼)的插件,一般用来看小说.</p>
<ol>
<li>打开settings的Other Settings下的<strong>touch fish<strong></li>
<li>输入文本的绝对路径</li>
<li>输入阅读的行数和每次阅读多少行</li>
<li>输入页码和每次阅读多少行</li>
<li>快捷键&uarr;向上读取内容</li>
<li>快捷键&darr;向下读取内容</li>
<li>在keymap里可以给本插件设置快捷键,可以快速呼出与隐藏</li>
</ol>
<p>项目地址:<a href="https://github.com/luojunhui/touch-fish">https://github.com/luojunhui/touch-fish</p>
]]>
</description>

Expand Down
13 changes: 8 additions & 5 deletions src/config/BookConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* BookConfigurable.class
*
* @author junhui
*/
public class BookConfigurable implements SearchableConfigurable {
Expand Down Expand Up @@ -101,15 +102,17 @@ public boolean isModified() {
*/
@Override
public void apply() throws ConfigurationException {
if (this.form != null){
if (this.form != null) {
Config config = ConfigService.getInstance().getState();
config.setBookPath(this.form.getBookPath());
config.setLine(this.form.getLine());
config.setRowCount(this.form.getRowCount());
config.setPage(this.form.getPage());
config.setPageSize(this.form.getPageSize());
// 更新文本内容
List<String> lines = null;
try {
lines = Files.readAllLines(Paths.get(config.getBookPath()));
int totalPage = (lines.size() + config.getPageSize() - 1) / config.getPageSize();
config.setTotalPage(totalPage);
} catch (IOException e) {
}
config.setLines(lines);
Expand All @@ -121,8 +124,8 @@ public void apply() throws ConfigurationException {
public void reset() {
Config config = ConfigService.getInstance().getState();
this.form.setBookPath(config.getBookPath());
this.form.setLine(config.getLine());
this.form.setRowCount(config.getRowCount());
this.form.setPage(config.getPage());
this.form.setPageSize(config.getPageSize());
}

/**
Expand Down
31 changes: 21 additions & 10 deletions src/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
/**
* Config.class
* 配置类
*
* @author junhui
*/
public class Config {
@OptionTag
private String bookPath;
@OptionTag
private Integer line = 0;
private Integer page = 1;
@OptionTag
private Integer rowCount = 0;
private Integer pageSize = 3;
@OptionTag
private Integer totalPage = 0;

@OptionTag
private List<String> lines;
Expand All @@ -32,20 +35,28 @@ public void setBookPath(String bookPath) {
this.bookPath = bookPath;
}

public Integer getLine() {
return line;
public Integer getPage() {
return page;
}

public void setPage(Integer page) {
this.page = page;
}

public Integer getPageSize() {
return pageSize;
}

public void setLine(Integer line) {
this.line = line;
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}

public Integer getRowCount() {
return rowCount;
public Integer getTotalPage() {
return totalPage;
}

public void setRowCount(Integer rowCount) {
this.rowCount = rowCount;
public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
}

public List<String> getLines() {
Expand Down
26 changes: 17 additions & 9 deletions src/config/PluginSettingForm.form
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?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="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<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"/>
<constraints>
<xy x="20" y="20" width="609" height="167"/>
<xy x="20" y="20" width="798" height="219"/>
</constraints>
<properties>
<enabled value="false"/>
Expand All @@ -23,7 +23,7 @@
</component>
<component id="49ebe" class="javax.swing.JTextField" binding="pathField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<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>
</constraints>
Expand All @@ -36,13 +36,13 @@
<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"/>
</constraints>
<properties>
<text value="当前记录行:"/>
<text value="当前页:"/>
</properties>
</component>
<component id="2139f" class="javax.swing.JTextField" binding="lineField">
<component id="2139f" class="javax.swing.JTextField" binding="pageTextField">
<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="150" height="-1"/>
<preferred-size width="272" height="30"/>
</grid>
</constraints>
<properties/>
Expand All @@ -52,17 +52,25 @@
<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"/>
</constraints>
<properties>
<text value="每次加载行数:"/>
<text value="每页加载行数:"/>
</properties>
</component>
<component id="9bf13" class="javax.swing.JTextField" binding="rowCountField">
<component id="9bf13" class="javax.swing.JTextField" binding="pageSizeTextField">
<constraints>
<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">
<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">
<preferred-size width="150" height="-1"/>
</grid>
</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>
47 changes: 34 additions & 13 deletions src/config/PluginSettingForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
/**
* PluginSettingForm.class
* 配置页的表单
*
* @author junhui
*/
public class PluginSettingForm {
private JPanel pluginSettingPanel;
private JTextField pathField;
private JTextField lineField;
private JTextField rowCountField;
private JTextField pageTextField;
private JTextField pageSizeTextField;

public JPanel getPluginSettingPanel() {
return this.pluginSettingPanel;
Expand All @@ -24,35 +25,55 @@ public JPanel getPluginSettingPanel() {
*/
private void createUIComponents() {
Config config = ConfigService.getInstance().getState();
String bookPath = config.getBookPath();
String bookPath = config.getBookPath().trim();
if (StringUtil.isNotEmpty(bookPath)) {
this.pathField.setText(bookPath);
this.lineField.setText(String.valueOf(config.getLine()));
this.rowCountField.setText(String.valueOf(config.getRowCount()));
this.pageTextField.setText(String.valueOf(config.getPage()));
this.pageSizeTextField.setText(String.valueOf(config.getPageSize()));
}
}

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

public int getLine() {
return Integer.valueOf(this.lineField.getText());
/**
* 获取设置的行数,不能小于1
*
* @return
*/
public int getPage() {
int line = Integer.valueOf(this.pageTextField.getText());
if (line < 1) {
this.setPage(1);
return 1;
}
return line;
}

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

public void setLine(int line) {
this.lineField.setText(String.valueOf(line));
public void setPage(int line) {
this.pageTextField.setText(String.valueOf(line));
}

public int getRowCount(){
return Integer.valueOf(this.rowCountField.getText());
/**
* 获取加载行数,不能小于1
*
* @return
*/
public int getPageSize() {
int rowCount = Integer.valueOf(this.pageSizeTextField.getText());
if (rowCount < 1) {
this.setPageSize(1);
return 1;
}
return rowCount;
}

public void setRowCount(int line) {
this.rowCountField.setText(String.valueOf(line));
public void setPageSize(int rowCount) {
this.pageSizeTextField.setText(String.valueOf(rowCount));
}
}
Loading

0 comments on commit 8053d05

Please sign in to comment.