1+ using ITHit . FileSystem . Windows . WinUI ;
12using ITHit . FileSystem . Windows . WinUI . Dialogs ;
23using Microsoft . UI . Xaml ;
34using WebDAVDrive . Services ;
@@ -13,12 +14,14 @@ public sealed partial class Settings : DialogWindow
1314 private readonly ResourceLoader resourceLoader = ResourceLoader . GetForViewIndependentUse ( ) ;
1415
1516 private readonly VirtualEngine engine ;
17+ private readonly Tray parentTrayWindow ;
1618
17- public Settings ( VirtualEngine engine ) : base ( )
19+ public Settings ( Tray trayWindow ) : base ( )
1820 {
1921 InitializeComponent ( ) ;
20- Resize ( 700 , 600 ) ;
21- this . engine = engine ;
22+ Resize ( 700 , 700 ) ;
23+ engine = ( trayWindow . Engine as VirtualEngine ) ! ;
24+ parentTrayWindow = trayWindow ;
2225 Title = $ "{ ServiceProvider . GetService < AppSettings > ( ) . ProductName } - { resourceLoader . GetString ( "SettingsWindow/Title" ) } ";
2326
2427 // Resize and center the window.
@@ -27,6 +30,7 @@ public Settings(VirtualEngine engine) : base()
2730 //Set values from engine
2831 AutomaticLockTimeout . Text = ( engine . AutoLockTimeoutMs / 1000 ) . ToString ( ) ;
2932 ManualLockTimeout . Text = engine . ManualLockTimeoutMs == - 1 ? string . Empty : ( engine . ManualLockTimeoutMs / 1000 ) . ToString ( ) ;
33+ TrayMaxHistoryItems . Text = engine . TrayMaxHistoryItems . ToString ( ) ;
3034 AutoLockEnable . IsOn = engine . AutoLock ;
3135 ReadOnlyOnLockedFiles . IsOn = engine . SetLockReadOnly ;
3236 }
@@ -39,7 +43,8 @@ private void OnCloseClicked(object sender, RoutedEventArgs e)
3943 private void OnSaveClicked ( object sender , RoutedEventArgs e )
4044 {
4145 bool isValidationError = false ;
42- AutomaticRequiredMessage . Visibility = AutomaticValidationMessage . Visibility = ManualValidationMessage . Visibility = Visibility . Collapsed ;
46+ AutomaticRequiredMessage . Visibility = AutomaticValidationMessage . Visibility = ManualValidationMessage . Visibility =
47+ TrayMaxHistoryItemsRequiredMessage . Visibility = TrayMaxHistoryItemsValidationMessage . Visibility = Visibility . Collapsed ;
4348
4449 //"Automatic lock timeout" field is required and should be a number
4550 if ( string . IsNullOrWhiteSpace ( AutomaticLockTimeout . Text ) )
@@ -62,16 +67,39 @@ private void OnSaveClicked(object sender, RoutedEventArgs e)
6267 ManualValidationMessage . Visibility = Visibility . Visible ;
6368 }
6469
70+ //"Tray max history items" field is required and should be a 10+ integer number
71+ if ( string . IsNullOrWhiteSpace ( TrayMaxHistoryItems . Text ) )
72+ {
73+ isValidationError = true ;
74+ TrayMaxHistoryItemsRequiredMessage . Visibility = Visibility . Visible ;
75+ TrayMaxHistoryItemsValidationMessage . Visibility = Visibility . Collapsed ;
76+ }
77+ else if ( ! int . TryParse ( TrayMaxHistoryItems . Text , out int trayMaxHistoryItems ) || trayMaxHistoryItems < 10 )
78+ {
79+ isValidationError = true ;
80+ TrayMaxHistoryItemsRequiredMessage . Visibility = Visibility . Collapsed ;
81+ TrayMaxHistoryItemsValidationMessage . Visibility = Visibility . Visible ;
82+ }
83+
6584 if ( ! isValidationError )
6685 {
6786 UserSettingsService userSettingsService = ServiceProvider . GetService < UserSettingsService > ( ) ;
87+ int trayMaxHistoryItemsShowing = int . Parse ( TrayMaxHistoryItems . Text ) ;
6888 userSettingsService . SaveSettings ( engine , new UserSettings
6989 {
7090 AutomaticLockTimeout = double . Parse ( AutomaticLockTimeout . Text ) * 1000 ,
7191 ManualLockTimeout = string . IsNullOrWhiteSpace ( ManualLockTimeout . Text ) ? - 1 : ( double . Parse ( ManualLockTimeout . Text ) * 1000 ) ,
92+ TrayMaxHistoryItems = trayMaxHistoryItemsShowing ,
7293 SetLockReadOnly = ReadOnlyOnLockedFiles . IsOn ,
7394 AutoLock = AutoLockEnable . IsOn
74- } ) ;
95+ } ) ;
96+ //update property of parent Tray window and clear history on the fly (if user provided smaller setting value)
97+ int ? oldValue = parentTrayWindow . TrayMaxHistoryItems ;
98+ parentTrayWindow . TrayMaxHistoryItems = trayMaxHistoryItemsShowing ;
99+ if ( oldValue . HasValue && oldValue . Value > trayMaxHistoryItemsShowing )
100+ {
101+ parentTrayWindow . CleanupHistoryItems ( ) ;
102+ }
75103
76104 Close ( ) ;
77105 }
0 commit comments