示例#1
0
        private void ItemColumn_KeyPress(object sender, CellKeyPressEventArgs args)
        {
            if (gridNavigator.ColumnKeyPress(args, colItem.Index, ItemColumnChoose,
                                             ItemColumnEvaluate, ItemColumnEditPrev, ItemColumnEditNext))
            {
                return;
            }

            string gdkKey = KeyShortcuts.KeyToString(args.EventKey);
            string quickGoods;

            if (!BusinessDomain.QuickItems.TryGetValue(gdkKey, out quickGoods))
            {
                return;
            }

            ItemColumnEvaluate(grid.EditedCell.Row, quickGoods);

            QtyColumnEvaluate(grid.EditedCell.Row, 1);

            if (selectedDetails.Count <= grid.EditedCell.Row + 1)
            {
                selectedDetails.Add(new SaleDetail());
            }

            EditGridCell(grid.EditedCell.Row + 1, colItem.Index);

            args.MarkAsHandled();
        }
        private void ProdItem_KeyPress(object sender, CellKeyPressEventArgs args)
        {
            if (SecondGridNavigator.ColumnKeyPress(args, colSecondItem.Index, ProdItemChoose,
                                                   ProdItemEvaluate, ProdItemEditPrev, ProdItemEditNext))
            {
                return;
            }

            string gdkKey = KeyShortcuts.KeyToString(args.EventKey);
            string quickGoods;

            if (!BusinessDomain.QuickItems.TryGetValue(gdkKey, out quickGoods))
            {
                return;
            }

            ProdItemEvaluate(grdProducts.EditedCell.Row, quickGoods);

            ProdQtyEvaluate(grdProducts.EditedCell.Row, 1);

            if (recipe.DetailsProd.Count <= grdProducts.EditedCell.Row + 1)
            {
                recipe.AddNewAdditionalDetail();
            }

            ProdEditGridField(grdProducts.EditedCell.Row + 1, colSecondItem.Index);

            args.MarkAsHandled();
        }
        private void MatItem_KeyPress(object sender, CellKeyPressEventArgs args)
        {
            if (GridNavigator.ColumnKeyPress(args, colItem.Index, MatItemChoose,
                                             MatItemEvaluate, MatItemEditPrev, MatItemEditNext))
            {
                return;
            }

            string gdkKey = KeyShortcuts.KeyToString(args.EventKey);
            string quickGoods;

            if (!BusinessDomain.QuickItems.TryGetValue(gdkKey, out quickGoods))
            {
                return;
            }

            if (!MatItemEvaluate(grdMaterials.EditedCell.Row, quickGoods))
            {
                return;
            }

            MatQtyEvaluate(grdMaterials.EditedCell.Row, 1);

            if (recipe.DetailsMat.Count <= grdMaterials.EditedCell.Row + 1)
            {
                recipe.AddNewDetail();
            }

            MatEditGridField(grdMaterials.EditedCell.Row + 1, colItem.Index);

            args.MarkAsHandled();
        }
