Refine widget cloning

This commit is contained in:
Ward from fusion-voyager-3 2024-01-19 14:13:52 +03:00
parent e93ba20dfd
commit ebbd61e84f
6 changed files with 65 additions and 103 deletions

View File

@ -107,7 +107,7 @@ pub fn build_ui(app: &adw::Application) {
keyboard_page(&content_stack);
// Add partitioning_page.rs as a page for content_stack
partitioning_page(&content_stack);
partitioning_page(&window, &content_stack);
// glib maximization
if glib_settings.boolean("is-maximized") == true {

View File

@ -161,23 +161,19 @@ pub fn eula_page(content_stack: &gtk::Stack) {
//// Add the eula_main_box as page: eula_page, Give it nice title
content_stack.add_titled(&eula_main_box, Some("eula_page"), "EULA");
let eula_accept_checkbutton_clone = eula_accept_checkbutton.clone();
let bottom_next_button_clone = bottom_next_button.clone();
eula_accept_checkbutton.connect_toggled(move |_| {
if eula_accept_checkbutton_clone.is_active() == true {
bottom_next_button_clone.set_sensitive(true);
eula_accept_checkbutton.connect_toggled(clone!(@weak eula_accept_checkbutton, @weak bottom_next_button => move |_| {
if eula_accept_checkbutton.is_active() == true {
bottom_next_button.set_sensitive(true);
} else {
bottom_next_button_clone.set_sensitive(false)
bottom_next_button.set_sensitive(false)
}
});
}));
let content_stack_clone = content_stack.clone();
let content_stack_clone2 = content_stack.clone();
bottom_next_button.connect_clicked(move |_| {
content_stack_clone.set_visible_child_name("keyboard_page")
});
bottom_back_button.connect_clicked(move |_| {
content_stack_clone2.set_visible_child_name("language_page")
});
bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("keyboard_page")
}));
bottom_back_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("language_page")
}));
}

View File

@ -146,9 +146,6 @@ pub fn keyboard_page(content_stack: &gtk::Stack) {
keyboard_selection_expander_row.add_row(&keyboard_selection_expander_row_viewport);
let keyboard_selection_expander_row_clone2 = keyboard_selection_expander_row.clone();
let bottom_next_button_clone = bottom_next_button.clone();
let mut current_keyboard_cli = Command::new("localectl")
.arg("status")
.stdin(Stdio::piped())
@ -190,15 +187,12 @@ pub fn keyboard_page(content_stack: &gtk::Stack) {
.build();
keyboard_layout_checkbutton.set_group(Some(&null_checkbutton));
keyboard_selection_expander_row_viewport_box.append(&keyboard_layout_checkbutton);
let keyboard_selection_expander_row_clone = keyboard_selection_expander_row.clone();
let keyboard_layout_checkbutton_clone = keyboard_layout_checkbutton.clone();
let bottom_next_button_clone2 = bottom_next_button.clone();
keyboard_layout_checkbutton.connect_toggled(move |_| {
if keyboard_layout_checkbutton_clone.is_active() == true {
keyboard_selection_expander_row_clone.set_title(&keyboard_layout);
bottom_next_button_clone2.set_sensitive(true);
keyboard_layout_checkbutton.connect_toggled(clone!(@weak keyboard_layout_checkbutton, @weak keyboard_selection_expander_row, @weak bottom_next_button => move |_| {
if keyboard_layout_checkbutton.is_active() == true {
keyboard_selection_expander_row.set_title(&keyboard_layout);
bottom_next_button.set_sensitive(true);
}
});
}));
if current_keyboard.contains(&(keyboard_layout_clone)) {
keyboard_layout_checkbutton.set_active(true);
}
@ -226,13 +220,11 @@ pub fn keyboard_page(content_stack: &gtk::Stack) {
//// Add the keyboard_main_box as page: keyboard_page, Give it nice title
content_stack.add_titled(&keyboard_main_box, Some("keyboard_page"), "Keyboard");
let content_stack_clone = content_stack.clone();
let content_stack_clone2 = content_stack.clone();
bottom_next_button.connect_clicked(move |_| {
content_stack_clone.set_visible_child_name("partitioning_page")
});
bottom_back_button.connect_clicked(move |_| {
content_stack_clone2.set_visible_child_name("eula_page")
});
bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("partitioning_page")
}));
bottom_back_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("eula_page")
}));
}

View File

