SettingsDialog.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.ComponentModel;
  3. using System.Diagnostics;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using Compdfkit_Tools.Helper;
  7. namespace PDFViewer
  8. {
  9. /// <summary>
  10. /// Interaction logic for SettingsDialog.xaml
  11. /// </summary>
  12. public partial class SettingsDialog : Window
  13. {
  14. public event EventHandler<string> LanguageChanged;
  15. public SettingsDialog()
  16. {
  17. InitializeComponent();
  18. Closing += MainWindow_Closing;
  19. Title = App.MainResourceManager.GetString("Title_Settings");
  20. }
  21. private void MainWindow_Closing(object sender, CancelEventArgs e)
  22. {
  23. Properties.Settings.Default.Divisor = GetDivisor();
  24. Properties.Settings.Default.Save();
  25. Compdfkit_Tools.Data.CPDFAnnotationData.Author = Properties.Settings.Default.DocumentAuthor;
  26. }
  27. private void EventSetter_ClickHandler(object sender, RoutedEventArgs e)
  28. {
  29. var webLocation = (sender as Button)?.Tag.ToString();
  30. if (!string.IsNullOrEmpty(webLocation))
  31. {
  32. Process.Start(webLocation);
  33. }
  34. }
  35. private int GetDivisor()
  36. {
  37. if (!DivisorTxb.IsValueValid)
  38. {
  39. return 10;
  40. }
  41. return int.TryParse(DivisorTxb.Text, out int divisor) ? divisor : 10;
  42. }
  43. private void SettingsDialog_Loaded(object sender, RoutedEventArgs e)
  44. {
  45. HighlightFormTog.IsChecked = Properties.Settings.Default.IsHighlightFormArea;
  46. HighlightLinkTog.IsChecked = Properties.Settings.Default.IsHighlightLinkArea;
  47. AuthorTxb.Text = Properties.Settings.Default.DocumentAuthor;
  48. SelectCurrentLanguage();
  49. DivisorTxb.Text = Properties.Settings.Default.Divisor.ToString();
  50. }
  51. private void SelectCurrentLanguage()
  52. {
  53. foreach (ComboBoxItem item in LanguageCmb.Items)
  54. {
  55. if (item.Tag.ToString() == App.CurrentCulture)
  56. {
  57. item.IsSelected = true;
  58. }
  59. }
  60. }
  61. private void AuthorTxb_TextChanged(object sender, TextChangedEventArgs e)
  62. {
  63. Properties.Settings.Default.DocumentAuthor = AuthorTxb.Text;
  64. }
  65. private void HighlightLinkTog_Click(object sender, RoutedEventArgs e)
  66. {
  67. if (HighlightLinkTog.IsChecked != null)
  68. Properties.Settings.Default.IsHighlightLinkArea = HighlightLinkTog.IsChecked.Value;
  69. }
  70. private void HighlightFormTog_Click(object sender, RoutedEventArgs e)
  71. {
  72. if (HighlightFormTog.IsChecked != null)
  73. Properties.Settings.Default.IsHighlightFormArea = HighlightFormTog.IsChecked.Value;
  74. }
  75. private void LanguageCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  76. {
  77. string language = ((ComboBoxItem)LanguageCmb.SelectedItem).Tag.ToString();
  78. if (language.Equals(App.CurrentCulture))
  79. {
  80. return;
  81. }
  82. MessageBoxResult result = MessageBox.Show(App.MainResourceManager.GetString("Tip_Restart"),
  83. App.MainResourceManager.GetString("Tip_RestartTitle"),
  84. MessageBoxButton.YesNo,
  85. MessageBoxImage.Question);
  86. if (result == MessageBoxResult.Yes)
  87. {
  88. Properties.Settings.Default.Cultrue = language;
  89. Properties.Settings.Default.Save();
  90. LanguageChanged?.Invoke(this, language);
  91. }
  92. else
  93. {
  94. SelectCurrentLanguage();
  95. }
  96. }
  97. }
  98. }