示例#4
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);
        }
        private void TryApplyShortcut()
        {
            TreeIter selectedRow  = GetSelectedRow();
            string   menuItemName = (string)treeViewMenu.Model.GetValue(selectedRow, 2);

            if (!IsFreeToUse(enteredAccelKey))
            {
                treeViewMenu.GrabFocus();
                return;
            }
            ApplyShortcut(menuItemName, enteredAccelKey);
            treeViewMenu.Model.SetValue(selectedRow, 1, KeyShortcuts.KeyToString(enteredAccelKey));
        }
        private static void AddCustomShortcut(TreeIter parent, TreeStore treeStore, string path, string name, string type)
        {
            // only menu shortcuts supported on the mac because of the GTK "cmd is alt" bug
            if (PlatformHelper.Platform == PlatformTypes.MacOSX &&
                (path.Contains("btn") || path == KeyShortcuts.CHOOSE_KEY || path == KeyShortcuts.HELP_KEY))
            {
                return;
            }

            string   parentPath       = (string)treeStore.GetValue(parent, 2);
            int      indexOfSeparator = path.LastIndexOf('/');
            TreeIter finalParent      = parent;

            if (indexOfSeparator >= 0)
            {
                string parentNode = path.Substring(0, indexOfSeparator);
                if (parentNode != parentPath)
                {
                    for (int i = 0; i < treeStore.IterNChildren(parent); i++)
                    {
                        TreeIter row;
                        treeStore.IterNthChild(out row, parent, i);
                        string child = (string)treeStore.GetValue(row, 2);
                        if (child.Substring(child.LastIndexOf('/') + 1) != parentNode)
                        {
                            continue;
                        }

                        finalParent = row;
                        break;
                    }
                    name = name.Substring(name.LastIndexOf('/') + 1);
                }
            }
            AccelKey key = KeyShortcuts.LookupEntry(path);

            // set "menu" as the type because these custom bindings cannot be the same as some real menu bindings
            if (finalParent.Equals(TreeIter.Zero))
            {
                treeStore.AppendValues(name, KeyShortcuts.KeyToString(key), path, type);
            }
            else
            {
                treeStore.AppendValues(finalParent, name, KeyShortcuts.KeyToString(key), path, type);
            }
        }
        private bool UsedInMenuOrSameScreen(AccelKey newKey)
        {
            TreeIter selectedRow  = GetSelectedRow();
            string   selectedName = (string)treeViewMenu.Model.GetValue(selectedRow, 2);
            string   selectedType = (string)treeViewMenu.Model.GetValue(selectedRow, 3);
            TreeIter ownerRow     = TreeIter.Zero;

            treeViewMenu.Model.Foreach((model, path, row) =>
            {
                string name = (string)model.GetValue(row, 2);
                if (selectedName == name)
                {
                    return(false);
                }

                string type  = (string)model.GetValue(row, 3);
                AccelKey key = KeyShortcuts.LookupEntry(name);
                // when comparing with menus, ignore paths containing a '/' because menus do not have such (in incomplete paths)
                if (selectedType == type && (selectedType != KeyShortcuts.MENU_NEIGHBOURING_SHORTCUT || !name.Contains("/")) &&
                    KeyShortcuts.KeyEqual((uint)newKey.Key, (uint)key.Key) && newKey.AccelMods == key.AccelMods)
                {
                    ownerRow = row;
                    return(true);
                }
                return(false);
            });

            if (!ownerRow.Equals(TreeIter.Zero))
            {
                string translation = Translator.GetString("The selected shortcut is already used for the \"{0}\" menu item. " +
                                                          "Do you want to remove the shortcut for \"{0}\" to reassign it?");
                string message = string.Format(translation, treeViewMenu.Model.GetValue(ownerRow, 0));
                if (Message.ShowDialog(Translator.GetString("Warning!"), string.Empty,
                                       message, "Icons.Question32.png",
                                       MessageButtons.YesNo) == ResponseType.Yes)
                {
                    string ownerItem = (string)treeViewMenu.Model.GetValue(ownerRow, 2);
                    ApplyShortcut(ownerItem, new AccelKey(Key.VoidSymbol, ModifierType.None, AccelFlags.Visible));
                    treeViewMenu.Model.SetValue(ownerRow, 1, KeyShortcuts.KeyToString(AccelKey.Zero));
                    return(false);
                }
                return(true);
            }
            return(false);
        }
