Beispiel #1
0
        private void RegisterHotKey(TextBox txt, Shortcuts.SC_Type Id, KeyEventArgs e)
        {
            ShortcutsKey key = new ShortcutsKey();

            if (e.KeyCode == Keys.ShiftKey)
            {
                return;
            }
            if (e.KeyCode == Keys.ControlKey)
            {
                return;
            }
            if (e.KeyCode == Keys.Alt)
            {
                return;
            }
            if (e.KeyCode == Keys.Menu)
            {
                return;                         // = Alt
            }
            // register hotkey
            key.key = e;
            sc.Key_Set(Id, key);

            txt.Text = key.GetDescriptionString();
        }
Beispiel #2
0
        /// <summary>
        /// Reads the hot key configuration and setup the UI elements accordingly
        /// </summary>
        /// <param name="Id">Configuration type to be read</param>
        /// <param name="cb">Checkbox to show enable/disable status</param>
        /// <param name="txt">Textbox to show description string</param>
        private void LoadHotKey(Shortcuts.SC_Type Id, CheckBox cb, TextBox txt)
        {
            ShortcutsKey key = sc.Key_Get(Id);

            cb.Checked = key.used;
            txt.Text   = key.GetDescriptionString();
        }
Beispiel #3
0
 /// <summary>
 /// Build empty hot key list, save window handle.
 /// Call Initialize() to start using hot keys
 /// </summary>
 public Shortcuts(IntPtr WindowHandle)
 {
     hwnd = WindowHandle;
     for (int i = 0; i < (int)SC_Type.SC_Type_MAX; i++)
     {
         sc_list[i] = new ShortcutsKey();
     }
 }
Beispiel #4
0
        /// <summary>
        /// Configures and enables a shortcut for a key
        /// </summary>
        public void Key_Set(SC_Type Id, ShortcutsKey key)
        {
            if (Key_Get(Id).used)
            {
                HotKeyRegister(Id, key, false);
            }

            HotKeyRegister(Id, key, true);
            sc_list.SetValue(key.ShallowCopy(), (int)Id);
        }
Beispiel #5
0
        /// <summary>
        /// Initializes oject by setting the method (and configure timer)
        /// </summary>
        public void Initialize(SC_HotKeyMethod HotKeyMethod)
        {
            NextStart_Method = method = HotKeyMethod;

            for (int i = 0; i < (int)SC_Type.SC_Type_MAX; i++)
            {
                sc_list[i] = new ShortcutsKey();
            }

            if (method == SC_HotKeyMethod.SC_HotKeyMethod_Async)
            {
                TimerProcKeepAliveReference = new OsLayer.TimerProc(timer_event); // stupid garbage collection fixup
                OsLayer.SetTimer(hwnd, 0, 20, TimerProcKeepAliveReference);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Enables or Disables a shortcut
        /// </summary>
        public void Key_SetState(SC_Type Id, bool IsEnabled)
        {
            ShortcutsKey key = Key_Get(Id);

            if (!key.valid)
            {
                return;
            }

            if (!key.used && IsEnabled)
            {
                HotKeyRegister(Id, key, true);
            }
            else if (key.used && !IsEnabled)
            {
                HotKeyRegister(Id, key, false);
            }

            sc_list.SetValue(key, (int)Id);
        }
Beispiel #7
0
        /// <summary>
        /// Validates a hotkey and when enabled registers it
        /// </summary>
        private bool LoadHotKeySettings(Shortcuts.SC_Type Type, int KeyCode, bool Enable)
        {
            ShortcutsKey key = new ShortcutsKey();

            key.key = new KeyEventArgs((Keys)KeyCode);
            if (Enable)
            {
                sc.Key_Set(Type, key);
                if (!sc.Key_Get(Type).valid)
                {
                    return(false);
                }
            }
            else
            {
                sc.Key_PreSet(Type, key);
            }

            return(true);
        }
        /// <summary>
        /// Stores user data in XML
        /// </summary>
        private void SaveSettings()
        {
            ShortcutsKey key = new ShortcutsKey();

            _settings.MainWidth    = this.Width;
            _settings.MainHeight   = this.Height;
            _settings.HotKeyMethod = (int)sc.NextStart_Method;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Reset);
            _settings.ShortcutResetEnable  = key.used;
            _settings.ShortcutResetKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Hit);
            _settings.ShortcutHitEnable  = key.used;
            _settings.ShortcutHitKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_HitUndo);
            _settings.ShortcutHitUndoEnable  = key.used;
            _settings.ShortcutHitUndoKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Split);
            _settings.ShortcutSplitEnable  = key.used;
            _settings.ShortcutSplitKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_SplitPrev);
            _settings.ShortcutSplitPrevEnable  = key.used;
            _settings.ShortcutSplitPrevKeyCode = (int)key.key.KeyData;
            _settings.Inputfile               = om.FilePathIn;
            _settings.OutputFile              = om.FilePathOut;
            _settings.ShowAttemptsCounter     = om.ShowAttemptsCounter;
            _settings.ShowHeadline            = om.ShowHeadline;
            _settings.ShowSessionProgress     = om.ShowSessionProgress;
            _settings.ShowSplitsCountFinished = om.ShowSplitsCountFinished;
            _settings.ShowSplitsCountUpcoming = om.ShowSplitsCountUpcoming;
            _settings.StyleUseHighContrast    = om.StyleUseHighContrast;
            _settings.StyleUseCustom          = om.StyleUseCustom;
            _settings.StyleCssUrl             = om.StyleCssUrl;
            _settings.StyleFontUrl            = om.StyleFontUrl;
            _settings.StyleFontName           = om.StyleFontName;
            _settings.StyleDesiredWidth       = om.StyleDesiredWidth;
            _settings.ProfileSelected         = (string)ComboBox1.SelectedItem;
            _settings.Profiles = profs;
            sm.WriteXML(_settings);
        }
