diff --git a/src/main/java/com/muedsa/intellij/textReader/action/NextLineAction.java b/src/main/java/com/muedsa/intellij/textReader/action/NextLineAction.java new file mode 100644 index 0000000..4704e50 --- /dev/null +++ b/src/main/java/com/muedsa/intellij/textReader/action/NextLineAction.java @@ -0,0 +1,21 @@ +package com.muedsa.intellij.textReader.action; + +import com.intellij.notification.NotificationType; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.muedsa.intellij.textReader.composes.ReaderWindow; +import com.muedsa.intellij.textReader.composes.ReaderWindowHolder; +import com.muedsa.intellij.textReader.notify.Notification; + +public class NextLineAction extends AnAction { + + @Override + public void actionPerformed(AnActionEvent e) { + ReaderWindow readerWindow = ReaderWindowHolder.get(e.getProject()); + if(readerWindow == null){ + Notification.sendHiddenNotify(e.getProject(), "未初始化ToolWindow, 请点击工具栏打开一次窗口", NotificationType.INFORMATION); + }else{ + Notification.sendHiddenNotify(e.getProject(), readerWindow.nextLine(), NotificationType.INFORMATION); + } + } +} diff --git a/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.form b/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.form index 90c34b9..342011c 100644 --- a/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.form +++ b/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.form @@ -3,9 +3,11 @@ - + - + + + @@ -150,7 +152,7 @@ - + @@ -424,6 +426,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 398db34..115b679 100644 --- a/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.java +++ b/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindow.java @@ -31,6 +31,9 @@ import java.util.stream.Collectors; public class ReaderWindow { + private final Project project; + private final ToolWindow toolWindow; + private JPanel readerPanel; private JBList titleList; private JButton fileButton; @@ -51,9 +54,7 @@ public class ReaderWindow { private JButton clearButton; private JSpinner paragraphSpaceSpinner; private JTextField searchTextField; - - private Project project; - private ToolWindow toolWindow; + private JSpinner lineSizeSpinner; private TextFile textFile; @@ -61,6 +62,9 @@ public class ReaderWindow { private static Vector CHAPTER_LIST = new Vector<>(0); + private Integer positionInChapter = 0; + private String noBlankChapterText; + public ReaderWindow(Project project, ToolWindow toolWindow) { this.project = project; this.toolWindow = toolWindow; @@ -68,6 +72,11 @@ public ReaderWindow(Project project, ToolWindow toolWindow) { createUIComponents(); init(); updateRegex(); + ReaderWindowHolder.put(project, this); + } + + public JPanel getContent(){ + return readerPanel; } private void createUIComponents(){ @@ -233,14 +242,8 @@ public void mouseClicked(MouseEvent e) { nextButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - int count = titleList.getItemsCount(); - int index = titleList.getSelectedIndex() + 1; - if(index + 1 <= count){ - titleList.setSelectedIndex(index); - setTextContent(); - } + nextChapter(); } - }); //上一章 @@ -254,6 +257,10 @@ public void mouseClicked(MouseEvent e) { } } }); + + //每行字数 + SpinnerModel lineSizeSpinnerModel = new SpinnerNumberModel(15, 0, 100, 1); + lineSizeSpinner.setModel(lineSizeSpinnerModel); } private void init(){ @@ -337,10 +344,6 @@ private void updateParagraphSpace(){ setTextContent(); } - public JPanel getContent(){ - return readerPanel; - } - private void setTextContent(){ Chapter chapter = titleList.getSelectedValue(); if(chapter != null){ @@ -353,6 +356,7 @@ private void setTextContent(){ sendNotify("文件读取错误", e.getLocalizedMessage(), NotificationType.ERROR); } textContent.setText(text); + noBlankChapterText = text.replaceAll("\\s*", ""); textContent.setCaretPosition(0); } } @@ -361,4 +365,40 @@ private void sendNotify(String title, String content, NotificationType type){ Notification.sendNotify(project, title, content, type); } + public String nextLine(){ + if(toolWindow.isAvailable()){ + int lineSize = (int)lineSizeSpinner.getValue(); + if(lineSize > 0){ + if(StringUtils.isEmpty(noBlankChapterText) || positionInChapter > noBlankChapterText.length()){ + if(nextChapter()){ + positionInChapter = 0; + noBlankChapterText = textContent.getText(); + }else{ + return "end!"; + } + } + String line = StringUtils.mid(noBlankChapterText, positionInChapter, lineSize); + positionInChapter += lineSize; + if(StringUtils.isAllBlank(line)){ + line = nextLine(); + } + return line; + } + return ">.< 0?"; + }else{ + return "正在初始化~~"; + } + } + + private boolean nextChapter(){ + int count = titleList.getItemsCount(); + int index = titleList.getSelectedIndex() + 1; + if(index + 1 <= count){ + titleList.setSelectedIndex(index); + setTextContent(); + return true; + }else{ + return false; + } + } } diff --git a/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindowHolder.java b/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindowHolder.java new file mode 100644 index 0000000..34c970f --- /dev/null +++ b/src/main/java/com/muedsa/intellij/textReader/composes/ReaderWindowHolder.java @@ -0,0 +1,17 @@ +package com.muedsa.intellij.textReader.composes; + +import com.intellij.openapi.project.Project; + +import java.util.concurrent.ConcurrentHashMap; + +public class ReaderWindowHolder { + public static final ConcurrentHashMap holder = new ConcurrentHashMap<>(); + + public static void put(Project project, ReaderWindow readerWindow){ + holder.put(project, readerWindow); + } + + public static ReaderWindow get(Project project){ + return holder.get(project); + } +} diff --git a/src/main/java/com/muedsa/intellij/textReader/notify/Notification.java b/src/main/java/com/muedsa/intellij/textReader/notify/Notification.java index 0fa72fe..4df035f 100644 --- a/src/main/java/com/muedsa/intellij/textReader/notify/Notification.java +++ b/src/main/java/com/muedsa/intellij/textReader/notify/Notification.java @@ -12,4 +12,10 @@ public static void sendNotify(Project project, String title, String content, Not .setTitle(title) .notify(project); } + + public static void sendHiddenNotify(Project project, String content, NotificationType type){ + NotificationGroupManager.getInstance().getNotificationGroup("com.muedsa.intellij.textReader.hiddenNotify") + .createNotification(content, type) + .notify(project); + } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 4f399c5..1c7067c 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ com.muedsa.intellij.textReader TextReaderSidebarTool - 2021.11.19 + 2021.11.26 MUEDSA 2021.11.26 +
    +
  • hidden line reader
  • +
+
+ +

2021.11.19

  • update name: TextReaderSidebarTool
  • @@ -103,10 +110,15 @@ factoryClass="com.muedsa.intellij.textReader.factory.ToolWindowFactoryImpl" icon="TextReaderSidebarToolIcons.BOOK_DEAD"/> + - + + + + \ No newline at end of file