// -------------------------------------------------------------------------------------------------- #region Form callbacks private void buttonTest_Click(object sender, EventArgs e) { string name = textBoxName.Text.Trim(); try { string[] commands = new string[listBoxMacro.Items.Count]; int index = 0; for (int idx = 0; idx < listBoxMacro.Items.Count; idx++) { commands[index++] = GetCommand(idx); } string fileName = Path.Combine(FolderMacros, Common.FileExtensionMacro); IrssMacro.WriteToFile(fileName, commands); this.Enabled = false; if (_ProcessCommand != null) { _ProcessCommand(Common.CmdPrefixMacro, false); } File.Delete(fileName); } catch (Exception ex) { IrssLog.Error(ex); MessageBox.Show(this, ex.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Enabled = true; }
private void buttonOK_Click(object sender, EventArgs e) { string name = textBoxName.Text.Trim(); if (name.Length == 0) { MessageBox.Show(this, "You must supply a name for this Macro", "Name missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxName.Focus(); return; } if (!Common.IsValidFileName(name)) { MessageBox.Show(this, "You must supply a valid name for this Macro", "Invalid name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxName.Focus(); return; } try { string[] commands = new string[listBoxMacro.Items.Count]; int index = 0; foreach (string item in listBoxMacro.Items) { commands[index++] = item; } string fileName = Path.Combine(Program.FolderMacros, name + Common.FileExtensionMacro); IrssMacro.WriteToFile(fileName, commands); } catch (Exception ex) { IrssLog.Error(ex); MessageBox.Show(this, ex.Message, "Failed writing macro to file", MessageBoxButtons.OK, MessageBoxIcon.Error); } DialogResult = DialogResult.OK; Close(); }
private void buttonOK_Click(object sender, EventArgs e) { if (!_insertionEnabled && !_editionEnabled) { return; } if (!EditedMacro) { // Insert DialogResult = DialogResult.OK; Close(); return; } // Save string name = textBoxName.Text.Trim(); string fname = name + Common.FileExtensionMacro; if (name.Length == 0) { MessageBox.Show(this, "You must supply a name for this Macro", "Name missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxName.Focus(); return; } if (!Common.IsValidFileName(name)) { MessageBox.Show(this, "You must supply a valid name for this Macro", "Invalid name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxName.Focus(); return; } string fileName = Path.Combine(FolderMacros, fname); if (name != _name && File.Exists(fileName)) { DialogResult result = MessageBox.Show(this, "This macro already exists.\r\nDo you want to overwrite " + fname + " ?" , "Overwrite file", MessageBoxButtons.YesNo , MessageBoxIcon.Exclamation); if (result != System.Windows.Forms.DialogResult.Yes) { textBoxName.Focus(); return; } } try { string[] commands = new string[listBoxMacro.Items.Count]; int index = 0; for (int idx = 0; idx < listBoxMacro.Items.Count; idx++) { commands[index++] = GetCommand(idx); } IrssMacro.WriteToFile(fileName, commands); EditedMacro = false; // Renamed macro: remove previous file if (name != _name && _name != "") { string oldName = Path.Combine(FolderMacros, _name + Common.FileExtensionMacro); File.Delete(oldName); } } catch (Exception ex) { IrssLog.Error(ex); MessageBox.Show(this, ex.Message, "Failed writing macro to file: " + fname, MessageBoxButtons.OK, MessageBoxIcon.Error); } }