OSDN Git Service

Initial release master
authorpluginfan <pluginfan@suremail.info>
Tue, 12 Apr 2016 15:59:19 +0000 (18:59 +0300)
committerpluginfan <pluginfan@suremail.info>
Tue, 12 Apr 2016 15:59:19 +0000 (18:59 +0300)
README.md
eSpeak Selection/NEWS [new file with mode: 0644]
eSpeak Selection/README.md [new file with mode: 0644]
eSpeak Selection/TODO [new file with mode: 0644]
eSpeak Selection/config.json [new file with mode: 0644]
eSpeak Selection/plugin.groovy [new file with mode: 0644]

index f08f725..1328dab 100644 (file)
--- a/README.md
+++ b/README.md
@@ -2,6 +2,7 @@
 
 Plugins written in [Groovy](http://groovy-lang.org/) script for [IntelliJ IDEA](http://jetbrains.com/idea/) based IDE's that can be enhanced through [LivePlugin](https://github.com/dkandalov/live-plugin) plugin connector.
 
+* [eSpeak Selection](https://osdn.jp/projects/ii-lp-script/scm/git/ii-lp-script/tree/master/eSpeak%20Selection/) -- Reads the current selection aloud.
 * [Line Sort](https://osdn.jp/projects/ii-lp-script/scm/git/ii-lp-script/tree/master/Line%20Sort/) -- Sorts the selected lines according to a sorting method.
 * [Move Caret to Word End](https://osdn.jp/projects/ii-lp-script/scm/git/ii-lp-script/tree/master/Move%20Caret%20To%20Word%20End/) -- Moves all carets to the closes word end.
 * [PrettyPrint](https://osdn.jp/projects/ii-lp-script/scm/git/ii-lp-script/tree/master/PrettyPrint/) -- Formats the current selection as prettified JSON or XML.
diff --git a/eSpeak Selection/NEWS b/eSpeak Selection/NEWS
new file mode 100644 (file)
index 0000000..fe3e01d
--- /dev/null
@@ -0,0 +1,3 @@
+Version 0.0 -- April 2016
+~~~~~~~~~~~~~~~~~~~~~~~~~
+Initial release.
diff --git a/eSpeak Selection/README.md b/eSpeak Selection/README.md
new file mode 100644 (file)
index 0000000..7d0fb1c
--- /dev/null
@@ -0,0 +1,13 @@
+# eSpeak Selection
+
+Reads the current selection aloud.
+
+Action:
+
+* `eSpeak Selection`
+
+Shortcut:
+
+* <kbd>Alt</kbd>-<kbd>E</kbd> -- eSpeak Selection
+
+Not really related to the source code, more a helper to understand it.
diff --git a/eSpeak Selection/TODO b/eSpeak Selection/TODO
new file mode 100644 (file)
index 0000000..57d85cb
--- /dev/null
@@ -0,0 +1 @@
+* Make it speak something also when there is no selection. Nicest would be to do it context sensitively : current string or current comment.
diff --git a/eSpeak Selection/config.json b/eSpeak Selection/config.json
new file mode 100644 (file)
index 0000000..3a9616c
--- /dev/null
@@ -0,0 +1,16 @@
+{
+
+    "generic": {
+        "skipMenu": false
+    },
+
+    "voice": [
+        "de",
+        "en"
+    ],
+
+    "option": [
+        "-s", "125"
+    ]
+
+}
diff --git a/eSpeak Selection/plugin.groovy b/eSpeak Selection/plugin.groovy
new file mode 100644 (file)
index 0000000..96bb47b
--- /dev/null
@@ -0,0 +1,51 @@
+// plugin  eSpeak Selection
+// version 0.0
+// release April 2016
+// author  Plugin Fan
+// license GPL v 3.0
+
+// Reads the current selection aloud:
+//     - Alt-E - eSpeak Selection
+//
+// Not really related to the source code, more a helper to understand it.
+
+
+import com.intellij.openapi.actionSystem.AnActionEvent
+import com.intellij.notification.NotificationType
+
+import groovy.json.JsonSlurper
+
+import static liveplugin.PluginUtil.*
+
+// load configuration
+def configName = pluginPath + '/config.json'
+def configFile = new File(configName)
+if (! configFile.exists())
+    return show("Configuration file “${configName}” not found", '', NotificationType.ERROR)
+
+config = new JsonSlurper().parse(configFile.toURL())
+
+// perform the speaking
+def eSpeak(project, voice)
+{
+    runDocumentWriteAction(project) {
+        currentEditorIn(project).with {
+            if (! selectionModel.hasSelection())
+                return
+
+            def espeak = new ProcessBuilder(['espeak', '-v', voice] + config.option).start()
+            def stream = new PrintStream(espeak.outputStream)
+            stream.println(selectionModel.getSelectedText(true))
+            stream.close()
+        }
+    }
+}
+
+registerAction('eSpeak Selection', 'alt E') { AnActionEvent event ->
+    def project = event.project
+
+    if (config.generic.skipMenu)
+        eSpeak(project, config.voice.first())
+    else
+        showPopupMenu(config.voice.collectEntries { voice -> [voice, { eSpeak(project, voice) } ] }, 'eSpeak Voice', event.dataContext)
+}