/// <summary> /// Creates a Macro Editor windows form. /// </summary> /// <param name="commandProcessor">The command processor.</param> /// <param name="macroFolder">The macro folder.</param> /// <param name="categories">The command categories to include.</param> /// <param name="fileName">Full path to the macro file.</param> public EditMacro(Processor commandProcessor, string macroFolder, string[] categories, string fileName) { if (commandProcessor == null) throw new ArgumentNullException("commandProcessor"); if (String.IsNullOrEmpty(macroFolder)) throw new ArgumentNullException("macroFolder"); if (categories == null) throw new ArgumentNullException("categories"); if (String.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName"); InitializeComponent(); _commandProcessor = commandProcessor; _macroFolder = macroFolder; _fileName = fileName; string macroPath = Path.GetDirectoryName(_fileName); string macroFile = Path.GetFileNameWithoutExtension(_fileName); string macroName = Path.Combine(macroPath, macroFile); if (macroName.StartsWith(_macroFolder, StringComparison.OrdinalIgnoreCase)) macroName = macroName.Substring(_macroFolder.Length); if (macroName.StartsWith(Common.FolderAppData, StringComparison.OrdinalIgnoreCase)) macroName = macroName.Substring(Common.FolderAppData.Length); textBoxName.Text = macroName; textBoxName.Enabled = false; Macro macro = new Macro(_fileName); foreach (Command command in macro.Commands) { ListViewItem item = new ListViewItem(command.GetUserDisplayText()); item.Tag = command.ToString(); listViewMacro.Items.Add(item); } PopulateCommandList(categories); }
private void buttonTest_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 (textBoxName.Enabled && !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 { Macro newMacro = new Macro(); foreach (ListViewItem item in listViewMacro.Items) { string itemTag = item.Tag as string; Command command = Processor.CreateCommand(itemTag); newMacro.Commands.Add(command); } newMacro.Execute(_commandProcessor); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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 (textBoxName.Enabled && !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 { Macro newMacro = new Macro(); foreach (ListViewItem item in listViewMacro.Items) { string itemTag = item.Tag as string; Command command = Processor.CreateCommand(itemTag); newMacro.Commands.Add(command); } if (textBoxName.Enabled) _fileName = _macroFolder + name + Processor.FileExtensionMacro; newMacro.Save(_fileName); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Failed writing macro to file", MessageBoxButtons.OK, MessageBoxIcon.Error); } DialogResult = DialogResult.OK; Close(); }
/// <summary> /// Execute this command. /// </summary> /// <param name="commandProcessor">The command processor.</param> public void Execute(Processor commandProcessor) { string[] processed = ProcessParameters(commandProcessor.Variables, Parameters); Macro macro = new Macro(processed[0]); macro.Execute(commandProcessor); }