diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2019-07-08 13:18:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-08 13:18:34 +0300 |
commit | 0a82be81f60207c92140245357170e99b7173376 (patch) | |
tree | 2fe75049e9b7c42aa40d6016f0d441b9f00ae674 /main/src/core/MonoDevelop.Core | |
parent | 659a3c6e322a3525c662fb7dbd9815d0e22c2376 (diff) | |
parent | d1ccadd5e955beffd2553220688391d01222e593 (diff) |
Merge pull request #8063 from mono/vsts936533
Avoid doing expensive work to trigger OnPathChanged when it might not be subscribed to
Diffstat (limited to 'main/src/core/MonoDevelop.Core')
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs index 416c0a84af..a7e15115d1 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectFile.cs @@ -173,8 +173,8 @@ namespace MonoDevelop.Projects set { Debug.Assert (!String.IsNullOrEmpty (value)); - FilePath oldVirtualPath = ProjectVirtualPath; FilePath oldPath = filename; + FilePath oldLink = Link; filename = FileService.GetFullPath (value); @@ -194,10 +194,9 @@ namespace MonoDevelop.Projects if (Project != null) UnevaluatedInclude = Include; - OnPathChanged (oldPath, filename, oldVirtualPath, ProjectVirtualPath); + OnPathChanged (oldPath, oldLink); - if (Project != null) - Project.NotifyFileRenamedInProject (new ProjectFileRenamedEventArgs (Project, this, oldPath)); + Project?.NotifyFileRenamedInProject (new ProjectFileRenamedEventArgs (Project, this, oldPath)); } } @@ -216,8 +215,8 @@ namespace MonoDevelop.Projects /// </summary> internal string GetResourceId (ResourceNamePolicy policy) { - if (string.IsNullOrEmpty (resourceId) && (Project is DotNetProject)) - return ((DotNetProject)Project).GetDefaultResourceIdForPolicy (this, policy); + if (string.IsNullOrEmpty (resourceId) && (Project is DotNetProject dnp)) + return dnp.GetDefaultResourceIdForPolicy (this, policy); return resourceId; } @@ -234,17 +233,18 @@ namespace MonoDevelop.Projects /// The file should be treated as effectively having this relative path within the project. If the file is /// a link or outside the project root, this will not be the same as the physical file. /// </summary> - public FilePath ProjectVirtualPath { - get { - if (!Link.IsNullOrEmpty) - return Link; - if (Project != null) { - var rel = Project.GetRelativeChildPath (FilePath); - if (!rel.ToString ().StartsWith ("..", StringComparison.Ordinal)) - return rel; - } - return FilePath.FileName; + public FilePath ProjectVirtualPath => GetProjectVirtualPath (Link, FilePath, Project); + + static FilePath GetProjectVirtualPath (FilePath link, FilePath filePath, Project project) + { + if (!link.IsNullOrEmpty) + return link; + if (project != null) { + var rel = project.GetRelativeChildPath (filePath); + if (!rel.ToString ().StartsWith ("..", StringComparison.Ordinal)) + return rel; } + return filePath.FileName; } @@ -470,8 +470,8 @@ namespace MonoDevelop.Projects public string ResourceId { get { // If the resource id is not set, return the project's default - if (BuildAction == MonoDevelop.Projects.BuildAction.EmbeddedResource && string.IsNullOrEmpty (resourceId) && Project is DotNetProject) - return ((DotNetProject)Project).GetDefaultResourceId (this); + if (BuildAction == MonoDevelop.Projects.BuildAction.EmbeddedResource && string.IsNullOrEmpty (resourceId) && Project is DotNetProject dnp) + return dnp.GetDefaultResourceId (this); return resourceId; } @@ -512,7 +512,9 @@ namespace MonoDevelop.Projects return pf; } - public virtual void Dispose () + public void Dispose () => OnDispose (); + + protected virtual void OnDispose () { } @@ -520,18 +522,20 @@ namespace MonoDevelop.Projects internal event EventHandler<ProjectFilePathChangedEventArgs> PathChanged; - void OnPathChanged (FilePath oldPath, FilePath newPath, FilePath oldVirtualPath, FilePath newVirtualPath) + void OnPathChanged (FilePath oldPath, FilePath oldLink) { - var handler = PathChanged; + PathChanged?.Invoke (this, CreateEventArgs ()); - if (handler != null) - handler (this, new ProjectFilePathChangedEventArgs (this, oldPath, newPath, oldVirtualPath, newVirtualPath)); + ProjectFilePathChangedEventArgs CreateEventArgs () + { + var oldVirtualPath = GetProjectVirtualPath (oldLink, oldPath, Project); + return new ProjectFilePathChangedEventArgs (this, oldPath, filename, oldVirtualPath, ProjectVirtualPath); + } } protected virtual void OnChanged (string property) { - if (Project != null) - Project.NotifyFilePropertyChangedInProject (this, property); + Project?.NotifyFilePropertyChangedInProject (this, property); } public virtual SourceCodeKind SourceCodeKind @@ -549,9 +553,9 @@ namespace MonoDevelop.Projects NewVirtualPath = newPath; } - public ProjectFile ProjectFile { get; private set; } - public FilePath OldVirtualPath { get; private set; } - public FilePath NewVirtualPath { get; private set; } + public ProjectFile ProjectFile { get; } + public FilePath OldVirtualPath { get; } + public FilePath NewVirtualPath { get; } } class ProjectFilePathChangedEventArgs : ProjectFileVirtualPathChangedEventArgs @@ -562,7 +566,7 @@ namespace MonoDevelop.Projects NewPath = newPath; } - public FilePath OldPath { get; private set; } - public FilePath NewPath { get; private set; } + public FilePath OldPath { get; } + public FilePath NewPath { get; } } } |