Beispiel #9
0
        /// <summary>
        /// Get the bound key of a shortcut
        /// </summary>
        public ShortcutsKey Key_Get(SC_Type Id)
        {
            ShortcutsKey key = (ShortcutsKey)sc_list.GetValue((int)Id);

            return(key.ShallowCopy());
        }
Beispiel #10
0
 /// <summary>
 /// Configures and disables a shortcut for a key
 /// </summary>
 public void Key_PreSet(SC_Type Id, ShortcutsKey key)
 {
     Key_Set(Id, key.ShallowCopy()); // configures and validate key (enable once)
     Key_SetState(Id, false);        // disable afterwards
 }
Beispiel #11
0
        /// <summary>
        /// Registers and unregisters a hotkey
        /// </summary>
        private void HotKeyRegister(SC_Type Id, ShortcutsKey key, bool Enable)
        {
            uint modifier = 0;

            if (key.key.Shift)
            {
                modifier += MOD_SHIFT;
            }
            if (key.key.Control)
            {
                modifier += MOD_CONTROL;
            }
            if (key.key.Alt)
            {
                modifier += MOD_ALT;
            }

            if (method == SC_HotKeyMethod.SC_HotKeyMethod_Sync)
            {
                if (Enable)
                {
                    if (OsLayer.SetHotKey(hwnd, (int)Id, modifier, (int)key.key.KeyCode))
                    {
                        key.used  = true;
                        key.valid = true;
                    }
                    else
                    {
                        // anything went wrong while registering, clear key..
                        key.used  = false;
                        key.valid = false;
                    }
                }
                else
                {
                    OsLayer.KillHotKey(hwnd, (int)Id);
                    key.used = false;
                }
            }
            else if (method == SC_HotKeyMethod.SC_HotKeyMethod_Async)
            {
                if (Enable)
                {
                    if (OsLayer.SetHotKey(hwnd, (int)Id, modifier, (int)key.key.KeyCode))
                    {
                        OsLayer.KillHotKey(hwnd, (int)Id); // don't use this method, we just used registration to check if keycode is valid and works
                        key.used  = true;
                        key.valid = true;
                    }
                    else
                    {
                        // anything went wrong while registering, clear key..
                        key.used  = false;
                        key.valid = false;
                    }
                }
                else
                {
                    key.used = false;
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Loads user data from XML
        /// </summary>
        private void LoadSettings()
        {
            ShortcutsKey key = new ShortcutsKey();

            om.DataUpdatePending = true;

            sm        = new SaveModule <SettingsRoot>(Application.ProductName + "Save.xml");
            _settings = sm.ReadXML();

            if (null == _settings)
            {
                // When no user save file is available, try loading the init file instead to provide predefined profiles and settings
                _settings = sm.ReadXML(Application.ProductName + "Init.xml");
            }
            if (null == _settings)
            {
                _settings = new SettingsRoot();

                // prepare defaults..
                _settings.Version              = 0;
                _settings.MainWidth            = 559;
                _settings.MainHeight           = 723;
                _settings.HotKeyMethod         = (int)Shortcuts.SC_HotKeyMethod.SC_HotKeyMethod_Async;
                _settings.ShortcutResetEnable  = false;
                _settings.ShortcutResetKeyCode = 0x10000 | 0x75; // Shift F6
                _settings.ShortcutHitEnable    = false;
                _settings.ShortcutHitKeyCode   = 0x10000 | 0x76; // Shift F7
                _settings.ShortcutSplitEnable  = false;
                _settings.ShortcutSplitKeyCode = 0x10000 | 0x77; // Shift F8
                _settings.Inputfile            = "HitCounter.template";
                _settings.OutputFile           = "HitCounter.html";
                _settings.ProfileSelected      = "Unnamed";
                _settings.Profiles             = new Profiles();
            }
            if (_settings.Version == 0) // Coming from version 1.9 or older
            {
                _settings.Version                 = 1;
                _settings.ShowAttemptsCounter     = true;
                _settings.ShowHeadline            = true;
                _settings.ShowSplitsCountFinished = 999;
                _settings.ShowSplitsCountUpcoming = 999;
                _settings.StyleUseHighContrast    = false;
                _settings.StyleUseCustom          = false;
                _settings.StyleCssUrl             = "stylesheet_pink.css";
                _settings.StyleFontUrl            = "https://fonts.googleapis.com/css?family=Fontdiner%20Swanky";
            }
            if (_settings.Version == 1) // Coming from version 1.10
            {
                _settings.Version             = 2;
                _settings.MainWidth          += 31; // added new checkbox to datagrid
                _settings.ShowSessionProgress = true;
                _settings.StyleDesiredWidth   = 0;
            }
            if (_settings.Version == 2) // Coming from version 1.11 to 1.14
            {
                _settings.Version = 3;
                _settings.ShortcutHitUndoEnable    = false;
                _settings.ShortcutHitUndoKeyCode   = 0x10000 | 0x78; // Shift F9
                _settings.ShortcutSplitPrevEnable  = false;
                _settings.ShortcutSplitPrevKeyCode = 0x10000 | 0x79; // Shift F10
            }
            if (_settings.Version == 3)                              // Coming from version 1.15
            {
                _settings.Version       = 4;
                _settings.StyleFontName = "Fontdiner Swanky";
            }

            // Apply settings..
            sc.Initialize((Shortcuts.SC_HotKeyMethod)_settings.HotKeyMethod);
            profs = _settings.Profiles;

            this.ComboBox1.Items.AddRange(profs.GetProfileList());
            if (this.ComboBox1.Items.Count == 0)
            {
                this.ComboBox1.Items.Add("Unnamed");
            }
            this.ComboBox1.SelectedItem = _settings.ProfileSelected;

            key.key = new KeyEventArgs((Keys)_settings.ShortcutResetKeyCode);
            if (_settings.ShortcutResetEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_Reset, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_Reset, key);
            }
            key.key = new KeyEventArgs((Keys)_settings.ShortcutHitKeyCode);
            if (_settings.ShortcutHitEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_Hit, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_Hit, key);
            }
            key.key = new KeyEventArgs((Keys)_settings.ShortcutHitUndoKeyCode);
            if (_settings.ShortcutHitUndoEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_HitUndo, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_HitUndo, key);
            }
            key.key = new KeyEventArgs((Keys)_settings.ShortcutSplitKeyCode);
            if (_settings.ShortcutSplitEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_Split, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_Split, key);
            }
            key.key = new KeyEventArgs((Keys)_settings.ShortcutSplitPrevKeyCode);
            if (_settings.ShortcutSplitPrevEnable)
            {
                sc.Key_Set(Shortcuts.SC_Type.SC_Type_SplitPrev, key);
            }
            else
            {
                sc.Key_PreSet(Shortcuts.SC_Type.SC_Type_SplitPrev, key);
            }

            pi.SetActiveSplit(0);
            pi.SetSessionProgress(0, true);

            if (_settings.MainWidth > 400)
            {
                this.Width = _settings.MainWidth;
            }
            if (_settings.MainHeight > 400)
            {
                this.Height = _settings.MainHeight;
            }

            om.ShowAttemptsCounter     = _settings.ShowAttemptsCounter;
            om.ShowHeadline            = _settings.ShowHeadline;
            om.ShowSessionProgress     = _settings.ShowSessionProgress;
            om.ShowSplitsCountFinished = _settings.ShowSplitsCountFinished;
            om.ShowSplitsCountUpcoming = _settings.ShowSplitsCountUpcoming;
            om.StyleUseHighContrast    = _settings.StyleUseHighContrast;
            om.StyleUseCustom          = _settings.StyleUseCustom;
            om.StyleCssUrl             = _settings.StyleCssUrl;
            om.StyleFontUrl            = _settings.StyleFontUrl;
            om.StyleFontName           = _settings.StyleFontName;
            om.StyleDesiredWidth       = _settings.StyleDesiredWidth;

            om.FilePathIn        = _settings.Inputfile;
            om.FilePathOut       = _settings.OutputFile; // setting output filepath will allow writing output, so keep this line last
            om.DataUpdatePending = false;
        }
