Fix #8089 - phase 1 - code ast navigation
[roobuilder] / src / Builder4 / GtkView.bjs
index 6dd3dc9..ca6a3fb 100644 (file)
@@ -7,33 +7,13 @@
    "# GtkSource.SearchContext searchcontext" : "",
    "# JsRender.JsRender file" : "null",
    "# Xcls_MainWindow main_window" : "",
+   "# int last_error_counter" : 0,
+   "# int last_search_end" : 0,
    "$ xns" : "Gtk",
-   "* init" : [
-    "{",
-    "",
-    "\tthis.css = new Gtk.CssProvider();",
-    "\t ",
-    "\tthis.css.load_from_string(",
-    "\t\t\"#gtkview-view-layout { background-color: #ccc; }\"",
-    "\t);",
-    "\t ",
-    "\tGtk.StyleContext.add_provider_for_display(",
-    "\t\tthis.el.get_display(),",
-    "\t\tthis.css,",
-    "\t\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
-    "\t);",
-    "\t\t",
-    "        ",
-    "}",
-    ""
-   ],
-   "Gtk.CssProvider css" : "",
    "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
    "bool hexpand" : true,
    "bool vexpand" : true,
    "id" : "GtkView",
-   "int last_error_counter" : 0,
-   "int last_search_end" : 0,
    "items" : [
     {
      "$ xns" : "Gtk",
          "items" : [
           {
            "# JsRender.Node? node_selected" : "",
+           "# bool loading" : false,
            "# string prop_selected" : "\"\"",
            "$ xns" : "GtkSource",
            "* init" : [
-            "\t{",
+            "{",
             "",
-            "",
-            "\tthis.css = new Gtk.CssProvider();",
-            "\t ",
-            "\tthis.css.load_from_string(\"#gtkview-view { font: 10px monospace ;}\");",
-            "\t ",
-            "\tGtk.StyleContext.add_provider_for_display(",
-            "\t\tthis.el.get_display(),",
-            "\t\tthis.css,",
-            "\t\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
-            "\t);",
-            "\t\t",
-            "\t\t ",
+            "  ",
             "\tthis.loading = true;",
             "",
-            "",
-            "",
+            " ",
             "\tvar attrs = new GtkSource.MarkAttributes();",
             "\t attrs.set_icon_name ( \"process-stop\");    ",
             "\tattrs.query_tooltip_text.connect(( mark) => {",
             ""
            ],
            "* pack" : "set_child",
-           "Gtk.CssProvider css" : "",
-           "bool loading" : false,
-           "bool zallow_node_scroll" : true,
+           "css_classes" : "{ \"code-editor\" }",
            "gboolean editable" : false,
            "gboolean show_line_marks" : true,
            "gboolean show_line_numbers" : true,
              "xtype" : "Buffer"
             },
             {
+             "# bool is_control" : false,
              "$ xns" : "Gtk",
+             "id" : "keystate",
              "listeners" : {
               "key_pressed" : [
                "(keyval, keycode, state) => {",
                "",
-               "\t",
+               "\tif (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {",
+               " \t\tthis.is_control = true;",
+               "\t}",
                "\t ",
                "\t if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {",
                "\t    GLib.debug(\"SAVE: ctrl-g  pressed\");",
                "\treturn false;",
                "}\t ",
                "\t"
+              ],
+              "key_released" : [
+               "(keyval, keycode, state) => {",
+               "",
+               "\t if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {",
+               " \t\tthis.is_control = false;",
+               "\t}",
+               "}",
+               ""
               ]
              },
              "xtype" : "EventControllerKey"
+            },
+            {
+             "# double distance" : "0.0f",
+             "$ xns" : "Gtk",
+             "Gtk.EventControllerScrollFlags flags" : "Gtk.EventControllerScrollFlags.VERTICAL",
+             "listeners" : {
+              "scroll" : [
+               "(dx, dy) => {",
+               "\tif (!_this.keystate.is_control) {",
+               "\t\treturn false;",
+               "\t}",
+               "\t//GLib.debug(\"scroll %f\",  dy);",
+               "\t",
+               "\tthis.distance += dy;",
+               "\t if (this.distance < -1) {",
+               "\t\tBuilderApplication.settings.editor_font_size ++;",
+               "\t\tthis.distance = 0;",
+               "\t}",
+               "\tif (this.distance > 1) {",
+               "\t\tBuilderApplication.settings.editor_font_size --;",
+               "\t\tthis.distance = 0;",
+               "\t}",
+               "",
+               "\treturn true;",
+               "}",
+               ""
+              ]
+             },
+             "xtype" : "EventControllerScroll"
             }
            ],
            "listeners" : {
             "    this.loading = true;",
             "    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);",
          "items" : [
           {
            "$ xns" : "Gtk",
-           "* init" : [
-            " ",
-            "this.css = new Gtk.CssProvider();",
-            "",
-            "this.css.load_from_string(\"",
-            "\t#gtkview-search-entry { font: 10px monospace ;}\"",
-            ");",
-            "",
-            "Gtk.StyleContext.add_provider_for_display(",
-            "\tthis.el.get_display(),",
-            "\tthis.css,",
-            "\tGtk.STYLE_PROVIDER_PRIORITY_APPLICATION",
-            ");",
-            "\t\t",
-            "",
-            ""
-           ],
            "Gtk.CssProvider css" : "",
            "bool hexpand" : true,
            "id" : "search_entry",
     "   \t\t}",
     "        ",
     "   \t\tvar xmlstr = JsRender.NodeToGlade.mungeFile( file);",
-    "   \t\tvar builder = new Gtk.Builder.from_string (xmlstr, xmlstr.length);",
+    "   \t\tvar builder = new Gtk.Builder();",
+    "   \t\ttry {",
+    "\t   \t\tif (!builder.add_from_string(xmlstr, xmlstr.length)) {",
+    "\t   \t\t\treturn;",
+    "\t\t\t}",
+    "\t\t} catch(GLib.Error e) {",
+    "\t\t\tGLib.debug(e.message);",
+    "\t\t\treturn;",
+    "\t\t}",
+    "   \t\t",
+    "",
     "   \t\tvar obj = (Gtk.Widget) builder.get_object(\"w\"+ file.tree.oid.to_string());",
     "   \t\t this.container.el.append(obj);",
     "\t    obj.show();",
     "",
     "",
     " ",
-    "\tGLib.debug(\"highlight errors\");\t\t ",
+    "\t//GLib.debug(\"highlight errors\");\t\t ",
     "",
     "\t // we should highlight other types of errors..",
     "",
     "\t\tbuf.remove_tag_by_name (\"ERR\", start, end);",
     "\t\tbuf.remove_tag_by_name (\"WARN\", start, end);",
     "\t\tbuf.remove_tag_by_name (\"DEPR\", start, end);",
-    "\t\tbuf.remove_source_marks (start, end, null);",
+    "\t\tbuf.remove_source_marks (start, end, \"ERR\");",
+    "\t\tbuf.remove_source_marks (start, end, \"WARN\");",
+    "\t\tbuf.remove_source_marks (start, end, \"DEPR\");",
     "\t\tthis.last_error_counter = file.error_counter ;",
-    "\t\tGLib.debug(\"higjlight has no errors\");",
+    "\t\t//GLib.debug(\"higjlight has no errors\");",
     "\t\treturn;",
     "\t}",
     " \tif (this.last_error_counter == file.error_counter) {",
     "\t",
     " ",
     "\t ",
-    "\tbuf.remove_source_marks (start, end, null);",
+    "\tbuf.remove_source_marks (start, end, \"ERR\");",
+    "\tbuf.remove_source_marks (start, end, \"WARN\");",
+    "\tbuf.remove_source_marks (start, end, \"DEPR\");",
     "\tbuf.remove_tag_by_name (\"ERR\", start, end);",
     "\tbuf.remove_tag_by_name (\"WARN\", start, end);",
     "\tbuf.remove_tag_by_name (\"DEPR\", start, end);",