@@ -58,7 +58,7 @@ use wayland_client::{protocol::wl_output::WlOutput, Proxy};
58
58
59
59
use crate :: {
60
60
clipboard:: { ClipboardCopy , ClipboardKind , ClipboardPaste } ,
61
- config:: { AppTheme , Config , DesktopConfig , Favorite , IconSizes , TabConfig } ,
61
+ config:: { AppTheme , Config , DesktopConfig , Favorite , IconSizes , SessionConfig , TabConfig } ,
62
62
desktop_dir, fl, home_dir,
63
63
key_bind:: key_binds,
64
64
localize:: LANGUAGE_SORTER ,
@@ -71,7 +71,7 @@ use crate::{
71
71
tab:: { self , HeadingOptions , ItemMetadata , Location , Tab , HOVER_DURATION } ,
72
72
} ;
73
73
74
- #[ derive( Clone , Debug ) ]
74
+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
75
75
pub enum Mode {
76
76
App ,
77
77
Desktop ,
@@ -305,10 +305,12 @@ pub enum Message {
305
305
Rename ( Option < Entity > ) ,
306
306
ReplaceResult ( ReplaceResult ) ,
307
307
RestoreFromTrash ( Option < Entity > ) ,
308
+ SaveSession ,
308
309
SearchActivate ,
309
310
SearchClear ,
310
311
SearchInput ( String ) ,
311
312
SearchSubmit ,
313
+ SessionConfig ( SessionConfig ) ,
312
314
SystemThemeModeChange ( cosmic_theme:: ThemeMode ) ,
313
315
TabActivate ( Entity ) ,
314
316
TabNext ,
@@ -1140,27 +1142,43 @@ impl App {
1140
1142
1141
1143
fn settings ( & self ) -> Element < Message > {
1142
1144
// TODO: Should dialog be updated here too?
1143
- widget:: settings:: view_column ( vec ! [ widget:: settings:: section( )
1144
- . title( fl!( "appearance" ) )
1145
- . add( {
1146
- let app_theme_selected = match self . config. app_theme {
1147
- AppTheme :: Dark => 1 ,
1148
- AppTheme :: Light => 2 ,
1149
- AppTheme :: System => 0 ,
1150
- } ;
1151
- widget:: settings:: item:: builder( fl!( "theme" ) ) . control( widget:: dropdown(
1152
- & self . app_themes,
1153
- Some ( app_theme_selected) ,
1154
- move |index| {
1155
- Message :: AppTheme ( match index {
1156
- 1 => AppTheme :: Dark ,
1157
- 2 => AppTheme :: Light ,
1158
- _ => AppTheme :: System ,
1159
- } )
1160
- } ,
1161
- ) )
1162
- } )
1163
- . into( ) ] )
1145
+ widget:: settings:: view_column ( vec ! [
1146
+ widget:: settings:: section( )
1147
+ . title( fl!( "appearance" ) )
1148
+ . add( {
1149
+ let app_theme_selected = match self . config. app_theme {
1150
+ AppTheme :: Dark => 1 ,
1151
+ AppTheme :: Light => 2 ,
1152
+ AppTheme :: System => 0 ,
1153
+ } ;
1154
+ widget:: settings:: item:: builder( fl!( "theme" ) ) . control( widget:: dropdown(
1155
+ & self . app_themes,
1156
+ Some ( app_theme_selected) ,
1157
+ move |index| {
1158
+ Message :: AppTheme ( match index {
1159
+ 1 => AppTheme :: Dark ,
1160
+ 2 => AppTheme :: Light ,
1161
+ _ => AppTheme :: System ,
1162
+ } )
1163
+ } ,
1164
+ ) )
1165
+ } )
1166
+ . into( ) ,
1167
+ widget:: settings:: section( )
1168
+ . title( fl!( "session" ) )
1169
+ . add(
1170
+ widget:: settings:: item:: builder( fl!( "restore-session" ) ) . toggler(
1171
+ self . config. session. restore,
1172
+ move |restore| {
1173
+ Message :: SessionConfig ( SessionConfig {
1174
+ restore,
1175
+ ..Default :: default ( )
1176
+ } )
1177
+ } ,
1178
+ ) ,
1179
+ )
1180
+ . into( ) ,
1181
+ ] )
1164
1182
. into ( )
1165
1183
}
1166
1184
}
@@ -2326,6 +2344,24 @@ impl Application for App {
2326
2344
self . operation ( Operation :: Restore { paths } ) ;
2327
2345
}
2328
2346
}
2347
+ Message :: SaveSession => {
2348
+ if self . config . session . restore && self . mode == Mode :: App {
2349
+ let session = SessionConfig {
2350
+ tabs : Some (
2351
+ self . tab_model
2352
+ . iter ( )
2353
+ . filter_map ( |entity| {
2354
+ self . tab_model
2355
+ . data :: < Tab > ( entity)
2356
+ . map ( |tab| tab. location . clone ( ) )
2357
+ } )
2358
+ . collect ( ) ,
2359
+ ) ,
2360
+ ..self . config . session
2361
+ } ;
2362
+ config_set ! ( session, session) ;
2363
+ }
2364
+ }
2329
2365
Message :: SearchActivate => {
2330
2366
self . search_active = true ;
2331
2367
return widget:: text_input:: focus ( self . search_id . clone ( ) ) ;
@@ -2355,6 +2391,9 @@ impl Application for App {
2355
2391
return self . search ( ) ;
2356
2392
}
2357
2393
}
2394
+ Message :: SessionConfig ( session) => {
2395
+ config_set ! ( session, session) ;
2396
+ }
2358
2397
Message :: SystemThemeModeChange ( _theme_mode) => {
2359
2398
return self . update_config ( ) ;
2360
2399
}
@@ -2429,9 +2468,12 @@ impl Application for App {
2429
2468
// Remove item
2430
2469
self . tab_model . remove ( entity) ;
2431
2470
2432
- // If that was the last tab, close window
2471
+ // If that was the last tab, close window and serialize empty session if necessary
2433
2472
if self . tab_model . iter ( ) . next ( ) . is_none ( ) {
2434
- return window:: close ( window:: Id :: MAIN ) ;
2473
+ return Command :: batch ( [
2474
+ self . update ( Message :: SaveSession ) ,
2475
+ window:: close ( window:: Id :: MAIN ) ,
2476
+ ] ) ;
2435
2477
}
2436
2478
2437
2479
return Command :: batch ( [ self . update_title ( ) , self . update_watcher ( ) ] ) ;
@@ -2695,6 +2737,7 @@ impl Application for App {
2695
2737
if let Some ( window_id) = self . window_id_opt . take ( ) {
2696
2738
return Command :: batch ( [
2697
2739
window:: close ( window_id) ,
2740
+ self . update ( Message :: SaveSession ) ,
2698
2741
Command :: perform ( async move { message:: app ( Message :: MaybeExit ) } , |x| x) ,
2699
2742
] ) ;
2700
2743
}
0 commit comments