예제 #1
0
        /// <summary>
        /// Returns a list of grouped views.
        /// </summary>
        /// <param name="views">The views.</param>
        /// <returns>Dictionary&lt;System.String, List&lt;ViewResult&gt;&gt;.</returns>
        private Dictionary <string, List <ViewResult> > GetGroupedViews(IEnumerable <ViewResult> views)
        {
            var groups = new Dictionary <string, List <ViewResult> >();

            foreach (var view in views.Where(v => v.View != null))
            {
                var group = SimpleView.GetGroup(view.View).Trim();
                if (string.IsNullOrEmpty(group) && !CombineAllEmptyGroups)
                {
                    group = SimpleView.GetTitle(view.View);
                }
                if (!groups.ContainsKey(group))
                {
                    groups.Add(group, new List <ViewResult> {
                        view
                    });
                }
                else
                {
                    groups[group].Add(view);
                }
            }
            return(groups);
        }
        /// <summary>
        /// Populates the list of items from actions and views.
        /// </summary>
        private void Repopulate()
        {
            var newItems = new List <ViewActionAndOpenViewItem>();

            if (Actions != null)
            {
                foreach (var action in Actions.Actions)
                {
                    if (!string.IsNullOrEmpty(action.GroupTitle))
                    {
                        var found = false;
                        foreach (var otherAction in newItems)
                        {
                            if (otherAction.Group == action.GroupTitle)
                            {
                                otherAction.SubItems.Add(new ViewActionAndOpenViewItem(action, ViewTabs));
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            newItems.Add(new ViewActionAndOpenViewItem(action, ViewTabs));
                        }
                    }
                    else
                    {
                        newItems.Add(new ViewActionAndOpenViewItem(action, ViewTabs));
                    }
                }
            }

            if (Views != null)
            {
                var viewIndex = -1;
                foreach (var view in Views)
                {
                    viewIndex++;
                    var groupTitle = string.Empty;
                    if (view.View != null)
                    {
                        groupTitle = SimpleView.GetGroup(view.View);
                    }
                    if (!string.IsNullOrEmpty(groupTitle))
                    {
                        var found = false;
                        foreach (var otherAction in newItems)
                        {
                            if (otherAction.Group == groupTitle)
                            {
                                otherAction.SubItems.Add(new ViewActionAndOpenViewItem(view, viewIndex, ViewTabs));
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            newItems.Add(new ViewActionAndOpenViewItem(view, viewIndex, ViewTabs));
                        }
                    }
                    else
                    {
                        newItems.Add(new ViewActionAndOpenViewItem(view, viewIndex, ViewTabs));
                    }
                }
            }

            ItemsSource = newItems;
        }