@ -146,9 +146,6 @@ pub fn language_page(content_stack: &gtk::Stack) {
language_selection_expander_row_viewport_listbox.append(&language_selection_expander_row);
language_selection_expander_row.add_row(&language_selection_expander_row_viewport);
let language_selection_expander_row_clone2 = language_selection_expander_row.clone();
let bottom_next_button_clone = bottom_next_button.clone();
let current_locale = match env::var_os("LANG") {
Some(v) => v.into_string().unwrap(),
@ -185,15 +182,12 @@ pub fn language_page(content_stack: &gtk::Stack) {
.build();
locale_checkbutton.set_group(Some(&null_checkbutton));
language_selection_expander_row_viewport_box.append(&locale_checkbutton);
let language_selection_expander_row_clone = language_selection_expander_row.clone();
let locale_checkbutton_clone = locale_checkbutton.clone();
let bottom_next_button_clone2 = bottom_next_button.clone();
locale_checkbutton.connect_toggled(move |_| {
if locale_checkbutton_clone.is_active() == true {
language_selection_expander_row_clone.set_title(&locale);
bottom_next_button_clone2.set_sensitive(true);
locale_checkbutton.connect_toggled(clone!(@weak locale_checkbutton, @weak language_selection_expander_row, @weak bottom_next_button => move |_| {
if locale_checkbutton.is_active() == true {
language_selection_expander_row.set_title(&locale);
bottom_next_button.set_sensitive(true);
}
});
}));
if current_locale.contains(&(locale_clone)) {
locale_checkbutton.set_active(true);
}
@ -221,13 +215,11 @@ pub fn language_page(content_stack: &gtk::Stack) {
//// Add the language_main_box as page: language_page, Give it nice title
content_stack.add_titled(&language_main_box, Some("language_page"), "Language");
let content_stack_clone = content_stack.clone();
let content_stack_clone2 = content_stack.clone();
bottom_next_button.connect_clicked(move |_| {
content_stack_clone.set_visible_child_name("eula_page")
});
bottom_back_button.connect_clicked(move |_| {
content_stack_clone2.set_visible_child_name("welcome_page")
});
bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("eula_page")
}));
bottom_back_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("welcome_page")
}));
}

View File

