Skip to content

Commit

Permalink
Use newer add/remove list pattern (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Wootten authored Jun 15, 2022
1 parent 71bc030 commit d2dc37f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/PrinterList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ public class Printers.PrinterList : Gtk.Grid {

var actionbar = new Gtk.ActionBar ();
actionbar.get_style_context ().add_class (Gtk.STYLE_CLASS_INLINE_TOOLBAR);
var add_button = new Gtk.Button.from_icon_name ("list-add-symbolic", Gtk.IconSize.BUTTON);
add_button.tooltip_text = _("Add Printer…");
var remove_button = new Gtk.Button.from_icon_name ("list-remove-symbolic", Gtk.IconSize.BUTTON);
remove_button.tooltip_text = _("Remove Printer");
remove_button.sensitive = false;

var add_button = new Gtk.Button.with_label (_("Add Printer…")) {
always_show_image = true,
image = new Gtk.Image.from_icon_name ("list-add-symbolic", Gtk.IconSize.SMALL_TOOLBAR),
margin_top = 3,
margin_bottom = 3
};
add_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

actionbar.add (add_button);
actionbar.add (remove_button);
add (scrolled);
add (actionbar);

list_box.row_selected.connect ((row) => {
remove_button.sensitive = (row != null);
if (row != null) {
stack.set_visible_child (((PrinterRow) row).page);
}
Expand All @@ -77,14 +79,6 @@ public class Printers.PrinterList : Gtk.Grid {
add_dialog.present ();
});

remove_button.clicked.connect (() => {
var printer = ((PrinterRow)list_box.get_selected_row ()).printer;

var remove_dialog = new RemoveDialog (printer);
remove_dialog.transient_for = (Gtk.Window) get_toplevel ();
remove_dialog.present ();
});

unowned PrinterManager manager = PrinterManager.get_default ();
foreach (var printer in manager.get_printers ()) {
add_printer (printer);
Expand Down
16 changes: 16 additions & 0 deletions src/Widgets/PrinterRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public class Printers.PrinterRow : Gtk.ListBoxRow {
}

construct {
var remove_button = new Gtk.Button.from_icon_name ("edit-delete-symbolic", Gtk.IconSize.MENU) {
valign = Gtk.Align.CENTER,
halign = Gtk.Align.END,
hexpand = true,
tooltip_text = _("Remove this printer")
};
remove_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

name_label = new Gtk.Label (null);
name_label.get_style_context ().add_class ("h3");
name_label.ellipsize = Pango.EllipsizeMode.END;
Expand Down Expand Up @@ -62,6 +70,7 @@ public class Printers.PrinterRow : Gtk.ListBoxRow {
grid.attach (overlay, 0, 0, 1, 2);
grid.attach (name_label, 1, 0, 1, 1);
grid.attach (status_label, 1, 1, 1, 1);
grid.attach (remove_button, 2, 0, 2, 2);
add (grid);
page = new PrinterPage (printer);

Expand All @@ -72,6 +81,13 @@ public class Printers.PrinterRow : Gtk.ListBoxRow {

printer.enabled_changed.connect (update_status);
show_all ();

remove_button.clicked.connect (() => {
var remove_dialog = new RemoveDialog (printer);
remove_dialog.transient_for = (Gtk.Window) get_toplevel ();
remove_dialog.present ();
});

printer.deleted.connect (() => {
page.destroy ();
destroy ();
Expand Down

0 comments on commit d2dc37f

Please sign in to comment.