Exemple #1
0
        /// <summary>
        /// Adds the specified switch to the specified actuator.
        /// Notifies the actuator about the switch.  Also adds the
        /// switch to the settings file and saves the settings file
        /// </summary>
        /// <param name="actuator">atuator to add to</param>
        /// <param name="switchSetting">switch to add</param>
        /// <returns>true on success</returns>
        public bool AddSwitch(IActuator actuator, SwitchSetting switchSetting)
        {
            var actuatorSetting = Config.Find(actuator.Descriptor.Id);

            if (actuatorSetting == null)
            {
                return(false);
            }

            var sw = actuatorSetting.Find(switchSetting.Name);

            if (sw != null)
            {
                return(true);
            }

            bool retVal = actuator.Load(new List <SwitchSetting>()
            {
                switchSetting
            });

            if (retVal)
            {
                actuatorSetting.SwitchSettings.Add(switchSetting);
                Config.Save();
            }

            return(retVal);
        }
Exemple #2
0
        /// <summary>
        /// Reads switch attributes from the XML file.
        /// </summary>
        /// <param name="xmlNode">The XML node that contains the Switch attributes</param>
        /// <returns>True on successful parse, false otherwise</returns>
        public virtual bool Load(SwitchSetting switchSetting)
        {
            Name        = switchSetting.Name;
            Source      = switchSetting.Source;
            Description = switchSetting.Description;
            Actuate     = switchSetting.Actuate;
            Enabled     = switchSetting.Enabled;
            AcceptTime  = CoreGlobals.AppPreferences.ResolveVariableInt(switchSetting.MinHoldTime, CoreGlobals.AppPreferences.MinActuationHoldTime, 0);

            if (!String.IsNullOrEmpty(switchSetting.BeepFile))
            {
                var beepFile = FileUtils.GetSoundPath(switchSetting.BeepFile);
                if (File.Exists(beepFile))
                {
                    try
                    {
                        _audio   = new SoundPlayer(beepFile);
                        BeepFile = beepFile;
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            Command = switchSetting.Command;

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Adds the specified switch to the list of switches supported
        /// by the actuator. switchSetting contains all the attributes of the
        /// switch.  The swtich is added to the actuators settings file and the
        /// file saved.
        /// </summary>
        /// <param name="actuator">Actuator to add to</param>
        /// <param name="switchSetting">Settings for the switch</param>
        /// <returns>true on success, false if actuator not found</returns>
        public bool RegisterSwitch(IActuator actuator, SwitchSetting switchSetting)
        {
            if (_actuators.Find(actuator.GetType()) == null)
            {
                return(false);
            }

            return(_actuators.AddSwitch(actuator, switchSetting));
        }
        private void buttonAddNew_Click(object sender, EventArgs e)
        {
            Hide();

            var editKeyboardActuatorForm = new EditKeyboardActuatorSwitchForm();

            var dialogResult = editKeyboardActuatorForm.ShowDialog();

            Show();

            if (dialogResult == DialogResult.OK)
            {
                var source = editKeyboardActuatorForm.ShortcutChanged ? editKeyboardActuatorForm.Shortcut : String.Empty;

                if (String.IsNullOrEmpty(source))
                {
                    return;
                }

                var switchName = generateSwitchName();

                var command = editKeyboardActuatorForm.MappedCommand;

                var switchSetting = new SwitchSetting(switchName, "Keyboard shortcut", command)
                {
                    Source = source
                };

                if (editKeyboardActuatorForm.IsTriggerSelect)
                {
                    switchSetting.ConfigureAsTriggerSwitch(true);
                    switchSetting.BeepFile = "beep.wav";
                }

                _actuatorSetting.SwitchSettings.Add(switchSetting);

                _isDirty = true;

                refreshDataGridView();
            }
        }
        /// <summary>
        /// Adds a new row to the datagrid representing a new
        /// switch
        /// </summary>
        /// <param name="switchSetting">parameters for the new switch</param>
        private void addDataGridRow(SwitchSetting switchSetting)
        {
            int rowNum = dataGridView2.Rows.Add(switchSetting.Source, switchSetting.Command);

            dataGridView2.Rows[rowNum].Tag = switchSetting;

            (dataGridView2[EnableColumn.Name, rowNum] as DataGridViewCheckBoxCell).Value = switchSetting.Enabled;

            (dataGridView2[TriggerColumn.Name, rowNum] as DataGridViewCheckBoxCell).Value =
                switchSetting.IsTriggerSwitch();

            dataGridView2[CommandColumn.Name, rowNum].Value = (switchSetting.IsTriggerSwitch() ||
                                                               String.IsNullOrEmpty(switchSetting.Command))
                ? _unmappedValue
                : formatCommandForDisplay(switchSetting.Command);

            dataGridView2[CommandColumn.Name, rowNum].Tag = dataGridView2[CommandColumn.Name, rowNum].Value;

            (dataGridView2[EditSwitchColumn.Name, rowNum] as DataGridViewButtonCell).Value   = "Change";
            (dataGridView2[DeleteSwitchColumn.Name, rowNum] as DataGridViewButtonCell).Value = "Remove";
        }