SettingsDialog.xaml.cs 4.2 KB

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