SettingsDialog.xaml.cs 3.9 KB

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