escape closes file dialog
[roobuilder] / src / Builder4 / DialogFiles.bjs
index 880c48b..fb42372 100644 (file)
@@ -5,6 +5,42 @@
   {
    "# Xcls_MainWindow win" : "",
    "$ xns" : "Gtk",
+   "* init" : [
+    "{",
+    "\tvar ev = new Gtk.EventControllerKey();",
+    "\tev.propagation_phase = Gtk.PropagationPhase.CAPTURE;",
+    "\t// my vars (dec)",
+    "",
+    "\t// set gobject values",
+    "",
+    "\t//listeners",
+    "\tev.key_released.connect( (keyval, keycode, state) => {",
+    "\t",
+    "\t\t// GLib.debug(\"key pressed %d\", (int)keycode);",
+    "\t\tif (keycode != 9) {",
+    "\t\t\treturn   ;",
+    "\t\t}",
+    "\t\tif (BuilderApplication.windows.size < 2 && ",
+    "\t\t\t_this.win.windowstate.file == null",
+    "\t\t) { ",
+    "\t\t\tBuilderApplication.singleton(null).quit();",
+    "\t\t\treturn  ;",
+    "\t\t}",
+    "\t",
+    "\t\t_this.el.hide();",
+    "\t\t",
+    "\t\t if (_this.win.windowstate.file == null) {\t\t ",
+    "\t\t\tBuilderApplication.removeWindow(_this.win);",
+    "\t\t\t    ",
+    "\t\t}",
+    "\t",
+    "\t\treturn  ;",
+    "\t});",
+    "\tev.ref(); //?? needed?",
+    "\t(this.el as Gtk.Widget).add_controller(ev);",
+    "}",
+    ""
+   ],
    "Gdk.Pixbuf missing_thumb_pixbuf" : "",
    "Gee.HashMap<string,Gdk.Pixbuf> image_cache" : "",
    "Project.Project selectedProject" : "",
           }
          ],
          "xtype" : "Paned"
+        },
+        {
+         "$ xns" : "Gtk",
+         "listeners" : {
+          "key_pressed" : [
+           "(keyval, keycode, state) => {",
+           "",
+           "\tif (keycode != Gdk.Key.Escape) {",
+           "\t\treturn true;",
+           "\t}",
+           "\tif (BuilderApplication.windows.size < 2 && ",
+           "\t\t_this.win.windowstate.file == null",
+           "\t) { ",
+           "\t\tBuilderApplication.singleton(null).quit();",
+           "\t\treturn true;",
+           "\t}",
+           "",
+           "\t_this.el.hide();",
+           "\t",
+           "\t if (_this.win.windowstate.file == null) {\t\t ",
+           "\t\tBuilderApplication.removeWindow(_this.win);",
+           "\t\t    ",
+           "\t}",
+           "",
+           "\treturn true;",
+           "}",
+           ""
+          ]
+         },
+         "xtype" : "EventControllerKey"
         }
        ],
        "xtype" : "Paned"