SettingsDialog.xaml.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Compdfkit_Tools.Data.CPDFAnnotationData.Author = Properties.Settings.Default.DocumentAuthor;
  23. }
  24. private void EventSetter_ClickHandler(object sender, RoutedEventArgs e)
  25. {
  26. var webLocation = (sender as Button)?.Tag.ToString();
  27. if (!string.IsNullOrEmpty(webLocation))
  28. {
  29. Process.Start(webLocation);
  30. }
  31. }
  32. private void SettingsDialog_Loaded(object sender, RoutedEventArgs e)
  33. {
  34. HighlightFormTog.IsChecked = Properties.Settings.Default.IsHighlightFormArea;
  35. HighlightLinkTog.IsChecked = Properties.Settings.Default.IsHighlightLinkArea;
  36. AuthorTxb.Text = Properties.Settings.Default.DocumentAuthor;
  37. ((ComboBoxItem)LanguageCmb.Items[0]).Content = Properties.Settings.Default.Language;
  38. LanguageCmb.SelectedIndex = 0;
  39. }
  40. private void AuthorTxb_TextChanged(object sender, TextChangedEventArgs e)
  41. {
  42. Properties.Settings.Default.DocumentAuthor = AuthorTxb.Text;
  43. }
  44. private void HighlightLinkTog_Click(object sender, RoutedEventArgs e)
  45. {
  46. if (HighlightLinkTog.IsChecked != null)
  47. Properties.Settings.Default.IsHighlightLinkArea = HighlightLinkTog.IsChecked.Value;
  48. }
  49. private void HighlightFormTog_Click(object sender, RoutedEventArgs e)
  50. {
  51. if (HighlightFormTog.IsChecked != null)
  52. Properties.Settings.Default.IsHighlightFormArea = HighlightFormTog.IsChecked.Value;
  53. }
  54. private void LanguageCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  55. {
  56. string language = ((ComboBoxItem)LanguageCmb.SelectedItem).Content.ToString();
  57. if (language.Equals(Properties.Settings.Default.Language))
  58. {
  59. return;
  60. }
  61. MessageBoxResult result = MessageBox.Show("You need to restart the application to apply the language change.\nDo you want to restart now?",
  62. "Restart Application",
  63. MessageBoxButton.YesNo,
  64. MessageBoxImage.Question);
  65. if (result == MessageBoxResult.Yes)
  66. {
  67. Properties.Settings.Default.Language = language;
  68. Properties.Settings.Default.Save();
  69. LanguageChanged?.Invoke(this, language);
  70. }
  71. else
  72. {
  73. LanguageCmb.SelectedIndex = 0;
  74. }
  75. }
  76. }
  77. }