Skip to content

Commit

Permalink
Bind share button sensitivity to at least one selected
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Apr 4, 2024
1 parent 8d6d258 commit 1917f63
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/ScreenCast/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ public class ScreenCast.Dialog : Granite.Dialog {
public SourceType source_types { get; construct; }
public bool allow_multiple { get; construct; }

private List<SelectionRow> window_rows;
private List<SelectionRow> 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<SelectionRow> window_rows;
private List<SelectionRow> monitor_rows;

construct {
window_rows = new List<SelectionRow> ();
monitor_rows = new List<SelectionRow> ();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1917f63

Please sign in to comment.