src/Builder4/Editor.bjs
authorAlan Knowles <alan@roojs.com>
Thu, 21 May 2015 07:06:27 +0000 (15:06 +0800)
committerAlan Knowles <alan@roojs.com>
Thu, 21 May 2015 07:06:27 +0000 (15:06 +0800)
src/Builder4/Editor.vala

src/Builder4/Editor.bjs
src/Builder4/Editor.vala

index e49fa75..3e1b1a8 100644 (file)
    "# string activeEditor" : "\"\"",
    "|   bool saveContents" : "  ()  {\n    \n    \n    \n    \n    \n    \n    \n   \n     \n     var str = _this.buffer.toString();\n     \n      \n     \n     \n     if (!_this.buffer.checkSyntax()) {\n         print(\"check syntax failed\");\n         //this.get('/StandardErrorDialog').show(\"Fix errors in code and save..\"); \n         //return false;\n     }\n     \n     // LeftPanel.model.changed(  str , false);\n     _this.dirty = false;\n     _this.save_button.el.sensitive = false;\n     \n     \n        \n     \n    // find the text for the node..\n    if (ptype == \"listener\") {\n        this.node.listeners.set(key,str);\n    \n    } else {\n         this.node.props.set(key,str);\n    }\n\n     \n    \n    // call the signal..\n    this.save();\n    \n    return true;\n\n} ",
    "# int pos_root_x" : "",
-   "* init" : "{\n    this.fname = \"\";\n}\n",
    "# int pos_root_y" : "",
    "# string ptype" : "\"\"",
-   "bool expand" : true,
-   "| void showPlainFile" : "(string fname)\n{\n    this.ptype = \"\";\n    this.key  = \"\";\n    this.node = null;\n    this.file = null;\n    this.fname = fname;\n    string str;\n    try {\n        GLib.FileUtils.get_contents(fname, out str);\n    } catch (Error e) {\n        str = \"\"; // a tad dangerios... - perhaps we should block editing...\n    }\n    \n    this.view.load(str);\n    this.key_edit.el.text = \"\";    \n\n}",
    "# string key" : "\"\"",
    "* pack" : "add",
    "xtype" : "Box",
@@ -27,7 +24,6 @@
    "# bool dirty" : false,
    "$ xns" : "Gtk",
    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
-   "string fname" : "",
    "@ void save" : "()",
    "$ homogeneous" : false,
    "# JsRender.Node node" : "null",
@@ -77,7 +73,7 @@
        "gboolean highlight_current_line" : true,
        "$ gboolean auto_indent" : true,
        "$ xns" : "Gtk",
