Sfoglia il codice sorgente

版本更新至1.0.2

yanyi 6 anni fa
parent
commit
0d3d3923e3

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
-# TranslationPlugin[ ![Download](https://api.bintray.com/packages/lamster2018/maven/easy-protector-release/images/download.svg) ](https://bintray.com/lamster2018/maven/easy-protector-release/_latestVersion)
+# TranslationPlugin[![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu)
 idea翻译插件
 
 ## 使用

+ 13 - 0
TeanslationPlugin.iml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PLUGIN_MODULE" version="4">
+  <component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 1 - 1
resources/META-INF/plugin.xml

@@ -1,7 +1,7 @@
 <idea-plugin>
     <id>Translation YanYi</id>
     <name>Translation YanYi</name>
-    <version>1.0</version>
+    <version>1.0.2</version>
     <vendor email="ben@yanyi.red" url="https://github.com/BenYanYi">BenYanYi</vendor>
 
     <description>

+ 24 - 8
src/com/yanyi/translation/Translation.java

@@ -2,6 +2,7 @@ package com.yanyi.translation;
 
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.ui.Messages;
 
 import java.awt.Toolkit;
@@ -14,7 +15,7 @@ import java.util.List;
 
 /**
  * @author YanYi
- * @date 2019/3/27 11:28
+ * @date 2019/3/27 11:28x
  * @email ben@yanyi.red
  * @overview
  */
@@ -24,6 +25,16 @@ public class Translation extends AnAction {
 
     @Override
     public void actionPerformed(AnActionEvent e) {
+//        String text = getSysClipboardText();
+//        if (text == null || text.equals("") || text.trim().equals("") || text.length() <= 0) {
+//            isDialog();
+//        } else {
+//            trans(text);
+//        }
+        isDialog();
+    }
+
+    private void isDialog() {
         String text = Messages.showInputDialog("请输入要翻译的内容", "提示", Messages.getQuestionIcon());
         trans(text);
     }
@@ -47,7 +58,9 @@ public class Translation extends AnAction {
                             str.append(transBean.getDst()).append(";");
                         }
                     }
-                    str.deleteCharAt(str.length() - 1);
+                    if (str.length() > 0) {
+                        str.deleteCharAt(str.length() - 1);
+                    }
                     show(text, str.toString());
                 } else {
                     show(text, "翻译失败");
@@ -60,17 +73,19 @@ public class Translation extends AnAction {
 
     private void show(String text, String msg) {
 //        //这个回调是线程里面的,所以要加个方法,不然会报错
-//        ApplicationManager.getApplication().invokeLater(() -> {
+        ApplicationManager.getApplication().invokeLater(() -> {
 //            //弹出翻译结果对话框
-        String str = Messages.showInputDialog(text, "翻译结果", Messages.getInformationIcon(), msg, null);
-        trans(str);
-//        });
+            Messages.showMessageDialog(text + "\n" + "->" + "\n" + msg, "翻译结果", Messages.getInformationIcon());
+            isDialog();
+//            String str = Messages.showInputDialog(text, "翻译结果", Messages.getInformationIcon(), msg, null);
+//            trans(str);
+        });
     }
 
     /**
      * 从剪切板获得文字。
      */
-    public static String getSysClipboardText() {
+    private String getSysClipboardText() {
         String ret = "";
         Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
         // 获取剪切板中的内容
@@ -81,8 +96,9 @@ public class Translation extends AnAction {
                 try {
                     ret = (String) clipTf
                             .getTransferData(DataFlavor.stringFlavor);
+                    return ret;
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    return "";
                 }
             }
         }