RR: Create DriveMountPoint Row widget

This commit is contained in:
Ward from fusion-voyager-3 2024-02-11 21:02:16 +03:00
parent 5af8f03011
commit fea499f938
5 changed files with 204 additions and 82 deletions

View File

@ -1,75 +0,0 @@
use gtk::glib;
use gtk::*;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use adw::subclass::prelude::*;
use adw::prelude::ActionRowExt;
use std::cell::{Cell, RefCell};
use glib::ObjectExt;
use gtk::Orientation::Horizontal;
use glib::GString;
// Object holding the state
#[derive(glib::Properties, Default)]
#[properties(wrapper_type = super::CustomButton)]
pub struct CustomButton {
#[property(get, set)]
filesystem: RefCell<String>,
partition: RefCell<String>,
mountpoint: RefCell<String>,
partition_scroll: gtk::ScrolledWindow
}
// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for CustomButton {
const NAME: &'static str = "MyGtkAppCustomButton";
type Type = super::CustomButton;
type ParentType = adw::ActionRow;
}
// Trait shared by all GObjects
// Trait shared by all GObjects
#[glib::derived_properties]
impl ObjectImpl for CustomButton {
fn constructed(&self) {
self.parent_constructed();
// Bind label to number
// `SYNC_CREATE` ensures that the label will be immediately set
let obj = self.obj();
let action_row_content_box = gtk::Box::builder()
.orientation(Horizontal)
.spacing(0)
.build();
let partition_row_expander = adw::ExpanderRow::builder()
.title("Partition")
.build();
action_row_content_box.append(&partition_row_expander);
obj.add_prefix(&action_row_content_box)
//obj.bind_property("number", obj.as_ref(), "label")
// .sync_create()
// .build();
}
}
// Trait shared by all widgets
impl WidgetImpl for CustomButton {}
// Trait shared by all buttons
// Trait shared by all buttons
impl ListBoxRowImpl for CustomButton {}
impl PreferencesRowImpl for CustomButton {}
impl ActionRowImpl for CustomButton {
//fn clicked(&self) {
// let incremented_number = self.obj().number() + 1;
// self.obj().set_number(incremented_number);
//}
}

179
src/drive_mount_row/imp.rs Normal file
View File

@ -0,0 +1,179 @@
use std::{
cell::{
Cell,
RefCell,
},
sync::{
OnceLock,
},
rc::{
Rc,
},
};
use glib::{
Properties,
subclass::Signal,
clone,
};
use gtk::{
glib,
prelude::*,
subclass::prelude::*,
*,
Orientation::Horizontal,
};
use adw::{
prelude::*,
subclass::prelude::*,
*,
};
// ANCHOR: custom_button
// Object holding the state
#[derive(Properties, Default)]
#[properties(wrapper_type = super::DriveMountRow)]
pub struct DriveMountRow {
#[property(get, set)]
mountopt: RefCell<String>,
#[property(get, set)]
partition: RefCell<String>,
#[property(get, set)]
mountpoint: RefCell<String>,
#[property(get, set)]
partition_scroll: Rc<RefCell<gtk::ScrolledWindow>>,
}
// ANCHOR_END: custom_button
// The central trait for subclassing a GObject
#[glib::object_subclass]
impl ObjectSubclass for DriveMountRow {
const NAME: &'static str = "DriveMountRow";
type Type = super::DriveMountRow;
type ParentType = adw::ActionRow;
}
// ANCHOR: object_impl
// Trait shared by all GObjects
#[glib::derived_properties]
impl ObjectImpl for DriveMountRow {
fn signals() -> &'static [Signal] {
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
SIGNALS.get_or_init(|| {
vec![Signal::builder("row-deleted")
.build()]
})
}
fn constructed(&self) {
self.parent_constructed();
// Bind label to number
// `SYNC_CREATE` ensures that the label will be immediately set
let obj = self.obj();
let action_row_content_box = gtk::Box::builder()
.orientation(Horizontal)
.spacing(0)
.build();
let partition_row_expander_adw_listbox = gtk::ListBox::builder()
.margin_end(5)
.margin_start(5)
.margin_top(5)
.margin_bottom(5)
.build();
partition_row_expander_adw_listbox.add_css_class("boxed-list");
let partition_row_expander = adw::ExpanderRow::builder()
.subtitle("Partition")
.build();
let mountpoint_entry_adw_listbox = gtk::ListBox::builder()
.halign(gtk::Align::Center)
.margin_top(5)
.margin_bottom(5)
.build();
mountpoint_entry_adw_listbox.add_css_class("boxed-list");
let mountpoint_entry_row = adw::EntryRow::builder()
.title("Mountpoint")
.build();
let mountopt_entry_adw_listbox = gtk::ListBox::builder()
.margin_top(5)
.margin_bottom(5)
.margin_start(5)
.halign(gtk::Align::Center)
.build();
mountopt_entry_adw_listbox.add_css_class("boxed-list");
let mountopt_entry_row = adw::EntryRow::builder()
.title("Additional Mount Options")
.build();
let partition_row_delete_button = gtk::Button::builder()
.margin_end(5)
.margin_start(5)
.margin_top(5)
.margin_bottom(5)
.height_request(60)
.width_request(60)
.icon_name("edit-delete")
.halign(gtk::Align::End)
.build();
partition_row_delete_button.connect_clicked(clone!( @weak obj => move |_| {
obj.emit_by_name::<()>("row-deleted", &[]);
}));
partition_row_expander_adw_listbox.append(&partition_row_expander);
action_row_content_box.append(&partition_row_expander_adw_listbox);
mountpoint_entry_adw_listbox.append(&mountpoint_entry_row);
action_row_content_box.append(&mountpoint_entry_adw_listbox);
mountopt_entry_adw_listbox.append(&mountopt_entry_row);
action_row_content_box.append(&mountopt_entry_adw_listbox);
action_row_content_box.append(&partition_row_delete_button);
obj.add_prefix(&action_row_content_box);
// Bind label to number
// `SYNC_CREATE` ensures that the label will be immediately set
let obj = self.obj();
obj.bind_property("partition", &partition_row_expander, "title")
.sync_create()
.bidirectional()
.build();
obj.bind_property("mountpoint", &mountpoint_entry_row, "text")
.sync_create()
.bidirectional()
.build();
obj.bind_property("mountopt", &mountopt_entry_row, "text")
.sync_create()
.bidirectional()
.build();
partition_row_expander.add_row(&obj.property::<gtk::ScrolledWindow>("partition_scroll"));
}
}
// Trait shared by all widgets
impl WidgetImpl for DriveMountRow {}
// Trait shared by all buttons
// Trait shared by all buttons
impl ListBoxRowImpl for DriveMountRow {}
impl PreferencesRowImpl for DriveMountRow {}
impl ActionRowImpl for DriveMountRow {
//fn clicked(&self) {
// let incremented_number = self.obj().number() + 1;
// self.obj().set_number(incremented_number);
//}
}

