diff --git a/src/Utils.vala b/src/Utils.vala index b2d03cd5..b9c07d17 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -85,7 +85,14 @@ namespace Network { public enum ItemType { DEVICE = 0, VIRTUAL, - INVALID + INVALID; + public string to_string () { + switch (this) { + case DEVICE: return _("Devices"); + case VIRTUAL: return _("Virtual"); + default: return _("Invalid"); + } + } } public static string state_to_string (NM.DeviceState state) { diff --git a/src/Widgets/DeviceList.vala b/src/Widgets/DeviceList.vala index c3793877..1a3f6bc6 100644 --- a/src/Widgets/DeviceList.vala +++ b/src/Widgets/DeviceList.vala @@ -21,8 +21,6 @@ namespace Network.Widgets { public class DeviceList : Gtk.ListBox { public signal void show_no_devices (bool show); - private Gtk.Label virtual_l; - private Gtk.Label devices_l; private DeviceItem proxy; private DeviceItem vpn; @@ -30,16 +28,6 @@ namespace Network.Widgets { selection_mode = Gtk.SelectionMode.SINGLE; activate_on_single_click = true; - virtual_l = new Gtk.Label (_("Virtual")) { - halign = Gtk.Align.START - }; - virtual_l.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); - - devices_l = new Gtk.Label (_("Devices")) { - halign = Gtk.Align.START - }; - devices_l.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); - set_header_func (update_headers); set_sort_func (sort_items); @@ -140,28 +128,10 @@ namespace Network.Widgets { private void update_headers (Gtk.ListBoxRow row, Gtk.ListBoxRow? before = null) { unowned DeviceItem row_item = (DeviceItem) row; unowned DeviceItem? before_item = (DeviceItem) before; - if (row_item.item_type == Utils.ItemType.VIRTUAL) { - if (before_item != null && before_item.item_type == Utils.ItemType.VIRTUAL) { - row.set_header (null); - return; - } - if (virtual_l.get_parent () != null) { - virtual_l.unparent (); - } - - row.set_header (virtual_l); - } else if (row_item.item_type == Utils.ItemType.DEVICE) { - if (before_item != null && before_item.item_type == Utils.ItemType.DEVICE) { - row.set_header (null); - return; - } - - if (devices_l.get_parent () != null) { - devices_l.unparent (); - } - row.set_header (devices_l); + if (before_item == null || row_item.item_type != before_item.item_type) { + row.set_header (new Granite.HeaderLabel (row_item.item_type.to_string ())); } else { row.set_header (null); }