Ejemplo n.º 1
0
        //NOTE: Ignoring base.Add and Remove.  This has a fixed number of blueprint parts

        #endregion

        #region Private Methods

        private void BuildToolBox(IEnumerable <PartToolItemBase> parts)
        {
            string[] tabNames = parts.
                                Select(o => o.TabName).
                                Distinct().
                                ToArray();

            if (tabNames.Length > 1)
            {
                throw new ArgumentException("parts span tabNames, not sure how to handle that: " + string.Join(", ", tabNames));
            }

            string[] categories = SortCategories(parts.Select(o => o.Category));

            Brush brushPrimary   = new SolidColorBrush(_colors.TabIcon_Primary);
            Brush brushSecondary = new SolidColorBrush(_colors.TabIcon_Secondary);

            // Remove existing tabs
            base.Tabs.Clear();

            // Make the tabs
            foreach (string category in categories)
            {
                TabItem tab = new TabItem()
                {
                    DataContext = this,
                    Header      = PartCategoryIcons.GetIcon(tabNames[0], category, brushPrimary, brushSecondary, 24),
                    ToolTip     = category,
                };

                ScrollViewer scroll = new ScrollViewer()
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                    Padding = new Thickness(0, 0, 6, 0),
                };

                UniformGrid panel = new UniformGrid()
                {
                    Columns  = 1,
                    MaxWidth = 200,
                };
                scroll.Content = panel;

                tab.Content = scroll;

                // Add the parts that belong in this tab/category
                //TODO: Sort these
                foreach (PartToolItemBase part in parts.Where(o => o.TabName == tabNames[0] && o.Category == category))
                {
                    panel.Children.Add(part.Visual2D);
                }

                base.Tabs.Add(tab);
            }
        }
Ejemplo n.º 2
0
        private int FindOrCreateTab(Tuple <PartToolItemBase, PartDesignBase> part)
        {
            int index = FindTab(part);

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

            string category = part.Item1.Category;

            // Figure out where to insert it
            string[] sorted = SortCategories(UtilityCore.Iterate <string>(_tabStats.Select(o => o.Item1), category));

            index = Array.IndexOf <string>(sorted, category);

            #region create tab

            TabItem tab = new TabItem()
            {
                DataContext = this,
                Header      = PartCategoryIcons.GetIcon(part.Item1.TabName, category, _brushPrimary, _brushSecondary, 24),
                ToolTip     = category,
            };

            ScrollViewer scroll = new ScrollViewer()
            {
                HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                Padding = new Thickness(0, 0, 6, 0),
            };

            UniformGrid panel = new UniformGrid()
            {
                Columns  = 1,
                MaxWidth = 200,
            };
            scroll.Content = panel;

            tab.Content = scroll;

            #endregion

            _tabStats.Insert(index, Tuple.Create(category, panel));
            base.Tabs.Insert(index, tab);

            return(index);
        }