diff --git a/build.gradle b/build.gradle
index 6f04388..6ce2e96 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,41 +1,61 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.21'
+ id "idea"
}
apply from: "$rootDir/scripts/verifier.gradle"
group 'com.github.jadepeng.rainbowfart'
-version '1.0.4'
+version '1.0.6'
-sourceCompatibility = 1.8
+sourceCompatibility = javaVersion
+targetCompatibility = javaVersion
repositories {
mavenLocal()
+ maven { url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
maven { url "https://maven.aliyun.com/nexus/content/groups/public/" }
maven { url "https://repo.eclipse.org/content/groups/releases/" }
+ maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://www.jetbrains.com/intellij-repository/releases" }
maven { url "https://www.jetbrains.com/intellij-repository/snapshots" }
+ mavenCentral()
}
dependencies {
- testCompile group: 'junit', name: 'junit', version: '4.12'
+ testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation('javazoom:jlayer:1.0.1')
- implementation('com.squareup.okhttp3:okhttp:3.13.1')
- implementation('commons-io:commons-io:2.7')
+ implementation('com.squareup.okhttp3:okhttp:4.9.3')
+ implementation('commons-io:commons-io:2.11.0')
}
+apply plugin: 'org.jetbrains.intellij'
intellij {
- version '2020.1.2'
- // not update since and util on build
+ pluginName name
+
+ version ideaVersion
updateSinceUntilBuild = false
}
+apply plugin: 'idea'
+idea {
+ project {
+ jdkName = javaVersion
+ languageLevel = javaVersion
+ }
+}
+
patchPluginXml {
changeNotes """
+ - 1.0.6
+ - 支持新版intellij
+ - 1.0.5
+ - fix(#6)
+
- 1.0.4
- - 更新intellij版本
+ - 更新intellij版本
- 1.0.3
- 支持设置语音包类型: TTS(在线语音合成),Custom(自定义), Builtin(内置)
@@ -49,5 +69,5 @@ patchPluginXml {
pluginVerifier {
pluginFileName = "$rootProject.name-$version"
- ides = ["IC-2018.1", "IC-2019.1", "IC-2020.1", "CL-2020.1"]
+ ides = ["IC-2018.1", "IC-2019.1", "IC-2020.1", "CL-2020.1", "IU-2021.3.1"]
}
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..eaeffb6
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,4 @@
+name="rainbow-fart"
+org.gradle.parallel=true
+ideaVersion=IU-213.6461.79
+javaVersion=11
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 9fad988..ff65bf1 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,2 +1 @@
-rootProject.name = 'rainbow-fart'
-
+rootProject.name = 'rainbow-fart'
\ No newline at end of file
diff --git a/src/main/java/com/github/jadepeng/rainbowfart/Constants.java b/src/main/java/com/github/jadepeng/rainbowfart/Constants.java
new file mode 100644
index 0000000..32c8c98
--- /dev/null
+++ b/src/main/java/com/github/jadepeng/rainbowfart/Constants.java
@@ -0,0 +1,6 @@
+package com.github.jadepeng.rainbowfart;
+
+public class Constants {
+ public static final String EVENT_PASTE = "ON_PASTE";
+ public static final String EVENT_COMMENTS = "ON_COMMENTS";
+}
diff --git a/src/main/java/com/github/jadepeng/rainbowfart/Context.java b/src/main/java/com/github/jadepeng/rainbowfart/Context.java
index a2b0e8a..bc1638a 100644
--- a/src/main/java/com/github/jadepeng/rainbowfart/Context.java
+++ b/src/main/java/com/github/jadepeng/rainbowfart/Context.java
@@ -12,6 +12,7 @@
import java.io.*;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.*;
@@ -80,7 +81,8 @@ public static void init(Manifest manifest) {
});
// build regex
- String regex = String.join("|", keyword2Contributes.keySet().stream().map(s -> s.replaceAll("\\$|\\.|\\+|\\(|\\)|\\[|\\]", "\\$&")).collect(Collectors.toList()));
+ String regex = keyword2Contributes.keySet().stream().map(s -> s.replaceAll("\\$|\\.|\\+|\\(|\\)|\\[|\\]", "\\$&")).collect(
+ Collectors.joining("|"));
keywordPattern = Pattern.compile(regex);
}
@@ -94,8 +96,7 @@ private static void resetSchedulePool() {
public static String getBuiltinTtsText() {
try {
- URL filePath = Context.class.getClassLoader().getResource("/default.json");
- return IOUtils.toString(filePath.openStream(), "utf-8");
+ return IOUtils.toString(Context.class.getResourceAsStream("/default.json"), StandardCharsets.UTF_8);
} catch (IOException e) {
return "";
}
@@ -108,8 +109,8 @@ static String readVoicePackageJson(String name) throws IOException {
if (isCustomer) {
return FileUtils.readFileToString(Paths.get(settings.getCustomVoicePackage(), name).toFile(), "utf-8");
}
- URL filePath = PluginStarter.class.getClassLoader().getResource(BUILD_IN_VOICE_PACKAGE + "/" + settings.getBuildinPackage() + "/" + name);
- return IOUtils.toString(filePath.openStream(), "utf-8");
+ URL filePath = PluginStarter.class.getResource(BUILD_IN_VOICE_PACKAGE + "/" + settings.getBuildinPackage() + "/" + name);
+ return IOUtils.toString(filePath.openStream(), StandardCharsets.UTF_8);
}
/**
@@ -122,7 +123,7 @@ public static void loadConfig() {
if (!settings.isEnable()) {
return;
}
- // TTS 使用配置里的数据
+ // TTS 使用配置里的数据 if if else h
String json = settings.getType() != VoicePackageType.TTS ? readVoicePackageJson("manifest.json") : settings.getTtsSettings().getResourceText();
if (StringUtils.isBlank(json)) {
json = getBuiltinTtsText();
@@ -139,7 +140,7 @@ public static void loadConfig() {
}
Context.init(manifest);
- } catch (IOException e) {
+ } catch (IOException ignored) {
}
}
@@ -224,12 +225,22 @@ public static void play(List contributes) {
preparePlayThreadPool.submit(() -> Mp3Player.play(contributes));
}
+ public static boolean playCandidates(String keywords) {
+ List voices = getCandidate(keywords);
+ if (!voices.isEmpty()) {
+ Context.play(voices);
+ return true;
+ }
+ return false;
+ }
+
public static void onEvent(String event) {
- System.out.println(event);
+ playCandidates(event);
}
- public static void onEvent(String event, Object args) {
+ public static void onEvent(String event, String args) {
System.out.println(event + ":" + args);
+ playCandidates(args);
}
public static void main(String[] args) {
diff --git a/src/main/java/com/github/jadepeng/rainbowfart/EventCollector.java b/src/main/java/com/github/jadepeng/rainbowfart/EventCollector.java
deleted file mode 100644
index 149ab81..0000000
--- a/src/main/java/com/github/jadepeng/rainbowfart/EventCollector.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.github.jadepeng.rainbowfart;
-
-public class EventCollector {
-}
diff --git a/src/main/java/com/github/jadepeng/rainbowfart/Mp3Player.java b/src/main/java/com/github/jadepeng/rainbowfart/Mp3Player.java
index 11263d3..c50d758 100644
--- a/src/main/java/com/github/jadepeng/rainbowfart/Mp3Player.java
+++ b/src/main/java/com/github/jadepeng/rainbowfart/Mp3Player.java
@@ -4,8 +4,10 @@
import com.github.jadepeng.rainbowfart.settings.FartSettings;
import com.github.jadepeng.rainbowfart.settings.VoicePackageType;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
+
import org.apache.commons.io.IOUtils;
import java.io.*;
@@ -43,21 +45,20 @@ public class Mp3Player {
ThreadFactory playerFactory = new ThreadFactoryBuilder()
.setNameFormat("player-pool-%d").build();
playerTheadPool = new ThreadPoolExecutor(1, 1,
- 0L, TimeUnit.MILLISECONDS,
- new LinkedBlockingQueue<>(1024), playerFactory, new ThreadPoolExecutor.AbortPolicy());
+ 0L, TimeUnit.MILLISECONDS,
+ new LinkedBlockingQueue<>(1024), playerFactory,
+ new ThreadPoolExecutor.AbortPolicy());
}
static boolean tryLoadFromBuiltInCache(String cacheFile, File targetFile) {
- URL cache = Context.class.getClassLoader().getResource("/cache/" + cacheFile);
+ URL cache = Context.class.getResource("/cache/" + cacheFile);
if (cache != null) {
try {
FileOutputStream outputStream = new FileOutputStream(targetFile);
IOUtils.copy(cache.openStream(), outputStream);
outputStream.close();
return true;
- } catch (FileNotFoundException e) {
- } catch (IOException e) {
- e.printStackTrace();
+ } catch (Exception ignored) {
}
}
@@ -67,7 +68,8 @@ static boolean tryLoadFromBuiltInCache(String cacheFile, File targetFile) {
static void playTTS(List contributes, FartSettings settings) {
List texts = contributes.stream().flatMap(c -> c.getText().stream()).collect(Collectors.toList());
String text = texts.get(new Random().nextInt() % texts.size());
- String cacheFileName = settings.getTtsSettings().getVcn() + (settings.getTtsSettings().getVcn() + text).hashCode() + ".mp3";
+ String cacheFileName =
+ settings.getTtsSettings().getVcn() + (settings.getTtsSettings().getVcn() + text).hashCode() + ".mp3";
File cacheFile = Paths.get(TEMP_TTS_CACHE_DIR, cacheFileName).toFile();
// If not exist, try online tts
if (!cacheFile.exists()) {
@@ -109,7 +111,8 @@ public static void play(List contributes) {
try {
InputStream inputStream = null;
if (settings.getType() == VoicePackageType.Builtin) {
- inputStream = Context.class.getResourceAsStream(Context.BUILD_IN_VOICE_PACKAGE + "/" + settings.getBuildinPackage() + "/" + file);
+ inputStream = Context.class.getResourceAsStream(
+ Context.BUILD_IN_VOICE_PACKAGE + "/" + settings.getBuildinPackage() + "/" + file);
} else {
File mp3File = Paths.get(settings.getCustomVoicePackage(), file).toFile();
if (mp3File.exists()) {
@@ -125,8 +128,7 @@ public static void play(List contributes) {
if (settings.getType() == VoicePackageType.Custom) {
inputStream.close();
}
- } catch (JavaLayerException e) {
- } catch (IOException e) {
+ } catch (Exception ignored) {
}
});
}
diff --git a/src/main/java/com/github/jadepeng/rainbowfart/extensions/CommentHandler.java b/src/main/java/com/github/jadepeng/rainbowfart/extensions/CommentHandler.java
index d611454..62b91c4 100644
--- a/src/main/java/com/github/jadepeng/rainbowfart/extensions/CommentHandler.java
+++ b/src/main/java/com/github/jadepeng/rainbowfart/extensions/CommentHandler.java
@@ -1,5 +1,6 @@
package com.github.jadepeng.rainbowfart.extensions;
+import com.github.jadepeng.rainbowfart.Constants;
import com.github.jadepeng.rainbowfart.Context;
import com.intellij.codeInsight.editorActions.CommentCompleteHandler;
import com.intellij.lang.CodeDocumentationAwareCommenter;
@@ -15,7 +16,7 @@ public boolean isCommentComplete(PsiComment comment, CodeDocumentationAwareComme
@Override
public boolean isApplicable(PsiComment comment, CodeDocumentationAwareCommenter commenter) {
- Context.onEvent("CommentComplete");
+ Context.onEvent(Constants.EVENT_COMMENTS);
return false;
}
}
diff --git a/src/main/java/com/github/jadepeng/rainbowfart/extensions/CopyPasteHanler.java b/src/main/java/com/github/jadepeng/rainbowfart/extensions/CopyPasteHanler.java
index 6106524..0ce908f 100644
--- a/src/main/java/com/github/jadepeng/rainbowfart/extensions/CopyPasteHanler.java
+++ b/src/main/java/com/github/jadepeng/rainbowfart/extensions/CopyPasteHanler.java
@@ -1,5 +1,6 @@
package com.github.jadepeng.rainbowfart.extensions;
+import com.github.jadepeng.rainbowfart.Constants;
import com.github.jadepeng.rainbowfart.Context;
import com.intellij.codeInsight.editorActions.CopyPastePostProcessor;
import com.intellij.codeInsight.editorActions.TextBlockTransferableData;
@@ -44,7 +45,7 @@ public List collectTransferableData(PsiFile file, Edi
buffer.append(text.subSequence(lineStart, lineEnd));
}
- Context.onEvent("onPaste", buffer.toString());
+ Context.onEvent(Constants.EVENT_PASTE, buffer.toString());
return Collections.emptyList();
}
diff --git a/src/main/java/com/github/jadepeng/rainbowfart/extensions/TypedHandler.java b/src/main/java/com/github/jadepeng/rainbowfart/extensions/TypedHandler.java
index df5b379..fc06d9f 100644
--- a/src/main/java/com/github/jadepeng/rainbowfart/extensions/TypedHandler.java
+++ b/src/main/java/com/github/jadepeng/rainbowfart/extensions/TypedHandler.java
@@ -6,6 +6,7 @@
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.TypedActionHandler;
+
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -14,7 +15,7 @@
import java.util.List;
/**
- * Typed Action Handler
+ * Typed Action Handler
*/
public class TypedHandler extends TypedActionHandlerBase {
@@ -26,22 +27,17 @@ public TypedHandler(@Nullable TypedActionHandler originalHandler) {
super(originalHandler);
}
-
@Override
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
inputHistory.add(String.valueOf(charTyped));
String str = StringUtils.join(inputHistory, "");
try {
- List voices = Context.getCandidate(str);
- if (!voices.isEmpty()) {
- Context.play(voices);
+ if (Context.playCandidates(str)) {
inputHistory.clear();
}
- }catch (Exception e){
- // TODO
+ } catch (Exception e) {
inputHistory.clear();
}
-
if (this.myOriginalHandler != null) {
this.myOriginalHandler.execute(editor, charTyped, dataContext);
}
diff --git a/src/main/java/com/github/jadepeng/rainbowfart/settings/SettingsComponent.java b/src/main/java/com/github/jadepeng/rainbowfart/settings/SettingsComponent.java
index 0287566..3793d87 100644
--- a/src/main/java/com/github/jadepeng/rainbowfart/settings/SettingsComponent.java
+++ b/src/main/java/com/github/jadepeng/rainbowfart/settings/SettingsComponent.java
@@ -1,34 +1,46 @@
package com.github.jadepeng.rainbowfart.settings;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.*;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.jdesktop.swingx.combobox.ListComboBoxModel;
+import org.jetbrains.annotations.NotNull;
+
import com.github.jadepeng.rainbowfart.Context;
import com.github.jadepeng.rainbowfart.bean.Manifest;
-import com.github.jadepeng.rainbowfart.settings.tts.*;
-import com.google.gson.*;
-import com.intellij.icons.AllIcons;
-import com.intellij.openapi.actionSystem.*;
+import com.github.jadepeng.rainbowfart.settings.tts.AddRowAction;
+import com.github.jadepeng.rainbowfart.settings.tts.DeleteRowAction;
+import com.github.jadepeng.rainbowfart.settings.tts.TTSColumnModel;
+import com.github.jadepeng.rainbowfart.settings.tts.TTSTableModel;
+import com.github.jadepeng.rainbowfart.settings.tts.TableCellTextAreaRenderer;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.intellij.openapi.actionSystem.ActionManager;
+import com.intellij.openapi.actionSystem.ActionToolbar;
+import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.openapi.ui.TextComponentAccessor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
-import com.intellij.ui.components.*;
-import com.intellij.ui.components.labels.LinkLabel;
+import com.intellij.ui.components.JBCheckBox;
+import com.intellij.ui.components.JBLabel;
+import com.intellij.ui.components.JBScrollPane;
+import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.jdesktop.swingx.combobox.ListComboBoxModel;
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-import javax.swing.border.TitledBorder;
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.stream.Collectors;
/**
* Setting Component
@@ -44,12 +56,11 @@ public class SettingsComponent {
Map name2vcn = new HashMap<>();
JPanel ttsGroup;
- // JBTextField txtApiId = new JBTextField();
-// JBTextField txtApiSecret = new JBTextField();
-// JBTextField txtAppKey = new JBTextField();
- ComboBox cbxVcn = new ComboBox();
- ComboBox cbxBuiltinPackage = new ComboBox(new ListComboBoxModel(Arrays.asList("built-in-voice-chinese", "built-in-voice-english", "tts-xiaoling")));
+ ComboBox cbxVcn = new ComboBox<>();
+
+ ComboBox cbxBuiltinPackage = new ComboBox(
+ new ListComboBoxModel(Arrays.asList("built-in-voice-chinese", "built-in-voice-english", "tts-xiaoling")));
TTSTableModel tableModel = new TTSTableModel();
@@ -58,8 +69,8 @@ public SettingsComponent() {
// load vcn
try {
loadVCN();
- this.cbxVcn.setModel(new ListComboBoxModel(this.name2vcn.entrySet().stream().map(e -> e.getKey()).collect(Collectors.toList())));
- } catch (IOException e) {
+ this.cbxVcn.setModel(new ListComboBoxModel(new ArrayList<>(this.name2vcn.keySet())));
+ } catch (Exception ignored) {
}
txtPackagePath.addBrowseFolderListener("Choose Custom Voice Package", "Custom Voice Package Path:", null,
@@ -135,7 +146,7 @@ public void actionPerformed(ActionEvent e) {
}
void loadVCN() throws IOException {
- URL filePath = getClass().getClassLoader().getResource("/vcn.json");
+ URL filePath = Context.class.getResource("/vcn.json");
String jsonText = IOUtils.toString(filePath.openStream(), "utf-8");
JsonObject vcnJson = new JsonParser().parse(jsonText).getAsJsonObject();
JsonArray data = vcnJson.getAsJsonArray("data");