~fabrixxm/confy-dev

Replace GTK Dialog with Adwaita Dialog v1 APPLIED

Michael Evans: 3
 Replace GTK Dialog with Adwaita Dialog
 Move delete button
 Rename save button

 7 files changed, 123 insertions(+), 97 deletions(-)
Thank you!
I'm just in the middle of rewriting the UI to replace deprecated
widgets :)
I'll review and test the patch asap!
Merged, thank you 👍️
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~fabrixxm/confy-dev/patches/55996/mbox | git am -3
Learn more about email & git

[PATCH 1/3] Replace GTK Dialog with Adwaita Dialog Export this patch

Switch from deprecated Gtk.Dialog to Adw.Dialog. Add signals to the
event editor for the different button actions.
---
This addresses https://todo.sr.ht/~fabrixxm/confy/22

 src/openwindow.blp              |   2 +-
 src/openwindow.py               |  38 +++++------
 src/widgets/eventeditdialog.blp | 114 ++++++++++++++++++--------------
 src/widgets/eventeditdialog.py  |  45 ++++++++-----
 4 files changed, 113 insertions(+), 86 deletions(-)

diff --git a/src/openwindow.blp b/src/openwindow.blp
index c79006a..8a7d864 100644
--- a/src/openwindow.blp
+++ b/src/openwindow.blp
@@ -4,7 +4,7 @@ using Adw 1;
template $ConfyOpenWindow : Adw.ApplicationWindow {
  icon-name: "net.kirgroup.confy";
  default-width: 600;
  default-height: 400;
  default-height: 440;

   Adw.ToastOverlay overlay {
     Gtk.Box {
diff --git a/src/openwindow.py b/src/openwindow.py
index e0103a9..40a6e90 100644
--- a/src/openwindow.py
+++ b/src/openwindow.py
@@ -118,29 +118,29 @@ class OpenWindow(Adw.ApplicationWindow):
        message.present()

    def edit_conf(self, conf, ok_cbk=None, del_cbk=None, can_cancel=True, can_delete=False):
        def _dialog_response(dialog, res):
            if res == EventEditDialog.OK:
                conf = d.get_conf()
                local.update_user_menu(conf.to_json())
                if conf.has_cache():
                    with conf.get_meta() as m:
                        m.title = conf.title
                        m.start = conf.start
                        m.end = conf.end
                self.update_list()
                if ok_cbk is not None:
                    ok_cbk(conf)
                d.destroy()
            elif res == EventEditDialog.DELETE:
                self.delete_conf(conf, lambda *_: d.destroy())
            else:
                d.destroy()
        def _save(dialog):
            conf = d.get_conf()
            local.update_user_menu(conf.to_json())
            if conf.has_cache():
                with conf.get_meta() as m:
                    m.title = conf.title
                    m.start = conf.start
                    m.end = conf.end
            self.update_list()
            if ok_cbk is not None:
                ok_cbk(conf)
            d.close()

        def _delete(dialog):
            self.delete_conf(conf, lambda *_: d.close())

        if conf is None:
            return
        d = EventEditDialog(self, conf, can_delete=can_delete, can_cancel=can_cancel)
        d.connect("response", _dialog_response)
        d.present()
        d.connect("save", _save)
        d.connect("delete", _delete)
        d.connect("cancel", lambda *args: d.close())
        d.present(self)

    def open_custom_url(self, *args):
        def _cbk(conf):
diff --git a/src/widgets/eventeditdialog.blp b/src/widgets/eventeditdialog.blp
index 3aca83c..b101f25 100644
--- a/src/widgets/eventeditdialog.blp
+++ b/src/widgets/eventeditdialog.blp
@@ -1,67 +1,79 @@
using Gtk 4.0;
using Adw 1;

template $ConfyEventEditDialog : Gtk.Dialog {
  can-focus: false;
  modal: true;
  destroy-with-parent: true;
  default-width: 640;
  default-height: 380;
template $ConfyEventEditDialog : Adw.Dialog {
  can-close: true;
  content-width: 640;
  content-height: 380;
  title: _("Edit event");

  [action response=ok]
  Gtk.Button ok_response {
    label: _("Ok");
    sensitive:  bind template.can-save;
  }
  Adw.ToolbarView {
    [top]
    Adw.HeaderBar {
      show-end-title-buttons: false;

  [action response=cancel]
  Gtk.Button cancel_response {
    label: _("Cancel");
    visible: bind template.can-cancel;
  }
      [start]
      Gtk.Button cancel {
        label: _("Cancel");
        clicked => $cancel_event();
        visible: bind template.can-cancel;
      }

  [action response=1]
  Gtk.Button delete_response {
    styles ['destructive-action']
    label: _("Delete");
    visible: bind template.can-delete;
  }
      [end]
      Gtk.Button save {
        styles ['suggested-action']
        label: _("Ok");
        sensitive:  bind template.can-save;
        clicked => $save_event();
      }

      [end]
      Gtk.Button delete {
        styles ['destructive-action']
        label: _("Delete");
        sensitive:  bind template.can-delete;
        clicked => $delete_event();
      }
    }

  Gtk.ScrolledWindow {
    Adw.Clamp {
      Gtk.Box {
        styles ['main-box']
        orientation: vertical;
    content: Gtk.ScrolledWindow {
      Adw.Clamp {
       Gtk.Box {
          styles ['main-box']
          orientation: vertical;

        Gtk.ListBox {
          styles ['boxed-list']
          Gtk.ListBox {
            styles ['boxed-list']

          Adw.EntryRow entry_url {
            title: _("URL");
            editable: false;
            changed => $validate_entry_required();
            realize => $validate_entry_required();
          }
          Adw.EntryRow entry_title {
            title: _("Title");
            changed => $validate_entry_required();
            realize => $validate_entry_required();
          }
          $ConfyDatePickerRow entry_start {
            title: _("Start");
            date_changed => $validate_date_order();
          }
          $ConfyDatePickerRow entry_end {
            title: _("End");
            date_changed => $validate_date_order();
            Adw.EntryRow entry_url {
              title: _("URL");
              editable: false;
              changed => $validate_entry_required();
              realize => $validate_entry_required();
            }
            Adw.EntryRow entry_title {
              title: _("Title");
              changed => $validate_entry_required();
              realize => $validate_entry_required();
            }
            $ConfyDatePickerRow entry_start {
              title: _("Start");
              date_changed => $validate_date_order();
            }
            $ConfyDatePickerRow entry_end {
              title: _("End");
              date_changed => $validate_date_order();
            }
            Adw.EntryRow entry_icon {
              title: _("Icon URL");
            }
          }
          Adw.EntryRow entry_icon {
            title: _("Icon URL");

          Gtk.Separator {
            styles ["spacer", "vertical"]
          }
        }
      }
    }
    };
  }

}
\ No newline at end of file
diff --git a/src/widgets/eventeditdialog.py b/src/widgets/eventeditdialog.py
index 559e67e..d193f8e 100644
--- a/src/widgets/eventeditdialog.py
+++ b/src/widgets/eventeditdialog.py
@@ -16,12 +16,13 @@
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


from gi.repository import GObject  
from gi.repository import Gtk  
from gi.repository import Adw
from gi.repository import GObject
from gi.repository import Gtk


@Gtk.Template(resource_path="/net/kirgroup/confy/widgets/eventeditdialog.ui")
class EventEditDialog(Gtk.Dialog):
class EventEditDialog(Adw.Dialog):
    __gtype_name__ = "ConfyEventEditDialog"

    CANCEL = Gtk.ResponseType.CANCEL
@@ -55,6 +56,18 @@ class EventEditDialog(Gtk.Dialog):
    def can_cancel_setter(self, value):
        self._can_cancel = value

    @GObject.Signal
    def save(self):
        pass

    @GObject.Signal
    def cancel(self):
        pass

    @GObject.Signal
    def delete(self):
        pass

    entry_url = Gtk.Template.Child()  # type: ignore
    entry_title = Gtk.Template.Child()  # type: ignore
    entry_start = Gtk.Template.Child()  # type: ignore
@@ -64,15 +77,8 @@ class EventEditDialog(Gtk.Dialog):
    def __init__(self, parent, conf, **kwargs):
        self._err = set()
        self.conf = conf
        opts = {
            'transient_for': parent,
            'use_header_bar': True,
        }
        opts.update(kwargs)
        super().__init__(**opts)

        self.set_default_response(self.OK)
        self.connect("response", self.on_response)
        super().__init__(**kwargs)

        self.setup_ui()


@@ -93,9 +99,18 @@ class EventEditDialog(Gtk.Dialog):
        elif 'icon' in self.conf.metadata:
            del self.conf.metadata['icon']

    def on_response(self, dialog, response):
        if response == self.OK:
            self._do_ok()
    @Gtk.Template.Callback()
    def save_event(self, entry):
        self._do_ok()
        self.emit("save")

    @Gtk.Template.Callback()
    def cancel_event(self, entry):
        self.emit("cancel")

    @Gtk.Template.Callback()
    def delete_event(self, entry):
        self.emit("delete")

    @Gtk.Template.Callback()
    def validate_entry_required(self, entry):
-- 
2.47.0

[PATCH 2/3] Move delete button Export this patch

Move the event editor delete button from the header bar to the bottom of
the editor. This is inspired by GNOME Calendar's event editor.
---
 src/openwindow.blp              |  2 +-
 src/widgets/eventeditdialog.blp | 17 ++++++++---------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/openwindow.blp b/src/openwindow.blp
index 8a7d864..6cc00ae 100644
--- a/src/openwindow.blp
+++ b/src/openwindow.blp
@@ -4,7 +4,7 @@ using Adw 1;
template $ConfyOpenWindow : Adw.ApplicationWindow {
  icon-name: "net.kirgroup.confy";
  default-width: 600;
  default-height: 440;
  default-height: 480;

   Adw.ToastOverlay overlay {
     Gtk.Box {
diff --git a/src/widgets/eventeditdialog.blp b/src/widgets/eventeditdialog.blp
index b101f25..bebaa09 100644
--- a/src/widgets/eventeditdialog.blp
+++ b/src/widgets/eventeditdialog.blp
@@ -4,7 +4,7 @@ using Adw 1;
template $ConfyEventEditDialog : Adw.Dialog {
  can-close: true;
  content-width: 640;
  content-height: 380;
  content-height: 420;
  title: _("Edit event");

  Adw.ToolbarView {
@@ -26,14 +26,6 @@ template $ConfyEventEditDialog : Adw.Dialog {
        sensitive:  bind template.can-save;
        clicked => $save_event();
      }

      [end]
      Gtk.Button delete {
        styles ['destructive-action']
        label: _("Delete");
        sensitive:  bind template.can-delete;
        clicked => $delete_event();
      }
    }

    content: Gtk.ScrolledWindow {
@@ -72,6 +64,13 @@ template $ConfyEventEditDialog : Adw.Dialog {
          Gtk.Separator {
            styles ["spacer", "vertical"]
          }

          Gtk.Button delete {
            styles ['destructive-action']
            label: _("Delete");
            clicked => $delete_event();
            visible: bind template.can-delete;
          }
        }
      }
    };
-- 
2.47.0

[PATCH 3/3] Rename save button Export this patch

Rename the event editor save button from "Ok" to "Save". This is gives a
stronger indication of the button action.
---
I am not sure how to update the translation files to get this new string in.
If you agree with the new wording, Iwould apprectiate your help with this.

 src/widgets/eventeditdialog.blp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/widgets/eventeditdialog.blp b/src/widgets/eventeditdialog.blp
index bebaa09..82b5912 100644
--- a/src/widgets/eventeditdialog.blp
+++ b/src/widgets/eventeditdialog.blp
@@ -22,7 +22,7 @@ template $ConfyEventEditDialog : Adw.Dialog {
      [end]
      Gtk.Button save {
        styles ['suggested-action']
        label: _("Ok");
        label: _("Save");
        sensitive:  bind template.can-save;
        clicked => $save_event();
      }
-- 
2.47.0
Thank you!
I'm just in the middle of rewriting the UI to replace deprecated
widgets :)
I'll review and test the patch asap!
Merged, thank you 👍️