PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/BookReader/BookReader/Dialogs/OptionWindow.xaml.cs

#
C# | 100 lines | 82 code | 15 blank | 3 comment | 16 complexity | 0ec795fbbb6bd88507b411879f721de7 MD5 | raw file
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Input;
  4. using BookReader.Dialogs;
  5. namespace BookReader
  6. {
  7. /// <summary>
  8. /// Interaction logic for Options.xaml
  9. /// </summary>
  10. public partial class OptionWindow : HeaderedDialogWindow
  11. {
  12. public OptionWindow()
  13. {
  14. InitializeComponent();
  15. }
  16. private void Window_Loaded(object sender, RoutedEventArgs e)
  17. {
  18. LoadSettings();
  19. }
  20. private void Cancel_Click(object sender, RoutedEventArgs e)
  21. {
  22. this.DialogResult = false;
  23. this.Close();
  24. }
  25. private bool _NeedToReload = false;
  26. public bool NeedToReload
  27. {
  28. get { return _NeedToReload; }
  29. set { _NeedToReload = value; }
  30. }
  31. private void Ok_Click(object sender, RoutedEventArgs e)
  32. {
  33. _NeedToReload = false;
  34. Properties.Settings.Default.ImageCacheCount = Convert.ToInt32(this.textBoxCache.Text);
  35. Properties.Settings.Default.ImageCacheDuration = Convert.ToInt32(this.sliderDurationCache.Value);
  36. if( Properties.Settings.Default.Catalog != this.textBoxPath.Text )
  37. _NeedToReload = true;
  38. Properties.Settings.Default.Catalog = this.textBoxPath.Text;
  39. Properties.Settings.Default.UseDebug = this.chkUseDebug.IsChecked == true ? true : false;
  40. if( this.rbNone.IsChecked == true )
  41. Properties.Settings.Default.UseAutoFit = 0;
  42. else
  43. if( this.rbWidth.IsChecked == true )
  44. Properties.Settings.Default.UseAutoFit = 1;
  45. else
  46. if( this.rbHeight.IsChecked == true )
  47. Properties.Settings.Default.UseAutoFit = 2;
  48. Properties.Settings.Default.Save();
  49. Properties.Settings.Default.Reload();
  50. this.DialogResult = true;
  51. this.Close();
  52. }
  53. private void btnBrowse_Click(object sender, RoutedEventArgs e)
  54. {
  55. using (System.Windows.Forms.FolderBrowserDialog browser = new System.Windows.Forms.FolderBrowserDialog())
  56. {
  57. browser.ShowNewFolderButton = false;
  58. browser.Description = "Select a folder containing your book...";
  59. browser.RootFolder = Environment.SpecialFolder.MyComputer;
  60. if (browser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  61. {
  62. this.textBoxPath.Text = browser.SelectedPath;
  63. }
  64. }
  65. }
  66. private void Reset_Click(object sender, RoutedEventArgs e)
  67. {
  68. Properties.Settings.Default.Reset();
  69. LoadSettings();
  70. }
  71. private void LoadSettings()
  72. {
  73. this.textBoxPath.Text = Properties.Settings.Default.Catalog;
  74. this.textBoxCache.Text = Properties.Settings.Default.ImageCacheCount.ToString();
  75. this.sliderDurationCache.Value = Properties.Settings.Default.ImageCacheDuration;
  76. this.chkUseDebug.IsChecked = Properties.Settings.Default.UseDebug;
  77. if (Properties.Settings.Default.UseAutoFit == 1)
  78. this.rbWidth.IsChecked = true;
  79. else if (Properties.Settings.Default.UseAutoFit == 2)
  80. this.rbHeight.IsChecked = true;
  81. else
  82. this.rbNone.IsChecked = true;
  83. }
  84. }
  85. }