From 1917f63563daeaecb5dbf0f65af629bcc958f6c3 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Thu, 4 Apr 2024 22:52:01 +0200 Subject: [PATCH] Bind share button sensitivity to at least one selected --- src/ScreenCast/Dialog.vala | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/ScreenCast/Dialog.vala b/src/ScreenCast/Dialog.vala index a4d46828..1796184c 100644 --- a/src/ScreenCast/Dialog.vala +++ b/src/ScreenCast/Dialog.vala @@ -2,13 +2,17 @@ public class ScreenCast.Dialog : Granite.Dialog { public SourceType source_types { get; construct; } public bool allow_multiple { get; construct; } + private List window_rows; + private List monitor_rows; + + private Gtk.Widget accept_button; + + private int n_selected = 0; + public Dialog (SourceType source_types, bool allow_multiple) { Object (source_types: source_types, allow_multiple: allow_multiple); } - private List window_rows; - private List monitor_rows; - construct { window_rows = new List (); monitor_rows = new List (); @@ -39,13 +43,29 @@ public class ScreenCast.Dialog : Granite.Dialog { group = row.check_button; list_box.append (row); + + row.notify["selected"].connect (() => { + if (row.selected) { + n_selected++; + } else { + n_selected--; + } + + update_sensitivity (); + }); } } get_content_area ().append (list_box); add_button (_("Cancel"), Gtk.ResponseType.CANCEL); - add_button (_("Share"), Gtk.ResponseType.ACCEPT).add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION); + accept_button = add_button (_("Share"), Gtk.ResponseType.ACCEPT); + accept_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION); + accept_button.sensitive = false; + } + + private void update_sensitivity () { + accept_button.sensitive = n_selected > 0; } private void header_func (Gtk.ListBoxRow row, Gtk.ListBoxRow? prev) {