PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

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