Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to gets an existing model representing the category in the toolbox. If a model
        /// does not exist for the category, one will be created and added to the toolbox.
        /// </summary>
        /// <param name="categoryName">The name of the category.</param>
        /// <returns>Returns the existing model if found; otherwise returns the model that was created for the category.</returns>
        private CategoryTreeNodeModel GetCategoryModel(string categoryName)
        {
            // Attempt to find an existing category model
            CategoryTreeNodeModel categoryModel = rootModel
                                                  .Children
                                                  .OfType <CategoryTreeNodeModel>()
                                                  .FirstOrDefault(x => x.Name == categoryName);

            // If not found, create one
            if (categoryModel is null)
            {
                categoryModel = CreateCategoryModel(categoryName);
                rootModel.Children.Add(categoryModel);
            }

            return(categoryModel);
        }
Ejemplo n.º 2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes an instance of the <c>MainControl</c> class.
        /// </summary>
        public MainControl()
        {
            InitializeComponent();

            // Create the root model that will be used to populate the toolbox
            rootModel = new CategoryTreeNodeModel()
            {
                Name       = "Toolbox",
                IsExpanded = true
            };
            treeListBox.RootItem = rootModel;

            // Initialize the data
            ResetToolbox();

            // Listen for changes in Favorites
            ControlDataRepository.Instance.FavoritesChanged += this.OnControlDataRepositoryFavoritesChanged;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tries to get the category and control models for the specified item.
        /// </summary>
        /// <param name="toolboxControl">The <see cref="TreeListBox"/> control.</param>
        /// <param name="item">The item to examine.</param>
        /// <param name="categoryModel">The resulting <see cref="CategoryTreeNodeModel"/>.</param>
        /// <param name="controlModel">The resulting <see cref="ControlTreeNodeModel"/>.</param>
        /// <returns>
        /// <c>true</c> if results were found; otherwise, <c>false</c>.
        /// </returns>
        private bool TryGetModelsFromItem(TreeListBox toolboxControl, object item, out CategoryTreeNodeModel categoryModel, out ControlTreeNodeModel controlModel)
        {
            if (item is ControlTreeNodeModel localControlModel)
            {
                controlModel = localControlModel;
                return(TryGetCategory(toolboxControl, controlModel, out categoryModel));
            }
            else if (item is EmptyPlaceholderTreeNodeModel emptyPlaceholderModel)
            {
                controlModel = null;
                return(TryGetCategory(toolboxControl, emptyPlaceholderModel, out categoryModel));
            }
            else if (item is CategoryTreeNodeModel localCategoryModel)
            {
                controlModel  = null;
                categoryModel = localCategoryModel;
                return(true);
            }

            categoryModel = null;
            controlModel  = null;
            return(false);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns whether the specified <see cref="CategoryTreeNodeModel" /> is for the Favorites category.
 /// </summary>
 /// <param name="categoryModel">The <see cref="CategoryTreeNodeModel"/> to examine.</param>
 /// <returns>
 /// <c>true</c> if the specified <see cref="CategoryTreeNodeModel" /> is for the Favorites category; otherwise, <c>false</c>.
 /// </returns>
 private bool IsFavoritesCategory(CategoryTreeNodeModel categoryModel)
 {
     return(categoryModel is FavoritesCategoryTreeNodeModel);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Tries to get the category model for the specified <see cref="ToolboxTreeNodeModel"/>.
        /// </summary>
        /// <param name="toolboxControl">The <see cref="TreeListBox"/> control.</param>
        /// <param name="itemModel">The <see cref="ToolboxTreeNodeModel"/> to examine.</param>
        /// <param name="categoryModel">The resulting <see cref="CategoryTreeNodeModel"/>.</param>
        /// <returns>
        /// <c>true</c> if a result was found; otherwise, <c>false</c>.
        /// </returns>
        private bool TryGetCategory(TreeListBox toolboxControl, ToolboxTreeNodeModel itemModel, out CategoryTreeNodeModel categoryModel)
        {
            categoryModel = null;
            if (itemModel is CategoryTreeNodeModel localCategoryModel)
            {
                categoryModel = localCategoryModel;
                return(true);
            }

            var navigator = toolboxControl.GetItemNavigator(itemModel);

            if (navigator.GoToParent())
            {
                categoryModel = navigator.CurrentItem as CategoryTreeNodeModel;
                return(categoryModel != null);
            }

            return(false);
        }