public void SetObjects(uint cObjects, object[] objects) { try { if (objects != null && cObjects > 0) { IVsBrowseObject browse = objects[0] as IVsBrowseObject; if (browse != null) { IVsHierarchy hier; uint id; browse.GetProjectItem(out hier, out id); Project = hier as IVsProject; if (Project != null) { Settings = new ProjectSettigns(Package.Instance.ProjectManagerFactory.GetProjectManager(Project)); Settings.Load(); ConfigurationView.LoadSettigns(Settings); Settings.ProjectManager.ProjectChanged += (sender, args) => { if (!ConfigurationView.Dirty) { Settings.Load(); ConfigurationView.LoadSettigns(Settings); } }; } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); } }
public void SetObjects(uint cObjects, object[] objects) { try { if (objects != null && cObjects > 0) { IVsBrowseObject browse = objects[0] as IVsBrowseObject; if (browse != null) { IVsHierarchy hier; uint id; browse.GetProjectItem(out hier, out id); Project = hier as IVsProject; if (Project != null) { Settings = new ProjectSettigns(Project); Settings.Load(); ConfigurationView.LoadSettigns(Settings); ProjectSubscription = Project.OnProjectUpdate(() => { if (!ConfigurationView.Dirty) { Settings.Load(); ConfigurationView.LoadSettigns(Settings); } }); } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); } }
/// <summary> /// Use the data passed in to initialize the Properties. /// </summary> /// <param name="dataObject"> /// This is normally only one our configuration object, which means that /// there will be only one elements in configs. /// If it is null, we should release it. /// </param> public void Initialize(object[] dataObjects) { // If we are editing multiple configuration at once, we may get multiple objects. foreach (object dataObject in dataObjects) { if (dataObject is IVsBrowseObject) { // Project properties page IVsBrowseObject browseObject = dataObject as IVsBrowseObject; IVsHierarchy pHier; uint pItemid; ErrorHandler.ThrowOnFailure(browseObject.GetProjectItem(out pHier, out pItemid)); buildPropStorage = (IVsBuildPropertyStorage)pHier; break; } else if (dataObject is IVsCfgBrowseObject) { // Configuration dependent properties page if (buildPropStorage == null) { IVsCfgBrowseObject browseObject = dataObject as IVsCfgBrowseObject; IVsHierarchy pHier; uint pItemid; ErrorHandler.ThrowOnFailure(browseObject.GetProjectItem(out pHier, out pItemid)); buildPropStorage = (IVsBuildPropertyStorage)pHier; } if (configs == null) { configs = new List <string>(); } string config; ErrorHandler.ThrowOnFailure((dataObject as IVsCfg).get_DisplayName(out config)); configs.Add(config); } } string assemblyInformationalVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion; SemanticVersion semanticAssemblyInformationalVersion = SemanticVersion.Parse(assemblyInformationalVersion); SemanticVersion semanticToolVersionInProject; bool semanticToolVersionInProjectSpecified = SemanticVersion.TryParse(GetPropertyValue(NuBuildToolVersionPropertyTag), out semanticToolVersionInProject); if (!semanticToolVersionInProjectSpecified || semanticToolVersionInProject < semanticAssemblyInformationalVersion) { SetPropertyValue(NuBuildToolVersionPropertyTag, assemblyInformationalVersion); } else if (semanticToolVersionInProjectSpecified && semanticToolVersionInProject > semanticAssemblyInformationalVersion) { throw new InvalidOperationException(String.Format("The project properties are edited with a higher version NuBuild ({0}). Update the NuBuild project system from {1} to the latest version!", semanticToolVersionInProject, assemblyInformationalVersion)); } }
protected string GetResourcesNamespace() { ThreadHelper.ThrowIfNotOnUIThread(); string resourcesNamespace = null; try { IntPtr punkVsBrowseObject; Guid vsBrowseObjectGuid = typeof(IVsBrowseObject).GUID; GetSite(ref vsBrowseObjectGuid, out punkVsBrowseObject); if (punkVsBrowseObject != IntPtr.Zero) { IVsBrowseObject vsBrowseObject = Marshal.GetObjectForIUnknown(punkVsBrowseObject) as IVsBrowseObject; Debug.Assert(vsBrowseObject != null, "Generator invoked by Site that is not IVsBrowseObject?"); Marshal.Release(punkVsBrowseObject); if (vsBrowseObject != null) { IVsHierarchy vsHierarchy; uint vsitemid; vsBrowseObject.GetProjectItem(out vsHierarchy, out vsitemid); Debug.Assert(vsHierarchy != null, "GetProjectItem should have thrown or returned a valid IVsHierarchy"); Debug.Assert(vsitemid != 0, "GetProjectItem should have thrown or returned a valid VSITEMID"); if (vsHierarchy != null) { object obj; vsHierarchy.GetProperty(vsitemid, (int)__VSHPROPID.VSHPROPID_DefaultNamespace, out obj); string objStr = obj as string; if (objStr != null) { resourcesNamespace = objStr; } } } } } catch (Exception e) { Debug.WriteLine(e.ToString()); Debug.Fail("These methods should succeed..."); } return(resourcesNamespace); }
internal BrowseObjectExtender(IServiceProvider serviceProvider, IVsBrowseObject browseObject, IExtenderSite site, int cookie) { Debug.Assert(serviceProvider != null, "serviceProvider"); Debug.Assert(browseObject != null, "browseObject"); Debug.Assert(site != null, "site"); Debug.Assert(cookie != 0, "cookie"); this.site = site; this.cookie = cookie; this.serviceProvider = serviceProvider; ErrorHandler.ThrowOnFailure(browseObject.GetProjectItem(out this.hierarchy, out this.itemId)); this.propertyStorage = (IVsBuildPropertyStorage)this.hierarchy; this.CustomToolParameters = new CustomToolParameters(this.serviceProvider, this.hierarchy, this.itemId); }
public void SetObjects(UInt32 cObjects, Object[] ppunk) { _unconfiguredProject = null; if (cObjects == 0) { // If we have never configured anything (maybe a failure occurred on open so app designer is closing us). In this case // do nothing if (_threadHandling != null) { SetObjects(true); } return; } if (ppunk.Length < cObjects) { throw new ArgumentOutOfRangeException("cObjects"); } List <string> configurations = new List <string>(); // Look for an IVsBrowseObject for (int i = 0; i < cObjects; ++i) { IVsBrowseObject browseObj = null; browseObj = ppunk[i] as IVsBrowseObject; if (browseObj != null) { IVsHierarchy hier = null; uint itemid; int hr; hr = browseObj.GetProjectItem(out hier, out itemid); if (hr == VSConstants.S_OK && itemid == VSConstants.VSITEMID_ROOT) { _unconfiguredProject = GetUnconfiguredProject(hier); // We need to save ThreadHandling because the appdesigner will call SetObjects with null, and then call // Deactivate(). We need to run Async code during Deactivate() which requires ThreadHandling. IUnconfiguredProjectVsServices projectVsServices = _unconfiguredProject.Services.ExportProvider.GetExportedValue <IUnconfiguredProjectVsServices>(); _threadHandling = projectVsServices.ThreadingService; } } } OnSetObjects(false); }
// The ResxCodeSingleFileGenerator expects to find the IVsBrowseObject interface on this // object. The NodePropeties object implements IVsBrowseObject, but we have no way to get // the NodeProperties object since we don't have a back reference to the hierarchy node that // owns this OleServiceProvider instance. So when a FileNode object is created, IVsBrowseObject is added // to the list of available services (in Project.CreateFileNode) and in the service // creator callback in Project, querying for the IVsBrowseObject service (which isn't really // a service) returns a reference to the NodeProperties object for the node. // // When this object is QI'd for IVsBrowseObject by the ResXCodeFileGenerator it is successful // and then it calls GetProjectItem(). We then get the real IVsBrowseObject implementation // and call GetProjectItem() on it. It's a bit of a hack, but it gets the ResXSingleFileGenerator // to work, and the only other alternative seems to be adding a property to this class that we // could store a reference to the owning node's NodeProperties object in. // // If this is ever fixed by the 2008 MPF code, this hack can be removed and replaced with // whatever they come up with. /// <summary> /// Maps back to the hierarchy or project item object corresponding to the browse object. /// </summary> /// <param name="hier">Reference to the hierarchy object.</param> /// <param name="itemid">Reference to the project item.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns> public virtual int GetProjectItem(out IVsHierarchy hier, out uint itemid) { ServiceData serviceInstance = services[typeof(IVsBrowseObject).GUID]; if (serviceInstance != null) { IVsBrowseObject bo = (IVsBrowseObject)serviceInstance.ServiceInstance; return(bo.GetProjectItem(out hier, out itemid)); } else { hier = null; itemid = 0; return(VSConstants.E_NOINTERFACE); } }
protected string GetResourcesNamespace() { string resourcesNamespace = null; try { IntPtr siteInterfacePointer; Guid vsBrowseObjectGuid = typeof(IVsBrowseObject).GUID; GetSite(ref vsBrowseObjectGuid, out siteInterfacePointer); if (IntPtr.Zero != siteInterfacePointer) { IVsHierarchy vsHierarchy; uint pItemId; object propertyValue; IVsBrowseObject vsBrowseObject = Marshal.GetObjectForIUnknown(siteInterfacePointer) as IVsBrowseObject; Marshal.Release(siteInterfacePointer); if (null == vsBrowseObject) { return(resourcesNamespace); } vsBrowseObject.GetProjectItem(out vsHierarchy, out pItemId); if (null == vsHierarchy) { return(resourcesNamespace); } vsHierarchy.GetProperty(pItemId, -2049, out propertyValue); string propertyText = propertyValue as string; if (null == propertyText) { return(resourcesNamespace); } resourcesNamespace = propertyText; } } catch (Exception ex) { if (Tools.ProjectUtilities.IsCriticalException(ex)) { throw; } } return(resourcesNamespace); }
private uint GetItemId(IVsHierarchy hierarchy) { object extObject; uint itemId = 0; IVsHierarchy tempHierarchy; hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_BrowseObject, out extObject); IVsBrowseObject browseObject = extObject as IVsBrowseObject; if (browseObject != null) { browseObject.GetProjectItem(out tempHierarchy, out itemId); } return(itemId); }
protected object CreateExtender(string ExtenderCATID, string ExtenderName, object ExtendeeObject, IExtenderSite ExtenderSite, int Cookie) { object extender = null; ExtendVersion extendVersion = GetExtendVersion(ExtenderCATID, ExtenderName, ExtendeeObject); if (extendVersion != ExtendVersion.None) { IVsBrowseObject browseObject = ExtendeeObject as IVsBrowseObject; if (browseObject == null) { return(null); } IVsHierarchy hierarchy; uint itemId; if (ErrorHandler.Failed(browseObject.GetProjectItem(out hierarchy, out itemId))) { return(null); } IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage == null) { return(null); } if (extendVersion == ExtendVersion.Antlr3) { extender = new GrammarFileObjectExtenderProperties(buildPropertyStorage, itemId); } else { extender = new GrammarFileObjectExtenderPropertiesV4(buildPropertyStorage, itemId); } } return(extender); }
public void SetObjects(uint cObjects, Object[] objects) { try { if (objects != null && cObjects > 0) { IVsBrowseObject browse = objects[0] as IVsBrowseObject; if (browse != null) { IVsHierarchy hier; uint id; browse.GetProjectItem(out hier, out id); Project = hier as IVsProject; if (Project != null) { Settings = new ProjectSettigns(Project); Settings.Load(); ConfigurationView.OutputDir = Settings.OutputDir; ConfigurationView.Ice = Settings.AllowIcePrefix ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.Checksum = Settings.Checksum ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.Streaming = Settings.Stream ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.Tie = Settings.Tie ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.Underscores = Settings.Underscore ? CheckState.Checked : CheckState.Unchecked; ConfigurationView.IncludeDirectories.Values = new List <String>( Settings.IncludeDirectories.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); ConfigurationView.AdditionalOptions = Settings.AdditionalOptions; ConfigurationView.LoadReferencedAssemblies(); ConfigurationView.Dirty = false; } } } } catch (Exception ex) { Package.UnexpectedExceptionWarning(ex); throw; } }
private void SetBuildStorage() { // Get the build storage associated with this property page. buildStorage = null; if (configs != null) { foreach (object config in configs) { if (config != null) { // try to retrieve the project using IVs(Cfg)BrowseObject IVsHierarchy project = null; IVsBrowseObject browse = config as IVsBrowseObject; if (browse != null) { uint itemid; browse.GetProjectItem(out project, out itemid); } else { IVsCfgBrowseObject cfgBrowse = config as IVsCfgBrowseObject; if (cfgBrowse != null) { uint itemid; cfgBrowse.GetProjectItem(out project, out itemid); } } // try to cast the project to a buildstorage buildStorage = project as IVsBuildPropertyStorage; if (buildStorage != null) { return; // we are done. } } } } }
public object GetExtender(string ExtenderCATID, string ExtenderName, object ExtendeeObject, IExtenderSite ExtenderSite, int Cookie) { ProjectReferenceExtender extender = null; if (CanExtend(ExtenderCATID, ExtenderName, ExtendeeObject)) { IVsBrowseObject browseObject = ExtendeeObject as IVsBrowseObject; if (browseObject != null) { IVsHierarchy hierarchyItem = null; uint itemId = VSConstants.VSITEMID_NIL; //get the hierarchy item (the item id will be wrong if the reference is not shown) browseObject.GetProjectItem(out hierarchyItem, out itemId); extender = new ProjectReferenceExtender(hierarchyItem, itemId, ExtenderSite, Cookie); } } return(extender); }
/// <summary>Gets name of resources class from resource logical name</summary> /// <param name="className">Original name of class. When this method exists this parameter is set to class name parsed from file logical name. The parameter is unchanged when logical name is not set.</param> private void GetClassNameFromLogicalName(ref string className) { try { IntPtr siteInterfacePointer; Guid vsBrowseObjectGuid = typeof(IVsBrowseObject).GUID; GetSite(ref vsBrowseObjectGuid, out siteInterfacePointer); if (IntPtr.Zero != siteInterfacePointer) { IVsHierarchy vsHierarchy; uint pItemId; IVsBrowseObject vsBrowseObject = Marshal.GetObjectForIUnknown(siteInterfacePointer) as IVsBrowseObject; vsBrowseObject.GetProjectItem(out vsHierarchy, out pItemId); IVsBuildPropertyStorage buildPropertyStorage = vsHierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage != null) { string LogicalName = null; try { buildPropertyStorage.GetItemAttribute(pItemId, "LogicalName", out LogicalName); } catch { } if (LogicalName != null) { if (LogicalName.EndsWith(".resources")) { LogicalName = LogicalName.Substring(0, LogicalName.Length - ".resources".Length); } if (LogicalName.Contains(".")) { LogicalName = LogicalName.Substring(LogicalName.LastIndexOf('.') + 1); } className = LogicalName; } } } }catch {} }
public void SetObjects(uint cObjects, object[] ppunk) { // If asked to, release our cached selected Project object(s) UnconfiguredProject = null; ConfiguredProperties = null; if (cObjects == 0) { // If we have never configured anything (maybe a failure occurred // on open so app designer is closing us). In this case do nothing. if (ThreadHandling != null) { SetObjects(true); } return; } if (ppunk.Length < cObjects) { throw new ArgumentOutOfRangeException(nameof(cObjects)); } List <ProjectProperties> configuredProjectsProperties = new List <ProjectProperties>(); // Look for an IVsBrowseObject for (int i = 0; i < cObjects; ++i) { IVsBrowseObject browseObj = null; browseObj = ppunk[i] as IVsBrowseObject; if (browseObj != null) { IVsHierarchy hier = null; uint itemid; int hr; hr = browseObj.GetProjectItem(out hier, out itemid); Debug.Assert(itemid == VSConstants.VSITEMID_ROOT, "Selected object should be project root node"); if (hr == VSConstants.S_OK && itemid == VSConstants.VSITEMID_ROOT) { UnconfiguredProject = hier.GetUnconfiguredProject(); // We need to save ThreadHandling because the appdesigner will call SetObjects with null, and then call // Deactivate(). We need to run Async code during Deactivate() which requires ThreadHandling. ThreadHandling = UnconfiguredProject.Services.ExportProvider.GetExportedValue <IThreadHandling>(); IVsProjectCfg2 pcg = ppunk[i] as IVsProjectCfg2; if (pcg != null) { string vsConfigName; pcg.get_CanonicalName(out vsConfigName); ThreadHandling.ExecuteSynchronously(async delegate { var provider = new ConfiguredRProjectExportProvider(); var configuredProjProps = await provider.GetExportAsync <ProjectProperties>(UnconfiguredProject, vsConfigName); configuredProjectsProperties.Add(configuredProjProps); }); } } } ConfiguredProperties = configuredProjectsProperties.ToArray(); } SetObjects(false); }
/// <summary>Gets namespace of resource</summary> /// <param name="forLogicalName">Use logical name; ignored when <see cref="ResourceNamespace"/> is not null</param> /// <returns>Resource namespace</returns> protected string GetResourcesNamespace(bool forLogicalName)//forLogicalName added by Ðonny { if (this.ResourceNamespace != null) { return(ResourceNamespace); } string resourcesNamespace = null; try { IntPtr siteInterfacePointer; Guid vsBrowseObjectGuid = typeof(IVsBrowseObject).GUID; GetSite(ref vsBrowseObjectGuid, out siteInterfacePointer); if (IntPtr.Zero != siteInterfacePointer) { IVsHierarchy vsHierarchy; uint pItemId; object propertyValue; IVsBrowseObject vsBrowseObject = Marshal.GetObjectForIUnknown(siteInterfacePointer) as IVsBrowseObject; vsBrowseObject.GetProjectItem(out vsHierarchy, out pItemId); //Added by Ðonny: //Support for <LogicalName> if (forLogicalName) { IVsBuildPropertyStorage buildPropertyStorage = vsHierarchy as IVsBuildPropertyStorage; if (buildPropertyStorage != null) { string LogicalName = null; try { buildPropertyStorage.GetItemAttribute(pItemId, "LogicalName", out LogicalName); } catch { } if (LogicalName != null) { if (LogicalName.EndsWith(".resources")) { return(LogicalName.Substring(0, LogicalName.Length - ".resources".Length)); } else { return(LogicalName); } } } } Marshal.Release(siteInterfacePointer); if (null == vsBrowseObject) { return(resourcesNamespace); } if (null == vsHierarchy) { return(resourcesNamespace); } vsHierarchy.GetProperty(pItemId, -2049, out propertyValue); string propertyText = propertyValue as string; if (null == propertyText) { return(resourcesNamespace); } resourcesNamespace = propertyText; } } catch (Exception ex) { if (ProjectUtilities.IsCriticalException(ex)) { throw; } } return(resourcesNamespace); }