示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        public Path(string input, Options o)
        {
            if (o.hasStatusFlags)
            {
                if (input.Length < 3)
                {
                    throw new InputException($"Switch for status flags is set, but path '{input}' does not contain a flag.");
                }

                if (input[1] == ' ' && input[2] != ' ')
                {
                    type = SC_Type.Hg;
                }
                else if (input[2] == ' ' && input.Length > 3 && input[3] != ' ')
                {
                    type = SC_Type.Git;
                }
                else
                {
                    throw new InputException($"Could not parse flags for path '{input}'.");
                }

                if (type == SC_Type.Git)
                {
                    if (input.Contains(" -> "))
                    {
                        // Git uses -> to denote moves.
                        // We leave these paths as they are
                        fullPath = input;
                        isExempt = true;
                        return;
                    }

                    statusFlags = input.Substring(0, 2).Replace(' ', '_');
                    fullPath    = input.Substring(3);
                    // Git puts qutations marks if paths have spaces
                    if (fullPath.StartsWith('"') && fullPath.EndsWith('"'))
                    {
                        fullPath = fullPath.Substring(1, fullPath.Length - 2);
                    }
                }
                else
                {
                    statusFlags = input.Substring(0, 1);
                    fullPath    = input.Substring(2);
                }
            }
            else
            {
                fullPath = input;
            }

            fullPath = fullPath.Replace('\\', '/');
            while (fullPath.Contains("//"))
            {
                fullPath = fullPath.Replace("//", "/");
            }

            var split = fullPath.Split('/');

            for (int i = 0; i < split.Length - 1; i++)
            {
                folders.Add(split[i]);
            }
            fileOrFolder = split[split.Length - 1];
        }
示例#4
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());
        }
示例#5
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
 }
示例#6
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;
                }
            }
        }