Skip to content

Commit

Permalink
v2.3.2,新增日志输出到idea.log
Browse files Browse the repository at this point in the history
  • Loading branch information
luojunhui committed Mar 19, 2022
1 parent 9ff6de5 commit 4307927
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 25 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'cn.luojunhui'
version '2.3.1'
version '2.3.2'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -43,4 +43,6 @@ buildSearchableOptions {

patchPluginXml {
version = project.version
sinceBuild = '162'
untilBuild = '221.*'
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ public BookSettingsComponent() {
.addLabeledComponent(new JBLabel("每页行数: "), pageSizeTextField, 1, false)
.addLabeledComponent(new JBLabel("当前页码: "), pageTextField, 1, false)
.getPanel();
//按钮绑定事件
this.chooseFileBtn.addBrowseFolderListener("选择文件", null, null,
FileChooserDescriptorFactory.createSingleFileDescriptor("txt"));

init();

}

/**
* 表单初始化赋值
*/
private void init() {
public void init() {
//按钮绑定事件
this.chooseFileBtn.addBrowseFolderListener("选择文件", null, null,
FileChooserDescriptorFactory.createSingleFileDescriptor("txt"));

BookSettingsState settings = BookSettingsState.getInstance().getState();
String bookPath = settings.getBookPath();
if (StringUtil.isNotEmpty(bookPath)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cn.luojunhui.touchfish.config;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.util.ExceptionUtil;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.Nullable;

Expand All @@ -12,6 +13,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;

/**
* 修改配置
Expand All @@ -20,6 +22,7 @@
* @date Date : 2020年11月27日
*/
public class BookSettingsConfigurable implements Configurable {
private static final Logger LOGGER = Logger.getInstance(BookSettingsConfigurable.class);
private BookSettingsComponent bookSettingsComponent;

public BookSettingsConfigurable() {
Expand All @@ -32,13 +35,19 @@ public BookSettingsConfigurable() {

/**
* 创建一个Component用于展示
* @return
* @return bookSettingsComponent
*/
@Nullable
@Override
public JComponent createComponent() {
if (this.bookSettingsComponent == null) {
this.bookSettingsComponent = new BookSettingsComponent();
try {
this.bookSettingsComponent.init();
}catch (Exception e){
String errInfo = "设置面板出现错误:\n" + ExceptionUtil.currentStackTrace();
LOGGER.error(errInfo,e);
}
}
return this.bookSettingsComponent.getPanel();
}
Expand All @@ -58,8 +67,8 @@ public boolean isModified() {
int inputPage = this.bookSettingsComponent.getPage();
int inputPageSize = this.bookSettingsComponent.getPageSize();
return !StringUtils.equals(settings.getBookPath().trim(), inputFilePath)
|| settings.getPage().intValue() != inputPage
|| settings.getPageSize().intValue() != inputPageSize;
|| settings.getPage() != inputPage
|| settings.getPageSize() != inputPageSize;
}

/**
Expand All @@ -71,17 +80,23 @@ public void apply() throws ConfigurationException {
return;
}
BookSettingsState settings = BookSettingsState.getInstance();
if (settings == null) {
String errInfo = "Touch Fish 工具设置对象为空,请查看idea.log查询更多信息";
LOGGER.error(errInfo);
throw new ConfigurationException(errInfo);
}
settings.setBookPath(this.bookSettingsComponent.getBookPath());
settings.setPage(this.bookSettingsComponent.getPage());
settings.setPageSize(this.bookSettingsComponent.getPageSize());
// 更新文本内容
List<String> lines = null;
List<String> lines;
try {
lines = Files.readAllLines(Paths.get(settings.getBookPath()));
int totalPage = (lines.size() + settings.getPageSize() - 1) / settings.getPageSize();
settings.setTotalPage(totalPage);
settings.setLines(lines);
} catch (IOException e) {
throw new ConfigurationException("读取文件失败!");
}
}

Expand All @@ -91,9 +106,12 @@ public void apply() throws ConfigurationException {
@Override
public void reset() {
BookSettingsState settings = BookSettingsState.getInstance().getState();
this.bookSettingsComponent.setBookPath(settings.getBookPath());
this.bookSettingsComponent.setPage(settings.getPage());
this.bookSettingsComponent.setPageSize(settings.getPageSize());
String bookPath = Optional.of(settings).map(s->s.getBookPath()).orElse("");
int page = Optional.of(settings).map(s->s.getPage()).orElse(1);
int pageSize = Optional.of(settings).map(s->s.getPageSize()).orElse(5);
this.bookSettingsComponent.setBookPath(bookPath);
this.bookSettingsComponent.setPage(page);
this.bookSettingsComponent.setPageSize(pageSize);
}

/**
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/cn/luojunhui/touchfish/windwos/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.ToolWindow;

Expand All @@ -20,9 +21,11 @@
* @author junhui
*/
public class Book {
private final int PREV = 0;
private final int NEXT = 1;
private final int CURRENT = 2;
private static final Logger LOGGER = Logger.getInstance(Book.class);

private static final int PREV = 0;
private static final int NEXT = 1;
private static final int CURRENT = 2;

private JPanel book;
private JTextPane text;
Expand All @@ -34,6 +37,12 @@ public Book(ToolWindow toolWindow) {

private void init() {
BookSettingsState settings = BookSettingsState.getInstance().getState();
if (settings == null) {
String info = "请先到插件面板设置阅读信息。";
LOGGER.info(info);
Notifications.Bus.notify(new Notification("", "tip", info, NotificationType.INFORMATION));
return;
}
if (StringUtil.isNotEmpty(settings.getBookPath())) {
this.readText(CURRENT);
} else {
Expand Down Expand Up @@ -66,10 +75,16 @@ public void keyReleased(KeyEvent keyEvent) {
/**
* 按页读取内容
*
* @param op
* @param op user option
*/
private void readText(int op) {
BookSettingsState settings = BookSettingsState.getInstance().getState();
if (settings == null) {
String info = "请先到插件面板设置阅读信息。";
LOGGER.info(info);
Notifications.Bus.notify(new Notification("", "tip", info, NotificationType.INFORMATION));
return;
}
int curPage = settings.getPage();
List list = null;
switch (op) {
Expand Down Expand Up @@ -121,8 +136,8 @@ private List<String> readFromPage(List<String> list, int page, int pageSize) {
}

private void setText(List list) {
if (list != null && list.size() > 0) {
StringBuffer sb = new StringBuffer();
if (list != null && !list.isEmpty()) {
StringBuilder sb = new StringBuilder();
list.forEach(s -> sb.append(s).append("\n"));
this.text.setText(sb.toString());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
<li>在keymap里可以给本插件设置快捷键,可以快速呼出与隐藏</li>
</ol>
<p>项目地址:<a href="https://github.com/luojunhui/touch-fish">https://github.com/luojunhui/touch-fish</p>
<p>如果有bug,请在help - Show Log in Explorer里查找idea.log相关报错信息,与我联系</p>
]]>
</description>

<!--插件版本变更日志,支持HTML标签 -->
<change-notes>
<![CDATA[
<ul>
<li>v2.3.2 support IntelliJ Platform version 2022.1 version</li>
<li>v2.3.1 using Gradle as a build system. fix bugs.</li>
<li>v2.3 change input file path to select file on settings form</li>
<li>v2.2 add change notes description in English</li>
Expand All @@ -45,9 +47,7 @@
]]>
</change-notes>


<idea-version since-build="145"/>
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.platform</depends>

<extensions defaultExtensionNs="com.intellij">
<applicationConfigurable groupId="tools"
Expand Down

0 comments on commit 4307927

Please sign in to comment.