diff --git a/build.gradle b/build.gradle index b959a9c..2b3a3cc 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'com.muedsa.intellij.text-reader-sidebar-tool' -version '2021.12.06' +version '2021.12.07' repositories { mavenCentral() diff --git a/src/main/java/com/muedsa/intellij/textReader/action/NextLineAction.java b/src/main/java/com/muedsa/intellij/textReader/action/NextLineAction.java index 4704e50..5a64c02 100644 --- a/src/main/java/com/muedsa/intellij/textReader/action/NextLineAction.java +++ b/src/main/java/com/muedsa/intellij/textReader/action/NextLineAction.java @@ -13,9 +13,13 @@ public class NextLineAction extends AnAction { public void actionPerformed(AnActionEvent e) { ReaderWindow readerWindow = ReaderWindowHolder.get(e.getProject()); if(readerWindow == null){ - Notification.sendHiddenNotify(e.getProject(), "未初始化ToolWindow, 请点击工具栏打开一次窗口", NotificationType.INFORMATION); + Notification.sendHiddenNotify(e.getProject(), "未初始化ToolWindow, 请点击工具栏打开一次窗口", NotificationType.WARNING); }else{ - Notification.sendHiddenNotify(e.getProject(), readerWindow.nextLine(), NotificationType.INFORMATION); + if(readerWindow.isReadyLineAction()){ + Notification.sendHiddenNotify(e.getProject(), readerWindow.nextLine(), NotificationType.INFORMATION); + }else{ + Notification.sendHiddenNotify(e.getProject(), "请选择文件载入或清除筛选项", NotificationType.WARNING); + } } } } diff --git a/src/main/java/com/muedsa/intellij/textReader/action/PreviousLineAction.java b/src/main/java/com/muedsa/intellij/textReader/action/PreviousLineAction.java index ea0a311..92c6a2d 100644 --- a/src/main/java/com/muedsa/intellij/textReader/action/PreviousLineAction.java +++ b/src/main/java/com/muedsa/intellij/textReader/action/PreviousLineAction.java @@ -15,7 +15,11 @@ public void actionPerformed(@NotNull AnActionEvent e) { if(readerWindow == null){ Notification.sendHiddenNotify(e.getProject(), "未初始化ToolWindow, 请点击工具栏打开一次窗口", NotificationType.INFORMATION); }else{ - Notification.sendHiddenNotify(e.getProject(), readerWindow.previousLine(), NotificationType.INFORMATION); + if(readerWindow.isReadyLineAction()){ + Notification.sendHiddenNotify(e.getProject(), readerWindow.previousLine(), NotificationType.INFORMATION); + }else{ + Notification.sendHiddenNotify(e.getProject(), "请选择文件载入或清除筛选项", NotificationType.WARNING); + } } } } diff --git a/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.java b/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.java index f2a7b5c..0ac99e4 100644 --- a/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.java +++ b/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.java @@ -348,22 +348,25 @@ private void updateParagraphSpace(){ setTextContent(); } - private void setTextContent(){ + private boolean setTextContent(){ Chapter chapter = titleList.getSelectedValue(); + boolean flag = false; if(chapter != null){ String text = ""; try{ text = ChapterUtil.formatChapterContent(textFile, chapter); + textContent.setText(text); + noBlankChapterText = text.replaceFirst("\n", "##").replaceAll("\\s*", ""); + textContent.setCaretPosition(0); + positionInChapter = 0; + flag = true; } catch (IOException e){ e.printStackTrace(); sendNotify("文件读取错误", e.getLocalizedMessage(), NotificationType.ERROR); } - textContent.setText(text); - noBlankChapterText = text.replaceFirst("\n", "##").replaceAll("\\s*", ""); - textContent.setCaretPosition(0); - positionInChapter = 0; } + return flag; } private void sendNotify(String title, String content, NotificationType type){ @@ -376,7 +379,10 @@ public String nextLine(){ int lineSize = (int)lineSizeSpinner.getValue(); if(lineSize > 0){ if(StringUtils.isEmpty(noBlankChapterText) || positionInChapter > noBlankChapterText.length()){ - nextChapter(); + if(!nextChapter()){ + line = "读取下一章失败!"; + return line; + } } line = StringUtils.mid(noBlankChapterText, positionInChapter, lineSize); positionInChapter += lineSize; @@ -396,8 +402,13 @@ public String previousLine(){ if(toolWindow.isAvailable()){ int lineSize = (int)lineSizeSpinner.getValue(); if(lineSize > 0){ - if(positionInChapter == 0){ - previousChapter(); + if(positionInChapter - lineSize == 0){ + if(!previousChapter()){ + line = "读取上一章失败!"; + positionInChapter = 0; + return line; + } + positionInChapter = noBlankChapterText.length() - lineSize; }else{ positionInChapter -= lineSize * 2; if(positionInChapter < 0){ @@ -412,20 +423,28 @@ public String previousLine(){ return line; } - private void nextChapter(){ + private boolean nextChapter(){ + boolean flag = false; int count = titleList.getItemsCount(); int index = titleList.getSelectedIndex() + 1; if(index + 1 <= count){ titleList.setSelectedIndex(index); - setTextContent(); + flag = setTextContent(); } + return flag; } - private void previousChapter(){ + private boolean previousChapter(){ + boolean flag = false; int index = titleList.getSelectedIndex() - 1; if(index >= 0){ titleList.setSelectedIndex(index); - setTextContent(); + flag = setTextContent(); } + return flag; + } + + public boolean isReadyLineAction(){ + return !titleList.isEmpty(); } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index ca41ffe..561766b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -9,6 +9,11 @@ ]]> 2021.12.07 + +

2021.12.06