diff --git a/SaveAllTheTime/DocumentMonitorService.cs b/SaveAllTheTime/DocumentMonitorService.cs index 7b3dba8..911d2df 100644 --- a/SaveAllTheTime/DocumentMonitorService.cs +++ b/SaveAllTheTime/DocumentMonitorService.cs @@ -228,9 +228,9 @@ public int OnAfterAttributeChangeEx(uint docCookie, uint grfAttribs, IVsHierarch bool shouldSaveActiveDocument() { - string name = _dte.ActiveDocument.FullName; + string name = _dte.ActiveDocument != null ? _dte.ActiveDocument.FullName : string.Empty; - if (name.EndsWith("resx", StringComparison.InvariantCulture)) { + if (name.EndsWith("resx", StringComparison.InvariantCulture) || string.IsNullOrEmpty(name)) { return false; } diff --git a/SaveAllTheTime/Extensions.cs b/SaveAllTheTime/Extensions.cs index e7961e6..7b26f6c 100644 --- a/SaveAllTheTime/Extensions.cs +++ b/SaveAllTheTime/Extensions.cs @@ -1,13 +1,12 @@ using System.Collections.Generic; using System.Linq; using EnvDTE; +using EnvDTE80; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell.Interop; namespace SaveAllTheTime { - - internal static class Extensions { internal static List GetDocumentWindowFrames(this IVsUIShell vsShell) @@ -45,21 +44,41 @@ internal static List GetContents(this IEnumWindowFrames enumFram internal static HashSet GetProjectItemPaths(this Solution solution) { - HashSet items = new HashSet(); - - var toAdd = solution.Projects - .Cast() + var projectItems = solution.AllProjects() .SelectMany(x => AllProjectItems(x) .Where(y => y.Properties != null) .Select(y => y.Properties.Item("FullPath")) .Where(z => z.Value != null) .Select(z => z.Value.ToString())); - foreach (string key in toAdd) { - items.Add(key); - } + return new HashSet(projectItems); + } + + static IEnumerable AllProjects(this Solution solution) + { + var mainProjects = solution.Projects.Cast(); + var subProjects = solution.Projects.Cast().Where(x => x.Kind == ProjectKinds.vsProjectKindSolutionFolder).SolutionFolderProjects(); - return items; + return mainProjects.Concat(subProjects); + } + + static IEnumerable SolutionFolderProjects(this IEnumerable projects) + { + return projects + .SelectMany(x => + Enumerable.Range(1, x.ProjectItems.Count) + .Select(y => x.ProjectItems.Item(y).SubProject) + .Where(p => p != null)) + .SelectMany(x => + x.Kind == ProjectKinds.vsProjectKindSolutionFolder ? + x.AsEnumerable().SolutionFolderProjects() : + x.AsEnumerable() + ); + } + + static IEnumerable AsEnumerable(this Project project) + { + yield return project; } static IEnumerable AllProjectItems(Project project) diff --git a/SaveAllTheTime/SaveAllTheTime.csproj b/SaveAllTheTime/SaveAllTheTime.csproj index f552c9c..b9090ec 100644 --- a/SaveAllTheTime/SaveAllTheTime.csproj +++ b/SaveAllTheTime/SaveAllTheTime.csproj @@ -49,6 +49,11 @@ False + + False + False + ..\..\..\Program Files (x86)\Common Files\microsoft shared\MSEnv\PublicAssemblies\envdte80.dll + ..\packages\LibGit2Sharp.0.11.1.10\lib\net35\LibGit2Sharp.dll diff --git a/SaveAllTheTime/Views/CommitHintView.xaml.cs b/SaveAllTheTime/Views/CommitHintView.xaml.cs index 974d153..9d364e3 100644 --- a/SaveAllTheTime/Views/CommitHintView.xaml.cs +++ b/SaveAllTheTime/Views/CommitHintView.xaml.cs @@ -42,6 +42,7 @@ public CommitHintView() this.WhenAnyObservable(x => x.ViewModel.RefreshStatus.ItemsInflight) .Select(x => x != 0 ? "Loading" : "NotLoading") + .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => VisualStateManager.GoToElementState(visualRoot, x, true)); this.BindCommand(ViewModel, x => x.Open, x => x.Open); @@ -61,11 +62,13 @@ public CommitHintView() .BindTo(this, x => x.visualRoot.Opacity); this.WhenAny(x => x.IsMouseOver, x => x.Value ? "Hover" : "NoHover") + .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => VisualStateManager.GoToElementState(visualRoot, x, true)); this.WhenAnyObservable( x => x.ViewModel.RefreshLastCommitTime.ThrownExceptions, x => x.ViewModel.RefreshStatus.ThrownExceptions) + .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => VisualStateManager.GoToElementState(visualRoot, "Error", true)); Observable.FromEventPattern(x => visualRoot.PreviewMouseUp += x, x => visualRoot.PreviewMouseUp += x)