@ -1,4 +1,3 @@
use adw::subclass::application;
// Use libraries
/// Use all gtk4 libraries (gtk4 -> gtk because cargo)
/// Use all libadwaita libraries (libadwaita -> adw because cargo)
@ -18,7 +17,7 @@ use std::time::Instant;
use std::env;
use pretty_bytes::converter::convert;
pub fn partitioning_page(content_stack: &gtk::Stack) {
pub fn partitioning_page(window: &adw::ApplicationWindow, content_stack: &gtk::Stack) {
// create the bottom box for next and back buttons
let bottom_box = gtk::Box::builder()
@ -317,25 +316,19 @@ pub fn partitioning_page(content_stack: &gtk::Stack) {
.build();
device_row.add_prefix(&device_button);
devices_selection_expander_row_viewport_box.append(&device_row);
// button connect clones
let device_button_clone = device_button.clone();
let devices_selection_expander_row_clone = devices_selection_expander_row.clone();
let bottom_next_button_clone = bottom_next_button.clone();
let partition_method_automatic_status_label_clone = partition_method_automatic_status_label.clone();
//
device_button.connect_toggled(move |_| {
if device_button_clone.is_active() == true {
devices_selection_expander_row_clone.set_title(&device);
device_button.connect_toggled(clone!(@weak device_button, @weak devices_selection_expander_row, @weak bottom_next_button, @weak partition_method_automatic_status_label => move |_| {
if device_button.is_active() == true {
devices_selection_expander_row.set_title(&device);
if device_size > 39000000000.0 {
partition_method_automatic_status_label_clone.hide();
bottom_next_button_clone.set_sensitive(true);
partition_method_automatic_status_label.hide();
bottom_next_button.set_sensitive(true);
} else {
partition_method_automatic_status_label_clone.show();
partition_method_automatic_status_label_clone.set_label("Disk Size too small, PikaOS needs 40GB Disk");
bottom_next_button_clone.set_sensitive(false);
partition_method_automatic_status_label.show();
partition_method_automatic_status_label.set_label("Disk Size too small, PikaOS needs 40GB Disk");
bottom_next_button.set_sensitive(false);
}
}
});
}));
}
let partition_method_automatic_luks_box = gtk::Box::builder()
@ -364,15 +357,13 @@ pub fn partitioning_page(content_stack: &gtk::Stack) {
.sensitive(false)
.build();
let partition_method_automatic_luks_checkbutton_clone = partition_method_automatic_luks_checkbutton.clone();
let partition_method_automatic_luks_password_entry_clone = partition_method_automatic_luks_password_entry.clone();
partition_method_automatic_luks_checkbutton.connect_toggled(move |_| {
if partition_method_automatic_luks_checkbutton_clone.is_active() == true {
partition_method_automatic_luks_password_entry_clone.set_sensitive(true);
partition_method_automatic_luks_checkbutton.connect_toggled(clone!(@weak partition_method_automatic_luks_checkbutton, @weak partition_method_automatic_luks_password_entry => move |_| {
if partition_method_automatic_luks_checkbutton.is_active() == true {
partition_method_automatic_luks_password_entry.set_sensitive(true);
} else {
partition_method_automatic_luks_password_entry_clone.set_sensitive(false);
partition_method_automatic_luks_password_entry.set_sensitive(false);
}
});
}));
partition_method_automatic_luks_listbox.append(&partition_method_automatic_luks_password_entry);
partition_method_automatic_luks_box.append(&partition_method_automatic_luks_checkbutton);
@ -458,7 +449,7 @@ pub fn partitioning_page(content_stack: &gtk::Stack) {
Some("Cancel"),
);
//partition_method_manual_chroot_dir_file_dialog.set_transient_for(Some(&application_window));
partition_method_manual_chroot_dir_file_dialog.set_transient_for(Some(window));
let partition_method_manual_chroot_dir_entry = adw::EntryRow::builder()
.title("Custom Root Mountpoint")
@ -524,12 +515,13 @@ pub fn partitioning_page(content_stack: &gtk::Stack) {
partition_method_manual_main_box.append(&partition_method_manual_luks_box);
partition_method_manual_main_box.append(&partition_method_manual_status_label);
// clone partition_method_manual_chroot_dir_file_dialog as rust becuase glib breaks it show function for some reason
let partition_method_manual_chroot_dir_file_dialog_clone = partition_method_manual_chroot_dir_file_dialog.clone();
let partition_method_manual_chroot_dir_file_dialog_clone2 = partition_method_manual_chroot_dir_file_dialog.clone();
partition_method_manual_chroot_dir_button.connect_clicked(move |_| {
partition_method_manual_chroot_dir_file_dialog_clone.show();
});
let partition_method_manual_chroot_dir_entry_clone = partition_method_manual_chroot_dir_entry.clone();
partition_method_manual_chroot_dir_file_dialog.connect_response(clone!(@weak partition_method_manual_chroot_dir_file_dialog => move |_, response| {
if response == gtk::ResponseType::Accept {
if partition_method_manual_chroot_dir_file_dialog.file().is_some() {
@ -559,24 +551,15 @@ pub fn partitioning_page(content_stack: &gtk::Stack) {
//// Add the partitioning_main_box as page: partitioning_page, Give it nice title
content_stack.add_titled(&partitioning_main_box, Some("partitioning_page"), "Partitioning");
let partitioning_stack_clone = partitioning_stack.clone();
automatic_method_button.connect_clicked(move |_| partitioning_stack_clone.set_visible_child_name("partition_method_automatic_page"));
//automatic_method_button.connect_clicked(move |_| println!("{}", partition_method_manual_chroot_dir_file_dialog_clone2.file().expect("l").path().expect("REASON").into_os_string().into_string().unwrap()));
let partitioning_stack_clone2 = partitioning_stack.clone();
manual_method_button.connect_clicked(move |_| partitioning_stack_clone2.set_visible_child_name("partition_method_manual_page"));
automatic_method_button.connect_clicked(clone!(@weak partitioning_stack => move |_| partitioning_stack.set_visible_child_name("partition_method_automatic_page")));
manual_method_button.connect_clicked(clone!(@weak partitioning_stack => move |_| partitioning_stack.set_visible_child_name("partition_method_manual_page")));
let content_stack_clone = content_stack.clone();
let content_stack_clone2 = content_stack.clone();
let partitioning_stack_clone3 = partitioning_stack.clone();
bottom_next_button.connect_clicked(move |_| {
content_stack_clone.set_visible_child_name("installation_page")
});
bottom_back_button.connect_clicked(move |_| {
content_stack_clone2.set_visible_child_name("keyboard_page")
});
bottom_back_button.connect_clicked(move |_| {
partitioning_stack_clone3.set_visible_child_name("partition_method_select_page")
});
bottom_next_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("installation_page")
}));
bottom_back_button.connect_clicked(clone!(@weak content_stack, @weak partitioning_stack => move |_| {
content_stack.set_visible_child_name("keyboard_page");
partitioning_stack.set_visible_child_name("partition_method_select_page");
}));
}

View File

@ -163,9 +163,8 @@ pub fn welcome_page(window: &adw::ApplicationWindow, content_stack: &gtk::Stack)
// / Content stack appends
//// Add the welcome_main_box as page: welcome_page, Give it nice title
content_stack.add_titled(&welcome_main_box, Some("welcome_page"), "Welcome");
let content_stack_clone = content_stack.clone();
let window_clone = window.clone();
install_media_button.connect_clicked(move |_| content_stack_clone.set_visible_child_name("language_page"));
live_media_button.connect_clicked(move |_| window_clone.hide());
install_media_button.connect_clicked(clone!(@weak content_stack => move |_| content_stack.set_visible_child_name("language_page")));
live_media_button.connect_clicked(clone!(@weak window => move |_| window.hide()));
}