From: Alan Date: Thu, 8 Feb 2024 10:34:00 +0000 (+0800) Subject: escape closes file dialog X-Git-Tag: release-5.0.3~15 X-Git-Url: http://git.roojs.org/?p=roobuilder;a=commitdiff_plain;h=173617f1a97bfc9af24e73f7da986fd192fd0747 escape closes file dialog --- diff --git a/src/Builder4/DialogFiles.bjs b/src/Builder4/DialogFiles.bjs index 880c48b6a..fb42372ba 100644 --- a/src/Builder4/DialogFiles.bjs +++ b/src/Builder4/DialogFiles.bjs @@ -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 image_cache" : "", "Project.Project selectedProject" : "", @@ -836,6 +872,36 @@ } ], "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" diff --git a/src/Builder4/DialogFiles.vala b/src/Builder4/DialogFiles.vala index 728d4c637..11e80aa05 100644 --- a/src/Builder4/DialogFiles.vala +++ b/src/Builder4/DialogFiles.vala @@ -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