コード例 #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>
        /// Adds the the specified template element/path combination to the list.
        /// </summary>
        public void Add(string templateElement, TagPath tagPath)
        {
            // Make sure that the template element that is attempting to be added exists in
            // the related Template for this list.
            bool validTemplate = false;

            foreach (TemplateTag templateTag in baseTemplate.TagSet)
            {
                if (templateTag.Name == templateElement)
                {
                    validTemplate = true;
                    break;
                }
            }

            if (validTemplate)
            {
                // Get the explicit location and add that path to the elements
                // (Or update an existing path if the named element already exists.)
                string     path = tagPath.ToPath(PathFormat.ExplicitLocation);
                ProjectTag tag  = new ProjectTag(templateElement, path);
                if (!templateTags.ContainsKey(templateElement))
                {
                    templateTags.Add(templateElement, tag);
                }
                else
                {
                    templateTags[templateElement].Path = path;
                }

                // If the tag is from the project, store the relative path
                // (no "p:\" prefix) to the templateTagHierarchy.
                if (tagPath.Location == TagLocation.Project)
                {
                    templateTagHierarchy.Add(tagPath.ToPath(PathFormat.Relative));
                    // We added a new file yar!!
                    OnFileAdded(path, templateElement);

                    TemplateTag templateTag = GetTemplateTag(templateElement);
                    if (templateTag != null)
                    {
                        // Again, haxzorzz!!
                        TagPath lePath = new TagPath(templateTag.DefaultFile + "." + templateTag.FileType,
                                                     "", TagLocation.Archive);
                        OnFileRemoved(lePath.ToPath(PathFormat.ExplicitLocation), templateTag.Name);
                    }
                }
            }
            else
            {
                throw new Exception("The specified element '" + templateElement + "' does not exist in the template '" +
                                    baseTemplate.Name + "'");
            }
        }