From 43079271c862a9a969a72063927186171e292255 Mon Sep 17 00:00:00 2001 From: P6003163 <130046422@qq.com> Date: Sat, 19 Mar 2022 22:38:47 +0800 Subject: [PATCH] =?UTF-8?q?v2.3.2=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=BE=93=E5=87=BA=E5=88=B0idea.log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++- .../config/BookSettingsComponent.java | 12 +++---- .../config/BookSettingsConfigurable.java | 34 ++++++++++++++----- .../cn/luojunhui/touchfish/windwos/Book.java | 27 +++++++++++---- src/main/resources/META-INF/plugin.xml | 6 ++-- 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index 0672409..e82f946 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group 'cn.luojunhui' -version '2.3.1' +version '2.3.2' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -43,4 +43,6 @@ buildSearchableOptions { patchPluginXml { version = project.version + sinceBuild = '162' + untilBuild = '221.*' } \ No newline at end of file diff --git a/src/main/java/cn/luojunhui/touchfish/config/BookSettingsComponent.java b/src/main/java/cn/luojunhui/touchfish/config/BookSettingsComponent.java index 0e35617..51a2e61 100644 --- a/src/main/java/cn/luojunhui/touchfish/config/BookSettingsComponent.java +++ b/src/main/java/cn/luojunhui/touchfish/config/BookSettingsComponent.java @@ -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)) { diff --git a/src/main/java/cn/luojunhui/touchfish/config/BookSettingsConfigurable.java b/src/main/java/cn/luojunhui/touchfish/config/BookSettingsConfigurable.java index b00b43f..1015170 100644 --- a/src/main/java/cn/luojunhui/touchfish/config/BookSettingsConfigurable.java +++ b/src/main/java/cn/luojunhui/touchfish/config/BookSettingsConfigurable.java @@ -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; @@ -12,6 +13,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; +import java.util.Optional; /** * 修改配置 @@ -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() { @@ -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(); } @@ -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; } /** @@ -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 lines = null; + List 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("读取文件失败!"); } } @@ -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); } /** diff --git a/src/main/java/cn/luojunhui/touchfish/windwos/Book.java b/src/main/java/cn/luojunhui/touchfish/windwos/Book.java index 4f87e8c..f0d62b3 100644 --- a/src/main/java/cn/luojunhui/touchfish/windwos/Book.java +++ b/src/main/java/cn/luojunhui/touchfish/windwos/Book.java @@ -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; @@ -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; @@ -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 { @@ -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) { @@ -121,8 +136,8 @@ private List readFromPage(List 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()); } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 1551d5e..23adb4e 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -27,6 +27,7 @@
  • 在keymap里可以给本插件设置快捷键,可以快速呼出与隐藏
  • 项目地址:https://github.com/luojunhui/touch-fish

    +

    如果有bug,请在help - Show Log in Explorer里查找idea.log相关报错信息,与我联系

    ]]> @@ -34,6 +35,7 @@ +
  • v2.3.2 support IntelliJ Platform version 2022.1 version
  • v2.3.1 using Gradle as a build system. fix bugs.
  • v2.3 change input file path to select file on settings form
  • v2.2 add change notes description in English
  • @@ -45,9 +47,7 @@ ]]>
    - - - com.intellij.modules.lang + com.intellij.modules.platform