/// <summary> /// Initializes a new instance of the <see cref="XSharpFileNode"/> class. /// </summary> /// <param name="root">The root <see cref="XSharpProjectNode"/> that contains this node.</param> /// <param name="element">The element that contains MSBuild properties.</param> /// <param name="isNonMemberItem">Flag that indicates if the file is not part of the project.</param> public XSharpFileNode(XSharpProjectNode root, ProjectElement element, bool isNonMemberItem) : base(root, element, isNonMemberItem) { this.UpdateHasDesigner(); this.CheckItemType(); root.AddURL(this.Url, this); }
// /// <summary> /// We come here : After a Project load (xFile == NULL), or after a File Save (xFile == the Saved file) /// </summary> private void OnFileWalkComplete(XFile xfile) { if (xfile == null) { return; } // Retrieve the corresponding node if (!xfile.HasCode || XSolution.IsClosing) { return; } // if (xfile.Virtual) { return; } XSharpProjectNode prjNode = (XSharpProjectNode)xfile.Project.ProjectNode; Microsoft.VisualStudio.Project.HierarchyNode node = prjNode.FindURL(xfile.FullPath); if (node != null) { XSharpModuleId module = new XSharpModuleId(prjNode.InteropSafeHierarchy, node.ID); module.ContentHashCode = xfile.ContentHashCode; CreateUpdateTreeRequest(xfile.SourcePath, module); } }
public override void Initialize() { base.Initialize(); generalPropertyPage = new XSharpGeneralPropertyPage(); customProjectPackage = new XSharpProjectPackage(); ((IVsPackage)customProjectPackage).SetSite(serviceProvider); customProjectFactory = new XSharpProjectFactory(customProjectPackage); base.SetMsbuildEngine(customProjectFactory); int canCreate; if (VSConstants.S_OK == ((IVsProjectFactory)customProjectFactory).CanCreateProject(projectFile, 2, out canCreate)) { PrivateType type = new PrivateType(typeof(XSharpProjectFactory)); PrivateObject obj = new PrivateObject(customProjectFactory, type); projectNode = (XSharpProjectNode)obj.Invoke("PreCreateForOuter", new object[] { IntPtr.Zero }); Guid iidProject = new Guid(); int pfCanceled; projectNode.Load(projectFile, "", "", 2, ref iidProject, out pfCanceled); } }
/// <summary> /// Creates a new project by cloning an existing template project. /// </summary> /// <returns></returns> protected override ProjectNode CreateProject() { XSharpProjectNode project = new XSharpProjectNode(this.package); project.SetSite((IOleServiceProvider)((IServiceProvider)this.package).GetService(typeof(IOleServiceProvider))); return(project); }
public static bool RemoveProject(XSharpProjectNode project) { if (!_projects.ContainsKey(project.ProjectIDGuid)) { return(false); } return(_projects.Remove(project.ProjectIDGuid)); }
public XSharpProjectReferenceNode(ProjectNode root, string referencedProjectName, string projectPath, string projectReference) : base(root, referencedProjectName, projectPath, projectReference) { XSharpProjectNode project = root as XSharpProjectNode; if (project != null) { project.AddURL(this.Url, this); } }
public XSharpProjectReferenceNode(ProjectNode root, ProjectElement element) : base(root, element) { XSharpProjectNode project = root as XSharpProjectNode; if (project != null) { project.AddURL(this.Url, this); } }
public XSharpPackageReferenceContainerNode(XSharpProjectNode parent) : base(parent) { base.Parent = parent; _vsPackageReferences = null; _vsPackageReferences = new OAVSPackageReferences(this); PackageReferenceNodes = new List <XSharpPackageReferenceNode>(); XSharpProjectNode = parent; base.VirtualNodeName = PackageReferencesNodeVirtualName; }
public XSharpPackageReferenceNode(ProjectNode projectManager, ProjectElement element) : base(projectManager, element) { XSharpProjectNode XSharpProject = projectManager as XSharpProjectNode; if (XSharpProject != null) { base.Parent = XSharpProject.PackageReferenceContainerNode; } }
internal static ErrorListManager RegisterProject(XSharpProjectNode project) { if (!_projects.ContainsKey(project.ProjectIDGuid)) { var manager = new ErrorListManager(project); manager.Factory = new ErrorsFactory(_provider, project.ProjectIDGuid); _provider.AddListFactory(manager.Factory); _projects.Add(project.ProjectIDGuid, manager); } return(_projects[project.ProjectIDGuid]); }
/// <summary> /// Creates a new project by cloning an existing template project. /// </summary> /// <returns></returns> protected override ProjectNode CreateProject() { XSharpProjectNode project = new XSharpProjectNode(this.package); IOleServiceProvider provider = null; var serviceProvider = this.package as IServiceProvider; // ProjectPackage already switches to UI thread inside GetService provider = (IOleServiceProvider)serviceProvider.GetService(typeof(IOleServiceProvider)); project.SetSite(provider); return(project); }
protected override void Dispose(bool disposing) { if (this.ProjectMgr is XSharpProjectNode) { XSharpProjectNode projectNode = (XSharpProjectNode)this.ProjectMgr; if (projectNode != null) { projectNode.RemoveURL(this); } } base.Dispose(disposing); }
public static bool RemoveProject(XSharpProjectNode project) { if (!_projects.ContainsKey(project.ProjectIDGuid)) { return(false); } var entry = _projects[project.ProjectIDGuid]; _provider.RemoveListFactory(entry.Factory); return(_projects.Remove(project.ProjectIDGuid)); }
internal void DetermineSubType() { // Parse the contents of the file and see if we have a windows form or a windows control XSharpProjectNode projectNode = ProjectMgr as XSharpProjectNode; XSharpModel.XFile xfile = projectNode.ProjectModel.FindFullPath(this.Url); if (xfile != null) { xfile.WaitParsing(); } // (something that inherits from system.windows.forms.form or system.windows.forms.usercontrol // We should do this with proper parsing. For now we simply test the first word after the INHERIT keyword // and then parse and bind to see if we can find the first type in the file. if (this.FileType == XFileType.SourceCode && this.Url.IndexOf(".designer.", StringComparison.OrdinalIgnoreCase) == -1) { string SubType = ""; string token = "INHERIT"; string source = System.IO.File.ReadAllText(this.Url); int pos = source.IndexOf(token, StringComparison.OrdinalIgnoreCase); if (pos > 0) { source = source.Substring(pos + token.Length); var words = source.Split(";\t \r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (words.Length > 0) { var parentclass = words[0].ToLower(); switch (parentclass) { case "form": case "system.windows.forms.form": SubType = ProjectFileAttributeValue.Form; break; case "usercontrol": case "system.windows.forms.usercontrol": SubType = ProjectFileAttributeValue.UserControl; break; } if (SubType != null && this.ItemNode.GetMetadata(ProjectFileConstants.SubType) != SubType) { this.ItemNode.SetMetadata(ProjectFileConstants.SubType, SubType); this.ItemNode.RefreshProperties(); this.UpdateHasDesigner(); this.ReDraw(UIHierarchyElement.Icon); } } } } return; }
/// <summary> /// Called when a project is loaded /// </summary> /// <param name="hierarchy"></param> public void RegisterHierarchy(IVsHierarchy hierarchy, XProject Prj, XSharpProjectNode ProjectNode) { // No Hierarchy or... Hierarchy already registered ? var optionsPage = XSharpProjectPackage.Instance.GetIntellisenseOptionsPage(); // disable classview for now if (optionsPage.DisableClassViewObjectView)// || true) { return; } if ((null == hierarchy) || hierarchies.ContainsKey(hierarchy)) { return; } // if (0 == objectManagerCookie) { IVsObjectManager2 objManager = provider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2; if (null == objManager) { return; } Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure( objManager.RegisterSimpleLibrary(library, out objectManagerCookie)); } // The project is the Root of the Library XSharpLibraryProject prjNode = new XSharpLibraryProject(Prj, hierarchy); library.AddNode(prjNode); //this._defaultNameSpace = prjNode.DefaultNameSpace; //Define Callback ProjectNode.ProjectModel.FileWalkComplete = new XProject.OnFileWalkComplete(OnFileWalkComplete); ProjectNode.ProjectModel.ProjectWalkComplete = new XProject.OnProjectWalkComplete(OnProjectWalkComplete); // Attach a listener to the Project/Hierarchy,so any change is raising an event HierarchyListener listener = new HierarchyListener(hierarchy); //listener.OnAddItem += new EventHandler<HierarchyEventArgs>(OnNewFile); listener.OnDeleteItem += new EventHandler <HierarchyEventArgs>(OnDeleteFile); listener.StartListening(); hierarchies.Add(hierarchy, listener); // and ask for any change in the files that are opened in Source editor. RegisterForRDTEvents(); }
protected override bool RenameDocument(string oldName, string newName, out HierarchyNode newNodeOut) { var result = base.RenameDocument(oldName, newName, out newNodeOut); if (result) { XSharpProjectNode project = ProjectMgr as XSharpProjectNode; if (project != null) { project.ProjectModel.RemoveFile(oldName); project.ProjectModel.AddFile(newName); project.ProjectModel.Walk(); } _fileType = XFileTypeHelpers.GetFileType(newName); } return(result); }
public override int SetEditLabel(string label) { int iResult; String sOldUrl = this.Url; iResult = base.SetEditLabel(label); if (iResult == VSConstants.S_OK && String.Compare(this.Url, sOldUrl, true) != 0) { XSharpProjectNode project = this.ProjectMgr as XSharpProjectNode; if (project != null) { project.RemoveURL(sOldUrl); project.AddURL(this.Url, this); } } return(iResult); }
public void CreateProjectTest() { int actual; int expected = 1; XSharpProjectFactory customProjectFactory = new XSharpProjectFactory(customProjectPackage); base.SetMsbuildEngine(customProjectFactory); ((IVsProjectFactory)customProjectFactory).CanCreateProject(projectFile, 2, out actual); Assert.AreEqual(expected, actual, "Cannot create project"); PrivateType type = new PrivateType(typeof(XSharpProjectFactory)); PrivateObject obj = new PrivateObject(customProjectFactory, type); XSharpProjectNode projectNode = (XSharpProjectNode)obj.Invoke("PreCreateForOuter", new object[] { IntPtr.Zero }); Assert.IsNotNull(projectNode, "Cannot create project"); }
internal virtual void LoadReferencesFromBuildProject(XSharpProjectNode buildProject) { foreach (var item in base.ProjectMgr.BuildProject.GetItems(ProjectFileConstants.PackageReference)) { var element = new ProjectElement(base.ProjectMgr, item, false); var referenceNode = new XSharpPackageReferenceNode(ProjectMgr, element); bool found = false; HierarchyNode i = base.FirstChild; while (i != null && !found) { if (string.Compare(i.Caption, referenceNode.Caption, StringComparison.OrdinalIgnoreCase) == 0) { found = true; } i = i.NextSibling; } if (!found) { AddChild(referenceNode); PackageReferenceNodes.Add(referenceNode); } } }
public XSharpFolderNode(XSharpProjectNode root, string directoryPath, ProjectElement element, bool isNonMemberItem) : base(root, directoryPath, element, isNonMemberItem) { root.AddURL(this.Url, this); }
public void ConstructorTest() { XSharpProjectNode customProject = new XSharpProjectNode(customProjectPackage); Assert.IsNotNull(customProject, "Constructor failed"); }
/// <summary> /// Initializes a new instance of the <see cref="XSharpFileNode"/> class. /// </summary> /// <param name="root">The project node.</param> /// <param name="e">The project element node.</param> internal XSharpFileNode(XSharpProjectNode root, ProjectElement element) : this(root, element, false) { }
internal String GetParentName() { // There needs to be a better way to handle this // CS uses a table with // Parent extension, Allowed child extensions // look at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Projects\{FAE04EC0-301F-11d3-BF4B-00C04F79EFBC}\RelatedFiles // .xaml .xaml.cs // .cs .designer.cs, .resx // .xsd .cs, .xsc, .xss, .xsx // .resx files (like Resources.resx) seem to be handled differently.. // we can hard code a similar table or read it from the registry like C# does. // CS also defines a 'relationtype'. See the CS Project System source code. String path = Path.GetFileName(this.Url).ToLowerInvariant(); String folder = Path.GetDirectoryName(this.Url) + "\\"; XSharpProjectNode project = this.ProjectMgr as XSharpProjectNode; int relationIndex = path.IndexOf("."); switch (this.FileType) { case XFileType.Header: case XFileType.ManagedResource: path = Path.ChangeExtension(path, ".prg"); if (project.FindURL(folder + path) == null) { path = null; } break; case XFileType.VODBServer: case XFileType.VOFieldSpec: case XFileType.VOForm: case XFileType.VOIndex: case XFileType.VOMenu: case XFileType.VOOrder: case XFileType.NativeResource: if (relationIndex >= 0) { path = path.Substring(0, relationIndex) + ".prg"; if (project.FindURL(folder + path) == null) { path = null; } } else { path = null; } break; default: if (path.EndsWith(".designer.prg")) { // could be Form.Prg // Resources.resx // Settings.Settings path = path.Substring(0, relationIndex); string parent = folder + path + ".prg"; if (project.FindURL(parent) != null) { return(parent); } parent = folder + path + ".resx"; if (project.FindURL(parent) != null) { return(parent); } parent = folder + path + ".settings"; if (project.FindURL(parent) != null) { return(parent); } return(""); } else if (path.EndsWith(".xaml.prg")) { path = path.Substring(0, relationIndex) + ".xaml"; if (project.FindURL(folder + path) == null) { path = null; } } else { path = string.Empty; } break; } if (!String.IsNullOrEmpty(path)) { String dir = Path.GetDirectoryName(this.Url); if (dir.EndsWith("\\resources")) { dir = dir.Substring(0, dir.Length - "\\resources".Length); } path = dir + "\\" + path; } return(path); }
internal void DetermineSubType() { // Parse the contents of the file and see if we have a windows form or a windows control XSharpProjectNode projectNode = ProjectMgr as XSharpProjectNode; XSharpModel.XFile xfile = projectNode.ProjectModel.FindFullPath(this.Url); if (xfile == null) { projectNode.ProjectModel.AddFile(this.Url); xfile = projectNode.ProjectModel.FindFullPath(this.Url); } if (xfile != null) { xfile.WaitParsing(); } // (something that inherits from system.windows.forms.form or system.windows.forms.usercontrol // We should do this with proper parsing. For now we simply test the first word after the INHERIT keyword // and then parse and bind to see if we can find the first type in the file. if (this.FileType == XFileType.SourceCode && this.Url.IndexOf(".designer.", StringComparison.OrdinalIgnoreCase) == -1) { string SubType = ""; string token = "INHERIT"; string source = System.IO.File.ReadAllText(this.Url); int pos = source.IndexOf(token, StringComparison.OrdinalIgnoreCase); if (pos > 0) { source = source.Substring(pos + token.Length); var words = source.Split(";\t \r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (words.Length > 0) { var parentclass = words[0].ToLower(); SubType = typeNameToSubtype(parentclass); if (string.IsNullOrEmpty(SubType)) { var usings = new List <string>(); if (xfile != null) { usings.AddRange(xfile.Usings); } var mgr = this.ProjectMgr as XSharpProjectNode; var type = mgr.ResolveType(parentclass, usings); if (type != null) { while (type.BaseType != null) { var bt = type.BaseType; SubType = typeNameToSubtype(bt.Name); if (!String.IsNullOrEmpty(SubType)) { break; } type = bt; } } else { var xtype = mgr.ResolveXType(parentclass, usings); if (xtype != null) { while (xtype != null && !String.IsNullOrEmpty(xtype.ParentName)) { var parent = xtype.ParentName; SubType = typeNameToSubtype(parent); if (!String.IsNullOrEmpty(SubType)) { break; } xtype = mgr.ResolveXType(parent, usings); } } } } if (SubType != null && this.ItemNode.GetMetadata(ProjectFileConstants.SubType) != SubType) { this.ItemNode.SetMetadata(ProjectFileConstants.SubType, SubType); this.ItemNode.RefreshProperties(); this.UpdateHasDesigner(); this.ReDraw(UIHierarchyElement.Icon); } } } } return; }
/// <summary> /// Constructor for the XSharpDependentFileNode /// </summary> /// <param name="root">Root of the hierarchy</param> /// <param name="e">Associated project element</param> public XSharpDependentFileNode(XSharpProjectNode root, ProjectElement e, bool isNonMemberItem) : base(root, e, isNonMemberItem) { HasParentNodeNameRelation = false; IsDependent = true; }
/// <summary> /// Constructor for the XSharpDependentFileNode /// </summary> /// <param name="root">Root of the hierarchy</param> /// <param name="e">Associated project element</param> public XSharpDependentFileNode(XSharpProjectNode root, ProjectElement e) : base(root, e, false) { }
// ========================================================================================= // Constructors // ========================================================================================= /// <summary> /// Initializes a new instance of the <see cref="XSharpFolderNode"/> class. /// </summary> /// <param name="root">The root <see cref="XSharpProjectNode"/> that contains this node.</param> /// <param name="directoryPath">Root of the hierarchy.</param> /// <param name="element">The element that contains MSBuild properties.</param> public XSharpFolderNode(XSharpProjectNode root, string directoryPath, ProjectElement element) : this(root, directoryPath, element, false) { }
internal ErrorListManager(XSharpProjectNode node) { Project = node; BuildErrors = new List <IErrorListItem>(); IntellisenseErrors = new List <IErrorListItem>(); }
public XSharpProjectOptions(XSharpProjectNode prjNode) : base() { _prjNode = prjNode; }
public XSharpPropertiesFolderNode(XSharpProjectNode root, string directoryPath, ProjectElement element) : base(root, directoryPath, element, false) { }