From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 2/2] tui: add "Deselect all" button to zfs/btrfs raid disk select
Date: Mon, 10 Jul 2023 15:26:26 +0200 [thread overview]
Message-ID: <20230710132632.512643-3-c.heiss@proxmox.com> (raw)
In-Reply-To: <20230710132632.512643-1-c.heiss@proxmox.com>
Another puzzle piece in the quest to align the TUI installer more to
its GUI counterpart.
Like the GUI installer, it will only be shown if >3 disks are
detected on the system.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
proxmox-tui-installer/src/views/bootdisk.rs | 46 ++++++++++++++++-----
proxmox-tui-installer/src/views/mod.rs | 17 ++++++++
2 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/proxmox-tui-installer/src/views/bootdisk.rs b/proxmox-tui-installer/src/views/bootdisk.rs
index 4970655..552cbc4 100644
--- a/proxmox-tui-installer/src/views/bootdisk.rs
+++ b/proxmox-tui-installer/src/views/bootdisk.rs
@@ -3,7 +3,8 @@ use std::{cell::RefCell, marker::PhantomData, rc::Rc};
use cursive::{
view::{Nameable, Resizable, ViewWrapper},
views::{
- Button, Dialog, DummyView, LinearLayout, NamedView, Panel, ScrollView, SelectView, TextView,
+ Button, Dialog, DummyView, LinearLayout, NamedView, PaddedView, Panel, ScrollView,
+ SelectView, TextView,
},
Cursive, View,
};
@@ -293,10 +294,34 @@ impl<T: View> MultiDiskOptionsView<T> {
);
}
- let disk_select_view = LinearLayout::vertical()
+ let mut disk_select_view = LinearLayout::vertical()
.child(TextView::new("Disk setup").center())
.child(DummyView)
- .child(ScrollView::new(disk_form));
+ .child(ScrollView::new(disk_form.with_name("multidisk-disk-form")));
+
+ if avail_disks.len() > 3 {
+ let do_not_use_index = selectable_disks.len() - 1;
+ let deselect_all_button = Button::new("Deselect all", move |siv| {
+ siv.call_on_name("multidisk-disk-form", |view: &mut FormView| {
+ view.call_on_childs(&|v: &mut SelectView<Option<Disk>>| {
+ // As there is no .on_select() callback defined on the
+ // SelectView's, the returned callback here can be safely
+ // ignored.
+ v.set_selection(do_not_use_index);
+ });
+ });
+ });
+
+ disk_select_view.add_child(PaddedView::lrtb(
+ 0,
+ 0,
+ 1,
+ 0,
+ LinearLayout::horizontal()
+ .child(DummyView.full_width())
+ .child(deselect_all_button),
+ ));
+ }
let options_view = LinearLayout::vertical()
.child(TextView::new("Advanced options").center())
@@ -335,13 +360,14 @@ impl<T: View> MultiDiskOptionsView<T> {
let disk_form = self
.view
- .get_child(view_top_index)?
- .downcast_ref::<LinearLayout>()?
- .get_child(0)?
- .downcast_ref::<LinearLayout>()?
- .get_child(2)?
- .downcast_ref::<ScrollView<FormView>>()?
- .get_inner();
+ .get_child_mut(view_top_index)?
+ .downcast_mut::<LinearLayout>()?
+ .get_child_mut(0)?
+ .downcast_mut::<LinearLayout>()?
+ .get_child_mut(2)?
+ .downcast_mut::<ScrollView<NamedView<FormView>>>()?
+ .get_inner_mut()
+ .get_mut();
let mut selected_disks = Vec::new();
diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs
index b1a1a13..aa78289 100644
--- a/proxmox-tui-installer/src/views/mod.rs
+++ b/proxmox-tui-installer/src/views/mod.rs
@@ -326,6 +326,15 @@ impl FormView {
.downcast_ref::<T>()
}
+ pub fn get_child_mut<T: View>(&mut self, index: usize) -> Option<&mut T> {
+ self.view
+ .get_child_mut(1)?
+ .downcast_mut::<ResizedView<LinearLayout>>()?
+ .get_inner_mut()
+ .get_child_mut(index)?
+ .downcast_mut::<T>()
+ }
+
pub fn get_value<T, R>(&self, index: usize) -> Option<R>
where
T: View + FormViewGetValue<R>,
@@ -346,6 +355,14 @@ impl FormView {
}
}
+ pub fn call_on_childs<T: View>(&mut self, callback: &dyn Fn(&mut T)) {
+ for i in 0..self.len() {
+ if let Some(v) = self.get_child_mut::<T>(i) {
+ callback(v);
+ }
+ }
+ }
+
pub fn len(&self) -> usize {
self.view
.get_child(1)
--
2.41.0
next prev parent reply other threads:[~2023-07-10 13:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-10 13:26 [pve-devel] [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Christoph Heiss
2023-07-10 13:26 ` [pve-devel] [PATCH installer 1/2] tui: fix clippy warnings Christoph Heiss
2023-07-10 13:26 ` Christoph Heiss [this message]
2023-07-13 14:10 ` [pve-devel] applied: [PATCH installer 0/2] tui: add "Deselect all" disks button for zfs/btrfs raid Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230710132632.512643-3-c.heiss@proxmox.com \
--to=c.heiss@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox