@@ -32,6 +32,9 @@ pub struct DashboardEditorDialog {
3232 slot_expand_all : bool ,
3333 slot_collapse_all : bool ,
3434 snap_on_edit : bool ,
35+ show_swap_buttons : bool ,
36+ show_remove_buttons : bool ,
37+ confirm_remove_slot : Option < usize > ,
3538}
3639
3740impl Default for DashboardEditorDialog {
@@ -50,6 +53,9 @@ impl Default for DashboardEditorDialog {
5053 slot_expand_all : false ,
5154 slot_collapse_all : false ,
5255 snap_on_edit : false ,
56+ show_swap_buttons : true ,
57+ show_remove_buttons : true ,
58+ confirm_remove_slot : None ,
5359 }
5460 }
5561}
@@ -135,6 +141,8 @@ impl DashboardEditorDialog {
135141 ui. label ( "Preview" ) ;
136142 ui. checkbox ( & mut self . show_preview , "Show preview" ) ;
137143 ui. checkbox ( & mut self . snap_on_edit , "Snap to free space on edit" ) ;
144+ ui. checkbox ( & mut self . show_swap_buttons , "Show swap" ) ;
145+ ui. checkbox ( & mut self . show_remove_buttons , "Show remove" ) ;
138146 if ui. button ( "Auto-place nearest" ) . clicked ( ) {
139147 if let Some ( idx) = self . selected_slot {
140148 if let Err ( err) = self . auto_place ( idx, registry) {
@@ -215,11 +223,39 @@ impl DashboardEditorDialog {
215223 } ) ;
216224
217225 ui. separator ( ) ;
226+ let mut confirm_remove = None ;
227+ if let Some ( idx) = self . confirm_remove_slot {
228+ if let Some ( slot) = self . config . slots . get ( idx) {
229+ let label = Self :: slot_label ( slot) ;
230+ let mut open = true ;
231+ egui:: Window :: new ( "Confirm remove" )
232+ . collapsible ( false )
233+ . resizable ( false )
234+ . open ( & mut open)
235+ . show ( ctx, |ui| {
236+ ui. label ( format ! ( "Remove slot '{label}'?" ) ) ;
237+ ui. horizontal ( |ui| {
238+ if ui. button ( "Remove" ) . clicked ( ) {
239+ confirm_remove = Some ( idx) ;
240+ open = false ;
241+ }
242+ if ui. button ( "Cancel" ) . clicked ( ) {
243+ open = false ;
244+ }
245+ } ) ;
246+ } ) ;
247+ if !open {
248+ self . confirm_remove_slot = None ;
249+ }
250+ } else {
251+ self . confirm_remove_slot = None ;
252+ }
253+ }
218254 let mut idx = 0 ;
219255 while idx < self . config . slots . len ( ) {
220256 let original_slot = self . config . slots [ idx] . clone ( ) ;
221257 let mut slot = original_slot. clone ( ) ;
222- let mut removed = false ;
258+ let mut removed = confirm_remove == Some ( idx ) ;
223259 let mut edited = false ;
224260 let mut swapped = false ;
225261 ui. push_id ( idx, |ui| {
@@ -245,52 +281,58 @@ impl DashboardEditorDialog {
245281 ui. with_layout (
246282 egui:: Layout :: right_to_left ( egui:: Align :: Center ) ,
247283 |ui| {
248- if ui. button ( "Remove" ) . clicked ( ) {
249- removed = true ;
284+ if self . show_remove_buttons
285+ && ui. button ( "Remove" ) . clicked ( )
286+ {
287+ self . confirm_remove_slot = Some ( idx) ;
250288 }
251289 if ui. button ( "Select" ) . clicked ( ) {
252290 self . selected_slot = Some ( idx) ;
253291 }
254- if let Some ( selected_idx) = self . selected_slot {
255- if selected_idx != idx
256- && ui. button ( "Swap with selected" ) . clicked ( )
257- {
258- if let Err ( err) = self . swap_slots (
259- selected_idx,
260- idx,
261- registry,
262- ) {
263- self . blocked_warning = Some ( err) ;
264- }
265- self . swap_anchor = None ;
266- swapped = true ;
267- }
268- }
269- let is_swap_source = self . swap_anchor == Some ( idx) ;
270- let swap_label = if is_swap_source {
271- "Swap source"
272- } else {
273- "Swap"
274- } ;
275- let swap_button = if is_swap_source {
276- egui:: Button :: new ( swap_label)
277- . fill ( egui:: Color32 :: from_rgb ( 60 , 120 , 200 ) )
278- } else {
279- egui:: Button :: new ( swap_label)
280- } ;
281- if ui. add ( swap_button) . clicked ( ) {
282- if is_swap_source {
283- self . swap_anchor = None ;
284- } else if let Some ( anchor) = self . swap_anchor {
285- if let Err ( err) =
286- self . swap_slots ( anchor, idx, registry)
292+ if self . show_swap_buttons {
293+ if let Some ( selected_idx) = self . selected_slot {
294+ if selected_idx != idx
295+ && ui. button ( "Swap with selected" ) . clicked ( )
287296 {
288- self . blocked_warning = Some ( err) ;
297+ if let Err ( err) = self . swap_slots (
298+ selected_idx,
299+ idx,
300+ registry,
301+ ) {
302+ self . blocked_warning = Some ( err) ;
303+ }
304+ self . swap_anchor = None ;
305+ swapped = true ;
289306 }
290- self . swap_anchor = None ;
291- swapped = true ;
307+ }
308+ let is_swap_source = self . swap_anchor == Some ( idx) ;
309+ let swap_label = if is_swap_source {
310+ "Swap source"
311+ } else {
312+ "Swap"
313+ } ;
314+ let swap_button = if is_swap_source {
315+ egui:: Button :: new ( swap_label)
316+ . fill ( egui:: Color32 :: from_rgb (
317+ 60 , 120 , 200 ,
318+ ) )
292319 } else {
293- self . swap_anchor = Some ( idx) ;
320+ egui:: Button :: new ( swap_label)
321+ } ;
322+ if ui. add ( swap_button) . clicked ( ) {
323+ if is_swap_source {
324+ self . swap_anchor = None ;
325+ } else if let Some ( anchor) = self . swap_anchor {
326+ if let Err ( err) =
327+ self . swap_slots ( anchor, idx, registry)
328+ {
329+ self . blocked_warning = Some ( err) ;
330+ }
331+ self . swap_anchor = None ;
332+ swapped = true ;
333+ } else {
334+ self . swap_anchor = Some ( idx) ;
335+ }
294336 }
295337 }
296338 } ,
0 commit comments