OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmAddPreset.cs
index 2beabc5..256b9b9 100644 (file)
@@ -5,61 +5,40 @@
           It may be used under the terms of the GNU General Public License. */\r
 \r
 using System;\r
-using System.Collections.Generic;\r
-using System.ComponentModel;\r
-using System.Data;\r
 using System.Drawing;\r
-using System.Text;\r
 using System.Windows.Forms;\r
-using System.IO;\r
 \r
 namespace Handbrake\r
 {\r
     public partial class frmAddPreset : Form\r
     {\r
-        private frmMain frmMainWindow;\r
-        public frmAddPreset(frmMain fmw)\r
+        private readonly frmMain _frmMainWindow;\r
+        readonly Presets.PresetsHandler _presetCode;\r
+        private readonly string _query = "";\r
+\r
+        public frmAddPreset(frmMain fmw, string queryString, Presets.PresetsHandler presetHandler)\r
         {\r
             InitializeComponent();\r
-            frmMainWindow = fmw;\r
+            _frmMainWindow = fmw;\r
+            _presetCode = presetHandler;\r
+            this._query = queryString;\r
         }\r
 \r
         private void btn_add_Click(object sender, EventArgs e)\r
         {\r
-            if (txt_preset_name.Text.Trim() == "")\r
-                MessageBox.Show("You have not entered a name for the preset.","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-            else if (txt_preset_name.Text.Trim().Contains("--"))\r
-                MessageBox.Show("The preset name can not contain two dashes '--'","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
-            else\r
+            if (_presetCode.Add(txt_preset_name.Text.Trim(), _query, check_pictureSettings.Checked))\r
             {\r
-                Functions.Common hb_common_func = new Functions.Common();\r
-\r
-                string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat";\r
-                try\r
-                {\r
-                    // Create a StreamWriter and open the file\r
-                    StreamWriter line = File.AppendText(userPresets);\r
-\r
-                    // Generate and write the preset string to the file\r
-                    String query = hb_common_func.GenerateTheQuery(frmMainWindow);\r
-                    String preset = "+ " + txt_preset_name.Text + ":  " + query;\r
-                    line.WriteLine(preset);\r
-\r
-                    // close the stream\r
-                    line.Close();\r
-                    line.Dispose();\r
-                    MessageBox.Show("Your profile has been sucessfully added.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);\r
-                }\r
-                catch (Exception exc)\r
-                {\r
-                    MessageBox.Show("Unable to write to the file. Please make sure the location has the correct permissions for file writing.\n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);\r
-                }\r
-                frmMainWindow.loadPresetPanel();\r
+                TreeNode presetTreeview = new TreeNode(txt_preset_name.Text.Trim()) { ForeColor = Color.Black };\r
+                _frmMainWindow.treeView_presets.Nodes.Add(presetTreeview);\r
                 this.Close();\r
-            }\r
+            } \r
+            else\r
+                MessageBox.Show("Sorry, that preset name already exists. Please choose another!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
         }\r
-    }\r
-}\r
-\r
-\r
 \r
+        private void btn_cancel_Click(object sender, EventArgs e)\r
+        {\r
+            this.Close();\r
+        }\r
+    }\r
+}
\ No newline at end of file