X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=win%2FC%23%2FfrmAddPreset.cs;h=256b9b9fc9c8ab880717047acfbb104b8ad37427;hb=db08019084d6be0e06aa516b36f297b50730c440;hp=2beabc53c84f502bc46097c91a1e06e1433f655c;hpb=e9f8c16ea4a74b484ca6d542419244ba3354a48d;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/win/C#/frmAddPreset.cs b/win/C#/frmAddPreset.cs index 2beabc53..256b9b9f 100644 --- a/win/C#/frmAddPreset.cs +++ b/win/C#/frmAddPreset.cs @@ -5,61 +5,40 @@ It may be used under the terms of the GNU General Public License. */ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Text; using System.Windows.Forms; -using System.IO; namespace Handbrake { public partial class frmAddPreset : Form { - private frmMain frmMainWindow; - public frmAddPreset(frmMain fmw) + private readonly frmMain _frmMainWindow; + readonly Presets.PresetsHandler _presetCode; + private readonly string _query = ""; + + public frmAddPreset(frmMain fmw, string queryString, Presets.PresetsHandler presetHandler) { InitializeComponent(); - frmMainWindow = fmw; + _frmMainWindow = fmw; + _presetCode = presetHandler; + this._query = queryString; } private void btn_add_Click(object sender, EventArgs e) { - if (txt_preset_name.Text.Trim() == "") - MessageBox.Show("You have not entered a name for the preset.","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else if (txt_preset_name.Text.Trim().Contains("--")) - MessageBox.Show("The preset name can not contain two dashes '--'","Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else + if (_presetCode.Add(txt_preset_name.Text.Trim(), _query, check_pictureSettings.Checked)) { - Functions.Common hb_common_func = new Functions.Common(); - - string userPresets = Application.StartupPath.ToString() + "\\user_presets.dat"; - try - { - // Create a StreamWriter and open the file - StreamWriter line = File.AppendText(userPresets); - - // Generate and write the preset string to the file - String query = hb_common_func.GenerateTheQuery(frmMainWindow); - String preset = "+ " + txt_preset_name.Text + ": " + query; - line.WriteLine(preset); - - // close the stream - line.Close(); - line.Dispose(); - MessageBox.Show("Your profile has been sucessfully added.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - } - catch (Exception exc) - { - 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); - } - frmMainWindow.loadPresetPanel(); + TreeNode presetTreeview = new TreeNode(txt_preset_name.Text.Trim()) { ForeColor = Color.Black }; + _frmMainWindow.treeView_presets.Nodes.Add(presetTreeview); this.Close(); - } + } + else + MessageBox.Show("Sorry, that preset name already exists. Please choose another!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } - } -} - - + private void btn_cancel_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} \ No newline at end of file