예제 #1
0
        public void ShowContextMenu()
        {
            var item = thumbList.SelectedItem as MultimediaLinkViewModel;

            if (item != null)
            {
                ContextMenu     menu    = new ContextMenu();
                MenuItemBuilder builder = new MenuItemBuilder();

                string filename = _tempFileManager.GetContentFileName(item.MultimediaID, item.Extension);

                thumbList.ContextMenu = menu;

                var verbMenuItems = SystemUtils.GetVerbsAsMenuItems(filename);
                foreach (MenuItem verbItem in verbMenuItems)
                {
                    menu.Items.Add(verbItem);
                }

                menu.Items.Add(new Separator());
                menu.Items.Add(builder.New("Add multimedia").Handler(() => { AddMultimedia(); }).Enabled(!IsReadOnly).MenuItem);
                menu.Items.Add(new Separator());
                menu.Items.Add(builder.New("Delete").Handler(() => { DeleteSelectedMultimedia(); }).Enabled(!IsReadOnly).MenuItem);
                menu.Items.Add(new Separator());
                menu.Items.Add(builder.New("Show items linked to this multimedia...").Handler(() => { ShowLinkedItems(); }).MenuItem);
                menu.Items.Add(new Separator());
                menu.Items.Add(builder.New("Edit Details...").Handler(() => { ShowProperties(); }).Enabled(!IsReadOnly).MenuItem);
            }
        }
예제 #2
0
 public ContextMenuBuilder(MessageFormatterFunc messageFormatter, ContextMenu menu = null)
 {
     _formatter             = messageFormatter;
     _menu                  = (menu == null ? new ContextMenu() : menu);
     _itemBuilder           = new MenuItemBuilder(_formatter);
     _itemBuilder.EndAction = (menuItem) => {
         _menu.Items.Add(menuItem);
     };
 }
예제 #3
0
        private void ShowPopupMenu()
        {
            ViewModelBase viewmodel = lvw.SelectedItem as ViewModelBase;

            if (viewmodel == null)
            {
                return;
            }

            ContextMenu     menu    = new ContextMenu();
            MenuItemBuilder builder = new MenuItemBuilder();

            menu.Items.Add(builder.New("_Unpin").Handler(() => { Unpin(viewmodel); }).MenuItem);

            var list = new List <ViewModelBase>();

            list.Add(viewmodel);
            var commands = PluginManager.Instance.SolicitCommandsForObjects(list);


            if (commands != null && commands.Count > 0)
            {
                menu.Items.Add(new Separator());
                foreach (Command loopvar in commands)
                {
                    Command cmd = loopvar; // include this in the closure scope, loopvar is outside, hence will always point to the last item...
                    if (cmd is CommandSeparator)
                    {
                        menu.Items.Add(new Separator());
                    }
                    else
                    {
                        menu.Items.Add(builder.New(cmd.Caption).Handler(() => { cmd.CommandAction(viewmodel); }).MenuItem);
                    }
                }
            }

            if (menu.HasItems)
            {
                lvw.ContextMenu = menu;
            }
        }
예제 #4
0
        private void AddLookupItem(ContextMenuBuilder builder, LookupType lookupType, params String[] aliases)
        {
            int index = -1;

            foreach (string alias in aliases)
            {
                var field = alias;

                for (int i = 0; i < Data.Columns.Count; ++i)
                {
                    var col = Data.Columns[i];
                    if (col.Name.Contains(alias))
                    {
                        index = i;
                        break;
                    }
                }

                if (index >= 0)
                {
                    break;
                }
            }

            if (index > -1)
            {
                var row = lvw.SelectedItem as MatrixRow;

                int objectId = 0;
                var enabled  = false;
                if (row[index] != null)
                {
                    if (Int32.TryParse(row[index].ToString(), out objectId) && objectId > 0)
                    {
                        enabled = true;
                    }
                }

                var pinnable = PluginManager.Instance.GetPinnableForLookupType(lookupType, objectId);

                var commands = new List <Command>();

                if (pinnable != null)
                {
                    var vm = PluginManager.Instance.GetViewModel(pinnable);
                    if (vm != null)
                    {
                        var selected = new List <ViewModelBase>();
                        selected.Add(vm);
                        commands.AddRange(PluginManager.Instance.SolicitCommandsForObjects(selected));
                    }
                }

                if (commands.Count > 0)
                {
                    MenuItemBuilder b = new MenuItemBuilder();

                    var typeItem = b.New(lookupType.ToString()).MenuItem;

                    typeItem.Items.Add(b.New("Pin {0} to pinboard", lookupType).Handler(() => {
                        PluginManager.Instance.PinObject(pinnable);
                    }).Enabled(enabled).MenuItem);
                    typeItem.Items.Add(new Separator());

                    commands.ForEach((cmd) => {
                        if (cmd is CommandSeparator)
                        {
                            typeItem.Items.Add(new Separator());
                        }
                        else
                        {
                            typeItem.Items.Add(b.New(cmd.Caption).Handler(() => {
                                cmd.CommandAction(pinnable);
                            }).Enabled(enabled).MenuItem);
                        }
                    });

                    builder.AddMenuItem(typeItem);
                }
                else
                {
                    builder.New("Edit " + lookupType.ToString()).Handler(() => {
                        PluginManager.Instance.EditLookupObject(lookupType, objectId);
                    }).Enabled(enabled).End();
                }
            }

            addSetOperations(builder, lookupType, aliases);
        }
예제 #5
0
        private void addSetOperations(ContextMenuBuilder builder, LookupType type, params string[] idColAliases)
        {
            int index = -1;

            foreach (string alias in idColAliases)
            {
                var field = alias;
                for (int i = 0; i < Data.Columns.Count; ++i)
                {
                    var col = Data.Columns[i];
                    if (col.Name.Contains(alias))
                    {
                        index = i;
                        break;
                    }
                }

                if (index >= 0)
                {
                    break;
                }
            }

            if (index > -1)
            {
                List <int> idSet = new List <int>();

                if (lvw.SelectedItems.Count > 1)
                {
                    foreach (object selected in lvw.SelectedItems)
                    {
                        var row         = selected as MatrixRow;
                        var selectedRow = Data.Rows.IndexOf(row);
                        idSet.Add((int)row[selectedRow]);
                    }
                }
                else
                {
                    Data.Rows.ForEach(row => {
                        var objectIndex = row[index];
                        if (objectIndex is int)
                        {
                            idSet.Add((int)row[index]);
                        }
                    });
                }

                if (idSet.Count > 0)
                {
                    var commands = PluginManager.Instance.SolicitCommandsForObjectSet(idSet, type);
                    if (commands != null && commands.Count > 0)
                    {
                        MenuItemBuilder b = new MenuItemBuilder();

                        var typeItem = b.New(type.ToString() + String.Format(" Set ({0} items)", idSet.Count)).MenuItem;

                        commands.ForEach((cmd) => {
                            if (cmd is CommandSeparator)
                            {
                                typeItem.Items.Add(new Separator());
                            }
                            else
                            {
                                typeItem.Items.Add(b.New(cmd.Caption).Handler(() => {
                                    cmd.CommandAction(idSet);
                                }).MenuItem);
                            }
                        });
                        builder.AddMenuItem(typeItem);
                    }
                }
            }
        }