Commit be339041 authored by Colomban Wendling's avatar Colomban Wendling

Avoid creating undo entries when setting the same value

Simply don't set the value if it's the same, so it avoids creating an
undo entry and also avoids refreshing the theme.
parent 221dd11c
......@@ -57,6 +57,10 @@ class RGBA(Gdk.RGBA):
self.green * 0xff,
self.blue * 0xff)
# for some reason the __ne__ operator of Gdk.RGBA is broken
def __ne__(self, other):
return not (self == other)
class CellRendererColor(Gtk.CellRenderer):
__gproperties__ = {
......@@ -247,8 +251,11 @@ class AppWindow(Gtk.ApplicationWindow):
column.pack_start(renderer, True)
column.add_attribute(renderer, 'color', self.ROW_COLOR)
def on_key_cell_edited(cell, path, text, data=None):
self.store.set(self.store.get_iter(path), self.ROW_KEY, text)
def on_key_cell_edited(cell, path, new_text, data=None):
iter = self.store.get_iter(path)
old_text = self.store.get(iter, self.ROW_KEY)[0]
if old_text != new_text:
self.store.set(iter, self.ROW_KEY, new_text)
cell = builder.get_object('cellrenderertext1')
cell.connect('edited', on_key_cell_edited)
......@@ -270,10 +277,11 @@ class AppWindow(Gtk.ApplicationWindow):
def on_row_activated(self, view, path, column, data=None):
iter = self.store.get_iter(path)
old_rgba = RGBA(self.store.get(iter, self.ROW_COLOR)[0])
dialog = Gtk.ColorChooserDialog()
dialog.set_transient_for(self)
dialog.set_rgba(RGBA(self.store.get(iter, self.ROW_COLOR)[0]))
dialog.set_rgba(old_rgba)
answer = dialog.run()
if answer == Gtk.ResponseType.ACCEPT or \
answer == Gtk.ResponseType.APPLY or \
......@@ -285,6 +293,7 @@ class AppWindow(Gtk.ApplicationWindow):
# Apparently old GI was broken...
rgba = RGBA()
dialog.get_rgba(rgba)
if old_rgba != rgba:
self.store.set(iter, self.ROW_COLOR, rgba.to_string())
dialog.destroy()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment