Commit 0aee8d6f by liangyuhang

fix:修复字体切换

parent 4e88417b
![novel1.gif](src%2Fmain%2Fresources%2Fimages%2Fnovel1.gif) ![novel1.gif](src%2Fmain%2Fresources%2Fimages%2Flnovel1.gif)
![novel2.gif](src%2Fmain%2Fresources%2Fimages%2Fnovel2.gif) ![novel2.gif](src%2Fmain%2Fresources%2Fimages%2Flnovel2.gif)
![novel3.gif](src%2Fmain%2Fresources%2Fimages%2Fnovel3.gif) ![novel3.gif](src%2Fmain%2Fresources%2Fimages%2Flnovel3.gif)
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,7 @@ plugins { ...@@ -4,7 +4,7 @@ plugins {
} }
group = "com.liang.novel" group = "com.liang.novel"
version = "1.0-SNAPSHOT" version = "1.0.5"
repositories { repositories {
mavenCentral() mavenCentral()
...@@ -29,7 +29,7 @@ tasks { ...@@ -29,7 +29,7 @@ tasks {
patchPluginXml { patchPluginXml {
sinceBuild.set("222") sinceBuild.set("222")
untilBuild.set("232.*") untilBuild.set("")
} }
signPlugin { signPlugin {
......
...@@ -27,7 +27,7 @@ public class BookMarkAction extends DumbAwareAction { ...@@ -27,7 +27,7 @@ public class BookMarkAction extends DumbAwareAction {
@Override @Override
public @NotNull ActionUpdateThread getActionUpdateThread() { public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT; return ActionUpdateThread.EDT;
} }
@Override @Override
......
...@@ -28,7 +28,7 @@ public class BookMarkListAction extends ToggleAction implements DumbAware { ...@@ -28,7 +28,7 @@ public class BookMarkListAction extends ToggleAction implements DumbAware {
@Override @Override
public @NotNull ActionUpdateThread getActionUpdateThread() { public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT; return ActionUpdateThread.EDT;
} }
@Override @Override
......
...@@ -29,7 +29,7 @@ public class FontSizeDecreaseAction extends DumbAwareAction { ...@@ -29,7 +29,7 @@ public class FontSizeDecreaseAction extends DumbAwareAction {
@Override @Override
public @NotNull ActionUpdateThread getActionUpdateThread() { public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT; return ActionUpdateThread.EDT;
} }
@Override @Override
......
...@@ -29,7 +29,7 @@ public class FontSizeIncreaseAction extends DumbAwareAction { ...@@ -29,7 +29,7 @@ public class FontSizeIncreaseAction extends DumbAwareAction {
@Override @Override
public @NotNull ActionUpdateThread getActionUpdateThread() { public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT; return ActionUpdateThread.EDT;
} }
@Override @Override
......
...@@ -23,6 +23,6 @@ public class NovelSettingAction extends DumbAwareAction { ...@@ -23,6 +23,6 @@ public class NovelSettingAction extends DumbAwareAction {
@Override @Override
public void actionPerformed(@NotNull AnActionEvent e) { public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject(); Project project = e.getProject();
ShowSettingsUtil.getInstance().showSettingsDialog(project, "小说设置"); ShowSettingsUtil.getInstance().showSettingsDialog(project, "lnovel");
} }
} }
...@@ -7,6 +7,7 @@ import com.intellij.openapi.actionSystem.Presentation; ...@@ -7,6 +7,7 @@ import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.openapi.wm.ToolWindowManager;
import com.liang.novel.plugin.constants.FontConstants;
import com.liang.novel.plugin.pojo.Book; import com.liang.novel.plugin.pojo.Book;
import com.liang.novel.plugin.state.NovelState; import com.liang.novel.plugin.state.NovelState;
import com.liang.novel.plugin.ui.ToolWindowUI; import com.liang.novel.plugin.ui.ToolWindowUI;
...@@ -27,7 +28,7 @@ public class RefreshToolWindowUIAction extends DumbAwareAction { ...@@ -27,7 +28,7 @@ public class RefreshToolWindowUIAction extends DumbAwareAction {
@Override @Override
public @NotNull ActionUpdateThread getActionUpdateThread() { public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT; return ActionUpdateThread.EDT;
} }
@Override @Override
...@@ -47,24 +48,33 @@ public class RefreshToolWindowUIAction extends DumbAwareAction { ...@@ -47,24 +48,33 @@ public class RefreshToolWindowUIAction extends DumbAwareAction {
@Override @Override
public void update(@NotNull AnActionEvent e) { public void update(@NotNull AnActionEvent e) {
Presentation presentation = e.getPresentation(); Presentation presentation = e.getPresentation();
presentation.setEnabled(false); presentation.setEnabled(isRefresh());
}
private Boolean isRefresh() {
Book toolWindowUIBook = toolWindowUI.getCurrentReadBook(); Book toolWindowUIBook = toolWindowUI.getCurrentReadBook();
Book novelStatebook = NovelState.getInstance().getCurrentReadBook(); NovelState instance = NovelState.getInstance();
Book novelStatebook = instance.getCurrentReadBook();
if (toolWindowUIBook != null) { //编辑书籍url时
if (novelStatebook != null) { if (toolWindowUIBook != null && novelStatebook != null && !toolWindowUIBook.getUrl().equals(novelStatebook.getUrl())) {
if (!toolWindowUIBook.getUrl().equals(novelStatebook.getUrl())) { return true;
presentation.setEnabled(true);
} }
} else { //删除书籍时
presentation.setEnabled(true); if (toolWindowUIBook != null && novelStatebook == null) {
return true;
} }
} else { //添加书籍时
if (novelStatebook != null) { if (toolWindowUIBook == null && novelStatebook != null) {
presentation.setEnabled(true); return true;
} }
//字体变动时
if (instance.getUseCustomFont()) {
return !toolWindowUI.getFontType().equals(instance.getFontType()) || !toolWindowUI.getFontSize().equals(instance.getFontSize());
} else {
return !toolWindowUI.getFontType().equals(FontConstants.DEFAULT_FONT_TYPE) || !toolWindowUI.getFontSize().equals(FontConstants.DEFAULT_FONT_SIZE);
} }
} }
} }
...@@ -30,7 +30,7 @@ public class ToggleChapterAction extends DumbAwareAction { ...@@ -30,7 +30,7 @@ public class ToggleChapterAction extends DumbAwareAction {
@Override @Override
public @NotNull ActionUpdateThread getActionUpdateThread() { public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT; return ActionUpdateThread.EDT;
} }
@Override @Override
......
package com.liang.novel.plugin.constants;
public class FontConstants {
public static final String DEFAULT_FONT_TYPE = "Monospaced";
public static final Integer DEFAULT_FONT_SIZE = 12;
}
...@@ -26,7 +26,7 @@ public class NovelNotification { ...@@ -26,7 +26,7 @@ public class NovelNotification {
} }
private static void addNotificationActions(Notification notification, Project project) { private static void addNotificationActions(Notification notification, Project project) {
notification.addAction(NotificationAction.createSimple("Setting", () -> ShowSettingsUtil.getInstance().showSettingsDialog(project, "小说设置"))); notification.addAction(NotificationAction.createSimple("Setting", () -> ShowSettingsUtil.getInstance().showSettingsDialog(project, "lnovel")));
notification.addAction(NotificationAction.createSimple("Git", () -> BrowserUtil.browse(GIT_LINK))); notification.addAction(NotificationAction.createSimple("Git", () -> BrowserUtil.browse(GIT_LINK)));
} }
......
...@@ -5,6 +5,7 @@ import com.intellij.openapi.components.PersistentStateComponent; ...@@ -5,6 +5,7 @@ import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State; import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage; import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.XmlSerializerUtil;
import com.liang.novel.plugin.constants.FontConstants;
import com.liang.novel.plugin.pojo.Book; import com.liang.novel.plugin.pojo.Book;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
...@@ -42,8 +43,8 @@ public class NovelState implements PersistentStateComponent<NovelState> { ...@@ -42,8 +43,8 @@ public class NovelState implements PersistentStateComponent<NovelState> {
public NovelState() { public NovelState() {
this.useCustomFont = false; this.useCustomFont = false;
this.fontType = "Monospaced"; this.fontType = FontConstants.DEFAULT_FONT_TYPE;
this.fontSize = 12; this.fontSize = FontConstants.DEFAULT_FONT_SIZE;
this.currentReadBookIndex = null; this.currentReadBookIndex = null;
this.bookList = new ArrayList<>(); this.bookList = new ArrayList<>();
} }
......
...@@ -7,6 +7,7 @@ import com.intellij.ui.components.JBList; ...@@ -7,6 +7,7 @@ import com.intellij.ui.components.JBList;
import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.JBScrollPane;
import com.intellij.uiDesigner.core.GridConstraints; import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.GridLayoutManager;
import com.liang.novel.plugin.constants.FontConstants;
import com.liang.novel.plugin.icons.Icons; import com.liang.novel.plugin.icons.Icons;
import com.liang.novel.plugin.pojo.Book; import com.liang.novel.plugin.pojo.Book;
import com.liang.novel.plugin.pojo.Chapter; import com.liang.novel.plugin.pojo.Chapter;
...@@ -221,7 +222,7 @@ public class ReadUI { ...@@ -221,7 +222,7 @@ public class ReadUI {
if (font != null) { if (font != null) {
this.font = font; this.font = font;
} else { } else {
this.font = new Font("Monospaced", Font.PLAIN, 12); //重设为平台字体 this.font = new Font(FontConstants.DEFAULT_FONT_TYPE, Font.PLAIN, FontConstants.DEFAULT_FONT_SIZE); //重设为平台字体
} }
if (StringUtils.isNotEmpty(contentTextArea.getText())) { if (StringUtils.isNotEmpty(contentTextArea.getText())) {
contentTextArea.setFont(this.font); contentTextArea.setFont(this.font);
......
...@@ -9,6 +9,7 @@ import com.intellij.uiDesigner.core.GridConstraints; ...@@ -9,6 +9,7 @@ import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager; import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.util.ui.components.BorderLayoutPanel; import com.intellij.util.ui.components.BorderLayoutPanel;
import com.liang.novel.plugin.actions.*; import com.liang.novel.plugin.actions.*;
import com.liang.novel.plugin.constants.FontConstants;
import com.liang.novel.plugin.pojo.Book; import com.liang.novel.plugin.pojo.Book;
import com.liang.novel.plugin.state.NovelState; import com.liang.novel.plugin.state.NovelState;
...@@ -39,8 +40,13 @@ public class ToolWindowUI { ...@@ -39,8 +40,13 @@ public class ToolWindowUI {
private void initContentPanel() { private void initContentPanel() {
this.novelState = NovelState.getInstance(); this.novelState = NovelState.getInstance();
if (novelState.getUseCustomFont()) {
this.fontType = novelState.getFontType(); this.fontType = novelState.getFontType();
this.fontSize = novelState.getFontSize(); this.fontSize = novelState.getFontSize();
} else {
this.fontType = FontConstants.DEFAULT_FONT_TYPE;
this.fontSize = FontConstants.DEFAULT_FONT_SIZE;
}
this.bookList = novelState.getBookList(); this.bookList = novelState.getBookList();
this.currentReadBookIndex = novelState.getCurrentReadBookIndex(); this.currentReadBookIndex = novelState.getCurrentReadBookIndex();
this.book = currentReadBookIndex != null ? bookList.get(currentReadBookIndex) : null; this.book = currentReadBookIndex != null ? bookList.get(currentReadBookIndex) : null;
...@@ -58,7 +64,7 @@ public class ToolWindowUI { ...@@ -58,7 +64,7 @@ public class ToolWindowUI {
private Component getReadUIPanel() { private Component getReadUIPanel() {
if (bookList.isEmpty()) { if (bookList.isEmpty()) {
ActionLink link = new ActionLink("请添加图书", e -> { ActionLink link = new ActionLink("请添加图书", e -> {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "小说设置"); ShowSettingsUtil.getInstance().showSettingsDialog(project, "lnovel");
}); });
return getCenteredComponent(link); return getCenteredComponent(link);
} else if (currentReadBookIndex == null) { } else if (currentReadBookIndex == null) {
...@@ -128,6 +134,14 @@ public class ToolWindowUI { ...@@ -128,6 +134,14 @@ public class ToolWindowUI {
return book; return book;
} }
public String getFontType() {
return fontType;
}
public Integer getFontSize() {
return fontSize;
}
{ {
// GUI initializer generated by IntelliJ IDEA GUI Designer // GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<< // >>> IMPORTANT!! <<<
......
...@@ -7,7 +7,13 @@ ...@@ -7,7 +7,13 @@
<vendor email="git@liangyuhang.com" url="https://www.wjlyh.com">liangyuhang</vendor> <vendor email="git@liangyuhang.com" url="https://www.wjlyh.com">liangyuhang</vendor>
<description><![CDATA[ <description><![CDATA[
暂无 It allows you to read novels on your local hard drive, it acts like a bookmark to remember your progress, so you can continue reading next time, and provides page-turning capabilities.
Product Description:
<ul>
<li>1.准备一本电子书txt</li>
<li>2.在设置中搜索lnovel,设置基本信息</li>
<li>3.你可以在IDE中的lnovel工具窗口阅读电子书</li>
</ul>
]]></description> ]]></description>
<depends>com.intellij.modules.platform</depends> <depends>com.intellij.modules.platform</depends>
...@@ -18,7 +24,7 @@ ...@@ -18,7 +24,7 @@
<notificationGroup id="MyNotificationGroup" displayType="BALLOON"/> <notificationGroup id="MyNotificationGroup" displayType="BALLOON"/>
<applicationConfigurable id="NovelSetting" instance="com.liang.novel.plugin.settings.NovelSetting" displayName="小说设置"/> <applicationConfigurable id="NovelSetting" instance="com.liang.novel.plugin.settings.NovelSetting" displayName="lnovel"/>
<applicationService serviceImplementation="com.liang.novel.plugin.state.NovelState"/> <applicationService serviceImplementation="com.liang.novel.plugin.state.NovelState"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment