diff --git a/NEWS b/NEWS index 5b82320..7d8db4b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +v11.1 - April 2021 +================== + +* Not to erase the text when pressing "Escape" #60 + v11 - February 2021 =================== diff --git a/README.md b/README.md index 1741896..774f8b7 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Then save your beautiful work by taking a screenshot. Intersect two lines and curve the second thanks to the `Ctrl` key. - ![How to draw an arrow](https://framagit.org/abakkk/DrawOnYourScreen/uploads/af8f96d33cfeff49bb922a1ef9f4a4ce/arrow-screencast.webm) + ![How to draw an arrow](https://framagit.org/abakkk/DrawOnYourScreen/-/raw/media/arrow.webm) * Duplicate an element: diff --git a/area.js b/area.js index f368a76..80ce3cf 100644 --- a/area.js +++ b/area.js @@ -845,9 +845,6 @@ var DrawingArea = new Lang.Class({ this.textEntry.clutterText.set_single_line_mode(false); this.textEntry.clutterText.set_activatable(false); - this.textEntry.clutterText.connect('activate', (clutterText) => { - this._stopWriting(); - }); let showCursorOnPositionChanged = true; this.textEntry.clutterText.connect('text-changed', clutterText => { @@ -868,7 +865,6 @@ var DrawingArea = new Lang.Class({ this.textEntry.clutterText.connect('key-press-event', (clutterText, event) => { if (event.get_key_symbol() == Clutter.KEY_Escape) { - this.currentElement.text = ""; this._stopWriting(); return Clutter.EVENT_STOP; } diff --git a/helper.js b/helper.js index 8616adb..e0eab8d 100644 --- a/helper.js +++ b/helper.js @@ -73,8 +73,13 @@ var DrawingHelper = new Lang.Class({ }, _updateHelpKeyLabel: function() { - let [keyval, mods] = Gtk.accelerator_parse(Me.internalShortcutSettings.get_strv('toggle-help')[0] || ''); - this._helpKeyLabel = Gtk.accelerator_get_label(keyval, mods); + try { + let [keyval, mods] = Gtk.accelerator_parse(Me.internalShortcutSettings.get_strv('toggle-help')[0] || ''); + this._helpKeyLabel = Gtk.accelerator_get_label(keyval, mods); + } catch(e) { + logError(e); + this._helpKeyLabel = " "; + } }, get helpKeyLabel() { @@ -172,10 +177,11 @@ var DrawingHelper = new Lang.Class({ this.set_position(Math.floor(this.monitor.width / 2 - this.width / 2), Math.floor(this.monitor.height / 2 - this.height / 2)); + // St.PolicyType: GS 3.32+ if (this.height == maxHeight) - this.vscrollbar_policy = Gtk.PolicyType.ALWAYS; + this.vscrollbar_policy = St.PolicyType ? St.PolicyType.ALWAYS : Gtk.PolicyType.ALWAYS; else - this.vscrollbar_policy = Gtk.PolicyType.NEVER; + this.vscrollbar_policy = St.PolicyType ? St.PolicyType.NEVER : Gtk.PolicyType.NEVER; if (Tweener) { Tweener.removeTweens(this); diff --git a/metadata.json b/metadata.json index 1272b75..c346f90 100644 --- a/metadata.json +++ b/metadata.json @@ -19,5 +19,5 @@ "3.38", "40" ], - "version": 11 + "version": 11.1 } diff --git a/prefs.js b/prefs.js index 2c93299..a0db58f 100644 --- a/prefs.js +++ b/prefs.js @@ -65,19 +65,10 @@ const setAccessibleDescription = function(widget, description) { }; const getChildrenOf = function(widget) { - if (IS_GTK3) { + if (IS_GTK3) return widget.get_children(); - } else { - let listModel = widget.observe_children(); - let i = 0; - let children = []; - let child; - while (!!(child = listModel.get_item(i))) { - children.push(child); - i++; - } - return children; - } + else + return [...widget]; }; function init() { @@ -612,7 +603,7 @@ const PrefRow = new GObject.Class({ } }); -const PixelSpinButton = new GObject.Class(Object.assign({ +const PixelSpinButton = new GObject.Class({ Name: `${UUID}-PixelSpinButton`, Extends: Gtk.SpinButton, Properties: { @@ -638,22 +629,24 @@ const PixelSpinButton = new GObject.Class(Object.assign({ this.adjustment.set_page_increment(step * 10); }, - vfunc_constructed() { - this.parent(); + on_output: function() { + this.text = _("%f px").format(Number(this.value).toFixed(2)); + return true; + }, + + // Prevent accidental scrolling (GTK 3). + on_scroll_event: function(event) { + if (this.has_focus) { + try { + GObject.signal_chain_from_overridden([this, event], false); + } catch(e) { } + + return Gdk.EVENT_STOP; + } - // No virtual functions with Gtk4 :/. - // Add 'px' unit. - this.connect('output', spinButton => { - this.text = _("%f px").format(Number(spinButton.value).toFixed(2)); - return true; - }); + return Gdk.EVENT_PROPAGATE; } -}, IS_GTK3 ? { - // Prevent accidental scrolling. - vfunc_scroll_event: function(event) { - return this.has_focus ? this.parent(event) : Gdk.EVENT_PROPAGATE; - } -} : {})); +}); // A color button that can be easily bound with a color string setting. const ColorStringButton = new GObject.Class({ @@ -676,20 +669,15 @@ const ColorStringButton = new GObject.Class({ this.set_rgba(newRgba); }, - vfunc_constructed() { - this.parent(); + on_color_set: function() { + let oldRgba = new Gdk.RGBA(); + oldRgba.parse(this.color_string); - // No virtual functions with Gtk4 :/. // Do nothing if the new color is equivalent to the old color (e.g. "black" and "rgb(0,0,0)"). - this.connect('color-set', colorButton => { - let oldRgba = new Gdk.RGBA(); - oldRgba.parse(colorButton.color_string); - - if (!this.rgba.equal(oldRgba)) { - this._color_string = colorButton.rgba.to_string(); - this.notify('color-string'); - } - }); + if (!this.rgba.equal(oldRgba)) { + this._color_string = this.rgba.to_string(); + this.notify('color-string'); + } } });