View File

@ -2,16 +2,21 @@ mod imp;
use glib::Object; use glib::Object;
use gtk::glib; use gtk::glib;
use gtk::ListBoxRow;
glib::wrapper! { glib::wrapper! {
pub struct CustomButton(ObjectSubclass<imp::CustomButton>) pub struct DriveMountRow(ObjectSubclass<imp::DriveMountRow>)
@extends adw::ActionRow, gtk::Widget, gtk::ListBoxRow, adw::PreferencesRow, @extends adw::ActionRow, gtk::Widget, gtk::ListBoxRow, adw::PreferencesRow,
@implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget; @implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget;
} }
impl CustomButton { impl DriveMountRow {
pub fn new() -> Self { pub fn new() -> Self {
Object::builder().build() Object::builder().build()
} }
}
impl Default for DriveMountRow {
fn default() -> Self {
Self::new()
}
} }

View File

@ -22,7 +22,7 @@ mod install_page;
mod done_page; mod done_page;
mod automatic_partitioning; mod automatic_partitioning;
mod manual_partitioning; mod manual_partitioning;
mod custom_button; mod drive_mount_row;
/// main function /// main function
fn main() { fn main() {

View File

@ -22,7 +22,7 @@ use std::time::*;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use crate::custom_button::CustomButton; use crate::drive_mount_row::DriveMountRow;
fn create_mount_row_list_box(device: &str) -> ActionRow { fn create_mount_row_list_box(device: &str) -> ActionRow {
// Create check button // Create check button
@ -223,13 +223,26 @@ pub fn manual_partitioning(window: &adw::ApplicationWindow, partitioning_stack:
partition_method_manual_main_box.append(&partition_method_manual_efi_error_label); partition_method_manual_main_box.append(&partition_method_manual_efi_error_label);
partition_method_manual_main_box.append(&partition_method_manual_gparted_button); partition_method_manual_main_box.append(&partition_method_manual_gparted_button);
let shit_button = CustomButton::new(); let shit_button = DriveMountRow::new();
shit_button.set_title("haggar"); shit_button.set_property("partition", "KAM");
shit_button.set_property("mountpoint", "KAM");
shit_button.set_property("mountopt", "KAM");
shit_button.set_property("partition_scroll", &gtk::ScrolledWindow::new());
let create_mount_row_list_box = gtk::ListBox::builder() let create_mount_row_list_box = gtk::ListBox::builder()
.build(); .build();
let partition_method_manual_main_box_clone = partition_method_manual_main_box.clone();
shit_button.connect_closure(
"row-deleted",
false,
closure_local!(move |_shit_button: DriveMountRow| {
partition_method_manual_main_box_clone.remove(&_shit_button)
}),
);
//shit_button.connect_clicked(clone!(@weak create_mount_row_list_box => move |_|{ //shit_button.connect_clicked(clone!(@weak create_mount_row_list_box => move |_|{
// create_mount_row_list_box.append(&create_mount_row("col")) // create_mount_row_list_box.append(&create_mount_row("col"))
//})); //}));