Ejemplo n.º 1
0
        private void buttonDeleteMacro_Click(object sender, EventArgs e)
        {
            if (listViewMacro.SelectedItems.Count != 1)
            {
                return;
            }

            string file     = listViewMacro.SelectedItems[0].Text;
            string fileName = TV3BlasterPlugin.PathCombine(file);

            if (File.Exists(fileName))
            {
                if (
                    MessageBox.Show(this, String.Format("Are you sure you want to delete \"{0}\"?", file), "Confirm delete",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    File.Delete(fileName);
                }
            }
            else
            {
                MessageBox.Show(this, "File not found: " + fileName, "Macro file missing", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }

            RefreshMacroList();
        }
Ejemplo n.º 2
0
        private void EditMacro()
        {
            if (listViewMacro.SelectedItems.Count != 1)
            {
                return;
            }

            try
            {
                string command  = listViewMacro.SelectedItems[0].Text;
                string fileName = TV3BlasterPlugin.PathCombine(command);

                if (File.Exists(fileName))
                {
                    MacroEditor macroEditor = new MacroEditor(command);
                    macroEditor.ShowDialog(this);
                }
                else
                {
                    RefreshMacroList();

                    throw new FileNotFoundException("Macro file missing", fileName);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                MessageBox.Show(this, ex.Message, "Failed to edit macro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
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 (!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
            {
                WriteToFile(TV3BlasterPlugin.PathCombine(name));
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                MessageBox.Show(this, ex.Message, "Failed writing macro to file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Ejemplo n.º 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 (!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
            {
                WriteToFile(TV3BlasterPlugin.PathCombine(name));

                TV3BlasterPlugin.ProcessCommand(Common.CmdPrefixMacro + name, false);
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                MessageBox.Show(this, ex.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 5
0
        private void listViewMacro_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            ListView origin = sender as ListView;

            if (origin == null)
            {
                e.CancelEdit = true;
                return;
            }

            if (String.IsNullOrEmpty(e.Label))
            {
                e.CancelEdit = true;
                return;
            }

            ListViewItem originItem = origin.Items[e.Item];

            string oldFileName = TV3BlasterPlugin.PathCombine(originItem.Text);

            if (!File.Exists(oldFileName))
            {
                MessageBox.Show("File not found: " + oldFileName, "Cannot rename, Original file not found", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                e.CancelEdit = true;
                return;
            }

            string name = e.Label.Trim();

            if (!Common.IsValidFileName(name))
            {
                MessageBox.Show("File name not valid: " + name, "Cannot rename, New file name not valid", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                e.CancelEdit = true;
                return;
            }

            try
            {
                string newFileName = TV3BlasterPlugin.PathCombine(name);
                File.Move(oldFileName, newFileName);
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(ex.Message, "Failed to rename file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a Macro Editor windows form.
        /// </summary>
        /// <param name="name">The name of an existing macro.</param>
        public MacroEditor(string name)
            : this()
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            textBoxName.Text    = name;
            textBoxName.Enabled = false;

            string fileName = TV3BlasterPlugin.
                              PathCombine(name);

            ReadFromFile(fileName);
        }