Example #1
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);
        }
Example #2
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;
        }