예제 #1
0
        private void ShowTaxonMenu(TaxonViewModel taxon, FrameworkElement source)
        {
            TaxonMenuFactory factory = new TaxonMenuFactory(taxon, this, _R);

            ContextMenu menu = null;
            if (source is TreeView) {
                var tvw = source as TreeView;
                if (tvw == tvwAllTaxa) {
                    menu = factory.BuildExplorerMenu();
                } else if (tvw == tvwResults) {
                    menu = factory.BuildFindResultsMenu();
                }
            }

            if (menu != null && menu.HasItems) {
                source.ContextMenu = menu;
            }
        }
        private void TreeViewItem_MouseRightButtonDown(object sender, MouseEventArgs e)
        {
            TreeViewItem item = sender as TreeViewItem;

            if (item == null)
            {
                return;
            }

            item.Focus();
            e.Handled = true;

            var model = tvwFavorites.SelectedItem as HierarchicalViewModelBase;

            Debug.Assert(model != null);

            int?favoriteId = null;

            TaxonViewModel tvm = null;


            bool isGroup = false;

            if (model is TaxonFavoriteViewModel)
            {
                var fav = model as TaxonFavoriteViewModel;
                favoriteId = fav.FavoriteID;
                if (!fav.IsGroup)
                {
                    var taxon = new TaxaService(User).GetTaxon(fav.TaxaID);
                    tvm = new TaxonViewModel(null, taxon, TaxonExplorer.GenerateTaxonDisplayLabel);
                }
                else
                {
                    isGroup = true;
                }
            }
            else if (model is TaxonViewModel)
            {
                tvm = model as TaxonViewModel;
            }

            if (tvm != null)
            {
                TaxonMenuFactory f = new TaxonMenuFactory(tvm, TaxonExplorer, TaxonExplorer._R);
                tvwFavorites.ContextMenu = f.BuildFavoritesMenu(model);
            }
            else
            {
                var builder = new ContextMenuBuilder(null);

                builder.New("Add favorite group").Handler(() => { AddFavoriteGroup(model); }).End();
                if (isGroup)
                {
                    builder.New("Rename group").Handler(() => { RenameFavoriteGroup(model as TaxonFavoriteViewModel); }).End();
                    builder.New("Remove favorite group").Handler(() => { DeleteFavoriteGroup(model); }).End();
                }

                tvwFavorites.ContextMenu = builder.ContextMenu;
            }
        }
예제 #3
0
        private void TreeViewItem_MouseRightButtonDown(object sender, MouseEventArgs e)
        {
            TreeViewItem item = sender as TreeViewItem;

            if (item == null) {
                return;
            }

            item.Focus();
            e.Handled = true;

            var model = tvwFavorites.SelectedItem as HierarchicalViewModelBase;

            Debug.Assert(model != null);

            int? favoriteId = null;

            TaxonViewModel tvm = null;

            bool isGroup = false;

            if (model is TaxonFavoriteViewModel) {
                var fav = model as TaxonFavoriteViewModel;
                favoriteId = fav.FavoriteID;
                if (!fav.IsGroup) {
                    var taxon = new TaxaService(User).GetTaxon(fav.TaxaID);
                    tvm = new TaxonViewModel(null, taxon, TaxonExplorer.GenerateTaxonDisplayLabel);
                } else {
                    isGroup = true;
                }

            } else if (model is TaxonViewModel) {
                tvm = model as TaxonViewModel;
            }

            if (tvm != null) {
                TaxonMenuFactory f = new TaxonMenuFactory(tvm, TaxonExplorer, TaxonExplorer._R);
                tvwFavorites.ContextMenu = f.BuildFavoritesMenu(model);
            } else {
                var builder = new ContextMenuBuilder(null);

                builder.New("Add favorite group").Handler(() => { AddFavoriteGroup(model); }).End();
                if (isGroup) {
                    builder.New("Rename group").Handler(() => { RenameFavoriteGroup(model as TaxonFavoriteViewModel); }).End();
                    builder.New("Remove favorite group").Handler(() => { DeleteFavoriteGroup(model); }).End();
                }

                tvwFavorites.ContextMenu = builder.ContextMenu;
            }
        }