-       "|   void load" : " (string str) {\n\n// show the help page for the active node..\n   //this.get('/Help').show();\n\n\n  // this.get('/BottomPane').el.set_current_page(0);\n    var buf = (Gtk.SourceBuffer)this.el.get_buffer();\n    buf.set_text(str, str.length);\n    buf.set_undo_manager(null); // reset undo...\n    \n    var lm = Gtk.SourceLanguageManager.get_default();\n    \n    var lang = \"vala\";    \n    if (_this.file != null) {\n         lang = _this.file.language;\n    }  \n    //?? is javascript going to work as js?\n    \n    ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language(lang));\n \n     \n    _this.dirty = false;\n    this.el.grab_focus();\n    _this.save_button.el.sensitive = false;\n}",
+       "|   void load" : " (string str) {\n\n// show the help page for the active node..\n   //this.get('/Help').show();\n\n\n  // this.get('/BottomPane').el.set_current_page(0);\n  var buf = (Gtk.SourceBuffer)this.el.get_buffer();\n    buf.set_text(str, str.length);\n    buf.set_undo_manager(null);\n    \n    var lm = Gtk.SourceLanguageManager.get_default();\n    \n    var lang = _this.file.language;\n    //?? is javascript going to work as js?\n    \n    ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language(lang));\n \n     \n    _this.dirty = false;\n    this.el.grab_focus();\n    _this.save_button.el.sensitive = false;\n}",
        "indent_width" : 4,
        "$ show_line_numbers" : true,
        "items" : [
@@ -90,7 +86,7 @@
          "id" : "buffer",
          "| bool highlightErrors" : "( Gee.HashMap<int,string> validate_res) {\n        this.error_line = validate_res.size;\n\n        if (this.error_line < 1) {\n              return true;\n        }\n        var tlines = this.el.get_line_count ();\n        Gtk.TextIter iter;\n        var valiter = validate_res.map_iterator();\n        while (valiter.next()) {\n        \n    //        print(\"get inter\\n\");\n            var eline = valiter.get_key();\n            if (eline > tlines) {\n                continue;\n            }\n            this.el.get_iter_at_line( out iter, eline);\n            //print(\"mark line\\n\");\n            this.el.create_source_mark(valiter.get_value(), \"error\", iter);\n        }   \n        return false;\n    }",
          "|   string toString" : "  () {\n    \n    Gtk.TextIter s;\n    Gtk.TextIter e;\n    this.el.get_start_iter(out s);\n    this.el.get_end_iter(out e);\n    var ret = this.el.get_text(s,e,true);\n    //print(\"TO STRING? \" + ret);\n    return ret;\n}\n ",
-         "|   bool checkSyntax" : " () {\n \n    if (this.check_running) {\n        print(\"Check is running\\n\");\n        if (this.check_queued) { \n            print(\"Check is already queued\");\n            return true;\n        }\n        this.check_queued = true;\n        print(\"Adding queued Check \");\n        GLib.Timeout.add_seconds(1, () => {\n            this.check_queued = false;\n            \n            this.checkSyntax();\n            return false;\n        });\n    \n\n        return true;\n    }\n   \n   \n    var p = Palete.factory(_this.file.xtype);   \n    \n    var str = this.toString();\n    \n     \n    if (this.error_line > 0) {\n         Gtk.TextIter start;\n         Gtk.TextIter end;     \n        this.el.get_bounds (out start, out end);\n\n        this.el.remove_source_marks (start, end, null);\n    }\n    \n    if (str.length < 1) {\n        print(\"checkSyntax - empty string?\\n\");\n        return true;\n    }\n    this.check_running = true;\n    \n    \n    if (_this.file.language == \"js\") {\n        this.check_running = false;\n        print(\"calling validate javascript\\n\"); \n        return this.highlightErrors(p.validateJavascript(\n            str, \n             _this.key, \n            _this.ptype,\n            _this.file,\n            _this.node\n        ));    \n        \n    }\n        \n        \n    print(\"calling validate vala\\n\");    \n    // clear the buttons.\n \n    \n    p.validateVala(\n        _this.window.windowstate,\n        str, \n         _this.key, \n        _this.ptype,\n        _this.file,\n        _this.node \n        \n        \n    );\n     \n    \n    \n    //print(\"done mark line\\n\");\n     \n    return true; // at present allow saving - even if it's invalid..\n}\n",
+         "|   bool checkSyntax" : " () {\n \n    if (this.check_running) {\n        print(\"Check is running\\n\");\n        if (this.check_queued) { \n            print(\"Check is already queued\");\n            return true;\n        }\n        this.check_queued = true;\n        print(\"Adding queued Check \");\n        GLib.Timeout.add_seconds(1, () => {\n            this.check_queued = false;\n            \n            this.checkSyntax();\n            return false;\n        });\n    \n\n        return true;\n    }\n    var str = this.toString();\n    \n    // needed???\n    if (this.error_line > 0) {\n         Gtk.TextIter start;\n         Gtk.TextIter end;     \n        this.el.get_bounds (out start, out end);\n\n        this.el.remove_source_marks (start, end, null);\n    }\n    \n    if (_this.file == null) {\n    \n        // assume it's gtk...\n        \n    \n    \n    }\n   \n    var p = Palete.factory(_this.file.xtype);   \n    \n\n    \n     \n    if (this.error_line > 0) {\n         Gtk.TextIter start;\n         Gtk.TextIter end;     \n        this.el.get_bounds (out start, out end);\n\n        this.el.remove_source_marks (start, end, null);\n    }\n    \n    if (str.length < 1) {\n        print(\"checkSyntax - empty string?\\n\");\n        return true;\n    }\n    this.check_running = true;\n    \n    \n    if (_this.file.language == \"js\") {\n        this.check_running = false;\n        print(\"calling validate javascript\\n\"); \n        return this.highlightErrors(p.validateJavascript(\n            str, \n             _this.key, \n            _this.ptype,\n            _this.file,\n            _this.node\n        ));    \n        \n    }\n        \n        \n    print(\"calling validate vala\\n\");    \n    // clear the buttons.\n \n    \n    p.validateVala(\n        _this.window.windowstate,\n        str, \n         _this.key, \n        _this.ptype,\n        _this.file,\n        _this.node \n        \n        \n    );\n     \n    \n    \n    //print(\"done mark line\\n\");\n     \n    return true; // at present allow saving - even if it's invalid..\n}\n",
          "* pack" : "set_buffer",
          "xtype" : "SourceBuffer",
          "bool check_running" : false,
index 1baaa85..8c1a540 100644 (file)
@@ -28,7 +28,6 @@ public class Editor : Object
     public JsRender.JsRender file;
     public bool pos;
     public bool dirty;
-    public string fname;
     public signal void save ();
     public JsRender.Node node;
 
@@ -50,19 +49,12 @@ public class Editor : Object
 
         // set gobject values
         this.el.homogeneous = false;
-        this.el.expand = true;
         var child_0 = new Xcls_Box2( _this );
         child_0.ref();
         this.el.pack_start (  child_0.el , false,true );
         var child_1 = new Xcls_RightEditor( _this );
         child_1.ref();
         this.el.pack_end (  child_1.el , true,true );
-
-        // init method
-
-        {
-            this.fname = "";
-        }
     }
 
     // user defined functions
