Represents a callback for a Hotkey binding.
Пример #1
0
        internal void Add(Hotkey hotkey, HotkeyCallback callback)
        {
            if (container.ContainsKey(hotkey))
            {
                throw new HotkeyAlreadyBoundException(
                          "This hotkey cannot be bound because it has been previously bound either by this " +
                          "application or another running application.");
            }

            container.Add(hotkey, callback);
        }
Пример #2
0
        /// <summary>
        /// Binds a <see cref="Hotkey"/> to a <see cref="HotkeyCallback"/>.
        /// </summary>
        /// <exception cref="HotkeyAlreadyBoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public HotkeyCallback Bind(Hotkey hotkeyCombo)
        {
            if (hotkeyCombo == null)
                throw new ArgumentNullException("hotkeyCombo");

            HotkeyCallback callback = new HotkeyCallback();
            container.Add(hotkeyCombo, callback);
            RegisterHotkey(hotkeyCombo);

            return callback;
        }
Пример #3
0
        internal void Add(Hotkey hotkey, HotkeyCallback callback)
        {
            if (container.ContainsKey(hotkey))
            {
                throw new HotkeyAlreadyBoundException(
                    "This hotkey cannot be bound because it has been previously bound either by this " +
                    "application or another running application.");
            }

            container.Add(hotkey, callback);
        }
Пример #4
0
        /// <summary>
        /// Binds a <see cref="Hotkey"/> to a <see cref="HotkeyCallback"/>.
        /// </summary>
        /// <exception cref="HotkeyAlreadyBoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public HotkeyCallback Bind(Hotkey hotkeyCombo)
        {
            if (hotkeyCombo == null)
            {
                throw new ArgumentNullException("hotkeyCombo");
            }

            HotkeyCallback callback = new HotkeyCallback();

            container.Add(hotkeyCombo, callback);
            RegisterHotkey(hotkeyCombo);

            return(callback);
        }
Пример #5
0
        private void OnHotkeyPressed(object sender, HotkeyPressedEventArgs e)
        {
            HotkeyCallback callback = container.Find(e.Hotkey);

            if (!callback.Assigned)
            {
                throw new InvalidOperationException(
                          "You did not specify a callback for the hotkey: \"" + e.Hotkey + "\". It's not your fault, " +
                          "because it wasn't possible to design the HotkeyBinder class in such a way that this is " +
                          "a statically typed pre-condition, but please specify a callback.");
            }

            callback.Invoke();
        }