コード例 #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
ファイル: Variables.cs プロジェクト: codyn-net/studio
        private void ShowPopup(Gdk.EventButton evnt)
        {
            Gtk.AccelGroup grp = new Gtk.AccelGroup();

            Gtk.Menu menu = new Gtk.Menu();
            menu.Show();
            menu.AccelGroup = grp;

            MenuItem item;

            item           = new MenuItem("Add");
            item.AccelPath = "<CdnStudio>/Widgets/Editors/Properties/Add";

            AccelMap.AddEntry("<CdnStudio>/Widgets/Editors/Properties/Add", (uint)Gdk.Key.KP_Add, Gdk.ModifierType.None);

            item.Show();
            item.Activated += DoAddProperty;

            menu.Append(item);

            item           = new MenuItem("Remove");
            item.AccelPath = "<CdnStudio>/Widgets/Editors/Properties/Remove";
            item.Show();

            AccelMap.AddEntry("<CdnStudio>/Widgets/Editors/Properties/Remove", (uint)Gdk.Key.KP_Subtract, Gdk.ModifierType.None);

            item.Sensitive  = (d_treeview.Selection.CountSelectedRows() > 0);
            item.Activated += DoRemoveProperty;

            menu.Append(item);

            menu.Popup(null, null, null, evnt.Button, evnt.Time);
        }
コード例 #3
0
        private static void DeleteItemKey(IntPtr data, string accelPath, uint accelKey, ModifierType accelMods, bool changed)
        {
            long itemId;
            bool result = IsKeyForItem(accelPath, out itemId);

            if (result)
            {
                AccelMap.ChangeEntry(accelPath, (uint)Key.VoidSymbol, 0, true);
            }
        }
コード例 #4
0
 public static void Save(IEnumerable <KeyValuePair <string, AccelKey> > changedShortcuts)
 {
     AccelMap.Foreach(IntPtr.Zero,
                      (pointer, accelPath, key, modifierType, changed) => AccelMap.ChangeEntry(accelPath, 0, 0, true));
     AccelMap.Load(StoragePaths.KeyMapFile);
     foreach (KeyValuePair <string, AccelKey> shortcut in changedShortcuts)
     {
         AccelMap.ChangeEntry(shortcut.Key, (uint)shortcut.Value.Key, shortcut.Value.AccelMods, true);
     }
     AccelMap.Save(StoragePaths.KeyMapFile);
     Load();
 }
コード例 #5
0
        private static void RemoveQuickItem(string key)
        {
            string quickItem = BusinessDomain.QuickItems [key];

            BusinessDomain.QuickItems.Remove(key);
            Item item = Item.GetByAny(quickItem);

            if (item != null)
            {
                AccelMap.ChangeEntry(KeyShortcuts.GetAccelPath(item.Id.ToString(CultureInfo.InvariantCulture)), (uint)Key.VoidSymbol, 0, true);
            }
        }
コード例 #6
0
 public EditQuickItems(MenuItemCollection mainMenu, AccelGroup accelGroup)
 {
     this.mainMenu   = mainMenu;
     this.accelGroup = accelGroup;
     itemShortcuts   = new BindList <ItemShortcut> ();
     changedMenus    = new List <string> ();
     AccelMap.Foreach(IntPtr.Zero, AddItemShortcut);
     if (itemShortcuts.Count == 0)
     {
         itemShortcuts.Add(new ItemShortcut());
     }
     Initialize();
 }
コード例 #7
0
        public static AccelKey LookupEntry(string accelPath)
        {
            AccelKey result = new AccelKey();

            AccelMap.Foreach(IntPtr.Zero, (data, path, key, mods, changed) =>
            {
                if (path == GetAccelPath(accelPath))
                {
                    result = new AccelKey((Key)key, mods, AccelFlags.Visible);
                }
            });
            AccelKey accelKey = result;

            return(accelKey);
        }
コード例 #8
0
        public static void Load()
        {
            string tempKeyMap = Path.GetTempFileName();

            File.WriteAllText(tempKeyMap, DataHelper.GetDefaultKeyMap());

            AccelMap.Load(tempKeyMap);
            foreach (ICustomKeyShortcut shortcut in CustomKeyShortcuts)
            {
                AccelMap.ChangeEntry(GetAccelPath(shortcut.Path), (uint)shortcut.DefaultKey, GetAllowedModifier(shortcut.DefaultModifier), true);
            }

            File.Delete(tempKeyMap);

            AccelMap.Load(StoragePaths.KeyMapFile);
        }
コード例 #9
0
        protected void Clear_Clicked(object o, EventArgs args)
        {
            if (itemShortcuts.Count == 1 && itemShortcuts [0].ItemId < 0)
            {
                EditGridCell(0, 0);
                return;
            }

            string title   = Translator.GetString("Warning!");
            string message = Translator.GetString("This action will delete the shortcuts for all items. Are you sure you want to continue?");

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

            AccelMap.Foreach(dlgEditQuickItems.Handle, DeleteItemKey);
            itemShortcuts.Clear();
            itemShortcuts.Add(new ItemShortcut());
            EditGridCell(0, 0);
        }
コード例 #10
0
        private bool UsedInMenu(int row)
        {
            bool result = true;

            AccelMap.Foreach(dlgEditQuickItems.Handle,
                             (data, accelPath, accelKey, accelMods, changed) =>
            {
                if (changedMenus.Contains(accelPath) || currentKey.Key == 0)
                {
                    return;
                }
                string name = accelPath.Substring(accelPath.IndexOf('/') + 1);
                MenuItemWrapper menuItem = mainMenu.FindMenuItem(name);
                if (menuItem != null && (uint)currentKey.Key == accelKey && currentKey.AccelMods == accelMods)
                {
                    string title       = Translator.GetString("Warning!");
                    string translation = Translator.GetString("The selected shortcut is already used for menu item \"{0}\". " +
                                                              "Do you want to remove the shortcut for \"{0}\" and assign it to \"{1}\"?");
                    string message = string.Format(translation, menuItem.Text, itemShortcuts [row].ItemName);
                    if (Message.ShowDialog(title, string.Empty, message, "Icons.Question32.png",
                                           MessageButtons.YesNo) == ResponseType.Yes)
                    {
                        AccelMap.ChangeEntry(accelPath, (uint)Key.VoidSymbol, 0, true);
                        changedMenus.Add(accelPath);
                        AccelKey key = KeyShortcuts.LookupEntry(name);
                        menuItem.Item.RemoveAccelerator(accelGroup, (uint)key.Key, key.AccelMods);
                    }
                    else
                    {
                        result = false;
                    }
                }
            });
            if (!result)
            {
                return(false);
            }
            return(true);
        }
コード例 #11
0
 protected void btnCancel_Clicked(object o, EventArgs args)
 {
     AccelMap.Load(StoragePaths.KeyMapFile);
     dlgEditQuickItems.Respond(ResponseType.Cancel);
 }
コード例 #12
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();
        }