Ejemplo n.º 1
0
 /// <summary>
 /// Makes the element the current selection.
 /// </summary>
 public void Select()
 {
     using (HierarchyNode node = new HierarchyNode(this.solution))
     {
         VsHelper.Select(this.serviceProvider, node);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the item content to the given string, optionally specifying the encoding.
        /// </summary>
        /// <param name="item">The item to overwrite.</param>
        /// <param name="content">The content to set for the item.</param>
        /// <param name="encoding">Optional encoding, which defaults to UTF8.</param>
        public static void SetContent(this IItem item, string content, Encoding encoding = null)
        {
            Guard.NotNull(() => item, item);
            Guard.NotNull(() => content, content);

            VsHelper.CheckOut(item.PhysicalPath);
            File.WriteAllText(item.PhysicalPath, content, encoding ?? Encoding.UTF8);
        }
Ejemplo n.º 3
0
        public virtual IItemContainer Unfold(string name, IItemContainer parent)
        {
            Guard.NotNullOrEmpty(() => name, name);
            Guard.NotNull(() => parent, parent);

            if (!typeof(HierarchyItem).IsAssignableFrom(parent.GetType()))
            {
                throw new NotSupportedException(Resources.VsFileTemplate_ErrorParentNotHierarchy);
            }

            Guard.NotNullOrEmpty(() => parent.PhysicalPath, parent.PhysicalPath);

            var targetPath = Path.Combine(Path.GetDirectoryName(parent.PhysicalPath), name);

            if (File.Exists(targetPath))
            {
                VsHelper.CheckOut(targetPath);
            }

            if (!this.SourcePath.Equals(targetPath, StringComparison.OrdinalIgnoreCase))
            {
                File.Copy(this.SourcePath, targetPath, this.overwrite);
            }

            var container = parent.As <dynamic>();

            EnvDTE.ProjectItem newlyAddedFile = null;

            if (!parent.Items.Any(i => i.Name == name))
            {
                newlyAddedFile = container.ProjectItems.AddFromFile(targetPath) as EnvDTE.ProjectItem;
            }

            if (this.openFile)
            {
                container.DTE.ItemOperations.OpenFile(targetPath);
            }
            else if (newlyAddedFile != null)
            {
                //
                // The file may have opened anyway, if we're not supposed to open it, we'll search for
                // the matching window and close it
                //
                foreach (EnvDTE.Window w in container.DTE.Windows)
                {
                    if (newlyAddedFile.Equals(w.ProjectItem))
                    {
                        w.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
                        break;
                    }
                }
            }

            return(parent.Items.FirstOrDefault(item => item.Kind == ItemKind.Item && item.Name == name));
        }
Ejemplo n.º 4
0
        public static void Checkout(this IItem item)
        {
            Guard.NotNull(() => item, item);

            VsHelper.CheckOut(item.PhysicalPath);
        }
Ejemplo n.º 5
0
 public void SelectItems(IEnumerable <IItemContainer> items)
 {
     VsHelper.Select(this.serviceProvider, items.Select(item => item.As <IHierarchyNode>()));
 }
Ejemplo n.º 6
0
 public void Select()
 {
     VsHelper.Select(this.ServiceProvider, this.HierarchyNode);
 }