Beispiel #1
0
        public void RefreshMacroList(string name = "")
        {
            if (_showMacroCmds)
            {
                // Create empty group
                if (_macroCommands == null)
                {
                    _macroCommands = new TreeNode("Macro");
                    treeViewCommandList.Nodes.Add(_macroCommands);
                    _editableGroups.Add(_macroCommands);
                }
                else
                {
                    _macroCommands.Nodes.Clear();
                }

                string[] macroList = IrssMacro.GetMacroList(FolderMacros, true);
                if (macroList != null && macroList.Length > 0)
                {
                    string cmdName = Common.CmdPrefixMacro + name;
                    foreach (string macro in macroList)
                    {
                        if (macro != Common.CmdPrefixMacro)
                        {
                            TreeNode node = _macroCommands.Nodes.Add(macro);
                            if (cmdName == macro)
                            {
                                treeViewCommandList.SelectedNode = node;
                            }
                        }
                    }
                }
            }
            treeViewCommandList_AfterSelect(null, null);
        }
Beispiel #2
0
        // --------------------------------------------------------------------------------------------------
        #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;
        }
Beispiel #3
0
        private void SetupMacroList()
        {
            comboBoxMacro.Items.Clear();

            string[] macroList = IrssMacro.GetMacroList(Program.FolderMacros, false);
            if (macroList != null && macroList.Length > 0)
            {
                comboBoxMacro.Items.AddRange(macroList);
                comboBoxMacro.SelectedIndex = 0;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a Macro Editor windows form.
        /// </summary>
        /// <param name="name">The name of an existing macro.</param>
        public MacroEditor(string name)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            InitializeComponent();

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

            string fileName = Path.Combine(Program.FolderMacros, name + Common.FileExtensionMacro);

            string[] commands = IrssMacro.ReadFromFile(fileName);

            listBoxMacro.Items.AddRange(commands);
        }
Beispiel #5
0
        /// <summary>
        /// Refreshes the macro command list.
        /// </summary>
        private void RefreshCommandList()
        {
            comboBoxCommands.Items.Clear();

            comboBoxCommands.Items.Add(Common.UITextRun);
            comboBoxCommands.Items.Add(Common.UITextPause);
            comboBoxCommands.Items.Add(Common.UITextSerial);
            comboBoxCommands.Items.Add(Common.UITextWindowMsg);
            comboBoxCommands.Items.Add(Common.UITextTcpMsg);
            comboBoxCommands.Items.Add(Common.UITextHttpMsg);
            comboBoxCommands.Items.Add(Common.UITextKeys);
            comboBoxCommands.Items.Add(Common.UITextMouse);
            comboBoxCommands.Items.Add(Common.UITextEject);
            comboBoxCommands.Items.Add(Common.UITextPopup);
            comboBoxCommands.Items.Add(Common.UITextVirtualKB);
            comboBoxCommands.Items.Add(Common.UITextSmsKB);
            comboBoxCommands.Items.Add(Common.UITextBeep);
            comboBoxCommands.Items.Add(Common.UITextSound);
            comboBoxCommands.Items.Add(Common.UITextDisplayMode);
            comboBoxCommands.Items.Add(Common.UITextStandby);
            comboBoxCommands.Items.Add(Common.UITextHibernate);
            comboBoxCommands.Items.Add(Common.UITextReboot);
            comboBoxCommands.Items.Add(Common.UITextShutdown);
            comboBoxCommands.Items.Add(Common.UITextLabel);
            comboBoxCommands.Items.Add(Common.UITextGotoLabel);
            comboBoxCommands.Items.Add(Common.UITextIf);
            comboBoxCommands.Items.Add(Common.UITextSetVar);
            comboBoxCommands.Items.Add(Common.UITextClearVars);
            comboBoxCommands.Items.Add(Common.UITextLoadVars);
            comboBoxCommands.Items.Add(Common.UITextSaveVars);

            string[] macroList = IrssMacro.GetMacroList(Program.FolderMacros, true);
            if (macroList != null && macroList.Length > 0)
            {
                comboBoxCommands.Items.AddRange(macroList);
            }

            string[] irList = Common.GetIRList(true);
            if (irList != null && irList.Length > 0)
            {
                comboBoxCommands.Items.AddRange(irList);
            }
        }
Beispiel #6
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
            {
                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();
        }
Beispiel #7
0
        private void LoadMenuMacros()
        {
            SetWindowTitle(UITextMacros);

            listViewMenu.LargeImageList = null;

            SetToListStyle();

            string[] macros = IrssMacro.GetMacroList(Program.FolderMacros, false);
            if (macros.Length == 0)
            {
                return;
            }

            foreach (string macro in macros)
            {
                ListViewItem item = new ListViewItem(macro);
                item.Tag = TagMacro + macro;

                listViewMenu.Items.Add(item);
            }
        }
Beispiel #8
0
        // --------------------------------------------------------------------------------------------------
        #region Constructor


        /// <summary>
        /// Creates a Macro Editor windows form.
        /// </summary>
        /// <param name="name">The name of an existing macro (default: new macro).</param>
        public MacroEditor(string name = "", IRServerInfo server = null, BlastIrDelegate blast = null, LearnIrDelegate learnIr = null, ProcessCommandDelegate processCommand = null, bool insertionEnabled = true)
        {
            if (name == null)
            {
                name = "";
            }

            _insertionEnabled = insertionEnabled;
            _editionEnabled   = !IsOpen(name);
            _OpenInstances.Add(name.ToLower());

            _name           = name;
            _server         = server;
            _blast          = blast;
            _learnIr        = learnIr;
            _ProcessCommand = processCommand;

            InitializeComponent();

            textBoxName.Text       = name;
            buttonTest.Enabled     = _ProcessCommand != null;
            buttonOK.Visible       = _insertionEnabled || _editionEnabled;
            buttonOK.Enabled       = _insertionEnabled;
            _MacroNameValid        = name != "";
            buttonShortcut.Enabled = _MacroNameValid;
            if (_editionEnabled && !_insertionEnabled || _name == "")
            {  // Show save first
                buttonOK.Enabled    = false;
                buttonOK.Text       = "Save";
                this.buttonOK.Image = global::IrssUtils.Properties.Resources.Save;
            }
            else
            {
                buttonOK.Enabled = _insertionEnabled;
            }

            if (_editionEnabled)
            {
                InitializeCommandManager();
            }
            else
            {
                // Relayout for Read-only mode
                labelInvalid.Text = "Macro is already open for edition";
                labelInvalid.Show();
                textBoxName.Enabled = false;

                groupBoxCommandSequence.Controls.Remove(splitContainerMain);
                groupBoxCommandSequence.Controls.Add(panelActions);
                this.MinimumSize = new System.Drawing.Size(310, this.Height);
                this.Width       = 350;
            }

            if (_name == "")
            {
                return;
            }

            try
            {
                string   fileName = Path.Combine(FolderMacros, name + Common.FileExtensionMacro);
                string[] commands = IrssMacro.ReadFromFile(fileName);
                foreach (var cmd in commands)
                {
                    InsertCommand(cmd);
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(this, ex.Message, "Failed to load macro: " + name + Common.FileExtensionMacro, MessageBoxButtons.OK, MessageBoxIcon.Error);
                textBoxName.Text = "";
            }

            _editedMacro = false;
        }
Beispiel #9
0
        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);
            }
        }