Exemplo n.º 1
0
        /// <summary>
        /// OnLoad handler for the form. Init the UI and populate
        /// the datagridview
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="eventArgs">eventargs</param>
        private void OnLoad(object sender, EventArgs eventArgs)
        {
            if (Actuator == null)
            {
                MessageBox.Show("Error.  Actuator to configure is null");
                Close();
            }

            float currentAspectRatio = (float)ClientSize.Height / ClientSize.Width;

            if (_designTimeAspectRatio != 0.0f && currentAspectRatio != _designTimeAspectRatio)
            {
                ClientSize = new System.Drawing.Size(ClientSize.Width, (int)(_designTimeAspectRatio * ClientSize.Width));
            }

            TopMost = false;
            TopMost = true;

            if (!String.IsNullOrEmpty(Title))
            {
                Text = Title;
            }
            else
            {
                Text = Text + " - " + Actuator.Name;
            }

            initializeUI();

            _actuatorConfig = ActuatorConfig.Load();

            _actuatorSetting = _actuatorConfig.Find(Actuator.Descriptor.Id);

            refreshDataGridView();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Refreshes the Gridview with data from the switches
        /// </summary>
        private void refreshDataGridView()
        {
            var actuatorConfig = ActuatorConfig.Load();

            var actuatorSetting = actuatorConfig.Find(Actuator.Descriptor.Id);

            foreach (var actuatorSwitch in Actuator.Switches)
            {
                var switchSetting = actuatorSetting.Find(actuatorSwitch.Name);
                if (switchSetting == null)
                {
                    continue;
                }

                int rowNum = dataGridView2.Rows.Add(actuatorSwitch.Name, actuatorSwitch.Description);
                dataGridView2.Rows[rowNum].Tag = actuatorSwitch;

                (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[MapColumn.Name, rowNum] as DataGridViewButtonCell).Value = "Map";
            }

            dataGridView2.AutoResizeRows();

            wrapText(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets data from the datagrid view, updates the switch settings
        /// and saves the settings to file
        /// </summary>
        private void updateDataFromUIAndSave()
        {
            var actuatorConfig = ActuatorConfig.Load();

            for (int ii = 0; ii < dataGridView2.Rows.Count; ii++)
            {
                var switchSetting = dataGridView2.Rows[ii].Tag as SwitchSetting;
                if (switchSetting == null)
                {
                    continue;
                }

                switchSetting.Enabled = (Boolean)dataGridView2[EnableColumn.Name, ii].Value;

                bool isTrigger = (Boolean)dataGridView2[TriggerColumn.Name, ii].Value;

                if (isTrigger)
                {
                    switchSetting.ConfigureAsTriggerSwitch(isTrigger);
                }
                else
                {
                    var command = dataGridView2[CommandColumn.Name, ii].Value as String;
                    if (command == _unmappedValue)
                    {
                        switchSetting.Command = String.Empty;
                    }
                    else
                    {
                        if (!command.StartsWith("@"))
                        {
                            command = "@" + command;
                        }

                        switchSetting.Command = command;
                    }
                }

                switchSetting.Source = dataGridView2[ShortcutColumn.Name, ii].Value as String;
            }

            var actuatorSetting = actuatorConfig.Find(Actuator.Name);

            if (actuatorSetting != null)
            {
                actuatorSetting.SwitchSettings = _actuatorSetting.SwitchSettings;

                actuatorConfig.Save();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Saves actuator settings to file.  Set the enabled
        /// attribute before saving
        /// </summary>
        public void SaveActuatorSettings()
        {
            var actuatorConfig = ActuatorConfig.Load();

            foreach (var actuatorSetting in actuatorConfig.ActuatorSettings)
            {
                var actuator = Find(actuatorSetting.Name);
                if (actuator != null)
                {
                    actuatorSetting.Enabled = actuator.Enabled;
                }
            }

            actuatorConfig.Save();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Displays preferences dialog for actuators.  User can enable/disable
        /// actuators and also configure switches for the actuator.  Uses the
        /// PreferencesCagegorySelectForm for configuring the actuators
        /// </summary>
        public void ShowPreferences()
        {
            if (_actuators == null)
            {
                return;
            }

            var list             = new List <PreferencesCategory>();
            var keyboardActuator = ActuatorManager.Instance.GetActuator(typeof(KeyboardActuator));

            foreach (var actuator in _actuators.ActuatorList)
            {
                list.Add(new PreferencesCategory(actuator, true, actuator.Enabled));
            }

            var form = new PreferencesCategorySelectForm
            {
                PreferencesCategories    = list,
                CategoryColumnHeaderText = "Actuator",
                Title = "Actuators"
            };

            form.ShowDialog();

            ActuatorConfig.ActuatorSettingsFileName = UserManager.GetFullPath(ActuatorSettingsFileName);
            var actuatorSettings = ActuatorConfig.Load();

            foreach (var category in form.PreferencesCategories)
            {
                if (category.PreferenceObj is IExtension)
                {
                    var extension       = category.PreferenceObj as IExtension;
                    var actuatorSetting = actuatorSettings.Find(extension.Descriptor.Id);
                    if (actuatorSetting != null)
                    {
                        actuatorSetting.Enabled = category.Enable;

                        foreach (var actuator in _actuators.ActuatorList.Where(actuator => Equals(actuatorSetting.Id, actuator.Descriptor.Id)))
                        {
                            actuator.Enabled = actuatorSetting.Enabled;
                        }
                    }
                }
            }

            actuatorSettings.Save();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads actuator settigns from the settings file.
        /// Walks through the extensions dirs, looks for actuators in there
        /// and caches the Types of the actuators.
        /// Configures the actuators with the settings from the settings file.
        /// Also if any acutators were discovered that are not in the settings file,
        /// adds them to the settings file and saves it.
        /// </summary>
        /// <param name="extensionDirs">directories to walk through</param>
        /// <param name="configFile">name of the actuators settings file</param>
        /// <param name="loadAll">whether to load even the disabled actuators</param>
        /// <returns>true on success</returns>
        public bool Load(IEnumerable <String> extensionDirs, String configFile, bool loadAll = false)
        {
            addKeyboardActuatorToCache();

            foreach (string dir in extensionDirs)
            {
                String extensionDir = dir + "\\" + ActuatorManager.ActuatorsRootDir;
                loadActuatorTypesIntoCache(extensionDir);
            }

            if (!File.Exists(configFile))
            {
                return(false);
            }

            ActuatorConfig.ActuatorSettingsFileName = configFile;
            Config = ActuatorConfig.Load();

            // walk through the settings file create and configure
            // actuators
            foreach (var actuatorSetting in Config.ActuatorSettings)
            {
                try
                {
                    bool enabled = (loadAll) || actuatorSetting.Enabled;
                    if (enabled && (actuatorSetting.Id != Guid.Empty))
                    {
                        if (!_actuatorsTypeCache.ContainsKey(actuatorSetting.Id))
                        {
                            continue;
                        }

                        var type = _actuatorsTypeCache[actuatorSetting.Id];
                        if (type != null)
                        {
                            var assembly = Assembly.LoadFrom(type.Assembly.Location);
                            var actuator = (IActuator)assembly.CreateInstance(type.FullName);
                            if (actuator != null)
                            {
                                actuator.OnRegisterSwitches();
                                actuator.Load(actuatorSetting.SwitchSettings);
                                actuator.Enabled = actuatorSetting.Enabled;
                                var actuatorEx = new ActuatorEx(actuator);
                                _actuatorsEx.Add(actuatorEx);
                                _actuators.Add(actuator);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                }
            }

            // now go through all the actuators that are not in the
            // settings file and add them to the settings file

            bool isDirty = false;

            foreach (var actuatorType in _actuatorsTypeCache.Values)
            {
                var attr = DescriptorAttribute.GetDescriptor(actuatorType);
                if (attr != null && attr.Id != Guid.Empty)
                {
                    var actuatorSetting = Config.Find(attr.Id);
                    if (actuatorSetting != null)
                    {
                        continue;
                    }

                    try
                    {
                        var assembly = Assembly.LoadFrom(actuatorType.Assembly.Location);
                        var actuator = (IActuator)assembly.CreateInstance(actuatorType.FullName);
                        if (actuator != null)
                        {
                            var actuatorEx = new ActuatorEx(actuator);
                            _actuatorsEx.Add(actuatorEx);
                            _actuators.Add(actuator);

                            actuatorSetting = new ActuatorSetting(attr.Name, attr.Id);
                            Config.ActuatorSettings.Add(actuatorSetting);

                            actuator.OnRegisterSwitches();
                            actuator.Load(actuatorSetting.SwitchSettings);

                            isDirty = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                    }
                }
            }

            if (isDirty)
            {
                Config.Save();
            }

            return(true);
        }