Commit 0aee8d6f by liangyuhang

fix:修复字体切换

parent 4e88417b
![novel1.gif](src%2Fmain%2Fresources%2Fimages%2Fnovel1.gif)
![novel2.gif](src%2Fmain%2Fresources%2Fimages%2Fnovel2.gif)
![novel3.gif](src%2Fmain%2Fresources%2Fimages%2Fnovel3.gif)
\ No newline at end of file
![novel1.gif](src%2Fmain%2Fresources%2Fimages%2Flnovel1.gif)
![novel2.gif](src%2Fmain%2Fresources%2Fimages%2Flnovel2.gif)
![novel3.gif](src%2Fmain%2Fresources%2Fimages%2Flnovel3.gif)
\ No newline at end of file
......@@ -4,7 +4,7 @@ plugins {
}
group = "com.liang.novel"
version = "1.0-SNAPSHOT"
version = "1.0.5"
repositories {
mavenCentral()
......@@ -29,7 +29,7 @@ tasks {
patchPluginXml {
sinceBuild.set("222")
untilBuild.set("232.*")
untilBuild.set("")
}
signPlugin {
......
......@@ -27,7 +27,7 @@ public class BookMarkAction extends DumbAwareAction {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
return ActionUpdateThread.EDT;
}
@Override
......
......@@ -28,7 +28,7 @@ public class BookMarkListAction extends ToggleAction implements DumbAware {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
return ActionUpdateThread.EDT;
}
@Override
......
......@@ -29,7 +29,7 @@ public class FontSizeDecreaseAction extends DumbAwareAction {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
return ActionUpdateThread.EDT;
}
@Override
......
......@@ -29,7 +29,7 @@ public class FontSizeIncreaseAction extends DumbAwareAction {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
return ActionUpdateThread.EDT;
}
@Override
......
......@@ -23,6 +23,6 @@ public class NovelSettingAction extends DumbAwareAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
ShowSettingsUtil.getInstance().showSettingsDialog(project, "小说设置");
ShowSettingsUtil.getInstance().showSettingsDialog(project, "lnovel");
}
}
......@@ -7,6 +7,7 @@ import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.wm.ToolWindow;
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.state.NovelState;
import com.liang.novel.plugin.ui.ToolWindowUI;
......@@ -27,7 +28,7 @@ public class RefreshToolWindowUIAction extends DumbAwareAction {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
return ActionUpdateThread.EDT;
}
@Override
......@@ -47,24 +48,33 @@ public class RefreshToolWindowUIAction extends DumbAwareAction {
@Override
public void update(@NotNull AnActionEvent e) {
Presentation presentation = e.getPresentation();
presentation.setEnabled(false);
presentation.setEnabled(isRefresh());
}
private Boolean isRefresh() {
Book toolWindowUIBook = toolWindowUI.getCurrentReadBook();
Book novelStatebook = NovelState.getInstance().getCurrentReadBook();
NovelState instance = NovelState.getInstance();
Book novelStatebook = instance.getCurrentReadBook();
if (toolWindowUIBook != null) {
if (novelStatebook != null) {
if (!toolWindowUIBook.getUrl().equals(novelStatebook.getUrl())) {
presentation.setEnabled(true);
}
} else {
presentation.setEnabled(true);
}
//编辑书籍url时
if (toolWindowUIBook != null && novelStatebook != null && !toolWindowUIBook.getUrl().equals(novelStatebook.getUrl())) {
return true;
}
//删除书籍时
if (toolWindowUIBook != null && novelStatebook == null) {
return true;
}
//添加书籍时
if (toolWindowUIBook == null && novelStatebook != null) {
return true;
}
//字体变动时
if (instance.getUseCustomFont()) {
return !toolWindowUI.getFontType().equals(instance.getFontType()) || !toolWindowUI.getFontSize().equals(instance.getFontSize());
} else {
if (novelStatebook != null) {
presentation.setEnabled(true);
}
return !toolWindowUI.getFontType().equals(FontConstants.DEFAULT_FONT_TYPE) || !toolWindowUI.getFontSize().equals(FontConstants.DEFAULT_FONT_SIZE);
}
}
}
......@@ -30,7 +30,7 @@ public class ToggleChapterAction extends DumbAwareAction {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
return ActionUpdateThread.EDT;
}
@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 {
}
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)));
}
......
......@@ -5,6 +5,7 @@ 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.liang.novel.plugin.constants.FontConstants;
import com.liang.novel.plugin.pojo.Book;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
......@@ -42,8 +43,8 @@ public class NovelState implements PersistentStateComponent<NovelState> {
public NovelState() {
this.useCustomFont = false;
this.fontType = "Monospaced";
this.fontSize = 12;
this.fontType = FontConstants.DEFAULT_FONT_TYPE;
this.fontSize = FontConstants.DEFAULT_FONT_SIZE;
this.currentReadBookIndex = null;
this.bookList = new ArrayList<>();
}
......
......@@ -7,6 +7,7 @@ import com.intellij.ui.components.JBList;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.uiDesigner.core.GridConstraints;
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.pojo.Book;
import com.liang.novel.plugin.pojo.Chapter;
......@@ -221,7 +222,7 @@ public class ReadUI {
if (font != null) {
this.font = font;
} 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())) {
contentTextArea.setFont(this.font);
......
......@@ -9,6 +9,7 @@ import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.util.ui.components.BorderLayoutPanel;
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.state.NovelState;
......@@ -39,8 +40,13 @@ public class ToolWindowUI {
private void initContentPanel() {
this.novelState = NovelState.getInstance();
this.fontType = novelState.getFontType();
this.fontSize = novelState.getFontSize();
if (novelState.getUseCustomFont()) {
this.fontType = novelState.getFontType();
this.fontSize = novelState.getFontSize();
} else {
this.fontType = FontConstants.DEFAULT_FONT_TYPE;
this.fontSize = FontConstants.DEFAULT_FONT_SIZE;
}
this.bookList = novelState.getBookList();
this.currentReadBookIndex = novelState.getCurrentReadBookIndex();
this.book = currentReadBookIndex != null ? bookList.get(currentReadBookIndex) : null;
......@@ -58,7 +64,7 @@ public class ToolWindowUI {
private Component getReadUIPanel() {
if (bookList.isEmpty()) {
ActionLink link = new ActionLink("请添加图书", e -> {
ShowSettingsUtil.getInstance().showSettingsDialog(project, "小说设置");
ShowSettingsUtil.getInstance().showSettingsDialog(project, "lnovel");
});
return getCenteredComponent(link);
} else if (currentReadBookIndex == null) {
......@@ -128,6 +134,14 @@ public class ToolWindowUI {
return book;
}
public String getFontType() {
return fontType;
}
public Integer getFontSize() {
return fontSize;
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
......
......@@ -7,7 +7,13 @@
<vendor email="git@liangyuhang.com" url="https://www.wjlyh.com">liangyuhang</vendor>
<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>
<depends>com.intellij.modules.platform</depends>
......@@ -18,7 +24,7 @@
<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"/>
......
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