diff options
author | Lluis Sanchez <lluis@xamarin.com> | 2014-04-01 18:53:21 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@xamarin.com> | 2014-04-01 18:53:21 +0400 |
commit | f04c7ecd6ccc0dc4acc608ade31cc4fa11cf9957 (patch) | |
tree | 6b9ffa9d7ac33c362939dbf28cbb43608fd7e8a2 /main/src/core/MonoDevelop.Core | |
parent | c813fb186c8180dc42a17056cdc7cb16be36b790 (diff) |
[Core] Shared assets project fixes
Syncronize referencing projects when files are added/removed/modified.
Set the project id when creating a shared project
Diffstat (limited to 'main/src/core/MonoDevelop.Core')
2 files changed, 85 insertions, 1 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProject.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProject.cs index 84bf75af5b..5aee9633b7 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProject.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProject.cs @@ -36,6 +36,8 @@ namespace MonoDevelop.Projects.SharedAssetsProjects public class SharedAssetsProject: Project { Solution currentSolution; + IDotNetLanguageBinding languageBinding; + string languageName; public SharedAssetsProject () { @@ -43,6 +45,12 @@ namespace MonoDevelop.Projects.SharedAssetsProjects public SharedAssetsProject (ProjectCreateInformation projectCreateInfo, XmlElement projectOptions) { + languageName = projectOptions.GetAttribute ("language"); + } + + public string LanguageName { + get { return languageName; } + set { languageName = value; } } public string DefaultNamespace { get; set; } @@ -55,10 +63,23 @@ namespace MonoDevelop.Projects.SharedAssetsProjects public override string[] SupportedLanguages { get { - return new [] {"C#"}; + return new [] {languageName}; } } + public IDotNetLanguageBinding LanguageBinding { + get { + if (languageBinding == null) + languageBinding = LanguageBindingService.GetBindingPerLanguageName (languageName) as IDotNetLanguageBinding; + return languageBinding; + } + } + + public override bool IsCompileable (string fileName) + { + return LanguageBinding.IsSourceCodeFile (fileName); + } + protected override BuildResult OnBuild (MonoDevelop.Core.IProgressMonitor monitor, ConfigurationSelector configuration) { return new BuildResult (); @@ -115,6 +136,62 @@ namespace MonoDevelop.Projects.SharedAssetsProjects } } } + + protected override void OnFilePropertyChangedInProject (ProjectFileEventArgs e) + { + base.OnFilePropertyChangedInProject (e); + foreach (var p in GetReferencingProjects ()) { + foreach (var f in e) { + var pf = (ProjectFile) f.ProjectFile.Clone (); + pf.Flags |= ProjectItemFlags.DontPersist | ProjectItemFlags.Hidden; + p.Files.Remove (pf.FilePath); + p.Files.Add (pf); + } + } + } + + protected override void OnFileAddedToProject (ProjectFileEventArgs e) + { + base.OnFileAddedToProject (e); + foreach (var p in GetReferencingProjects ()) { + foreach (var f in e) { + var pf = (ProjectFile) f.ProjectFile.Clone (); + pf.Flags |= ProjectItemFlags.DontPersist | ProjectItemFlags.Hidden; + p.Files.Add (pf); + } + } + } + + protected override void OnFileRemovedFromProject (ProjectFileEventArgs e) + { + base.OnFileRemovedFromProject (e); + foreach (var p in GetReferencingProjects ()) { + foreach (var f in e) { + p.Files.Remove (f.ProjectFile.FilePath); + } + } + } + + protected override void OnFileRenamedInProject (ProjectFileRenamedEventArgs e) + { + base.OnFileRenamedInProject (e); + foreach (var p in GetReferencingProjects ()) { + foreach (var f in e) { + var pf = (ProjectFile) f.ProjectFile.Clone (); + p.Files.Remove (f.OldName); + pf.Flags |= ProjectItemFlags.DontPersist | ProjectItemFlags.Hidden; + p.Files.Add (pf); + } + } + } + + IEnumerable<DotNetProject> GetReferencingProjects () + { + if (ParentSolution == null) + return new DotNetProject[0]; + + return ParentSolution.GetAllSolutionItems<DotNetProject> ().Where (p => p.References.Any (r => r.GetItemsProjectPath () != null)); + } } internal static class SharedAssetsProjectExtensions diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildHandler.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildHandler.cs index cd8097027e..d38acac226 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildHandler.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildHandler.cs @@ -55,6 +55,9 @@ namespace MonoDevelop.Projects.SharedAssetsProjects if (projitemsFile == null) return; + // TODO: load the type from msbuild + ((SharedAssetsProject)EntityItem).LanguageName = "C#"; + projitemsFile = Path.Combine (Path.GetDirectoryName (msproject.FileName), projitemsFile); MSBuildProject p = new MSBuildProject (); @@ -84,6 +87,10 @@ namespace MonoDevelop.Projects.SharedAssetsProjects var newProject = EntityItem.FileName == null || !File.Exists (EntityItem.FileName); if (newProject) { + var grp = msproject.GetGlobalPropertyGroup (); + if (grp == null) + grp = msproject.AddNewPropertyGroup (false); + grp.SetPropertyValue ("ProjectGuid", EntityItem.ItemId, false); var import = msproject.AddNewImport (@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"); import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"; msproject.AddNewImport (@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props"); |