Add partition selection sections
This commit is contained in:
parent
0635bdf0c3
commit
1f8c99d6ba
2 changed files with 58 additions and 7 deletions
23
src/app.rs
23
src/app.rs
|
|
@ -61,9 +61,11 @@ pub struct App {
|
|||
tick_rate: f64,
|
||||
// App
|
||||
cur_mode: Mode,
|
||||
disk_dest: Option<Disk>,
|
||||
disk_id_dest: Option<usize>,
|
||||
disk_id_source: Option<usize>,
|
||||
disk_list: Arc<Mutex<Vec<Disk>>>,
|
||||
disk_source: Option<Disk>,
|
||||
part_num_boot: Option<usize>,
|
||||
part_num_os: Option<usize>,
|
||||
driver: Option<Driver>,
|
||||
prev_mode: Mode,
|
||||
selections: Vec<Option<usize>>,
|
||||
|
|
@ -109,10 +111,12 @@ impl App {
|
|||
tick_rate,
|
||||
// App
|
||||
cur_mode: Mode::ScanDisks,
|
||||
disk_dest: None,
|
||||
disk_id_dest: None,
|
||||
disk_id_source: None,
|
||||
disk_list: Arc::new(Mutex::new(Vec::new())),
|
||||
disk_source: None,
|
||||
driver: None,
|
||||
part_num_boot: None,
|
||||
part_num_os: None,
|
||||
prev_mode: Mode::ScanDisks,
|
||||
selections: vec![None, None],
|
||||
table_type: None,
|
||||
|
|
@ -302,6 +306,17 @@ impl App {
|
|||
self.action_tx.send(Action::SetMode(Mode::ScanDisks))?;
|
||||
}
|
||||
Action::Select(one, two) => {
|
||||
match self.cur_mode {
|
||||
Mode::SelectDisks => {
|
||||
self.disk_id_source = one.clone();
|
||||
self.disk_id_dest = two.clone();
|
||||
}
|
||||
Mode::SelectParts => {
|
||||
self.part_num_boot = one.clone();
|
||||
self.part_num_os = two.clone();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.selections[0] = one;
|
||||
self.selections[1] = two;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ use crate::{
|
|||
pub struct Left {
|
||||
command_tx: Option<UnboundedSender<Action>>,
|
||||
config: Config,
|
||||
disk_id_dest: Option<usize>,
|
||||
table_type: Option<PartitionTableType>,
|
||||
title_text: String,
|
||||
list_disks: StatefulList<Disk>,
|
||||
list_drivers: StatefulList<Driver>,
|
||||
|
|
@ -148,6 +150,7 @@ impl Component for Left {
|
|||
Mode::SelectTableType => {
|
||||
// Only need to select one entry
|
||||
if let Some(table_type) = self.list_table_types.pop_selected() {
|
||||
self.table_type = Some(table_type.clone());
|
||||
command_tx.send(Action::SelectTableType(table_type))?;
|
||||
}
|
||||
}
|
||||
|
|
@ -168,6 +171,11 @@ impl Component for Left {
|
|||
_ => {}
|
||||
},
|
||||
Action::Select(Some(index), None) => self.selections[0] = Some(index),
|
||||
Action::Select(_, Some(index)) => {
|
||||
if self.mode == Mode::SelectDisks {
|
||||
self.disk_id_dest = Some(index);
|
||||
}
|
||||
}
|
||||
Action::SetMode(new_mode) => {
|
||||
let prev_mode = self.mode;
|
||||
self.mode = new_mode;
|
||||
|
|
@ -209,10 +217,34 @@ impl Component for Left {
|
|||
self.title_text = String::from("Processing");
|
||||
}
|
||||
(_, Mode::SelectParts) => {
|
||||
// TODO: Get list of partitions
|
||||
self.selections[0] = None;
|
||||
self.selections[1] = None;
|
||||
self.title_text = String::from("Select Boot and OS Partitions")
|
||||
self.title_text = String::from("Select Boot and OS Partitions");
|
||||
|
||||
// Get list of partitions for destination disk
|
||||
if let Some(index) = &self.disk_id_dest {
|
||||
if let Some(disk) = self.list_disks.items.get(*index).to_owned() {
|
||||
self.list_parts.set_items(disk.parts.clone());
|
||||
|
||||
// Auto-select first partition and highlight likely OS partition
|
||||
if let Some(table_type) = &self.table_type {
|
||||
match table_type {
|
||||
PartitionTableType::Guid => {
|
||||
if disk.parts.len() >= 3 {
|
||||
self.selections[0] = Some(0);
|
||||
self.list_parts.state.select(Some(2));
|
||||
}
|
||||
}
|
||||
PartitionTableType::Legacy => {
|
||||
if disk.parts.len() >= 2 {
|
||||
self.selections[0] = Some(0);
|
||||
self.list_parts.state.select(Some(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(Mode::SelectDisks | Mode::SelectParts, Mode::Confirm) => {
|
||||
self.title_text = String::from("Confirm Selections")
|
||||
|
|
@ -310,7 +342,11 @@ impl Component for Left {
|
|||
if let Some(selection_one) = self.selections[0] {
|
||||
if selection_one == index {
|
||||
item_style = Style::new().yellow();
|
||||
item_text_tail = " ~already selected~";
|
||||
item_text_tail = match self.mode {
|
||||
Mode::SelectDisks => " ~source disk~",
|
||||
Mode::SelectParts => " ~boot volume~",
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
list_items.push(
|
||||
|
|
|
|||
Loading…
Reference in a new issue