escape closes file dialog
authorAlan <alan@roojs.com>
Thu, 8 Feb 2024 10:34:00 +0000 (18:34 +0800)
committerAlan <alan@roojs.com>
Thu, 8 Feb 2024 10:34:00 +0000 (18:34 +0800)
src/Builder4/DialogFiles.bjs
src/Builder4/DialogFiles.vala

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"
index 728d4c6..11e80aa 100644 (file)
@@ -71,6 +71,42 @@ public class DialogFiles : Object
                this.el.child = child_1.el;
                var child_2 = new Xcls_HeaderBar43( _this );
                this.el.titlebar = child_2.el;
+
+               // init method
+
+               {
+                       var ev = new Gtk.EventControllerKey();
+                       ev.propagation_phase = Gtk.PropagationPhase.CAPTURE;
+                       // my vars (dec)
+               
+                       // set gobject values
+               
+                       //listeners
+                       ev.key_released.connect( (keyval, keycode, state) => {
+                       
+                               // GLib.debug("key pressed %d", (int)keycode);
+                               if (keycode != 9) {
+                                       return   ;
+                               }
+                               if (BuilderApplication.windows.size < 2 && 
+                                       _this.win.windowstate.file == null
+                               ) { 
+                                       BuilderApplication.singleton(null).quit();
+                                       return  ;
+                               }
+                       
+                               _this.el.hide();
+                               
+                                if (_this.win.windowstate.file == null) {               
+                                       BuilderApplication.removeWindow(_this.win);
+                                           
+                               }
+                       
+                               return  ;
+                       });
+                       ev.ref(); //?? needed?
+                       (this.el as Gtk.Widget).add_controller(ev);
+               }
        }
 
        // user defined functions
@@ -280,6 +316,9 @@ public class DialogFiles : Object
                        this.el.start_child = _this.projectscroll.el;
                        new Xcls_filepane( _this );
                        this.el.end_child = _this.filepane.el;
+                       var child_3 = new Xcls_EventControllerKey411( _this );
+                       child_3.ref();
+                       this.el.add_controller(  child_3.el );
                }
 
                // user defined functions
@@ -1693,6 +1732,51 @@ public class DialogFiles : Object
 
 
 
+       public class Xcls_EventControllerKey411 : Object
+       {
+               public Gtk.EventControllerKey el;
+               private DialogFiles  _this;
+
+
+                       // my vars (def)
+
+               // ctor
+               public Xcls_EventControllerKey411(DialogFiles _owner )
+               {
+                       _this = _owner;
+                       this.el = new Gtk.EventControllerKey();
+
+                       // my vars (dec)
+
+                       // set gobject values
+
+                       //listeners
+                       this.el.key_pressed.connect( (keyval, keycode, state) => {
+                       
+                               if (keycode != Gdk.Key.Escape) {
+                                       return true;
+                               }
+                               if (BuilderApplication.windows.size < 2 && 
+                                       _this.win.windowstate.file == null
+                               ) { 
+                                       BuilderApplication.singleton(null).quit();
+                                       return true;
+                               }
+                       
+                               _this.el.hide();
+                               
+                                if (_this.win.windowstate.file == null) {               
+                                       BuilderApplication.removeWindow(_this.win);
+                                           
+                               }
+                       
+                               return true;
+                       });
+               }
+
+               // user defined functions
+       }
+
 
 
        public class Xcls_HeaderBar43 : Object