@@ -4,7 +4,7 @@ use crate::terminal_combo_row::TerminalComboRow;
44use adw:: prelude:: * ;
55use adw:: subclass:: prelude:: * ;
66use glib:: { clone, derived_properties, Properties } ;
7- use gtk:: { glib , gio } ;
7+ use gtk:: { gio , glib } ;
88use std:: cell:: RefCell ;
99use tracing:: error;
1010
@@ -16,7 +16,6 @@ mod imp {
1616 pub struct PreferencesDialog {
1717 #[ property( get, set, construct) ]
1818 pub root_store : RefCell < RootStore > ,
19-
2019 pub terminal_combo_row : RefCell < Option < TerminalComboRow > > ,
2120 pub delete_btn : gtk:: Button ,
2221 pub add_terminal_btn : gtk:: Button ,
@@ -38,19 +37,20 @@ mod imp {
3837 fn constructed ( & self ) {
3938 self . parent_constructed ( ) ;
4039 let obj = self . obj ( ) ;
41-
40+
4241 obj. set_title ( "Preferences" ) ;
4342
4443 let page = adw:: PreferencesPage :: new ( ) ;
4544
4645 // Terminal Settings Group
4746 let terminal_group = adw:: PreferencesGroup :: new ( ) ;
4847 terminal_group. set_title ( "Terminal Settings" ) ;
49-
48+
5049 // Initialize terminal combo row
5150 let terminal_combo_row = TerminalComboRow :: new_with_params ( obj. root_store ( ) ) ;
52- self . terminal_combo_row . replace ( Some ( terminal_combo_row. clone ( ) ) ) ;
53-
51+ self . terminal_combo_row
52+ . replace ( Some ( terminal_combo_row. clone ( ) ) ) ;
53+
5454 // Initialize delete button
5555 self . delete_btn . set_label ( "Delete" ) ;
5656 self . delete_btn . add_css_class ( "destructive-action" ) ;
@@ -148,7 +148,7 @@ impl PreferencesDialog {
148148 let imp = self . imp ( ) ;
149149 if let ( Some ( terminal_combo_row) , Some ( delete_btn) ) = (
150150 imp. terminal_combo_row . borrow ( ) . as_ref ( ) ,
151- Some ( & imp. delete_btn )
151+ Some ( & imp. delete_btn ) ,
152152 ) {
153153 if let Some ( selected) = terminal_combo_row. selected_item ( ) {
154154 let selected_name = selected
@@ -171,13 +171,13 @@ impl PreferencesDialog {
171171 Some ( row) => row. clone ( ) ,
172172 None => return ,
173173 } ;
174-
174+
175175 let selected = terminal_combo_row
176176 . selected_item ( )
177177 . and_downcast_ref :: < gtk:: StringObject > ( )
178178 . unwrap ( )
179179 . string ( ) ;
180-
180+
181181 let dialog = adw:: AlertDialog :: builder ( )
182182 . heading ( "Delete this terminal?" )
183183 . body ( format ! (
@@ -205,25 +205,24 @@ impl PreferencesDialog {
205205 . delete_terminal( & selected)
206206 {
207207 Ok ( _) => {
208- glib:: MainContext :: ref_thread_default( ) . spawn_local(
209- async move {
210- if let Some ( terminal_combo_row) = this. imp( ) . terminal_combo_row. borrow( ) . as_ref( ) {
211- terminal_combo_row. reload_terminals( ) ;
212- terminal_combo_row. set_selected_by_name(
213- & this. root_store( )
214- . terminal_repository( )
215- . default_terminal( )
216- . await
217- . map( |x| x. name)
218- . unwrap_or_default( ) ,
219- ) ;
220- }
221-
222- this. add_toast( adw:: Toast :: new(
223- "Terminal removed successfully" ,
224- ) ) ;
225- } ,
226- ) ;
208+ glib:: MainContext :: ref_thread_default( ) . spawn_local( async move {
209+ if let Some ( terminal_combo_row) =
210+ this. imp( ) . terminal_combo_row. borrow( ) . as_ref( )
211+ {
212+ terminal_combo_row. reload_terminals( ) ;
213+ terminal_combo_row. set_selected_by_name(
214+ & this
215+ . root_store( )
216+ . terminal_repository( )
217+ . default_terminal( )
218+ . await
219+ . map( |x| x. name)
220+ . unwrap_or_default( ) ,
221+ ) ;
222+ }
223+
224+ this. add_toast( adw:: Toast :: new( "Terminal removed successfully" ) ) ;
225+ } ) ;
227226 }
228227 Err ( err) => {
229228 error!( error = %err, "Failed to delete terminal" ) ;
@@ -260,9 +259,7 @@ impl PreferencesDialog {
260259 let program_entry = adw:: EntryRow :: builder ( ) . title ( "Program Path" ) . build ( ) ;
261260
262261 // Separator argument entry
263- let separator_entry = adw:: EntryRow :: builder ( )
264- . title ( "Separator Argument" )
265- . build ( ) ;
262+ let separator_entry = adw:: EntryRow :: builder ( ) . title ( "Separator Argument" ) . build ( ) ;
266263
267264 group. add ( & name_entry) ;
268265 group. add ( & program_entry) ;
@@ -348,7 +345,9 @@ impl PreferencesDialog {
348345 // Show success toast
349346 let toast = adw:: Toast :: new( "Custom terminal added successfully" ) ;
350347
351- if let Some ( terminal_combo_row) = this. imp( ) . terminal_combo_row. borrow( ) . as_ref( ) {
348+ if let Some ( terminal_combo_row) =
349+ this. imp( ) . terminal_combo_row. borrow( ) . as_ref( )
350+ {
352351 terminal_combo_row. reload_terminals( ) ;
353352 terminal_combo_row. set_selected_by_name( & terminal. name) ;
354353 }
@@ -366,21 +365,4 @@ impl PreferencesDialog {
366365
367366 custom_dialog. present ( Some ( self ) ) ;
368367 }
369-
370- fn add_toast ( & self , toast : adw:: Toast ) {
371- // Try to find a parent window with a toast overlay
372- let mut widget = self . parent ( ) ;
373- while let Some ( parent) = widget {
374- if let Some ( window) = parent. downcast_ref :: < crate :: window:: DistroShelfWindow > ( ) {
375- window. imp ( ) . toast_overlay . add_toast ( toast) ;
376- return ;
377- }
378- widget = parent. parent ( ) ;
379- }
380-
381- // Fallback: create a simple alert dialog if no toast overlay is found
382- let alert = adw:: AlertDialog :: new ( toast. title ( ) . as_deref ( ) , None ) ;
383- alert. add_response ( "ok" , "OK" ) ;
384- alert. present ( Some ( self ) ) ;
385- }
386368}
0 commit comments