From 540ed5c80043ab00e3e0e56ee55446eab9babdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 24 Sep 2024 10:31:34 -0700 Subject: [PATCH 1/5] PartitionMenu: write check values as single method with early returns --- src/Widgets/PartitionMenu.vala | 69 ++++++++++++++-------------------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index b10a319ec..ac4ef47a7 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -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; @@ -250,39 +250,38 @@ 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; + return; } - } - - private void update_values (SetMount set_mount) { - var mount = get_mount (); - var filesystem = mount == "swap" - ? InstallerDaemon.FileSystem.SWAP - : get_file_system (); - string? error = null; - try { - set_mount (new Installer.Mount ( - partition_path, - parent_disk, - mount, - partition_bar.get_partition_size (), - (format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0) - + (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), - filesystem, - this - )); - } catch (GLib.Error why) { - error = why.message; + if (use_as.active == 4 && !custom.text.has_prefix ("/")) { + partition_bar.icon = new ThemedIcon ("dialog-warning-symbolic"); + partition_bar.tooltip_text = _("Custom value is invalid"); + return; } - partition_bar.icon = new ThemedIcon ( - error == null ? "process-completed-symbolic" : "dialog-warning-symbolic" - ); + var mount = get_mount (); + var filesystem = mount == "swap" ? InstallerDaemon.FileSystem.SWAP : get_file_system (); - if (error != null) { - partition_bar.tooltip_text = error; + try { + set_mount ( + new Installer.Mount ( + partition_path, + parent_disk, + mount, + partition_bar.get_partition_size (), + (format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0) + + (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), + filesystem, + this + ) + ); + + partition_bar.icon = new ThemedIcon ("process-completed-symbolic"); + } catch (GLib.Error e) { + partition_bar.icon = new ThemedIcon ("dialog-warning-symbolic"); + partition_bar.tooltip_text = e.message; } } @@ -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 ("/"); - } } From 9534b4cb5f66cbe02ad5ebe5d5eb96e29d418773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 24 Sep 2024 10:33:33 -0700 Subject: [PATCH 2/5] Revert some indentation change --- src/Widgets/PartitionMenu.vala | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index ac4ef47a7..e95dee3ba 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -265,18 +265,16 @@ public class Installer.PartitionMenu : Gtk.Popover { var filesystem = mount == "swap" ? InstallerDaemon.FileSystem.SWAP : get_file_system (); try { - set_mount ( - new Installer.Mount ( - partition_path, - parent_disk, - mount, - partition_bar.get_partition_size (), - (format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0) + - (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), - filesystem, - this - ) - ); + set_mount (new Installer.Mount ( + partition_path, + parent_disk, + mount, + partition_bar.get_partition_size (), + (format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0) + + (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), + filesystem, + this + )); partition_bar.icon = new ThemedIcon ("process-completed-symbolic"); } catch (GLib.Error e) { From c5f763c63be561ef3f6b4dd9f2adb778f8fd3c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 24 Sep 2024 10:34:40 -0700 Subject: [PATCH 3/5] Better warning text --- src/Widgets/PartitionMenu.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index e95dee3ba..8e636c1b2 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -257,7 +257,7 @@ public class Installer.PartitionMenu : Gtk.Popover { if (use_as.active == 4 && !custom.text.has_prefix ("/")) { partition_bar.icon = new ThemedIcon ("dialog-warning-symbolic"); - partition_bar.tooltip_text = _("Custom value is invalid"); + partition_bar.tooltip_text = _("Custom value must begin with /"); return; } From c1a71b48ae963c0e31e1d2e23116f69c01426c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 1 Oct 2024 07:48:26 -0700 Subject: [PATCH 4/5] Reset tooltip text, fix indentation --- src/Widgets/PartitionMenu.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index 8e636c1b2..7e68b20fd 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -252,6 +252,7 @@ public class Installer.PartitionMenu : Gtk.Popover { private void check_values (SetMount set_mount) { if (!use_partition.active) { partition_bar.icon = null; + partition_bar.tooltip_text = null; return; } @@ -271,7 +272,7 @@ public class Installer.PartitionMenu : Gtk.Popover { mount, partition_bar.get_partition_size (), (format_partition.active ? InstallerDaemon.MountFlags.FORMAT : 0) - + (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), + + (is_lvm ? InstallerDaemon.MountFlags.LVM : 0), filesystem, this )); From 7ee5d22b0bab34af2ea2a6ead1e893e3b38e8688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 1 Oct 2024 07:49:52 -0700 Subject: [PATCH 5/5] Also set null with valid --- src/Widgets/PartitionMenu.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index 7e68b20fd..35ee8e01f 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -278,6 +278,7 @@ public class Installer.PartitionMenu : Gtk.Popover { )); 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;