Beispiel #13
0
        /// <summary>
        /// Stores user data in XML
        /// </summary>
        private void SaveSettings()
        {
            ShortcutsKey key = new ShortcutsKey();

            // Remember window position and sates
            if (this.WindowState == FormWindowState.Normal) // Don't save window size and location when maximized or minimized
            {
                _settings.MainWidth  = this.Width;
                _settings.MainHeight = this.Height;
                if (Program.IsOnScreen(_settings.MainPosX, _settings.MainPosY, _settings.MainWidth))
                {
                    // remember values when not outside of screen
                    _settings.MainPosX = this.Left;
                    _settings.MainPosY = this.Top;
                }
            }
            _settings.ReadOnlyMode = this.ReadOnlyMode;
            _settings.AlwaysOnTop  = this.TopMost;
            _settings.DarkMode     = Program.DarkMode;

            // Store hot keys..
            _settings.HotKeyMethod = (int)sc.NextStart_Method;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Reset);
            _settings.ShortcutResetEnable  = key.used;
            _settings.ShortcutResetKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Hit);
            _settings.ShortcutHitEnable  = key.used;
            _settings.ShortcutHitKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_HitUndo);
            _settings.ShortcutHitUndoEnable  = key.used;
            _settings.ShortcutHitUndoKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_WayHit);
            _settings.ShortcutWayHitEnable  = key.used;
            _settings.ShortcutWayHitKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_WayHitUndo);
            _settings.ShortcutWayHitUndoEnable  = key.used;
            _settings.ShortcutWayHitUndoKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Split);
            _settings.ShortcutSplitEnable  = key.used;
            _settings.ShortcutSplitKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_SplitPrev);
            _settings.ShortcutSplitPrevEnable  = key.used;
            _settings.ShortcutSplitPrevKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_PB);
            _settings.ShortcutPBEnable  = key.used;
            _settings.ShortcutPBKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_TimerStart);
            _settings.ShortcutTimerStartEnable  = key.used;
            _settings.ShortcutTimerStartKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_TimerStop);
            _settings.ShortcutTimerStopEnable  = key.used;
            _settings.ShortcutTimerStopKeyCode = (int)key.key.KeyData;

            // Store customizing..
            int  TotalSplits, TotalActiveSplit, SuccessionHits, SuccessionHitsWay, SuccessionHitsPB;
            long TotalTime;

            profCtrl.GetCalculatedSums(out TotalSplits, out TotalActiveSplit, out SuccessionHits, out SuccessionHitsWay, out SuccessionHitsPB, out TotalTime, true);
            _settings.SuccessionHits    = SuccessionHits;                                       // obsolete since version 7 - keep for backwards compatibility
            _settings.SuccessionHitsWay = SuccessionHitsWay;                                    // obsolete since version 7 - keep for backwards compatibility
            _settings.SuccessionHitsPB  = SuccessionHitsPB;                                     // obsolete since version 7 - keep for backwards compatibility
            _settings.SuccessionTitle   = _settings.Succession.HistorySplitTitle;               // obsolete since version 7 - keep for backwards compatibility

            // Store profile data..
            _settings.ProfileSelected = profCtrl.SelectedProfile;         // obsolete since version 7 - keep for backwards compatibility
            _settings.Profiles.SaveProfile(profCtrl.SelectedProfileInfo); // Make sure all changes have been saved eventually (for safety)

            sm.WriteXML(_settings);
        }
