[sushi/wip/cosimoc/no-clutter: 3/50] text: simplify renderer state



commit 89647ae27f4ea9a99e7528bd9b828b01d803baaa
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Apr 8 21:33:22 2017 -0700

    text: simplify renderer state

 src/js/viewers/text.js | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)
---
diff --git a/src/js/viewers/text.js b/src/js/viewers/text.js
index 11af034..5aaa566 100644
--- a/src/js/viewers/text.js
+++ b/src/js/viewers/text.js
@@ -37,6 +37,20 @@ const Sushi = imports.gi.Sushi;
 const MimeHandler = imports.ui.mimeHandler;
 const Utils = imports.ui.utils;
 
+function _getGeditScheme() {
+    let geditScheme = 'tango';
+    let schemaName = 'org.gnome.gedit.preferences.editor';
+    let installedSchemas = Gio.Settings.list_schemas();
+    if (installedSchemas.indexOf(schemaName) > -1) {
+        let geditSettings = new Gio.Settings({ schema: schemaName });
+        let geditSchemeName = geditSettings.get_string('scheme');
+        if (geditSchemeName != '')
+            geditScheme = geditSchemeName;
+    }
+
+    return geditScheme;
+}
+
 const TextRenderer = new Lang.Class({
     Name: 'TextRenderer',
 
@@ -50,21 +64,10 @@ const TextRenderer = new Lang.Class({
         this._file = file;
         this._callback = callback;
 
-        this._textLoader = new Sushi.TextLoader();
-        this._textLoader.connect('loaded',
-                                 Lang.bind(this, this._onBufferLoaded));
-        this._textLoader.uri = file.get_uri();
-
-        this._geditScheme = 'tango';
-        let schemaName = 'org.gnome.gedit.preferences.editor';
-        let installedSchemas = Gio.Settings.list_schemas();
-        if (installedSchemas.indexOf(schemaName) > -1) {
-            let geditSettings = new Gio.Settings({ schema: schemaName });
-            let geditSchemeName = geditSettings.get_string('scheme');
-            if (geditSchemeName != '')
-                this._geditScheme = geditSchemeName;
-        }
-
+        let textLoader = new Sushi.TextLoader();
+        textLoader.connect('loaded',
+                           Lang.bind(this, this._onBufferLoaded));
+        textLoader.uri = file.get_uri();
     },
 
     render : function() {
@@ -72,20 +75,20 @@ const TextRenderer = new Lang.Class({
     },
 
     _onBufferLoaded : function(loader, buffer) {
-        this._buffer = buffer;
-        this._buffer.highlight_syntax = true;
+        buffer.highlight_syntax = true;
 
         let styleManager = GtkSource.StyleSchemeManager.get_default();
-        let scheme = styleManager.get_scheme(this._geditScheme);
+        let geditScheme = _getGeditScheme();
+        let scheme = styleManager.get_scheme(geditScheme);
         this._buffer.set_style_scheme(scheme);
 
-        this._view = new GtkSource.View({ buffer: this._buffer,
+        this._view = new GtkSource.View({ buffer: buffer,
                                           editable: false,
                                           cursor_visible: false,
                                           monospace: true });
         this._view.set_can_focus(false);
 
-        if (this._buffer.get_language())
+        if (buffer.get_language())
             this._view.set_show_line_numbers(true);
 
         this._view.connect('button-press-event', Lang.bind(this, function(view, event) {


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