SettingsDialog.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace PDFViewer
  7. {
  8. /// <summary>
  9. /// Interaction logic for SettingsDialog.xaml
  10. /// </summary>
  11. public partial class SettingsDialog : Window
  12. {
  13. public event EventHandler<string> LanguageChanged;
  14. public SettingsDialog()
  15. {
  16. InitializeComponent();
  17. Closing += MainWindow_Closing;
  18. }
  19. private void MainWindow_Closing(object sender, CancelEventArgs e)
  20. {
  21. Properties.Settings.Default.Save();
  22. }
  23. private void EventSetter_ClickHandler(object sender, RoutedEventArgs e)
  24. {
  25. var webLocation = (sender as Button)?.Tag.ToString();
  26. if (!string.IsNullOrEmpty(webLocation))
  27. {
  28. Process.Start(webLocation);
  29. }
  30. }
  31. private void SettingsDialog_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. HighlightFormTog.IsChecked = Properties.Settings.Default.IsHighlightFormArea;
  34. HighlightLinkTog.IsChecked = Properties.Settings.Default.IsHighlightLinkArea;
  35. AuthorTxb.Text = Properties.Settings.Default.DocumentAuthor;
  36. ((ComboBoxItem)LanguageCmb.Items[0]).Content = Properties.Settings.Default.Language;
  37. LanguageCmb.SelectedIndex = 0;
  38. }
  39. private void AuthorTxb_TextChanged(object sender, TextChangedEventArgs e)
  40. {
  41. Properties.Settings.Default.DocumentAuthor = AuthorTxb.Text;
  42. }
  43. private void HighlightLinkTog_Click(object sender, RoutedEventArgs e)
  44. {
  45. if (HighlightLinkTog.IsChecked != null)
  46. Properties.Settings.Default.IsHighlightLinkArea = HighlightLinkTog.IsChecked.Value;
  47. }
  48. private void HighlightFormTog_Click(object sender, RoutedEventArgs e)
  49. {
  50. if (HighlightFormTog.IsChecked != null)
  51. Properties.Settings.Default.IsHighlightFormArea = HighlightFormTog.IsChecked.Value;
  52. }
  53. private void LanguageCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  54. {
  55. string language = ((ComboBoxItem)LanguageCmb.SelectedItem).Content.ToString();
  56. if (language.Equals(Properties.Settings.Default.Language))
  57. {
  58. return;
  59. }
  60. MessageBoxResult result = MessageBox.Show("You need to restart the application to apply the language change.\nDo you want to restart now?",
  61. "Restart Application",
  62. MessageBoxButton.YesNo,
  63. MessageBoxImage.Question);
  64. if (result == MessageBoxResult.Yes)
  65. {
  66. Properties.Settings.Default.Language = language;
  67. Properties.Settings.Default.Save();
  68. LanguageChanged?.Invoke(this, language);
  69. }
  70. else
  71. {
  72. LanguageCmb.SelectedIndex = 0;
  73. }
  74. }
  75. }
  76. }