示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Macro"/> class.
        /// </summary>
        /// <param name="fileName">Name of the macro file to open.</param>
        public Macro(string fileName) : this()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(fileName);

            XmlNodeList commandSequence = doc.DocumentElement.SelectNodes("item");

            foreach (XmlNode item in commandSequence)
            {
                string  xml     = item.Attributes["xml"].Value;
                Command command = Processor.CreateCommand(xml);
                _commands.Add(command);
            }
        }
示例#2
0
        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();
        }
示例#3
0
        private void EditMacroCommand()
        {
            if (listViewMacro.SelectedItems.Count != 1)
            {
                return;
            }

            ListViewItem selected = listViewMacro.SelectedItems[0];

            string  selectedTag = selected.Tag as string;
            Command command     = Processor.CreateCommand(selectedTag);

            if (_commandProcessor.Edit(command, this))
            {
                selected.Text = command.GetUserDisplayText();
                selected.Tag  = command.ToString();
            }
        }
示例#4
0
        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);
            }
        }