Exemple #1
0
        /// <summary>
        /// Adds another file (child) item below the parent item.
        /// This will throw an Exception if parent is null.
        /// </summary>
        /// <param name="itemName"></param>
        /// <param name="parent"></param>
        /// <param name="itemType"></param>
        /// <returns></returns>
        public ISolutionBaseItem AddChild(
            string itemName,
            SolutionItemType itemType,
            ISolutionBaseItem parent)
        {
            var internalItem = parent as ISolutionItem;

            if (internalItem == null)
            {
                throw new System.ArgumentException("Paremeter parent cannot have children.");
            }

            switch (itemType)
            {
            case SolutionItemType.SolutionRootItem:
                return(AddSolutionRootItem(itemName));

            case SolutionItemType.File:
                return(internalItem.AddFile(itemName));

            case SolutionItemType.Folder:
                return(internalItem.AddFolder(itemName));

            case SolutionItemType.Project:
                return(internalItem.AddProject(itemName));

            default:
                throw new ArgumentOutOfRangeException(itemType.ToString());
            }
        }
        /// <summary>
        /// Adding a new next child item via In-place Edit Box requires that
        /// we know whether 'New Folder','New Folder 1', 'New Folder 2' ...
        /// is the next appropriate name - this method determines that name
        /// and returns it for a given type of a (to be created) child item.
        /// </summary>
        /// <param name="nextTypeTpAdd"></param>
        /// <returns></returns>
        public string SuggestNextChildName(SolutionItemType nextTypeTpAdd)
        {
            string suggestMask = null;

            switch (nextTypeTpAdd)
            {
            case SolutionItemType.SolutionRootItem:
                suggestMask = "New Solution";
                break;

            case SolutionItemType.File:
                suggestMask = "New File";
                break;

            case SolutionItemType.Folder:
                suggestMask = "New Folder";
                break;

            case SolutionItemType.Project:
                suggestMask = "New Project";
                break;

            default:
                throw new ArgumentOutOfRangeException(nextTypeTpAdd.ToString());
            }

            var nextChild = _Children.TryGet(suggestMask);

            if (nextChild == null)
            {
                return(suggestMask);
            }

            string suggestChild = null;

            for (int i = 1; i < _Children.Count + 100; i++)
            {
                suggestChild = string.Format("{0} {1}", suggestMask, i);

                nextChild = _Children.TryGet(suggestChild);
                if (nextChild == null)
                {
                    break;
                }
            }

            return(suggestChild);
        }
        /// <summary>
        /// Adds a child item with the given type
        /// (<see cref="SolutionItemType.SolutionRootItem"/> cannot be added here).
        /// </summary>
        /// <param name="displayName"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public IItem AddChild(string displayName, SolutionItemType type)
        {
            if (HasDummyChild == true)
            {
                ResetChildren(false);
            }

            switch (type)
            {
            case SolutionItemType.File:
                return(AddChild(displayName, new FileViewModel(this, displayName)));

            case SolutionItemType.Folder:
                return(AddChild(displayName, new FolderViewModel(this, displayName, false)));

            case SolutionItemType.Project:
                return(AddChild(displayName, new ProjectViewModel(this, displayName, false)));

            default:
            case SolutionItemType.SolutionRootItem:
                // this is only constructed in the SolutionViewModel
                throw new System.ArgumentOutOfRangeException(type.ToString());
            }
        }
Exemple #4
0
        /// <summary>
        /// Get a DynamicResource from ResourceDictionary or a static ImageSource (as fallback) for not expanded folder item.
        /// </summary>
        /// <param name="itemType"></param>
        /// <param name="isItemExpanded"></param>
        /// <returns></returns>
        private object GetImage(SolutionItemType itemType, bool isItemExpanded)
        {
            string uriPath = null;

            switch (itemType)
            {
            case Models.SolutionItemType.SolutionRootItem:
                uriPath = "SolutionIcon";
                break;

            case Models.SolutionItemType.File:
                uriPath = "FileIcon";
                break;

            case Models.SolutionItemType.Folder:
                if (isItemExpanded == true)
                {
                    uriPath = "FolderIconOpen";
                }
                else
                {
                    uriPath = "FolderIcon";
                }
                break;

            case Models.SolutionItemType.Project:
                uriPath = "ProjectIcon";
                break;

            default:
                throw new ArgumentOutOfRangeException(itemType.ToString());
            }

            object item = null;

            // Find Icon source in ResouceDictionary and return it
            if (uriPath != null)
            {
                item = Application.Current.Resources[uriPath];

                if (item != null)
                {
                    return(item);
                }
            }

            // item was not available in resourcedictionary, so as a fallback
            // we try a static reference since that should be better than returning null
            string pathValue = null;

            switch (itemType)
            {
            case Models.SolutionItemType.SolutionRootItem:
                pathValue = "pack://application:,,,/SolutionLib;component/Resources/Solutions/Light/AppFlyout_16x.png";
                break;

            case Models.SolutionItemType.File:
                uriPath = "pack://application:,,,/SolutionLib;component/Resources/Files/Light/Document_16x.png";
                break;

            case Models.SolutionItemType.Folder:
                if (isItemExpanded == true)
                {
                    uriPath = "pack://application:,,,/SolutionLib;component/Resources/Folders/Light/FolderOpen_32x.png";
                }
                else
                {
                    uriPath = "pack://application:,,,/SolutionLib;component/Resources/Folders/Light/Folder_32x.png";
                }
                break;

            case Models.SolutionItemType.Project:
                uriPath = "pack://application:,,,/SolutionLib;component/Resources/Projects/Light/Application_16x.png";
                break;

            default:
                throw new ArgumentOutOfRangeException(itemType.ToString());
            }

            if (pathValue != null)
            {
                try
                {
                    Uri         imagePath = new Uri(pathValue, UriKind.RelativeOrAbsolute);
                    ImageSource source    = new System.Windows.Media.Imaging.BitmapImage(imagePath);

                    return(source);
                }
                catch
                {
                }
            }

            // Attempt to load fallback folder from ResourceDictionary
            item = Application.Current.Resources["FolderIcon"];

            if (item != null)
            {
                return(item);
            }
            else
            {
                // Attempt to load fallback folder from fixed Uri
                pathValue = "pack://application:,,,/SolutionLib;component/Resources/Folders/Light/Folder_32x.png";

                try
                {
                    Uri         imagePath = new Uri(pathValue, UriKind.RelativeOrAbsolute);
                    ImageSource source    = new System.Windows.Media.Imaging.BitmapImage(imagePath);

                    return(source);
                }
                catch
                {
                }
            }

            return(null);
        }
Exemple #5
0
 void AdjustGoSolutionItemType(GameObject go, SolutionItemType solutionItemType)
 {
     go.name = solutionItemType.ToString();
 }