meson.build.o7QLX02
[roobuilder] / src / Builder4 / GtkView.bjs
index 5d63044..9ec0001 100644 (file)
            ],
            "* pack" : "set_child",
            "Gtk.CssProvider css" : "",
-           "bool allow_node_scroll" : true,
-           "bool loading" : true,
+           "bool loading" : false,
+           "bool zallow_node_scroll" : true,
            "gboolean editable" : false,
            "gboolean show_line_marks" : true,
            "gboolean show_line_numbers" : true,
              "$ xns" : "GtkSource",
              "* pack" : "set_buffer",
              "bool dirty" : false,
+             "bool in_cursor_change" : false,
              "id" : "buffer",
              "int error_line" : "-1",
+             "int last_line" : "-1",
              "listeners" : {
-              "notify[\"cursor_position\"]" : [
-               "() => {",
+              "cursor_moved" : [
+               "( ) => {",
+               "GLib.debug(\"cursor moved called\");",
                "",
                "",
-               "    if (_this.sourceview.loading) {",
+               " \tif (this.in_cursor_change ) {",
+               "        GLib.debug(\"cursor changed : %d [ignoring nested call)\", this.el.cursor_position);",
                "        return;",
                "    }",
                "   ",
                "    this.el.get_iter_at_offset(out cpos, this.el.cursor_position);",
                "    ",
                "    var ln = cpos.get_line();",
-               "",
+               "    if (this.last_line == ln ){",
+               "    \treturn;",
+               "\t}",
+               "\tthis.last_line = ln;",
                "    var node = _this.file.lineToNode(ln);",
                "",
                "    if (node == null) {",
                "        print(\"can not find node\\n\");",
                "        return;",
                "    }",
-               "    _this.sourceview.loading = true;",
+               "    this.in_cursor_change  = true;",
                "    var ltree = _this.main_window.windowstate.left_tree;",
                "    ltree.model.selectNode(node);",
-               "    _this.sourceview.loading = false;",
-               "    ",
-               "    //print(\"got tree path %s\\n\", tp);",
-               "    //if (tp != \"\") {",
-               "      // this.allow_node_scroll = false;        ",
-               "     //  print(\"changing cursor on tree..\\n\");",
-               "        //ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);",
-               "        // scrolling is disabled... as node selection calls scroll 10ms after it changes.",
-               "        ///GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {",
-               "         //   this.allow_node_scroll = true;",
-               "         //   return false;",
-               "      //  });",
-               "   // }",
-               "    ",
-               "    // highlight the node..",
-               "    ",
-               "  ",
-               "",
-               " }"
+               "    this.in_cursor_change  = false;",
+               "}",
+               ""
               ]
              },
              "xtype" : "Buffer"
             ]
            },
            "string name" : "gtkview-view",
+           "uint tab_width" : 4,
            "xtype" : "View",
            "| string toString" : [
             "() {",
             "    var buf = this.el.get_buffer();",
             "    buf.set_text(\"\",0);",
             "    var sbuf = (GtkSource.Buffer) buf;",
-            "",
+            "\tvar cpos = buf.cursor_position;",
             "    ",
+            "   \tprint(\"BEFORE LOAD cursor = %d\\n\", cpos);",
+            "        var vadj_pos = this.el.get_vadjustment().get_value();",
             "",
             "    if (_this.file == null || _this.file.xtype != \"Gtk\") {",
             "        print(\"xtype != Gtk\");",
             "  ",
             "     ",
             "   _this.main_window.windowstate.updateErrorMarksAll(); ",
-            "   ",
+            "   //  restore the cursor position?",
+            "    // after reloading the contents.",
+            "     GLib.Timeout.add(500, () => {",
+            "\t\t_this.buffer.in_cursor_change = true;",
+            "        print(\"RESORTING cursor to = %d\\n\", cpos);",
+            "\t\tGtk.TextIter cpos_iter;",
+            "\t\tbuf.get_iter_at_offset(out cpos_iter, cpos);",
+            "\t\tbuf.place_cursor(cpos_iter); ",
+            "\t\t",
+            "\t\tthis.el.get_vadjustment().set_value(vadj_pos);;",
+            "\t\t_this.buffer.in_cursor_change = false;",
+            " ",
+            "\t\t",
+            "\t\t",
+            "\t\t//_this.buffer.checkSyntax();",
+            "\t\treturn false;",
+            "\t});",
             "  ",
             "    ",
             "    this.loading = false; ",
             "    var sbuf = (GtkSource.Buffer) buf;",
             "",
             "   ",
-            "    // while(Gtk.events_pending()) {",
-            "     //    Gtk.main_iteration();",
-            "   //  }",
+            " ",
             "    ",
             "   ",
             "    // clear all the marks..",
             "    Gtk.TextIter cur_iter;",
             "    sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);",
             "    ",
-            "    //var cur_line = cur_iter.get_line();",
-            "    //if (cur_line > sel.line_start && cur_line < sel.line_end) {",
             "    ",
-            "    //} else {",
-            "    if (this.allow_node_scroll) {",
-            "\t\t ",
+            "    if (!_this.buffer.in_cursor_change) {",
+            "",
             "    \tthis.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);",
-            "\t}",
+            "\t}  ",
             "    ",
             "     ",
             "    ",
     " ",
     "",
     " ",
-    "\t",
-    "\tvar offset = 0;",
     "\t ",
     "",
     "\tvar tlines = buf.get_line_count () +1;",
     "\t\t",
     "\t     Gtk.TextIter iter;",
     "//        print(\"get inter\\n\");",
-    "\t    var eline = err.line - offset;",
-    "\t    GLib.debug(\"GOT ERROR on line %d -- converted to %d  (offset = %d)\",",
-    "\t    \terr.line ,eline, offset);",
+    "\t    var eline = err.line + 1;",
+    "\t    GLib.debug(\"GOT ERROR on line %d -- converted to %d \",",
+    "\t    \terr.line ,eline);",
     "\t    ",
     "\t    ",
     "\t    if (eline > tlines || eline < 0) {",