Beispiel #14
0
        /// <summary>
        /// Stores user data in XML
        /// </summary>
        private void SaveSettings()
        {
            ShortcutsKey key = new ShortcutsKey();

            if (this.WindowState == FormWindowState.Normal) // Don't save window size and location when maximized or minimized
            {
                _settings.MainWidth  = this.Width;
                _settings.MainHeight = this.Height - gpSuccession.Height + gpSuccession_Height; // always save expandend values
                if (IsOnScreen(_settings.MainPosX, _settings.MainPosY, _settings.MainWidth, _settings.MainHeight))
                {
                    // remember values when not outside of screen
                    _settings.MainPosX = this.Left;
                    _settings.MainPosY = this.Top;
                }
            }
            _settings.AlwaysOnTop  = this.TopMost;
            _settings.HotKeyMethod = (int)sc.NextStart_Method;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Reset);
            _settings.ShortcutResetEnable  = key.used;
            _settings.ShortcutResetKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Hit);
            _settings.ShortcutHitEnable  = key.used;
            _settings.ShortcutHitKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_HitUndo);
            _settings.ShortcutHitUndoEnable  = key.used;
            _settings.ShortcutHitUndoKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_WayHit);
            _settings.ShortcutWayHitEnable  = key.used;
            _settings.ShortcutWayHitKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_WayHitUndo);
            _settings.ShortcutWayHitUndoEnable  = key.used;
            _settings.ShortcutWayHitUndoKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_Split);
            _settings.ShortcutSplitEnable  = key.used;
            _settings.ShortcutSplitKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_SplitPrev);
            _settings.ShortcutSplitPrevEnable  = key.used;
            _settings.ShortcutSplitPrevKeyCode = (int)key.key.KeyData;
            key = sc.Key_Get(Shortcuts.SC_Type.SC_Type_PB);
            _settings.ShortcutPBEnable  = key.used;
            _settings.ShortcutPBKeyCode = (int)key.key.KeyData;

            _settings.Inputfile  = om.FilePathIn;
            _settings.OutputFile = om.FilePathOut;

            _settings.ShowAttemptsCounter     = om.ShowAttemptsCounter;
            _settings.ShowHeadline            = om.ShowHeadline;
            _settings.ShowFooter              = om.ShowFooter;
            _settings.ShowSessionProgress     = om.ShowSessionProgress;
            _settings.ShowProgressBar         = om.ShowProgressBar;
            _settings.ShowSplitsCountFinished = om.ShowSplitsCountFinished;
            _settings.ShowSplitsCountUpcoming = om.ShowSplitsCountUpcoming;
            _settings.ShowHitsCombined        = om.ShowHitsCombined;
            _settings.ShowNumbers             = om.ShowNumbers;
            _settings.ShowPB         = om.ShowPB;
            _settings.ShowSuccession = om.ShowSuccession;
            _settings.Purpose        = (int)om.Purpose;
            _settings.Severity       = (int)om.Severity;

            _settings.StyleUseHighContrast      = om.StyleUseHighContrast;
            _settings.StyleUseHighContrastNames = om.StyleUseHighContrastNames;
            _settings.StyleUseRoman             = om.StyleUseRoman;
            _settings.StyleProgressBarColored   = om.StyleProgressBarColored;
            _settings.StyleUseCustom            = om.StyleUseCustom;
            _settings.StyleCssUrl        = om.StyleCssUrl;
            _settings.StyleFontUrl       = om.StyleFontUrl;
            _settings.StyleFontName      = om.StyleFontName;
            _settings.StyleDesiredWidth  = om.StyleDesiredWidth;
            _settings.StyleSuperscriptPB = om.StyleSuperscriptPB;

            _settings.SuccessionTitle   = om.SuccessionTitle;
            _settings.SuccessionHits    = om.SuccessionHits;
            _settings.SuccessionHitsWay = om.SuccessionHitsWay;
            _settings.SuccessionHitsPB  = om.SuccessionHitsPB;

            _settings.ProfileSelected = (string)ComboBox1.SelectedItem;

            profs.SaveProfile(false); // Make sure all changes have been saved eventually
            _settings.Profiles = profs;

            sm.WriteXML(_settings);
        }