[gnome-shell-extensions] convenience: update for the new extension API



commit 7517d8ab6a6b696cd3fda9ae0b28418675e7750a
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Wed Feb 8 15:21:41 2012 +0100

    convenience: update for the new extension API
    
    Extension helper and metadata are now different objects, so the
    first needs be retrieved from ExtensionUtils.
    Also, reduce the number of required arguments (by using the new
    metadata keys) and make generic enough for usage by other extensions.
    Includes documentation.

 lib/convenience.js |   46 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 9 deletions(-)
---
diff --git a/lib/convenience.js b/lib/convenience.js
index 49de620..6421ef5 100644
--- a/lib/convenience.js
+++ b/lib/convenience.js
@@ -1,17 +1,45 @@
+/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
+
 const Gettext = imports.gettext;
 const Gio = imports.gi.Gio;
 
-function initTranslations(metadata) {
-    let localeDir = metadata.dir.get_child('locale').get_path();
-    Gettext.bindtextdomain('gnome-shell-extensions', localeDir);
+const ExtensionUtils = imports.misc.extensionUtils;
+
+/**
+ * initTranslations:
+ * @domain: (optional): the gettext domain to use
+ *
+ * Initialize Gettext to load translations from extensionsdir/locale.
+ * If @domain is not provided, it will be taken from metadata['gettext-domain']
+ */
+function initTranslations(domain) {
+    let extension = ExtensionUtils.getCurrentExtension();
+
+    domain = domain || extension.metadata['gettext-domain'];
+
+    let localeDir = extension.dir.get_child('locale').get_path();
+    Gettext.bindtextdomain(domain, localeDir);
 }
 
-function getSettings(metadata, extension_id) {
-    let schemaDir = metadata.dir.get_child('schemas').get_path();
+/**
+ * getSettings:
+ * @schema: (optional): the GSettings schema id
+ *
+ * Builds and return a GSettings schema for @schema, using schema files
+ * in extensionsdir/schemas. If @schema is not provided, it is taken from
+ * metadata['settings-schema'].
+ */
+function getSettings(schema) {
+    let extension = ExtensionUtils.getCurrentExtension();
+
+    schema = schema || extension.metadata['settings-schema'];
+
+    let schemaDir = extension.dir.get_child('schemas').get_path();
     let schemaSource = Gio.SettingsSchemaSource.new_from_directory(schemaDir,
-								  Gio.SettingsSchemaSource.get_default(),
-								  false);
-    let schema = schemaSource.lookup('org.gnome.shell.extensions.' + extension_id, false);
-    return new Gio.Settings({ settings_schema: schema });
+                                                                   Gio.SettingsSchemaSource.get_default(),
+                                                                   false);
+    let schemaObj = schemaSource.lookup(schema, false);
+
+    return new Gio.Settings({ settings_schema: schemaObj });
 }
 								  



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]