@@ -26,6 +26,7 @@ use std::{
26
26
any:: TypeId ,
27
27
collections:: HashMap ,
28
28
env, fs, io,
29
+ num:: NonZeroU64 ,
29
30
path:: { Path , PathBuf } ,
30
31
process,
31
32
sync:: { Mutex , OnceLock } ,
@@ -307,6 +308,7 @@ impl PartialEq for WatcherWrapper {
307
308
pub enum Message {
308
309
AppTheme ( AppTheme ) ,
309
310
AutoSaveSender ( futures:: channel:: mpsc:: Sender < AutoSaveEvent > ) ,
311
+ AutoSaveTimeout ( Option < NonZeroU64 > ) ,
310
312
Config ( Config ) ,
311
313
ConfigState ( ConfigState ) ,
312
314
CloseFile ,
@@ -1148,6 +1150,11 @@ impl App {
1148
1150
. font_sizes
1149
1151
. iter ( )
1150
1152
. position ( |font_size| font_size == & self . config . font_size ) ;
1153
+ let save_seconds = self
1154
+ . config
1155
+ . auto_save_secs
1156
+ . map ( |secs| secs. to_string ( ) )
1157
+ . unwrap_or_default ( ) ;
1151
1158
widget:: settings:: view_column ( vec ! [
1152
1159
widget:: settings:: view_section( fl!( "appearance" ) )
1153
1160
. add(
@@ -1198,6 +1205,16 @@ impl App {
1198
1205
. toggler( self . config. vim_bindings, Message :: VimBindings ) ,
1199
1206
)
1200
1207
. into( ) ,
1208
+ widget:: settings:: view_section( fl!( "session" ) )
1209
+ . add(
1210
+ widget:: settings:: item:: builder( fl!( "auto-save-secs" ) ) . control(
1211
+ widget:: text_input( fl!( "seconds" ) , save_seconds) . on_input( |s| {
1212
+ let secs = s. parse( ) . ok( ) ;
1213
+ Message :: AutoSaveTimeout ( secs)
1214
+ } ) ,
1215
+ ) ,
1216
+ )
1217
+ . into( ) ,
1201
1218
] )
1202
1219
. into ( )
1203
1220
}
@@ -1450,6 +1467,16 @@ impl Application for App {
1450
1467
Message :: AutoSaveSender ( sender) => {
1451
1468
self . auto_save_sender = Some ( sender) ;
1452
1469
}
1470
+ Message :: AutoSaveTimeout ( timeout) => {
1471
+ self . config . auto_save_secs = timeout;
1472
+ if let Some ( timeout) = timeout {
1473
+ return Command :: batch ( [
1474
+ self . save_config ( ) ,
1475
+ self . update_auto_saver ( AutoSaveEvent :: UpdateTimeout ( timeout) ) ,
1476
+ ] ) ;
1477
+ }
1478
+ return self . save_config ( ) ;
1479
+ }
1453
1480
Message :: Config ( config) => {
1454
1481
if config != self . config {
1455
1482
log:: info!( "update config" ) ;
@@ -2133,7 +2160,10 @@ impl Application for App {
2133
2160
] ) ;
2134
2161
}
2135
2162
2136
- return self . update_tab ( ) ;
2163
+ return Command :: batch ( [
2164
+ self . update_tab ( ) ,
2165
+ self . update_auto_saver ( AutoSaveEvent :: Cancel ( entity) ) ,
2166
+ ] ) ;
2137
2167
}
2138
2168
Message :: TabContextAction ( entity, action) => {
2139
2169
if let Some ( Tab :: Editor ( tab) ) = self . tab_model . data_mut :: < Tab > ( entity) {
@@ -2701,13 +2731,14 @@ impl Application for App {
2701
2731
Some ( dialog) => dialog. subscription ( ) ,
2702
2732
None => subscription:: Subscription :: none ( ) ,
2703
2733
} ,
2704
- auto_save_subscription ( self . config . auto_save_secs . unwrap ( ) ) . map (
2705
- |update| match update {
2734
+ match self . config . auto_save_secs {
2735
+ Some ( secs ) => auto_save_subscription ( secs ) . map ( |update| match update {
2706
2736
AutoSaveEvent :: Ready ( sender) => Message :: AutoSaveSender ( sender) ,
2707
2737
AutoSaveEvent :: Save ( entity) => Message :: SaveAny ( entity) ,
2708
2738
_ => unreachable ! ( ) ,
2709
- } ,
2710
- ) ,
2739
+ } ) ,
2740
+ None => subscription:: Subscription :: none ( ) ,
2741
+ } ,
2711
2742
] )
2712
2743
}
2713
2744
}
0 commit comments