Beispiel #1
0
        private void _menuItem_Click(GItemCommand <TKey, TValue> command)
        {
            if (command.AddToCommandsStack)
            {
                if (command.AllowMultipleSelection)
                {
                    List <ITableCommand <TKey, TValue> > commands = new List <ITableCommand <TKey, TValue> >();
                    SearchEngine.Collection.Disable();

                    for (int index = 0; index < _listView.SelectedItems.Count; index++)
                    {
                        TValue rItem = (TValue)_listView.SelectedItems[index];
                        var    cmd   = command.Command(rItem);

                        if (cmd != null)
                        {
                            commands.Add(cmd);
                        }
                    }

                    if (commands.Count > 0)
                    {
                        Table.Commands.AddGroupedCommands(commands);
                    }

                    SearchEngine.Collection.UpdateAndEnable();
                    Update();
                }
                else
                {
                    try {
                        if (_listView.SelectedItem != null)
                        {
                            TValue rItem = (TValue)_listView.SelectedItem;
                            Table.Commands.StoreAndExecute(command.Command(rItem));
                        }
                    }
                    catch (Exception err) {
                        ErrorHandler.HandleException(err);
                    }
                }
            }
            else
            {
                if (command.GenericCommand == null)
                {
                    ErrorHandler.HandleException("The added command in the generic database tab hasn't been compiled properly.");
                    return;
                }

                command.GenericCommand(_listView.SelectedItems.OfType <TValue>().ToList());
            }
        }
Beispiel #2
0
        private void _initMenus()
        {
            foreach (GItemCommand <TKey, TValue> commandCopy in Settings.AddedCommands)
            {
                if (commandCopy.Visibility != Visibility.Visible)
                {
                    continue;
                }

                GItemCommand <TKey, TValue> command = commandCopy;
                MenuItem item = new MenuItem();
                item.Header = command.DisplayName;
                item.Click += (e, a) => _menuItem_Click(command);

                Image image = new Image();
                image.Source = ApplicationManager.PreloadResourceImage(command.ImagePath);
                item.Icon    = image;

                if (command.Shortcut != null)
                {
                    ApplicationShortcut.Link(command.Shortcut, () => _menuItem_Click(command), this);
                    item.InputGestureText = ApplicationShortcut.FindDislayName(command.Shortcut);
                }

                _listView.ContextMenu.Items.Insert(command.InsertIndex, item);
            }

            _miDelete.Click          += _menuItemDeleteItem_Click;
            _miCopyTo.Click          += _menuItemCopyItemTo_Click;
            _miShowSelected.Click    += _menuItemKeepSelectedItemsOnly_Click;
            _miChangeId.Click        += _miChangeId_Click;
            _miSelectInNotepad.Click += _miSelectInNotepad_Click;
            _miCut.Click             += _miCut_Click;

            if (!Settings.CanChangeId)
            {
                _miChangeId.Visibility = Visibility.Collapsed;
            }

            var shortcut = ApplicationShortcut.FromString("Ctrl-W", "Open in Notepad++");

            ApplicationShortcut.Link(shortcut, () => _miSelectInNotepad_Click(null, null), this);
        }