示例#8
0
 private void ColumnShortcut_KeyPressEvent(object sender, CellKeyPressEventArgs args)
 {
     if (args.Editing && KeyShortcuts.CombinationValidForItem(args.EventKey))
     {
         currentKey      = new AccelKey(args.EventKey.Key, args.EventKey.State, AccelFlags.Visible);
         args.Entry.Text = KeyShortcuts.KeyToString(currentKey);
         args.MarkAsHandled();
     }
     switch (args.EventKey.Key)
     {
     case Key.BackSpace:
     case Key.Delete:
         currentKey      = AccelKey.Zero;
         args.Entry.Text = string.Empty;
         break;
     }
     gridNavigator.ColumnKeyPress(args, args.Cell.Column, ShortcutColumnEvaluate, ShortcutColumnEditPrev, ShortcutColumnEditNext);
 }
        private static bool IsUsedInQuickItems(AccelKey newKey)
        {
            string key = KeyShortcuts.KeyToString(newKey);

            if (!BusinessDomain.QuickItems.ContainsKey(key))
            {
                return(false);
            }

            using (Message dialog = GetInUseQuickItemMessage(key)) {
                dialog.Buttons = MessageButtons.YesNo;
                if (dialog.Run() != ResponseType.Yes)
                {
                    return(true);
                }

                RemoveQuickItem(key);
                return(false);
            }
        }
        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;
        }
        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();
        }
        private void AddNodes(TreeStore treeStore, IEnumerable <Widget> menuItems, TreeIter parent)
        {
            // TODO: this method, and some of its callees, use too many hard-coded strings, improve this
            string parentName = string.Empty;

            foreach (MenuItem menuItem in menuItems)
            {
                Label label = menuItem.Child as Label;
                if (label == null)
                {
                    continue;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction(menuItem.Name) != UserRestrictionState.Allowed)
                {
                    continue;
                }

                AccelKey key = KeyShortcuts.LookupEntry(menuItem.Name);
                parentName = menuItem.Parent.Name;
                TreeIter row = parent.Equals(TreeIter.Zero) ?
                               treeStore.AppendValues(label.Text, KeyShortcuts.KeyToString(key), menuItem.Name, KeyShortcuts.MENU_NEIGHBOURING_SHORTCUT) :
                               treeStore.AppendValues(parent, label.Text, KeyShortcuts.KeyToString(key), menuItem.Name, KeyShortcuts.MENU_NEIGHBOURING_SHORTCUT);

                Container container = menuItem.Submenu as Container;
                if (container != null)
                {
                    AddNodes(treeStore, (container).Children, row);
                }

                switch (menuItem.Name)
                {
                case "mnuEditPartners":
                case "mnuEditGoods":
                case "mnuEditUsers":
                case "mnuEditObjects":
                case "mnuEditVATGroups":
                case "mnuEditDevices":
                case "mnuEditAdminPriceRules":
                    AddEditDialogShortcuts(row, treeStore, menuItem.Name);
                    break;

                case "mnuOperTradeObject":
                    AddPOSShortcuts(row, treeStore, menuItem.Name);
                    break;
                }

                MenuItem item = menuItem;
                foreach (ICustomKeyShortcut shortcut in
                         from customKeyShortcut in KeyShortcuts.CustomKeyShortcuts
                         where customKeyShortcut.Parent == item.Name
                         orderby customKeyShortcut.Ordinal
                         select customKeyShortcut)
                {
                    AddCustomShortcut(row, treeStore, shortcut.Path, shortcut.Label, shortcut.Type);
                }
            }

            if (parentName == menu.Menu.Name)
            {
                AddCustomShortcut(parent, treeStore, KeyShortcuts.CHOOSE_KEY, Translator.GetString("Select"), KeyShortcuts.MENU_NEIGHBOURING_SHORTCUT);
            }

            if (parentName == "mnuOperations_menu")
            {
                AddCustomShortcut(parent, treeStore, "txtPartner", Translator.GetString("Partner"), KeyShortcuts.MENU_NEIGHBOURING_SHORTCUT);
                AddCustomShortcut(parent, treeStore, "btnSave", Translator.GetString("Save Operation"), KeyShortcuts.MENU_NEIGHBOURING_SHORTCUT);
                AddCustomShortcut(parent, treeStore, "btnClear", Translator.GetString("Clear Operation"), KeyShortcuts.MENU_NEIGHBOURING_SHORTCUT);
            }

            if (parentName == "mnuHelp_menu")
            {
                AddCustomShortcut(parent, treeStore, KeyShortcuts.HELP_KEY, Translator.GetString("Show Help"), KeyShortcuts.MENU_NEIGHBOURING_SHORTCUT);
            }
        }