コード例 #1
0
        protected void btnOK_Clicked(object o, EventArgs args)
        {
            if (grid.EditedCell.IsValid && grid.EditedCell.Row < itemShortcuts.Count &&
                !ShortcutColumnEvaluate(grid.EditedCell.Row, string.Empty))
            {
                return;
            }

            BusinessDomain.QuickItems.Clear();
            List <KeyValuePair <string, AccelKey> > changedShortcuts = new List <KeyValuePair <string, AccelKey> > ();

            foreach (ItemShortcut itemShortcut in itemShortcuts)
            {
                if (itemShortcut.ItemId < 0)
                {
                    continue;
                }
                string accelPath = KeyShortcuts.GetAccelPath(itemShortcut.ItemId.ToString());
                AccelMap.ChangeEntry(accelPath, (uint)itemShortcut.Shortcut.Key,
                                     KeyShortcuts.GetAllowedModifier(itemShortcut.Shortcut.AccelMods), true);
                if (itemShortcut.Shortcut.Key > 0)
                {
                    string key = KeyShortcuts.KeyToString(itemShortcut.Shortcut.Key, itemShortcut.Shortcut.AccelMods);
                    BusinessDomain.QuickItems.Add(key, itemShortcut.ItemName);
                }
                changedShortcuts.Add(new KeyValuePair <string, AccelKey> (accelPath, itemShortcut.Shortcut));
            }
            KeyShortcuts.Save(changedShortcuts);
            dlgEditQuickItems.Respond(ResponseType.Ok);
        }
コード例 #2
0
        private void AddItemShortcut(IntPtr data, string accelPath, uint accelKey, ModifierType accelMods, bool changed)
        {
            long itemId;

            if (IsKeyForItem(accelPath, out itemId) && accelKey != 0 && accelKey != (uint)Key.VoidSymbol)
            {
                ItemShortcut itemShortcut = new ItemShortcut();
                if (!itemShortcut.ItemEvaluate(Item.GetById(itemId), PriceGroup.RegularPrice))
                {
                    return;
                }

                itemShortcut.Shortcut = new AccelKey((Key)accelKey, KeyShortcuts.GetAllowedModifier(accelMods), AccelFlags.Visible);
                itemShortcuts.Add(itemShortcut);
            }
        }
コード例 #3
0
        private void WbpPrintPreview_KeyPressEvent(object o, KeyPressEventArgs args)
        {
            if (KeyShortcuts.Equal(args.Event, KeyShortcuts.HelpKey) && !string.IsNullOrEmpty(HelpFile))
            {
                FormHelper.ShowWindowHelp(HelpFile);
                return;
            }

            switch (args.Event.Key)
            {
            case Key.Escape:
                RequestClose();
                return;

            case Key.F9:
                btnPrint_Clicked(null, EventArgs.Empty);
                return;

            case Key.Left:
                currentPreview.StartPage--;
                return;

            case Key.Right:
                currentPreview.StartPage++;
                return;

            case Key.End:
                if (KeyShortcuts.GetAllowedModifier(args.Event.State) == KeyShortcuts.ControlModifier)
                {
                    currentPreview.StartPage = currentPreview.TotalPages - 1;
                }

                return;

            case Key.Home:
                if (KeyShortcuts.GetAllowedModifier(args.Event.State) == KeyShortcuts.ControlModifier)
                {
                    currentPreview.StartPage = 0;
                }

                return;
            }
        }
コード例 #4
0
        protected void Key_KeyPress(object o, KeyPressEventArgs args)
        {
            Entry txtKey = (Entry)o;

            if (!IsSelectionValid(GetSelectedRow()))
            {
                return;
            }

            Key          key;
            ModifierType mod;

            KeyShortcuts.MapRawKeys(args.Event, out key, out mod);
            AccelKey newAccelKey = new AccelKey(key, mod, AccelFlags.Visible);

            if (KeyShortcuts.CombinationValid(key, mod))
            {
                enteredAccelKey = newAccelKey;
                txtKey.Text     = KeyShortcuts.KeyToString(enteredAccelKey);
            }
            switch (args.Event.Key)
            {
            case Key.BackSpace:
                if (KeyShortcuts.GetAllowedModifier(args.Event.State) == ModifierType.None)
                {
                    enteredAccelKey = new AccelKey(Key.VoidSymbol, ModifierType.None, AccelFlags.Visible);
                    txtKey.Text     = string.Empty;
                }
                break;

            case Key.KP_Enter:
            case Key.Return:
            case Key.Escape:
                return;
            }
            args.RetVal = true;
        }
