Esempio n. 1
0
        /// <summary>
        /// Kann zu Designzwecken verwendet werden.
        /// </summary>
        public LearnContext()
        {
            // Define buttons
            ClearConfiguration = new _Command(() => true, () => { });
            ClearKeySequences  = new _Command(() => true, () => { });
            SaveConfiguration  = new _Command(() => true, () => { });
            AddNewSequence     = new _Command(() => true, () => { });
            Exit = new _Command(() => true, () => { });

            // Load defaults
            Path          = new FileInfo(@"c:\temp\test.xml");
            Configuration = new RCSettings();

            // Finish
            CurrentKey = AllKeys[0];
        }
Esempio n. 2
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];
        }
Esempio n. 3
0
        /// <summary>
        /// Kann zu Designzwecken verwendet werden.
        /// </summary>
        public LearnContext()
        {
            // Define buttons
            ClearConfiguration = new _Command( () => true, () => { } );
            ClearKeySequences = new _Command( () => true, () => { } );
            SaveConfiguration = new _Command( () => true, () => { } );
            AddNewSequence = new _Command( () => true, () => { } );
            Exit = new _Command( () => true, () => { } );

            // Load defaults
            Path = new FileInfo( @"c:\temp\test.xml" );
            Configuration = new RCSettings();

            // Finish
            CurrentKey = AllKeys[0];
        }
Esempio n. 4
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];
        }