Example #1
0
        public InputKey? this[params MappingItem[] index]
        {
            get
            {
                // Create the key
                var key = new InputMapping();

                // Add index
                if (index != null)
                {
                    key.Items.AddRange(index);
                }

                // Find it
                InputMapping existing;
                if (m_Mappings.TryGetValue(key, out existing))
                {
                    return(existing.Meaning);
                }
                else
                {
                    return(null);
                }
            }
            set
            {
                // Create the key
                var key = new InputMapping {
                    Meaning = value.GetValueOrDefault()
                };

                // Add index
                if (index != null)
                {
                    key.Items.AddRange(index);
                }

                // Check mode
                if (value.HasValue)
                {
                    m_Mappings[key] = key;
                }
                else
                {
                    m_Mappings.Remove(key);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Ergänzt eine Abbildungsvorschrift während des Ladevorgangs.
        /// </summary>
        /// <param name="mapping">Eine Vorschrift.</param>
        /// <exception cref="ArgumentNullException">Es wurde keine Vorschrift angegeben.</exception>
        /// <returns>Gesetzt, wenn die Vorschrift tatsächlich ergänzt wurde.</returns>
        public bool Add( InputMapping mapping )
        {
            // Validate
            if (mapping == null)
                throw new ArgumentNullException( "mapping" );

            // Got it
            if (m_Mappings.ContainsKey( mapping ))
                return false;

            // Just remember           
            m_Mappings.Add( mapping, mapping );

            // Report
            return true;
        }
Example #3
0
        /// <summary>
        /// Ergänzt eine Abbildungsvorschrift während des Ladevorgangs.
        /// </summary>
        /// <param name="mapping">Eine Vorschrift.</param>
        /// <exception cref="ArgumentNullException">Es wurde keine Vorschrift angegeben.</exception>
        /// <returns>Gesetzt, wenn die Vorschrift tatsächlich ergänzt wurde.</returns>
        public bool Add(InputMapping mapping)
        {
            // Validate
            if (mapping == null)
            {
                throw new ArgumentNullException("mapping");
            }

            // Got it
            if (m_Mappings.ContainsKey(mapping))
            {
                return(false);
            }

            // Just remember
            m_Mappings.Add(mapping, mapping);

            // Report
            return(true);
        }
Example #4
0
        public InputKey? this[params MappingItem[] index]
        {
            get
            {
                // Create the key
                var key = new InputMapping();

                // Add index
                if (index != null)
                    key.Items.AddRange( index );

                // Find it
                InputMapping existing;
                if (m_Mappings.TryGetValue( key, out existing ))
                    return existing.Meaning;
                else
                    return null;
            }
            set
            {
                // Create the key
                var key = new InputMapping { Meaning = value.GetValueOrDefault() };

                // Add index
                if (index != null)
                    key.Items.AddRange( index );

                // Check mode
                if (value.HasValue)
                    m_Mappings[key] = key;
                else
                    m_Mappings.Remove( key );
            }
        }
Example #5
0
        /// <summary>
        /// Erzeugt eine neue Arbeitsumgebung.
        /// </summary>
        /// <param name="path">Die zu verwendende Konfigurationsdatei.</param>
        /// <param name="exitAction">Wird beim Beenden aufgerufen.</param>
        private LearnContext( FileInfo path, Action exitAction )
        {
            // Reset the whole configuration
            ClearConfiguration =
                new _Command( () => Configuration.Mappings.Length > 0, () =>
                    {
                        // Process
                        Configuration.Mappings = null;

                        // We changed
                        m_Changed = true;

                        // Refresh nearly all
                        RefreshButtons( ClearConfiguration, ClearKeySequences, SaveConfiguration );
                    } );


            // Reset the configuration of a single key
            ClearKeySequences =
                new _Command( () => Configuration.Mappings.Any( m => m.Meaning == m_CurrentKey ), () =>
                    {
                        // Process
                        Configuration.Mappings = Configuration.Mappings.Where( m => m.Meaning != m_CurrentKey ).ToArray();

                        // We changed
                        m_Changed = true;

                        // Refresh
                        RefreshButtons( ClearConfiguration, ClearKeySequences, SaveConfiguration );
                    } );

            // Save the configuration and leave
            SaveConfiguration =
                new _Command( () => m_Changed, () =>
                    {
                        // Safe process
                        try
                        {
                            // Send to disk
                            Configuration.Save( Path.FullName );

                            // Done
                            Exit.Execute( null );
                        }
                        catch (Exception e)
                        {
                            // Show error
                            MessageBox.Show( e.Message, Properties.Resources.RC_Learn_SaveError );
                        }
                    } );

            // Register a new sequence
            AddNewSequence =
                new _Command( () => m_Sequence.Count > 0, () =>
                    {
                        // Test for add
                        if (m_Sequence.Count > 0)
                        {
                            // Create mapping
                            var mapping = new InputMapping { Meaning = m_CurrentKey };

                            // Fill sequence
                            mapping.Items.AddRange( m_Sequence );

                            // Add if not already there
                            if (Configuration.Add( mapping ))
                            {
                                // Now we changed
                                m_Changed = true;
                            }
                        }

                        // Reset
                        RegisterSequence( null );

                        // Refresh
                        RefreshButtons( ClearKeySequences, ClearConfiguration, SaveConfiguration );
                    } );

            // Other buttons
            Exit = new _Command( () => true, exitAction );

            // Remember
            Path = path;

            // Load configuration
            if (path.Exists)
                Configuration = RCSettings.Load( path.FullName );
            else
                Configuration = new RCSettings();

            // Finish
            CurrentKey = AllKeys[0];
        }
Example #6
0
        /// <summary>
        /// Erzeugt eine neue Arbeitsumgebung.
        /// </summary>
        /// <param name="path">Die zu verwendende Konfigurationsdatei.</param>
        /// <param name="exitAction">Wird beim Beenden aufgerufen.</param>
        private LearnContext(FileInfo path, Action exitAction)
        {
            // Reset the whole configuration
            ClearConfiguration =
                new _Command(() => Configuration.Mappings.Length > 0, () =>
            {
                // Process
                Configuration.Mappings = null;

                // We changed
                m_Changed = true;

                // Refresh nearly all
                RefreshButtons(ClearConfiguration, ClearKeySequences, SaveConfiguration);
            });


            // Reset the configuration of a single key
            ClearKeySequences =
                new _Command(() => Configuration.Mappings.Any(m => m.Meaning == m_CurrentKey), () =>
            {
                // Process
                Configuration.Mappings = Configuration.Mappings.Where(m => m.Meaning != m_CurrentKey).ToArray();

                // We changed
                m_Changed = true;

                // Refresh
                RefreshButtons(ClearConfiguration, ClearKeySequences, SaveConfiguration);
            });

            // Save the configuration and leave
            SaveConfiguration =
                new _Command(() => m_Changed, () =>
            {
                // Safe process
                try
                {
                    // Send to disk
                    Configuration.Save(Path.FullName);

                    // Done
                    Exit.Execute(null);
                }
                catch (Exception e)
                {
                    // Show error
                    MessageBox.Show(e.Message, Properties.Resources.RC_Learn_SaveError);
                }
            });

            // Register a new sequence
            AddNewSequence =
                new _Command(() => m_Sequence.Count > 0, () =>
            {
                // Test for add
                if (m_Sequence.Count > 0)
                {
                    // Create mapping
                    var mapping = new InputMapping {
                        Meaning = m_CurrentKey
                    };

                    // Fill sequence
                    mapping.Items.AddRange(m_Sequence);

                    // Add if not already there
                    if (Configuration.Add(mapping))
                    {
                        // Now we changed
                        m_Changed = true;
                    }
                }

                // Reset
                RegisterSequence(null);

                // Refresh
                RefreshButtons(ClearKeySequences, ClearConfiguration, SaveConfiguration);
            });

            // Other buttons
            Exit = new _Command(() => true, exitAction);

            // Remember
            Path = path;

            // Load configuration
            if (path.Exists)
            {
                Configuration = RCSettings.Load(path.FullName);
            }
            else
            {
                Configuration = new RCSettings();
            }

            // Finish
            CurrentKey = AllKeys[0];
        }