コード例 #1
0
        public void RemoveByElementName(string elementName)
        {
            ProjectTag[] values = new ProjectTag[templateTags.Values.Count];
            templateTags.Values.CopyTo(values, 0);
            foreach (ProjectTag tag in values)
            {
                if (tag.TemplateElement == elementName)
                {
                    templateTags.Remove(tag.TemplateElement);
                    TagPath basePath = new TagPath(tag.Path);
                    if (basePath.Location == TagLocation.Project)
                    {
                        string relativePath = basePath.ToPath(PathFormat.Relative);
                        templateTagHierarchy.RemoveFile(relativePath);
                    }
                    OnFileRemoved(tag.Path, elementName);

                    TemplateTag templateTag = GetTemplateTag(elementName);
                    if (templateTag != null)
                    {
                        // Generate the FileAdded event with the default filename - this is so that the
                        // ProjectExplorer can update it's Essential Tags list.
                        // This is kind of hackish, because the ProjectFile shouldn't be worrying
                        // about the PE at all.  A more appropriate place to put this functionality would
                        // be in the ProjectNodeSource, but that would complicate some things and would
                        // force me to write additional code.  And we all know how lazy I am! :D
                        TagPath path = new TagPath(templateTag.DefaultFile + "." + templateTag.FileType,
                                                   "", TagLocation.Archive);
                        OnFileAdded(path.ToPath(PathFormat.ExplicitLocation), templateTag.Name);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Removes the specified tag from the list of tag references for this project.
        /// </summary>
        /// <param name="path">The path of the reference to remove.</param>
        /// <param name="autoRevertTemplateTag">If the reference points to an essential tag, specifies if it will automatically be reverted to its default tag.  Normally, the user is prompted in this scenario.</param>
        /// <returns>A value indicating if the reference was removed.</returns>
        public bool RemoveTagReference(string path, bool autoRevertEssentialTag)
        {
            // In order to see if this is a referenced essential tag, we need to
            // create a project-scoped explicit path to check against.
            // TODO: After shared folder / prefabs are implemented, we will also need to check those.
            TagPath projectPath = new TagPath(path);

            projectPath.Location = TagLocation.Project;
            string projectPathString = projectPath.ToPath(PathFormat.ExplicitLocation);

            // Check the essential tags collection (templates), not the normal references table (projectReferencesTable).
            if (templates.ContainsPath(projectPathString))
            {
                // This is an essential tag, so get it's corresponding template name.
                // Ex: 'levels\test\bloodgulch\bloodgulch.scenario' would be the 'Scenario' template element.
                string templateName = templates.GetTemplateNameBypath(projectPathString);

                // If we aren't auto-reverting, generate the TemplateReverting event to prompt the user.
                bool revertEssentialTag = autoRevertEssentialTag;

                if (!autoRevertEssentialTag)
                {
                    // The value returned here indicates whether the event was cancelled, so we want the inverse of it.
                    revertEssentialTag = !OnTemplateReverting(projectPathString, templateName);
                }

                if (revertEssentialTag)
                {
                    templates.RemoveByTagPath(projectPathString); // User chose to remove, or auto-revert was set.
                }
                else
                {
                    return(false); // Nothing was removed.
                }
            }
            else // This was not an essential tag.
            {
                if (FileExists(path))
                {
                    // Remove the reference from the references table and raise the corresponding event.
                    projectReferencesTable.RemoveFile(path);
                    OnFileRemoved(path);
                }
            }
            return(true); // References were removed.
        }