コード例 #5
0
        protected void Clear_Clicked(object o, EventArgs args)
        {
            string title   = Translator.GetString("Warning!");
            string message = Translator.GetString("This action will reset all key shortcuts to their default values. Are you sure you want to continue?");

            if (Message.ShowDialog(title, string.Empty, message, "Icons.Question32.png",
                                   MessageButtons.YesNo) != ResponseType.Yes)
            {
                return;
            }

            // Load the default key map
            string temp = Path.GetTempFileName();

            File.WriteAllText(temp, DataHelper.GetDefaultKeyMap());
            AccelMap.Load(temp);
            File.Delete(temp);

            // Get the key shortcuts in a dictionary
            Dictionary <string, AccelKey> shortcuts = new Dictionary <string, AccelKey> ();
            ResponseType choice = ResponseType.None;

            AccelMap.Foreach(IntPtr.Zero,
                             (data, accelPath, accelKey, accelMods, changed) =>
            {
                string key  = KeyShortcuts.KeyToString((Key)accelKey, accelMods);
                string name = accelPath.Substring(accelPath.IndexOf('/') + 1);
                long itemId;
                if (long.TryParse(name, out itemId))
                {
                    return;
                }

                if (!BusinessDomain.QuickItems.ContainsKey(key) ||
                    (menu.FindMenuItem(name) == null && name != KeyShortcuts.CHOOSE_KEY && name != KeyShortcuts.HELP_KEY))
                {
                    return;
                }

                switch (choice)
                {
                case ResponseType.None:
                    using (Message messageBox = GetInUseQuickItemMessage(key)) {
                        messageBox.Buttons        = MessageButtons.YesNo | MessageButtons.Cancel | MessageButtons.Remember;
                        ResponseType responseType = messageBox.Run();
                        switch (responseType)
                        {
                        case ResponseType.Yes:
                            RemoveQuickItem(key, shortcuts);
                            if (messageBox.RememberChoice)
                            {
                                choice = responseType;
                            }
                            break;

                        case ResponseType.No:
                            shortcuts.Add(accelPath, AccelKey.Zero);
                            if (messageBox.RememberChoice)
                            {
                                choice = responseType;
                            }
                            break;

                        case ResponseType.DeleteEvent:
                        case ResponseType.Cancel:
                            choice = ResponseType.Cancel;
                            break;
                        }
                    }
                    break;

                case ResponseType.Yes:
                    RemoveQuickItem(key, shortcuts);
                    break;

                case ResponseType.No:
                    shortcuts.Add(accelPath, AccelKey.Zero);
                    break;
                }
            });
            if (choice == ResponseType.Cancel)
            {
                LoadTreeView();
                return;
            }
            File.Delete(StoragePaths.KeyMapFile);
            bool quickGoods = false;

            AccelMap.Foreach(IntPtr.Zero, (data, path, key, mods, changed) =>
            {
                string wholeKey = KeyShortcuts.KeyToString((Key)key, mods);
                if (!BusinessDomain.QuickItems.ContainsKey(wholeKey))
                {
                    return;
                }

                AccelMap.ChangeEntry(path, key, KeyShortcuts.GetAllowedModifier(mods), true);
                quickGoods = true;
            });

            if (quickGoods)
            {
                AccelMap.Save(StoragePaths.KeyMapFile);
            }

            AccelMap.Foreach(IntPtr.Zero,
                             (data, accelPath, accelKey, accelMods, changed) =>
            {
                if (!shortcuts.ContainsKey(accelPath))
                {
                    return;
                }

                AccelKey key = shortcuts [accelPath];
                AccelMap.ChangeEntry(accelPath, (uint)key.Key,
                                     KeyShortcuts.GetAllowedModifier(key.AccelMods), true);
            });

            foreach (ICustomKeyShortcut shortcut in KeyShortcuts.CustomKeyShortcuts)
            {
                AccelMap.ChangeEntry(KeyShortcuts.GetAccelPath(shortcut.Path), (uint)shortcut.DefaultKey,
                                     KeyShortcuts.GetAllowedModifier(shortcut.DefaultModifier), true);
            }
            LoadTreeView();
        }
コード例 #6
0
        private void ApplyShortcut(string menuItemName, AccelKey accelKey)
        {
            string accelPath = KeyShortcuts.GetAccelPath(menuItemName);

            changedShortcuts.Add(new KeyValuePair <string, AccelKey> (accelPath,
                                                                      new AccelKey(accelKey.Key, KeyShortcuts.GetAllowedModifier(accelKey.AccelMods), AccelFlags.Visible)));
            MenuItemWrapper menuItemWrapper = menu.FindMenuItem(menuItemName);

            if (menuItemWrapper == null)
            {
                return;
            }
            if (accelKey.Key != Key.VoidSymbol)
            {
                return;
            }

            AccelKey key = KeyShortcuts.LookupEntry(menuItemName);

            menuItemWrapper.Item.RemoveAccelerator(accelGroup, (uint)key.Key, key.AccelMods);
        }