diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index 274f124..943b116 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -6,7 +6,7 @@
- 悄咪咪地看小说
+ XD
]]>
-
+
+
diff --git a/src/com/muedsa/intellij/textReader/TextFile.java b/src/com/muedsa/intellij/textReader/TextFile.java
index a28a454..896944d 100644
--- a/src/com/muedsa/intellij/textReader/TextFile.java
+++ b/src/com/muedsa/intellij/textReader/TextFile.java
@@ -4,8 +4,7 @@
import info.monitorenter.cpdetector.io.CodepageDetectorProxy;
import info.monitorenter.cpdetector.io.JChardetFacade;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.nio.charset.Charset;
public class TextFile {
@@ -24,6 +23,14 @@ public TextFile(VirtualFile file) throws IOException {
charset = detector.detectCodepage(inputStream, 200);
}
+ public TextFile(String filePath) throws IOException {
+ this.filePath = filePath;
+ inputStream = new BufferedInputStream(new FileInputStream(new File(filePath)));
+ CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
+ detector.add(JChardetFacade.getInstance());
+ charset = detector.detectCodepage(inputStream, 200);
+ }
+
public String getFilePath() {
return filePath;
}
diff --git a/src/com/muedsa/intellij/textReader/composes/ReaderWindow.java b/src/com/muedsa/intellij/textReader/composes/ReaderWindow.java
index 188f7bf..aeaf852 100644
--- a/src/com/muedsa/intellij/textReader/composes/ReaderWindow.java
+++ b/src/com/muedsa/intellij/textReader/composes/ReaderWindow.java
@@ -1,7 +1,7 @@
package com.muedsa.intellij.textReader.composes;
-import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
+import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
@@ -11,6 +11,7 @@
import com.muedsa.intellij.textReader.TextFile;
import com.muedsa.intellij.textReader.factory.NotificationFactory;
import com.muedsa.intellij.textReader.file.TextFileChooserDescriptor;
+import com.muedsa.intellij.textReader.state.TextReaderStateService;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@@ -37,11 +38,14 @@ public class ReaderWindow {
private TextFile textFile;
+ private TextReaderStateService textReaderStateService;
+
public ReaderWindow(Project project, ToolWindow toolWindow) {
this.project = project;
this.toolWindow = toolWindow;
new NotificationFactory(project);
createUIComponents();
+ init();
}
private void createUIComponents(){
@@ -71,6 +75,8 @@ public void actionPerformed(ActionEvent e) {
textFile = new TextFile(file);
Vector list = Chapter.getChapters(textFile, chapterPrefix.getText(), chapterSuffix.getText());
titleList.setListData(list);
+ textReaderStateService.setFilePath(textFile.getFilePath());
+ textReaderStateService.setChapters(list);
}
catch (IOException error){
error.printStackTrace();
@@ -115,6 +121,20 @@ public void mouseClicked(MouseEvent e) {
});
}
+ private void init(){
+ textReaderStateService = ServiceManager.getService(TextReaderStateService.class);
+ if(textReaderStateService != null && textReaderStateService.getFilePath() != null && textReaderStateService.getChapters() != null){
+ try {
+ textFile = new TextFile(textReaderStateService.getFilePath());
+ titleList.setListData(textReaderStateService.getChapters());
+ }
+ catch (IOException error){
+ error.printStackTrace();
+ NotificationFactory.sendNotify("持久化文件加载错误", error.getLocalizedMessage(), NotificationType.ERROR);
+ }
+ }
+ }
+
public JPanel getContent(){
return readerPanel;
}
diff --git a/src/com/muedsa/intellij/textReader/state/TextReaderStateService.java b/src/com/muedsa/intellij/textReader/state/TextReaderStateService.java
new file mode 100644
index 0000000..d6e95c2
--- /dev/null
+++ b/src/com/muedsa/intellij/textReader/state/TextReaderStateService.java
@@ -0,0 +1,43 @@
+package com.muedsa.intellij.textReader.state;
+
+import com.intellij.openapi.components.PersistentStateComponent;
+import com.intellij.openapi.components.State;
+import com.intellij.openapi.components.Storage;
+import com.intellij.util.xmlb.XmlSerializerUtil;
+import com.muedsa.intellij.textReader.Chapter;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Vector;
+@State(name = "com.muedsa.intellij.textReader.chapter", storages = {@Storage(value = "$APP_CONFIG$/muedsa_tr.xml")})
+public class TextReaderStateService implements PersistentStateComponent {
+
+ private Vector chapters = new Vector<>();
+
+ private String filePath;
+
+ public Vector getChapters() {
+ return chapters;
+ }
+
+ public void setChapters(Vector chapters) {
+ this.chapters = chapters;
+ }
+
+ public String getFilePath() {
+ return filePath;
+ }
+
+ public void setFilePath(String filePath) {
+ this.filePath = filePath;
+ }
+
+ @Override
+ public TextReaderStateService getState() {
+ return this;
+ }
+
+ @Override
+ public void loadState(@NotNull TextReaderStateService state) {
+ XmlSerializerUtil.copyBean(state, this);
+ }
+}