Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PartitionMenu: write check_values as single function with early returns #815

Merged
merged 9 commits into from
Oct 1, 2024
47 changes: 17 additions & 30 deletions src/Widgets/PartitionMenu.vala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public class Installer.PartitionMenu : Gtk.Popover {
}
}
use_as.set_active (select);
update_values (set_mount);
check_values (set_mount);
} else {
unset_mount (partition_path);
partition_bar.icon = null;
Expand Down Expand Up @@ -250,18 +250,21 @@ public class Installer.PartitionMenu : Gtk.Popover {
}

private void check_values (SetMount set_mount) {
if (values_ready ()) {
update_values (set_mount);
if (!use_partition.active) {
partition_bar.icon = null;
partition_bar.tooltip_text = null;
return;
}

if (use_as.active == 4 && !custom.text.has_prefix ("/")) {
partition_bar.icon = new ThemedIcon ("dialog-warning-symbolic");
partition_bar.tooltip_text = _("Custom value must begin with /");
return;
}
}

private void update_values (SetMount set_mount) {
var mount = get_mount ();
var filesystem = mount == "swap"
? InstallerDaemon.FileSystem.SWAP
: get_file_system ();
var filesystem = mount == "swap" ? InstallerDaemon.FileSystem.SWAP : get_file_system ();

string? error = null;
try {
set_mount (new Installer.Mount (
partition_path,
Expand All @@ -273,16 +276,12 @@ public class Installer.PartitionMenu : Gtk.Popover {
filesystem,
this
));
} catch (GLib.Error why) {
error = why.message;
}

partition_bar.icon = new ThemedIcon (
error == null ? "process-completed-symbolic" : "dialog-warning-symbolic"
);

if (error != null) {
partition_bar.tooltip_text = error;
partition_bar.icon = new ThemedIcon ("process-completed-symbolic");
partition_bar.tooltip_text = null;
} catch (GLib.Error e) {
partition_bar.icon = new ThemedIcon ("dialog-warning-symbolic");
partition_bar.tooltip_text = e.message;
danirabbit marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -327,16 +326,4 @@ public class Installer.PartitionMenu : Gtk.Popover {
return custom.get_text ();
}
}

private bool values_ready () {
return use_partition.active && (!custom_set () || custom_valid ());
}

private bool custom_set () {
return use_as.get_active () == 4;
}

private bool custom_valid () {
return custom.get_text ().has_prefix ("/");
}
}