[gnome-builder] libide: add basic scriping example.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add basic scriping example.
- Date: Mon, 23 Mar 2015 23:35:58 +0000 (UTC)
commit 5375f32921096dc24497c1f43b9ebf873e16c774
Author: Christian Hergert <christian hergert me>
Date: Mon Feb 16 14:03:39 2015 -0800
libide: add basic scriping example.
examples/scripts/README.md | 11 ++++++++++
examples/scripts/search-provider.js | 38 +++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/examples/scripts/README.md b/examples/scripts/README.md
new file mode 100644
index 0000000..54b5405
--- /dev/null
+++ b/examples/scripts/README.md
@@ -0,0 +1,11 @@
+# IDE Scripting Examples
+
+This directory contains various examples you can take inspiration from when
+writing your own IDE extensions.
+
+Extensions are placed in ~/.config/gnome-builder/scripts/. Currently,
+JavaScript is supported. However, more languages may be added in the future
+based on demands.
+
+Simply place a `*.js` file in the proper directory, and it will be loaded
+when the `Ide.Context` is initialized.
diff --git a/examples/scripts/search-provider.js b/examples/scripts/search-provider.js
new file mode 100644
index 0000000..eb2608a
--- /dev/null
+++ b/examples/scripts/search-provider.js
@@ -0,0 +1,38 @@
+/* ~/.config/gnome-builder/scripts/script1.js */
+
+const Ide = imports.gi.Ide;
+const GObject = imports.gi.GObject;
+
+/* just some examples of things you can access */
+let Project = Context.get_project();
+let BuildSystem = Context.get_build_system();
+let Vcs = Context.get_vcs();
+
+/* get a handle to the search engine */
+let SearchEngine = Context.get_search_engine();
+
+/* create a custom provider subclass */
+const MySearchProvider = new GObject.Class({
+ Name: 'MySearchProvider',
+ Extends: Ide.SearchProvider,
+
+ /* perform the search operation. can be asynchronous */
+ vfunc_populate: function(search_context, search_terms, max_results, cancellable) {
+ let result = new Ide.SearchResult({
+ 'context': Context,
+ 'title': 'weeee',
+ 'subtitle': 'more weeeeeee',
+ 'score': 0.5
+ });
+ search_context.add_result(this, result);
+ search_context.provider_completed(this);
+ },
+
+ /* this is what is shown in the search ui describing the action */
+ vfunc_get_verb: function() {
+ return "foobar";
+ }
+});
+
+/* add our custom provider to the search engine */
+SearchEngine.add_provider(new MySearchProvider({'context': Context}));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]