summaryrefslogtreecommitdiffstats
path: root/win/C#/frmAddPreset.cs
blob: a04b074281c7acdedec637ed6ff1b5d9f9c8f378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*  frmAddPreset.cs $
    This file is part of the HandBrake source code.
    Homepage: <http://handbrake.fr>.
    It may be used under the terms of the GNU General Public License. */

namespace Handbrake
{
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using Presets;

    /// <summary>
    /// The Add Preset Window
    /// </summary>
    public partial class frmAddPreset : Form
    {
        /// <summary>
        /// The Main  Window
        /// </summary>
        private readonly frmMain mainWindow;

        /// <summary>
        /// The Preset Handler
        /// </summary>
        private readonly PresetsHandler presetCode;

        /// <summary>
        /// The CLI Query
        /// </summary>
        private readonly string query = string.Empty;

        /// <summary>
        /// Initializes a new instance of the <see cref="frmAddPreset"/> class.
        /// </summary>
        /// <param name="fmw">
        /// The fmw.
        /// </param>
        /// <param name="queryString">
        /// The query string.
        /// </param>
        /// <param name="presetHandler">
        /// The preset handler.
        /// </param>
        public frmAddPreset(frmMain fmw, string queryString, PresetsHandler presetHandler)
        {
            InitializeComponent();
            mainWindow = fmw;
            presetCode = presetHandler;
            this.query = queryString;
        }

        /// <summary>
        /// Handle the Add button event.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void BtnAddClick(object sender, EventArgs e)
        {
            if (presetCode.Add(txt_preset_name.Text.Trim(), query, check_pictureSettings.Checked))
            {
                TreeNode presetTreeview = new TreeNode(txt_preset_name.Text.Trim()) {ForeColor = Color.Black};
                mainWindow.treeView_presets.Nodes.Add(presetTreeview);
                this.Close();
            }
            else
                MessageBox.Show("Sorry, that preset name already exists. Please choose another!", "Warning", 
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        /// <summary>
        /// Handle the Cancel button event
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void BtnCancelClick(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}