Skip to content

Commit

Permalink
Use is_empty() instead of length checks on collections (#407)
Browse files Browse the repository at this point in the history
* cleanup: Use is_empty() instead of length checks on collections

This is finally possible now that we no longer use our own generated Vapi files for GLib.

Signed-off-by: Evan Maddock <maddock.evan@vivaldi.net>

* cleanup: Make logic easier to read

Signed-off-by: Evan Maddock <maddock.evan@vivaldi.net>

---------

Signed-off-by: Evan Maddock <maddock.evan@vivaldi.net>
  • Loading branch information
EbonJaeger authored Aug 5, 2023
1 parent 991aa30 commit 00a9102
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/abomination/AppGroup.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Budgie.Abomination {
}

public Gdk.Pixbuf? get_icon() {
if (this.get_windows().length() == 0 || this.get_windows().nth_data(0).get_class_group() == null) {
if (this.get_windows().is_empty() || this.get_windows().nth_data(0).get_class_group() == null) {
return null;
}
return this.get_windows().nth_data(0).get_class_group().get_icon();
Expand Down
4 changes: 2 additions & 2 deletions src/abomination/abomination.vala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace Budgie.Abomination {
if (group != null) {
group.remove_window(window);

if (group.get_windows().length() == 0) { // remove empty group
if (group.get_windows().is_empty()) { // remove empty group
this.running_app_groups.remove(group.get_name());
debug("Removed group: %s", group.get_name());
}
Expand Down Expand Up @@ -257,7 +257,7 @@ namespace Budgie.Abomination {
new_group_windows.foreach((window) => {
group.remove_window(window);

if (group.get_windows().length() == 0) { // remove empty group
if (group.get_windows().is_empty()) { // remove empty group
this.running_app_groups.remove(old_group_name);
debug("Removed group: %s", old_group_name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/tabswitcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace Budgie {
private void on_hide() {
var selection = window_box.get_selected_children();
Gtk.FlowBoxChild? current = null;
if (selection != null && selection.length() > 0) {
if (selection != null && !selection.is_empty()) {
current = selection.nth_data(0) as Gtk.FlowBoxChild;
}

Expand Down
4 changes: 2 additions & 2 deletions src/panel/applets/icon-tasklist/IconButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ public class IconButton : Gtk.ToggleButton {
if (this.first_app == null) { // Not already set
List<weak Wnck.Window> class_windows = this.class_group.get_windows();

if (class_windows.length() != 0) { // Have windows in class group
if (!class_windows.is_empty()) { // Have windows in class group
Wnck.Window first_window = class_windows.nth_data(0);

if (first_window != null) {
Expand Down Expand Up @@ -860,7 +860,7 @@ public class IconButton : Gtk.ToggleButton {
windows = new List<unowned Wnck.Window>();
}

if (windows.length() == 0) {
if (windows.is_empty()) {
this.launch_app(Gtk.get_current_event_time());
} else if (this.app_info != null) {
string[] actions = this.app_info.list_actions();
Expand Down
6 changes: 3 additions & 3 deletions src/panel/applets/icon-tasklist/IconTasklistApplet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ public class IconTasklistApplet : Budgie.Applet {
if (!button.pinned) {
wrapper.gracefully_die();
} else {
// the button that we were going to replace is pinned, so instead of removing it from the view,
// the button that we were going to replace is pinned, so instead of removing it from the view,
// just remove its class group and first app, then update it visually. this prevents apps like
// the LibreOffice launcher from vanishing after a document is opened, despite being pinned
// the LibreOffice launcher from vanishing after a document is opened, despite being pinned
button.set_class_group(null);
button.first_app = null;
button.update();
Expand Down Expand Up @@ -396,7 +396,7 @@ public class IconTasklistApplet : Budgie.Applet {
}

if (button.get_class_group() != null) {
if (button.get_class_group().get_windows().length() == 0) { // when we don't have windows in the group anymore, it's safe to remove the group
if (button.get_class_group().get_windows().is_empty()) { // when we don't have windows in the group anymore, it's safe to remove the group
button.set_class_group(null);
} else if (!button.pinned) { // update button ID to use the one of the first app in group
Budgie.Abomination.RunningApp? first_app = abomination.get_first_app_of_group(button.get_class_group().get_name());
Expand Down
6 changes: 4 additions & 2 deletions src/panel/applets/places-indicator/PlacesIndicatorWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ public class PlacesIndicatorWindow : Budgie.Popover {
*/
private void check_expand() {
if (mounts_listbox.get_visible()) {
mounts_listbox.set_visible(mounts_listbox.get_children().length() != 0);
var has_children = !mounts_listbox.get_children().is_empty();
mounts_listbox.set_visible(has_children);
}

if (networks_listbox.get_visible()) {
networks_listbox.set_visible(networks_listbox.get_children().length() != 0);
var has_children = !networks_listbox.get_children().is_empty();
networks_listbox.set_visible(has_children);
}

if (places_section.get_visible()) {
Expand Down
2 changes: 1 addition & 1 deletion src/panel/applets/tray/DBusMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public class DBusMenu : Object {
var submenu = all_nodes.get(0).submenu;

// avoid showing empty menus, e.g. if an app provides invalid data (like jetbrains toolbox)
if (submenu.get_children().length() > 0) {
if (!submenu.get_children().is_empty()) {
submenu.popup_at_pointer(event);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/panel/applets/workspaces/WorkspaceItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace Workspaces {
}
});

if (rest_of_the_icons.get_children().length() == 0) {
if (rest_of_the_icons.get_children().is_empty()) {
popover.hide();
}

Expand Down
2 changes: 1 addition & 1 deletion src/panel/applets/workspaces/WorkspacesApplet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ namespace Workspaces {
});
int index = item.get_workspace().get_number();
unowned List<int>? dyn = dynamically_created_workspaces.find(index);
if (window_list.length() == 0 && dyn != null) {
if (window_list.is_empty() && dyn != null) {
dynamically_created_workspaces.remove(index);
dyn = dynamically_created_workspaces.find(index+1);
if (dyn == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/panel/manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ namespace Budgie {
Gdk.Rectangle win = Gdk.Rectangle();
Gdk.Rectangle pan = Gdk.Rectangle();

if (window == null && this.window_list.length() == 0) {
if (window == null && this.window_list.is_empty()) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/panel/panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ namespace Budgie {
for (var i = 0; i < regions.length; i++) {
Gtk.Box region = regions[i];

if (region.get_children().length() > 0) { // If this has a child
if (!region.get_children().is_empty()) { // If this has a child
if (!region.get_visible()) { // Not already visible
region.show(); // Ensure we show the panel specifically. Using show_all results in hidden widgets of children being shown, like Budgie Menu label. Only happens in weird cases like reset.
region.queue_draw(); // Ensure we queue a draw
Expand Down Expand Up @@ -834,7 +834,7 @@ namespace Budgie {
}

lock (expected_uuids) {
if (expected_uuids.length() == 0) {
if (expected_uuids.is_empty()) {
this.is_fully_loaded = true;
this.panel_loaded();
}
Expand Down
2 changes: 1 addition & 1 deletion src/raven/main_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace Budgie {

public void remove_widget_instance(Gtk.Bin? widget_instance) {
box.remove(widget_instance);
if (box.get_children().length() == 0) {
if (box.get_children().is_empty()) {
box.add(widget_placeholder);
}
requested_draw();
Expand Down
2 changes: 1 addition & 1 deletion src/raven/widgets/sound-input/sound_input.vala
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public class SoundInputRavenWidget : Budgie.RavenWidget {
* has_devices will check if we have devices associated with this type
*/
public bool has_devices() {
return (devices.size() != 0) && (mixer.get_cards().length() != 0);
return (devices.size() != 0) && (!mixer.get_cards().is_empty());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/raven/widgets/sound-output/sound_output.vala
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public class SoundOutputRavenWidget : Budgie.RavenWidget {
* has_devices will check if we have devices associated with this type
*/
public bool has_devices() {
return (devices.size() != 0) && (mixer.get_cards().length() != 0);
return (devices.size() != 0) && (!mixer.get_cards().is_empty());
}

/**
Expand Down Expand Up @@ -473,7 +473,7 @@ public class SoundOutputRavenWidget : Budgie.RavenWidget {

apps.steal(id); // Remove the apps

if (apps_listbox.get_children().length() == 0) {
if (apps_listbox.get_children().is_empty()) {
apps_listbox.hide();
apps_area.show();
}
Expand Down

0 comments on commit 00a9102

Please sign in to comment.