SettingsDialog.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. FontSubsettingTog.IsChecked = Properties.Settings.Default.FontSubsetting;
  55. AuthorTxb.Text = Properties.Settings.Default.DocumentAuthor;
  56. AnnotatorTxb.Text = Properties.Settings.Default.AnnotationAuthor;
  57. SelectCurrentLanguage();
  58. DivisorTxb.Text = Properties.Settings.Default.Divisor.ToString();
  59. }
  60. private void SelectCurrentLanguage()
  61. {
  62. foreach (ComboBoxItem item in LanguageCmb.Items)
  63. {
  64. if (item.Tag.ToString() == App.CurrentCulture)
  65. {
  66. item.IsSelected = true;
  67. }
  68. }
  69. }
  70. private void AuthorTxb_TextChanged(object sender, TextChangedEventArgs e)
  71. {
  72. Properties.Settings.Default.DocumentAuthor = AuthorTxb.Text;
  73. }
  74. private void HighlightLinkTog_Click(object sender, RoutedEventArgs e)
  75. {
  76. if (HighlightLinkTog.IsChecked != null)
  77. Properties.Settings.Default.IsHighlightLinkArea = HighlightLinkTog.IsChecked.Value;
  78. }
  79. private void HighlightFormTog_Click(object sender, RoutedEventArgs e)
  80. {
  81. if (HighlightFormTog.IsChecked != null)
  82. Properties.Settings.Default.IsHighlightFormArea = HighlightFormTog.IsChecked.Value;
  83. }
  84. private void LanguageCmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
  85. {
  86. string language = ((ComboBoxItem)LanguageCmb.SelectedItem).Tag.ToString();
  87. if (language.Equals(App.CurrentCulture))
  88. {
  89. return;
  90. }
  91. MessageBoxResult result = MessageBox.Show(App.MainResourceManager.GetString("Tip_Restart"),
  92. App.MainResourceManager.GetString("Tip_RestartTitle"),
  93. MessageBoxButton.YesNo,
  94. MessageBoxImage.Question);
  95. if (result == MessageBoxResult.Yes)
  96. {
  97. Properties.Settings.Default.Cultrue = language;
  98. Properties.Settings.Default.Save();
  99. LanguageChanged?.Invoke(this, language);
  100. }
  101. else
  102. {
  103. SelectCurrentLanguage();
  104. }
  105. }
  106. private void AnnotatorTxb_TextChanged(object sender, TextChangedEventArgs e)
  107. {
  108. Properties.Settings.Default.AnnotationAuthor = AnnotatorTxb.Text;
  109. }
  110. private void FontSubsettingTog_Click(object sender, RoutedEventArgs e)
  111. {
  112. Properties.Settings.Default.FontSubsetting = FontSubsettingTog.IsChecked.Value;
  113. }
  114. }
  115. }