@@ -17,7 +17,8 @@ public partial class MainWindow : Window
1717 public MainWindow ( )
1818 {
1919 InitializeComponent ( ) ;
20- Closing += MainWindow_Closing ;
20+ UpdateSettingsPathDisplay ( ) ;
21+ Closing += MainWindow_Closing ;
2122 LoadSettings ( ) ;
2223 LoadCategories ( ) ;
2324 RefreshTriggerList ( ) ;
@@ -26,9 +27,48 @@ public MainWindow()
2627 ApplyTheme ( _currentTheme ) ;
2728 }
2829
29- #region Theme Management
3030
3131
32+
33+ #region Settings management
34+ private void UpdateSettingsPathDisplay ( )
35+ {
36+ SettingsPathTextBox . Text = TriggerDatabase . SettingsPath ;
37+ DatabaseLocationText . Text = TriggerDatabase . DatabasePath ;
38+ }
39+
40+ private void ChangeLocationButton_Click ( object sender , RoutedEventArgs e )
41+ {
42+ var dialog = new SettingsLocationDialog ( ) ;
43+ if ( dialog . ShowDialog ( ) == true )
44+ {
45+ try
46+ {
47+ TriggerDatabase . Instance . MoveSettingsTo ( dialog . SelectedMode , dialog . CustomPath ) ;
48+ UpdateSettingsPathDisplay ( ) ;
49+
50+ // Refresh trigger list and keyboard hook since database may have moved
51+ RefreshTriggerList ( ) ;
52+ ( ( App ) Application . Current ) . RefreshKeyboardHook ( ) ;
53+
54+ var confirmDialog = new ConfirmDialog ( "Success" , $ "Location of settings and database files changed successfully.", "OK" , false , null ) ;
55+ confirmDialog . Owner = this ;
56+ confirmDialog . ShowDialog ( ) ;
57+ }
58+ catch ( Exception ex )
59+ {
60+ var errorDialog = new ConfirmDialog ( "Error" , $ "Failed to change location: { ex . Message } ", "OK" , false , null ) ;
61+ errorDialog . Owner = this ;
62+ errorDialog . ShowDialog ( ) ;
63+ }
64+ }
65+ }
66+ #endregion
67+
68+
69+
70+ #region Closing window management
71+
3272 private void MainWindow_Closing ( object ? sender , CancelEventArgs e )
3373 {
3474 if ( TriggerDatabase . Instance . Settings . MinimizeToTrayOnClose )
@@ -48,6 +88,10 @@ private void MinimizeToTrayCheckBox_Changed(object sender, RoutedEventArgs e)
4888 TriggerDatabase . Instance . Save ( ) ;
4989 }
5090
91+ #endregion
92+
93+ #region Theme Management
94+
5195 private void Theme_Click ( object sender , RoutedEventArgs e )
5296 {
5397 _currentTheme = _currentTheme switch
@@ -357,17 +401,15 @@ private void SettingsScrollViewer_Loaded(object sender, RoutedEventArgs e)
357401 SettingsScrollViewer . ScrollToTop ( ) ;
358402 }
359403
360- private void LoadSettings ( )
361- {
362- StartupCheckBox . IsChecked = StartupManager . IsRegisteredForStartup ( ) ;
363- SpeedSlider . Value = TriggerDatabase . Instance . Settings . TriggerSpeed ;
364- UpdateSpeedText ( ) ;
365- DatabasePathText . Text = TriggerDatabase . DatabasePath ;
366- DatabaseLocationText . Text = TriggerDatabase . DatabasePath ;
367- SettingsPathText . Text = TriggerDatabase . SettingsPath ;
368-
369- _currentTheme = TriggerDatabase . Instance . Settings . Theme ?? "Light" ;
370- }
404+ private void LoadSettings ( )
405+ {
406+ StartupCheckBox . IsChecked = StartupManager . IsRegisteredForStartup ( ) ;
407+ SpeedSlider . Value = TriggerDatabase . Instance . Settings . TriggerSpeed ;
408+ UpdateSpeedText ( ) ;
409+ DatabaseLocationText . Text = TriggerDatabase . DatabasePath ;
410+
411+ _currentTheme = TriggerDatabase . Instance . Settings . Theme ?? "Light" ;
412+ }
371413
372414 private void StartupCheckBox_Changed ( object sender , RoutedEventArgs e )
373415 {
@@ -490,59 +532,6 @@ private void Import_Click(object sender, RoutedEventArgs e)
490532 }
491533 }
492534
493- private void BrowseDatabase_Click ( object sender , RoutedEventArgs e )
494- {
495- var dialog = new Microsoft . Win32 . SaveFileDialog
496- {
497- Filter = "JSON files (*.json)|*.json" ,
498- FileName = "triggers.json" ,
499- Title = "Choose Database Location"
500- } ;
501-
502- if ( dialog . ShowDialog ( ) == true )
503- {
504- var oldPath = TriggerDatabase . DatabasePath ;
505-
506- if ( System . IO . File . Exists ( oldPath ) && oldPath != dialog . FileName )
507- {
508- if ( System . IO . File . Exists ( dialog . FileName ) )
509- {
510- var confirmDialog = new ConfirmDialog (
511- "File Exists" ,
512- "A file already exists at this location. Overwrite it?" ,
513- "Overwrite" ,
514- true ) ;
515- confirmDialog . Owner = this ;
516-
517- if ( confirmDialog . ShowDialog ( ) != true )
518- return ;
519-
520- System . IO . File . Delete ( dialog . FileName ) ;
521- }
522-
523- System . IO . File . Move ( oldPath , dialog . FileName ) ;
524- }
525-
526- TriggerDatabase . Instance . SetCustomDatabasePath ( dialog . FileName ) ;
527- TriggerDatabase . Instance . Load ( ) ;
528- RefreshTriggerList ( ) ;
529- DatabaseLocationText . Text = dialog . FileName ;
530- DatabasePathText . Text = dialog . FileName ;
531-
532- ( ( App ) Application . Current ) . RefreshKeyboardHook ( ) ;
533- }
534- }
535-
536- private void ResetDatabaseLocation_Click ( object sender , RoutedEventArgs e )
537- {
538- TriggerDatabase . Instance . SetCustomDatabasePath ( null ) ;
539- TriggerDatabase . Instance . Load ( ) ;
540- RefreshTriggerList ( ) ;
541- DatabaseLocationText . Text = TriggerDatabase . DatabasePath ;
542- DatabasePathText . Text = TriggerDatabase . DatabasePath ;
543-
544- ( ( App ) Application . Current ) . RefreshKeyboardHook ( ) ;
545- }
546535
547536 private void Author_Click ( object sender , RoutedEventArgs e )
548537 {
@@ -564,4 +553,4 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
564553 Hide ( ) ;
565554 e . Cancel = false ;
566555 }
567- }
556+ }
0 commit comments