1 // Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
3 // This program is part of BurageSnap.
5 // BurageSnap is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.
19 using System.ComponentModel;
21 using System.Windows.Forms;
22 using BurageSnap.Properties;
26 public partial class OptionDialog : Form
28 private readonly Config _config;
29 private readonly ErrorProvider _errorProvider = new ErrorProvider();
31 public OptionDialog(Config config)
33 InitializeComponent();
37 private void buttonOk_Click(object sender, EventArgs e)
39 var ringbuffer = int.Parse(textBoxRingBuffer.Text);
40 if (checkBoxAnimationGif.Checked && ringbuffer == 0)
42 DialogResult = DialogResult.None;
43 _errorProvider.SetError(textBoxRingBuffer,
44 Resources.OptionDialog_buttonOk_Click_Ring_buffer_for_animation_GIF);
47 _errorProvider.SetError(textBoxRingBuffer, "");
48 _config.TopMost = checkBoxTopMost.Checked;
49 _config.Interval = int.Parse(textBoxInterval.Text);
50 _config.RingBuffer = ringbuffer;
51 var title = comboBoxWindowTitle.Text;
54 comboBoxWindowTitle.Items.Remove(title);
55 comboBoxWindowTitle.Items.Insert(0, title);
56 for (var i = comboBoxWindowTitle.Items.Count; i > 10; i--)
57 comboBoxWindowTitle.Items.RemoveAt(10);
59 _config.TitleHistory = (from object item in comboBoxWindowTitle.Items select item.ToString()).ToArray();
60 _config.Folder = textBoxFolder.Text;
61 _config.Format = radioButtonJpg.Checked ? OutputFormat.Jpg : OutputFormat.Png;
62 _config.AnimationGif = checkBoxAnimationGif.Checked;
65 private void OptionDialog_Load(object sender, EventArgs e)
67 checkBoxTopMost.Checked = _config.TopMost;
68 textBoxInterval.Text = _config.Interval.ToString();
69 textBoxRingBuffer.Text = _config.RingBuffer.ToString();
70 comboBoxWindowTitle.Items.Clear();
71 // ReSharper disable once CoVariantArrayConversion
72 comboBoxWindowTitle.Items.AddRange(_config.TitleHistory);
73 comboBoxWindowTitle.Text = _config.TitleHistory[0];
74 textBoxFolder.Text = _config.Folder;
75 textBoxFolder.Select(textBoxFolder.TextLength, 0);
76 radioButtonJpg.Checked = _config.Format == OutputFormat.Jpg;
77 radioButtonPng.Checked = _config.Format == OutputFormat.Png;
78 checkBoxAnimationGif.Checked = _config.AnimationGif;
81 private void buttonBrowse_Click(object sender, EventArgs e)
83 folderBrowserDialog.SelectedPath = textBoxFolder.Text;
84 if (folderBrowserDialog.ShowDialog(this) != DialogResult.OK)
86 textBoxFolder.Text = folderBrowserDialog.SelectedPath;
87 textBoxFolder.Select(textBoxFolder.TextLength, 0);
90 private void textBoxInterval_Validating(object sender, CancelEventArgs e)
93 if (int.TryParse(textBoxInterval.Text, out interval) && 0 < interval && interval < 1000 * 1000)
95 _errorProvider.SetError(textBoxInterval, "");
99 _errorProvider.SetError(textBoxInterval, Resources.OptionDialog_textBoxInterval_Validating_Interval);
102 private void textBoxRingBuffer_Validating(object sender, CancelEventArgs e)
105 if (int.TryParse(textBoxRingBuffer.Text, out frames) && 0 <= frames && frames <= 100)
107 _errorProvider.SetError(textBoxRingBuffer, "");
111 _errorProvider.SetError(textBoxRingBuffer, Resources.OptionDialog_textBoxRingBuffer_Validating);