@@ -109,24 +101,6 @@ public class Editor : Object
         
         return true;
     
-    }
-    public void showPlainFile (string fname)
-    {
-        this.ptype = "";
-        this.key  = "";
-        this.node = null;
-        this.file = null;
-        this.fname = fname;
-        string str;
-        try {
-            GLib.FileUtils.get_contents(fname, out str);
-        } catch (Error e) {
-            str = ""; // a tad dangerios... - perhaps we should block editing...
-        }
-        
-        this.view.load(str);
-        this.key_edit.el.text = "";    
-    
     }
     public   void show (JsRender.JsRender file, JsRender.Node node, string ptype, string key)
     {
@@ -354,16 +328,13 @@ public class Editor : Object
         
         
           // this.get('/BottomPane').el.set_current_page(0);
-            var buf = (Gtk.SourceBuffer)this.el.get_buffer();
+          var buf = (Gtk.SourceBuffer)this.el.get_buffer();
             buf.set_text(str, str.length);
-            buf.set_undo_manager(null); // reset undo...
+            buf.set_undo_manager(null);
             
             var lm = Gtk.SourceLanguageManager.get_default();
             
-            var lang = "vala";    
-            if (_this.file != null) {
-                 lang = _this.file.language;
-            }  
+            var lang = _this.file.language;
             //?? is javascript going to work as js?
             
             ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lm.get_language(lang));
@@ -467,11 +438,28 @@ public class Editor : Object
         
                 return true;
             }
-           
+            var str = this.toString();
+            
+            // needed???
+            if (this.error_line > 0) {
+                 Gtk.TextIter start;
+                 Gtk.TextIter end;     
+                this.el.get_bounds (out start, out end);
+        
+                this.el.remove_source_marks (start, end, null);
+            }
+            
+            if (_this.file == null) {
+            
+                // assume it's gtk...
+                
+            
+            
+            }
            
             var p = Palete.factory(_this.file.xtype);   
             
-            var str = this.toString();
+        
             
              
             if (this.error_line > 0) {