Esempio n. 1
0
        internal bool HotkeyExists(PNHotKey hk)
        {
            PNHotKey phk = null;

            switch (tabHK.SelectedIndex)
            {
            case 0:
                phk = m_KeysMain.FirstOrDefault(h => h.Shortcut == hk.Shortcut && h.ID != hk.ID);
                break;

            case 1:
                phk = m_KeysNote.FirstOrDefault(h => h.Shortcut == hk.Shortcut && h.ID != hk.ID);
                break;

            case 2:
                phk = m_KeysEdit.FirstOrDefault(h => h.Shortcut == hk.Shortcut && h.ID != hk.ID);
                break;

            case 3:
                phk = m_KeysGroups.FirstOrDefault(h => h.Shortcut == hk.Shortcut && h.ID != hk.ID);
                break;
            }
            if (phk != null)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        internal void SetHotkey(PNHotKey hk)
        {
            PNHotKey phk = null;

            switch (tabHK.SelectedIndex)
            {
            case 0:
                phk = m_KeysMain.FirstOrDefault(h => h.MenuName == hk.MenuName);
                break;

            case 1:
                phk = m_KeysNote.FirstOrDefault(h => h.MenuName == hk.MenuName);
                break;

            case 2:
                phk = m_KeysEdit.FirstOrDefault(h => h.MenuName == hk.MenuName);
                break;

            case 3:
                phk = m_KeysGroups.FirstOrDefault(h => h.MenuName == hk.MenuName);
                break;
            }
            if (phk != null)
            {
                phk.CopyFrom(hk);
            }
        }
Esempio n. 3
0
        private void tabHK_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                PNHotKey   hk = null;
                PNTreeItem tvi;
                switch (tabHK.SelectedIndex)
                {
                case 0:
                    tvi = tvwHKMain.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hk = m_KeysMain.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 1:
                    tvi = tvwHKNote.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hk = m_KeysNote.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 2:
                    tvi = tvwHKEdit.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hk = m_KeysEdit.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 3:
                    tvi = tvwHKGroups.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hk = m_KeysGroups.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;
                }
                if (hk != null)
                {
                    txtHotKey.Text = hk.Shortcut;
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
Esempio n. 4
0
        private void setButtonsEnabled(PNTreeItem node)
        {
            try
            {
                if (node.Image.Equals(_ImageSubmenu))
                {
                    //cmdAddHK.IsEnabled = false;
                    //cmdEditHK.IsEnabled = false;
                    cmdDeleteHK.IsEnabled = false;
                    txtHotKey.Visibility  = Visibility.Hidden;
                }
                else
                {
                    var      name = (string)node.Tag;
                    PNHotKey hk   = null;
                    switch (tabHK.SelectedIndex)
                    {
                    case 0:
                        hk = m_KeysMain.FirstOrDefault(h => h.MenuName == name);
                        break;

                    case 1:
                        hk = m_KeysNote.FirstOrDefault(h => h.MenuName == name);
                        break;

                    case 2:
                        hk = m_KeysEdit.FirstOrDefault(h => h.MenuName == name);
                        break;

                    case 3:
                        hk = m_KeysGroups.FirstOrDefault(h => h.MenuName == name);
                        break;
                    }

                    if (hk == null)
                    {
                        return;
                    }
                    cmdDeleteHK.IsEnabled = hk.VK != 0;
                    txtHotKey.Visibility  = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
Esempio n. 5
0
 private string createHotKeyDelete(PNHotKey hk)
 {
     try
     {
         var sb = new StringBuilder();
         sb.Append("UPDATE HOT_KEYS SET MODIFIERS = 0, VK = 0, SHORTCUT = ''");
         sb.Append(" WHERE MENU_NAME = '");
         sb.Append(hk.MenuName);
         sb.Append("' AND HK_TYPE = ");
         sb.Append((int)hk.Type);
         return(sb.ToString());
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return("");
     }
 }
Esempio n. 6
0
        internal static Keys GetShortcut(PNHotKey hk)
        {
            var keys = Keys.None;

            if ((hk.Modifiers & HotkeyModifiers.MOD_CONTROL) > 0)
            {
                keys |= Keys.Control;
            }
            if ((hk.Modifiers & HotkeyModifiers.MOD_ALT) > 0)
            {
                keys |= Keys.Menu;
            }
            if ((hk.Modifiers & HotkeyModifiers.MOD_SHIFT) > 0)
            {
                keys |= Keys.Shift;
            }
            if ((hk.Modifiers & HotkeyModifiers.MOD_WIN) > 0)
            {
                keys |= Keys.LWin;
            }
            switch (hk.VK)
            {
            case VK_0:
                keys |= Keys.D0;
                break;

            case VK_1:
                keys |= Keys.D1;
                break;

            case VK_2:
                keys |= Keys.D2;
                break;

            case VK_3:
                keys |= Keys.D3;
                break;

            case VK_4:
                keys |= Keys.D4;
                break;

            case VK_5:
                keys |= Keys.D5;
                break;

            case VK_6:
                keys |= Keys.D6;
                break;

            case VK_7:
                keys |= Keys.D7;
                break;

            case VK_8:
                keys |= Keys.D8;
                break;

            case VK_9:
                keys |= Keys.D9;
                break;

            case VK_F1:
                keys |= Keys.F1;
                break;

            case VK_F2:
                keys |= Keys.F2;
                break;

            case VK_F3:
                keys |= Keys.F3;
                break;

            case VK_F4:
                keys |= Keys.F4;
                break;

            case VK_F5:
                keys |= Keys.F5;
                break;

            case VK_F6:
                keys |= Keys.F6;
                break;

            case VK_F7:
                keys |= Keys.F7;
                break;

            case VK_F8:
                keys |= Keys.F8;
                break;

            case VK_F9:
                keys |= Keys.F9;
                break;

            case VK_F10:
                keys |= Keys.F10;
                break;

            case VK_F11:
                keys |= Keys.F11;
                break;

            case VK_F12:
                keys |= Keys.F12;
                break;

            case VK_F13:
                keys |= Keys.F13;
                break;

            case VK_F14:
                keys |= Keys.F14;
                break;

            case VK_F15:
                keys |= Keys.F15;
                break;

            case VK_F16:
                keys |= Keys.F16;
                break;

            case VK_F17:
                keys |= Keys.F17;
                break;

            case VK_F18:
                keys |= Keys.F18;
                break;

            case VK_F19:
                keys |= Keys.F19;
                break;

            case VK_F20:
                keys |= Keys.F20;
                break;

            case VK_F21:
                keys |= Keys.F21;
                break;

            case VK_F22:
                keys |= Keys.F22;
                break;

            case VK_F23:
                keys |= Keys.F23;
                break;

            case VK_F24:
                keys |= Keys.F24;
                break;

            case VK_NUMPAD0:
                keys |= Keys.NumPad0;
                break;

            case VK_NUMPAD1:
                keys |= Keys.NumPad1;
                break;

            case VK_NUMPAD2:
                keys |= Keys.NumPad2;
                break;

            case VK_NUMPAD3:
                keys |= Keys.NumPad3;
                break;

            case VK_NUMPAD4:
                keys |= Keys.NumPad4;
                break;

            case VK_NUMPAD5:
                keys |= Keys.NumPad5;
                break;

            case VK_NUMPAD6:
                keys |= Keys.NumPad6;
                break;

            case VK_NUMPAD7:
                keys |= Keys.NumPad7;
                break;

            case VK_NUMPAD8:
                keys |= Keys.NumPad8;
                break;

            case VK_NUMPAD9:
                keys |= Keys.NumPad9;
                break;

            case VK_A:
                keys |= Keys.A;
                break;

            case VK_B:
                keys |= Keys.B;
                break;

            case VK_C:
                keys |= Keys.C;
                break;

            case VK_D:
                keys |= Keys.D;
                break;

            case VK_E:
                keys |= Keys.E;
                break;

            case VK_F:
                keys |= Keys.F;
                break;

            case VK_G:
                keys |= Keys.G;
                break;

            case VK_H:
                keys |= Keys.H;
                break;

            case VK_I:
                keys |= Keys.I;
                break;

            case VK_J:
                keys |= Keys.J;
                break;

            case VK_K:
                keys |= Keys.K;
                break;

            case VK_L:
                keys |= Keys.L;
                break;

            case VK_M:
                keys |= Keys.M;
                break;

            case VK_N:
                keys |= Keys.N;
                break;

            case VK_O:
                keys |= Keys.O;
                break;

            case VK_P:
                keys |= Keys.P;
                break;

            case VK_Q:
                keys |= Keys.Q;
                break;

            case VK_R:
                keys |= Keys.R;
                break;

            case VK_S:
                keys |= Keys.S;
                break;

            case VK_T:
                keys |= Keys.T;
                break;

            case VK_U:
                keys |= Keys.U;
                break;

            case VK_V:
                keys |= Keys.V;
                break;

            case VK_W:
                keys |= Keys.W;
                break;

            case VK_X:
                keys |= Keys.X;
                break;

            case VK_Y:
                keys |= Keys.Y;
                break;

            case VK_Z:
                keys |= Keys.Z;
                break;

            case VK_ADD:
                keys |= Keys.Add;
                break;

            case VK_BACK:
                keys = Keys.Back;
                break;

            case VK_DELETE:
                keys = Keys.Delete;
                break;

            case VK_DIVIDE:
                keys = Keys.Divide;
                break;

            case VK_DOWN:
                keys = Keys.Down;
                break;

            case VK_END:
                keys = Keys.End;
                break;

            case VK_ESCAPE:
                keys = Keys.Escape;
                break;

            case VK_HOME:
                keys = Keys.Home;
                break;

            case VK_INSERT:
                keys = Keys.Insert;
                break;

            case VK_LEFT:
                keys = Keys.Left;
                break;

            case VK_MULTIPLY:
                keys = Keys.Multiply;
                break;

            case VK_NEXT:
                keys = Keys.Next;
                break;

            case VK_OEM_1:
                keys = Keys.Oem1;
                break;

            case VK_OEM_2:
                keys = Keys.Oem2;
                break;

            case VK_OEM_3:
                keys = Keys.Oem3;
                break;

            case VK_OEM_4:
                keys = Keys.Oem4;
                break;

            case VK_OEM_5:
                keys = Keys.Oem5;
                break;

            case VK_OEM_6:
                keys = Keys.Oem6;
                break;

            case VK_OEM_7:
                keys = Keys.Oem7;
                break;

            case VK_OEM_8:
                keys = Keys.Oem8;
                break;

            case VK_OEM_COMMA:
                keys = Keys.Oemcomma;
                break;

            case VK_OEM_MINUS:
                keys = Keys.OemMinus;
                break;

            case VK_OEM_PERIOD:
                keys = Keys.OemPeriod;
                break;

            case VK_OEM_PLUS:
                keys = Keys.Oemplus;
                break;

            case VK_PAUSE:
                keys = Keys.Pause;
                break;

            case VK_PRIOR:
                keys = Keys.Prior;
                break;

            case VK_RETURN:
                keys = Keys.Return;
                break;

            case VK_RIGHT:
                keys = Keys.Right;
                break;

            case VK_SCROLL:
                keys = Keys.Scroll;
                break;

            case VK_SPACE:
                keys = Keys.Space;
                break;

            case VK_SUBTRACT:
                keys = Keys.Subtract;
                break;

            case VK_TAB:
                keys = Keys.Tab;
                break;

            case VK_UP:
                keys = Keys.Up;
                break;
            }
            return(keys);
        }
Esempio n. 7
0
 internal static bool RegisterHK(IntPtr hwnd, PNHotKey hk)
 {
     return(RegisterHotKey(hwnd, hk.ID, (uint)hk.Modifiers, hk.VK));
 }
Esempio n. 8
0
        private void txtHotKey_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                var check     = false;
                var modString = "";
                var keyString = "";
                var hk        = new PNHotKey
                {
                    Modifiers = HotkeysStatic.GetModifiers(ref modString),
                    VK        = HotkeysStatic.GetKey(ref keyString),
                    Shortcut  = modString + keyString
                };

                if (hk.Modifiers == HotkeyModifiers.MOD_NONE)
                {
                    if (hk.VK >= HotkeysStatic.VK_F1 && hk.VK <= HotkeysStatic.VK_F24)
                    {
                        check = true;
                    }
                }
                else
                {
                    if (hk.VK > 0)
                    {
                        check = true;
                    }
                }
                if (!check)
                {
                    return;
                }
                string message, caption;
                if (PNStrings.RestrictedHotkeys.Contains(hk.Shortcut) ||
                    PNStatic.HotKeysEdit.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) ||
                    PNStatic.HotKeysGroups.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) ||
                    PNStatic.HotKeysNote.Any(h => h.Modifiers == hk.Modifiers && h.VK == hk.VK) ||
                    hk.Modifiers == HotkeyModifiers.MOD_SHIFT && (hk.VK >= HotkeysStatic.VK_A && hk.VK <= HotkeysStatic.VK_Z))
                {
                    message  = hk.Shortcut + '\n';
                    message += PNLang.Instance.GetMessageText("hk_registered_1", "This combination of keys is already registered.");
                    message += '\n';
                    message += PNLang.Instance.GetMessageText("hk_registered_2", "Choose another one, please.");
                    caption  = PNLang.Instance.GetCaptionText("restricted_keys", "Invalid keys");
                    PNMessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    e.Handled = true;
                    return;
                }
                if (HotkeysStatic.RegisterHK(_HwndSource.Handle, hk))
                {
                    HotkeysStatic.UnregisterHK(_HwndSource.Handle, hk.ID);
                }
                else
                {
                    message  = hk.Shortcut + '\n';
                    message += PNLang.Instance.GetMessageText("hk_registered_1", "This combination of keys is already registered.");
                    message += '\n';
                    message += PNLang.Instance.GetMessageText("hk_registered_2", "Choose another one, please.");
                    caption  = PNLang.Instance.GetCaptionText("restricted_keys", "Invalid keys");
                    PNMessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    e.Handled = true;
                    return;
                }
                PNTreeItem tvi       = null;
                PNHotKey   hkCurrent = null;
                switch (tabHK.SelectedIndex)
                {
                case 0:
                    tvi = tvwHKMain.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hkCurrent = m_KeysMain.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 1:
                    tvi = tvwHKNote.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hkCurrent = m_KeysNote.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 2:
                    tvi = tvwHKEdit.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hkCurrent = m_KeysEdit.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 3:
                    tvi = tvwHKGroups.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hkCurrent = m_KeysGroups.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;
                }
                if (hkCurrent != null)
                {
                    hkCurrent.Modifiers = hk.Modifiers;
                    hkCurrent.Shortcut  = hk.Shortcut;
                    hkCurrent.VK        = hk.VK;
                    setButtonsEnabled(tvi);
                    txtHotKey.Text = hk.Shortcut;
                    var defKey = new DefKey(hkCurrent.ID, hkCurrent.Type, hkCurrent.MenuName)
                    {
                        Icon =
                            isHotkeyInDatabase(
                                tabHK.SelectedIndex == 0
                                    ? PNStatic.HotKeysMain
                                    : (tabHK.SelectedIndex == 1
                                        ? PNStatic.HotKeysNote
                                        : (tabHK.SelectedIndex == 2 ? PNStatic.HotKeysEdit : PNStatic.HotKeysGroups)),
                                hk)
                                ? (BitmapSource)TryFindResource("check")
                                : null,
                        MenuRange =
                            tabHK.SelectedIndex == 0
                                ? tbpHKMain.Header.ToString()
                                : (tabHK.SelectedIndex == 1
                                    ? tbpHKNote.Header.ToString()
                                    : (tabHK.SelectedIndex == 2
                                        ? tbpHKEdit.Header.ToString()
                                        : tbpHKGroups.Header.ToString())),
                        MenuText =
                            tabHK.SelectedIndex < 3
                                ? PNLang.Instance.GetMenuText(
                                tabHK.SelectedIndex == 0
                                        ? "main_menu"
                                        : (tabHK.SelectedIndex == 1 ? "note_menu" : "edit_menu"), hkCurrent.MenuName,
                                hkCurrent.MenuName)
                                : hkCurrent.MenuName,
                        Shortcut = hkCurrent.Shortcut
                    };
                    if (tabHK.SelectedIndex == 3)
                    {
                        var arr = hkCurrent.MenuName.Split('_');
                        if (arr.Length == 2)
                        {
                            var gr = PNStatic.Groups.GetGroupByID(Convert.ToInt32(arr[0]));
                            if (gr != null)
                            {
                                var defCap = arr[1] == "show"
                                    ? PNLang.Instance.GetCaptionText("show_group", "Show group")
                                    : PNLang.Instance.GetCaptionText("hide_group", "Hide group");
                                defKey.MenuText = gr.Name + "/" + defCap;
                            }
                        }
                    }
                    //remove existing key
                    var existingKey = _DefKeys.FirstOrDefault(k => k.Id == defKey.Id);
                    if (existingKey != null)
                    {
                        _DefKeys.Remove(existingKey);
                    }
                    _DefKeys.Add(defKey);
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }
Esempio n. 9
0
 private bool isHotkeyInDatabase(List <PNHotKey> keys, PNHotKey hk)
 {
     return(keys.Any(h => h.ID == hk.ID && h.Shortcut == hk.Shortcut && h.MenuName == hk.MenuName));
 }
Esempio n. 10
0
        private void cmdDeleteHK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var message = PNLang.Instance.GetMessageText("delete_hot_keys", "Delete selected hot keys combination?");
                if (PNMessageBox.Show(message, PNStrings.PROG_NAME, MessageBoxButton.YesNo, MessageBoxImage.Question) !=
                    MessageBoxResult.Yes)
                {
                    return;
                }
                PNHotKey   hk  = null;
                PNTreeItem tvi = null;
                switch (tabHK.SelectedIndex)
                {
                case 0:
                    tvi = tvwHKMain.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hk = m_KeysMain.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 1:
                    tvi = tvwHKNote.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hk = m_KeysNote.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 2:
                    tvi = tvwHKEdit.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hk = m_KeysEdit.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;

                case 3:
                    tvi = tvwHKGroups.SelectedItem as PNTreeItem;
                    if (tvi == null)
                    {
                        break;
                    }
                    hk = m_KeysGroups.FirstOrDefault(h => h.MenuName == (string)tvi.Tag);
                    setButtonsEnabled(tvi);
                    break;
                }
                if (hk == null)
                {
                    return;
                }
                var defKey = _DefKeys.FirstOrDefault(dk => dk.Id == hk.ID);
                if (defKey != null)
                {
                    _DefKeys.Remove(defKey);
                }
                hk.Clear();
                txtHotKey.Text = "";
                setButtonsEnabled(tvi);
                if (txtHotKey.IsFocused)
                {
                    PNStatic.SendKey(Key.Tab);
                }
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
            }
        }