From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 78AD3CB8D for ; Mon, 10 Jul 2023 15:27:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 596CE18270 for ; Mon, 10 Jul 2023 15:26:37 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 10 Jul 2023 15:26:36 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id DF317428FB for ; Mon, 10 Jul 2023 15:26:35 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 10 Jul 2023 15:26:26 +0200 Message-ID: <20230710132632.512643-3-c.heiss@proxmox.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230710132632.512643-1-c.heiss@proxmox.com> References: <20230710132632.512643-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.064 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH installer 2/2] tui: add "Deselect all" button to zfs/btrfs raid disk select X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jul 2023 13:27:07 -0000 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 --- 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 MultiDiskOptionsView { ); } - 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>| { + // 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 MultiDiskOptionsView { let disk_form = self .view - .get_child(view_top_index)? - .downcast_ref::()? - .get_child(0)? - .downcast_ref::()? - .get_child(2)? - .downcast_ref::>()? - .get_inner(); + .get_child_mut(view_top_index)? + .downcast_mut::()? + .get_child_mut(0)? + .downcast_mut::()? + .get_child_mut(2)? + .downcast_mut::>>()? + .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::() } + pub fn get_child_mut(&mut self, index: usize) -> Option<&mut T> { + self.view + .get_child_mut(1)? + .downcast_mut::>()? + .get_inner_mut() + .get_child_mut(index)? + .downcast_mut::() + } + pub fn get_value(&self, index: usize) -> Option where T: View + FormViewGetValue, @@ -346,6 +355,14 @@ impl FormView { } } + pub fn call_on_childs(&mut self, callback: &dyn Fn(&mut T)) { + for i in 0..self.len() { + if let Some(v) = self.get_child_mut::(i) { + callback(v); + } + } + } + pub fn len(&self) -> usize { self.view .get_child(1) -- 2.41.0