From c9e3306f3a430ed15155ac45ef097f9d7dbafe03 Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 14 Feb 2024 16:41:48 +0800 Subject: [PATCH] Fix #8033 - text size zoom --- src/Builder4/Editor.bjs | 45 ++++++++++++++++++++- src/Builder4/Editor.vala | 71 ++++++++++++++++++++++++++++++--- src/Builder4/GtkView.bjs | 44 +++++++++++++++++++- src/Builder4/GtkView.vala | 70 +++++++++++++++++++++++++++++--- src/Builder4/WindowRooView.bjs | 45 ++++++++++++++++++++- src/Builder4/WindowRooView.vala | 71 ++++++++++++++++++++++++++++++--- 6 files changed, 325 insertions(+), 21 deletions(-) diff --git a/src/Builder4/Editor.bjs b/src/Builder4/Editor.bjs index 0033aa4c4..9d335fd75 100644 --- a/src/Builder4/Editor.bjs +++ b/src/Builder4/Editor.bjs @@ -467,12 +467,26 @@ ] }, { + "# bool is_control" : false, "$ xns" : "Gtk", + "id" : "keystate", "listeners" : { + "key_pressed" : [ + "(keyval, keycode, state) => {", + "", + " \tif (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {", + " \t\tthis.is_control = true;", + "\t}", + "\treturn false;", + "}", + "" + ], "key_released" : [ "(keyval, keycode, state) => {", "", - " ", + " \t if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {", + " \t\tthis.is_control = false;", + "\t}", " if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {", " GLib.debug(\"SAVE: ctrl-S pressed\");", " _this.saveContents();", @@ -518,6 +532,35 @@ ] }, "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;", + "\tif (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" : { diff --git a/src/Builder4/Editor.vala b/src/Builder4/Editor.vala index 6d7d33440..0a52e8766 100644 --- a/src/Builder4/Editor.vala +++ b/src/Builder4/Editor.vala @@ -17,6 +17,7 @@ public class Editor : Object public Xcls_RightEditor RightEditor; public Xcls_view view; public Xcls_buffer buffer; + public Xcls_keystate keystate; public Xcls_search_entry search_entry; public Xcls_search_results search_results; public Xcls_nextBtn nextBtn; @@ -642,9 +643,11 @@ public class Editor : Object this.el.highlight_current_line = true; new Xcls_buffer( _this ); this.el.buffer = _this.buffer.el; - var child_2 = new Xcls_EventControllerKey10( _this ); - child_2.ref(); - this.el.add_controller( child_2.el ); + new Xcls_keystate( _this ); + this.el.add_controller( _this.keystate.el ); + var child_3 = new Xcls_EventControllerScroll63( _this ); + child_3.ref(); + this.el.add_controller( child_3.el ); // init method @@ -1075,28 +1078,33 @@ public class Editor : Object } } - public class Xcls_EventControllerKey10 : Object + public class Xcls_keystate : Object { public Gtk.EventControllerKey el; private Editor _this; // my vars (def) + public bool is_control; // ctor - public Xcls_EventControllerKey10(Editor _owner ) + public Xcls_keystate(Editor _owner ) { _this = _owner; + _this.keystate = this; this.el = new Gtk.EventControllerKey(); // my vars (dec) + this.is_control = false; // set gobject values //listeners this.el.key_released.connect( (keyval, keycode, state) => { - + if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) { + this.is_control = false; + } if (keyval == Gdk.Key.s && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) { GLib.debug("SAVE: ctrl-S pressed"); _this.saveContents(); @@ -1138,6 +1146,57 @@ public class Editor : Object }); + this.el.key_pressed.connect( (keyval, keycode, state) => { + + if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) { + this.is_control = true; + } + return false; + }); + } + + // user defined functions + } + + public class Xcls_EventControllerScroll63 : Object + { + public Gtk.EventControllerScroll el; + private Editor _this; + + + // my vars (def) + public double distance; + + // ctor + public Xcls_EventControllerScroll63(Editor _owner ) + { + _this = _owner; + this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL ); + + // my vars (dec) + this.distance = 0.0f; + + // set gobject values + + //listeners + this.el.scroll.connect( (dx, dy) => { + if (!_this.keystate.is_control) { + return false; + } + //GLib.debug("scroll %f", dy); + + this.distance += dy; + if (this.distance < 1) { + BuilderApplication.settings.editor_font_size ++; + this.distance = 0; + } + if (this.distance > -1) { + BuilderApplication.settings.editor_font_size --; + this.distance = 0; + } + + return true; + }); } // user defined functions diff --git a/src/Builder4/GtkView.bjs b/src/Builder4/GtkView.bjs index 34a781888..7a8873195 100644 --- a/src/Builder4/GtkView.bjs +++ b/src/Builder4/GtkView.bjs @@ -198,12 +198,16 @@ "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\");", @@ -219,9 +223,47 @@ "\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;", + "\tif (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" : { diff --git a/src/Builder4/GtkView.vala b/src/Builder4/GtkView.vala index c3f9c0e8e..dfed0168c 100644 --- a/src/Builder4/GtkView.vala +++ b/src/Builder4/GtkView.vala @@ -20,6 +20,7 @@ public class Xcls_GtkView : Object public Xcls_sourceviewscroll sourceviewscroll; public Xcls_sourceview sourceview; public Xcls_buffer buffer; + public Xcls_keystate keystate; public Xcls_search_entry search_entry; public Xcls_search_results search_results; public Xcls_nextBtn nextBtn; @@ -640,9 +641,11 @@ public class Xcls_GtkView : Object this.el.tab_width = 4; new Xcls_buffer( _this ); this.el.set_buffer ( _this.buffer.el ); - var child_2 = new Xcls_EventControllerKey11( _this ); - child_2.ref(); - this.el.add_controller( child_2.el ); + new Xcls_keystate( _this ); + this.el.add_controller( _this.keystate.el ); + var child_3 = new Xcls_EventControllerScroll37( _this ); + child_3.ref(); + this.el.add_controller( child_3.el ); // init method @@ -953,28 +956,39 @@ public class Xcls_GtkView : Object // user defined functions } - public class Xcls_EventControllerKey11 : Object + public class Xcls_keystate : Object { public Gtk.EventControllerKey el; private Xcls_GtkView _this; // my vars (def) + public bool is_control; // ctor - public Xcls_EventControllerKey11(Xcls_GtkView _owner ) + public Xcls_keystate(Xcls_GtkView _owner ) { _this = _owner; + _this.keystate = this; this.el = new Gtk.EventControllerKey(); // my vars (dec) + this.is_control = false; // set gobject values //listeners + this.el.key_released.connect( (keyval, keycode, state) => { + + if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) { + this.is_control = false; + } + }); this.el.key_pressed.connect( (keyval, keycode, state) => { - + if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) { + this.is_control = true; + } if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) { GLib.debug("SAVE: ctrl-g pressed"); @@ -994,6 +1008,50 @@ public class Xcls_GtkView : Object // user defined functions } + public class Xcls_EventControllerScroll37 : Object + { + public Gtk.EventControllerScroll el; + private Xcls_GtkView _this; + + + // my vars (def) + public double distance; + + // ctor + public Xcls_EventControllerScroll37(Xcls_GtkView _owner ) + { + _this = _owner; + this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL ); + + // my vars (dec) + this.distance = 0.0f; + + // set gobject values + + //listeners + this.el.scroll.connect( (dx, dy) => { + if (!_this.keystate.is_control) { + return false; + } + //GLib.debug("scroll %f", dy); + + this.distance += dy; + if (this.distance < 1) { + BuilderApplication.settings.editor_font_size ++; + this.distance = 0; + } + if (this.distance > -1) { + BuilderApplication.settings.editor_font_size --; + this.distance = 0; + } + + return true; + }); + } + + // user defined functions + } + public class Xcls_Box12 : Object diff --git a/src/Builder4/WindowRooView.bjs b/src/Builder4/WindowRooView.bjs index b8e0f5d05..71df426b0 100644 --- a/src/Builder4/WindowRooView.bjs +++ b/src/Builder4/WindowRooView.bjs @@ -722,13 +722,17 @@ ] }, { + "# bool is_control" : false, "$ xns" : "Gtk", "* pack" : "add_controller", + "id" : "keystate", "listeners" : { "key_pressed" : [ "(keyval, keycode, state) => {", "", - " ", + " \tif (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {", + " \t\tthis.is_control = true;", + "\t}", " ", " \tif (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {", "\t GLib.debug(\"SAVE: ctrl-g pressed\");", @@ -750,9 +754,48 @@ " ", "}", "" + ], + "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;", + "\tif (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" : { diff --git a/src/Builder4/WindowRooView.vala b/src/Builder4/WindowRooView.vala index e017fea6a..1d028a5ab 100644 --- a/src/Builder4/WindowRooView.vala +++ b/src/Builder4/WindowRooView.vala @@ -23,6 +23,7 @@ public class Xcls_WindowRooView : Object public Xcls_sourceviewscroll sourceviewscroll; public Xcls_sourceview sourceview; public Xcls_buffer buffer; + public Xcls_keystate keystate; public Xcls_search_entry search_entry; public Xcls_search_results search_results; public Xcls_nextBtn nextBtn; @@ -1097,9 +1098,11 @@ public class Xcls_WindowRooView : Object this.el.css_classes = { "code-editor" }; new Xcls_buffer( _this ); this.el.set_buffer ( _this.buffer.el ); - var child_2 = new Xcls_EventControllerKey16( _this ); - child_2.ref(); - this.el.add_controller ( child_2.el ); + new Xcls_keystate( _this ); + this.el.add_controller ( _this.keystate.el ); + var child_3 = new Xcls_EventControllerScroll32( _this ); + child_3.ref(); + this.el.add_controller( child_3.el ); // init method @@ -1639,28 +1642,40 @@ public class Xcls_WindowRooView : Object } } - public class Xcls_EventControllerKey16 : Object + public class Xcls_keystate : Object { public Gtk.EventControllerKey el; private Xcls_WindowRooView _this; // my vars (def) + public bool is_control; // ctor - public Xcls_EventControllerKey16(Xcls_WindowRooView _owner ) + public Xcls_keystate(Xcls_WindowRooView _owner ) { _this = _owner; + _this.keystate = this; this.el = new Gtk.EventControllerKey(); // my vars (dec) + this.is_control = false; // set gobject values //listeners + this.el.key_released.connect( (keyval, keycode, state) => { + + + if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) { + this.is_control = false; + } + }); this.el.key_pressed.connect( (keyval, keycode, state) => { - + if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) { + this.is_control = true; + } if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) { GLib.debug("SAVE: ctrl-g pressed"); @@ -1686,6 +1701,50 @@ public class Xcls_WindowRooView : Object // user defined functions } + public class Xcls_EventControllerScroll32 : Object + { + public Gtk.EventControllerScroll el; + private Xcls_WindowRooView _this; + + + // my vars (def) + public double distance; + + // ctor + public Xcls_EventControllerScroll32(Xcls_WindowRooView _owner ) + { + _this = _owner; + this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL ); + + // my vars (dec) + this.distance = 0.0f; + + // set gobject values + + //listeners + this.el.scroll.connect( (dx, dy) => { + if (!_this.keystate.is_control) { + return false; + } + //GLib.debug("scroll %f", dy); + + this.distance += dy; + if (this.distance < 1) { + BuilderApplication.settings.editor_font_size ++; + this.distance = 0; + } + if (this.distance > -1) { + BuilderApplication.settings.editor_font_size --; + this.distance = 0; + } + + return true; + }); + } + + // user defined functions + } + public class Xcls_Box17 : Object -- 2.39.2