[meld] sourceview: Expose a Boolean-ised text wrapping property
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] sourceview: Expose a Boolean-ised text wrapping property
- Date: Fri, 18 Jan 2019 21:29:20 +0000 (UTC)
commit c508896f43a87d8962da40b50256e643cae40990
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Jan 6 07:25:16 2019 +1000
sourceview: Expose a Boolean-ised text wrapping property
This exists so that we have a property that can be bound to a
PropertyAction for use in a popover menu toggle.
I experimented with *not* doing this and exposing three radio buttons to
match our three possible wrapping states, but it felt extremely clunky
in the UI and was hard to label.
The logic here for deciding what "enable wrapping" means here looks
pretty odd, but it comes down to:
* if we have some wrapping setting (i.e., wrap at characters) by
default then respect that when re-enabling the wrapping; and
* if we don't wrap by default then just use word wrapping.
since this was the behaviour that felt least-wrong to me.
meld/sourceview.py | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
---
diff --git a/meld/sourceview.py b/meld/sourceview.py
index 5004c81d..948b6ce4 100644
--- a/meld/sourceview.py
+++ b/meld/sourceview.py
@@ -123,6 +123,15 @@ class MeldSourceView(GtkSource.View):
type=bool, default=False, getter=get_show_line_numbers,
setter=set_show_line_numbers)
+ wrap_mode_bool = GObject.Property(
+ type=bool, default=False,
+ nick="Wrap mode (Boolean version)",
+ blurb=(
+ "Mirror of the wrap-mode GtkTextView property, reduced to "
+ "a single Boolean for UI ease-of-use."
+ ),
+ )
+
replaced_entries = (
# We replace the default GtkSourceView undo mechanism
(Gdk.KEY_z, Gdk.ModifierType.CONTROL_MASK),
@@ -228,6 +237,29 @@ class MeldSourceView(GtkSource.View):
def do_realize(self):
bind_settings(self)
+
+ def wrap_mode_from_bool(binding, from_value):
+ if from_value:
+ settings_mode = settings.get_enum('wrap-mode')
+ if settings_mode == Gtk.WrapMode.NONE:
+ mode = Gtk.WrapMode.WORD
+ else:
+ mode = settings_mode
+ else:
+ mode = Gtk.WrapMode.NONE
+ return mode
+
+ def wrap_mode_to_bool(binding, from_value):
+ return bool(from_value)
+
+ self.bind_property(
+ 'wrap-mode-bool', self, 'wrap-mode',
+ GObject.BindingFlags.BIDIRECTIONAL,
+ wrap_mode_from_bool,
+ wrap_mode_to_bool,
+ )
+ self.wrap_mode_bool = wrap_mode_to_bool(None, self.props.wrap_mode)
+
self.on_setting_changed(meldsettings, 'font')
self.on_setting_changed(meldsettings, 'style-scheme')
return GtkSource.View.do_realize(self)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]