Skip to content

Commit

Permalink
Save files inside a solution folder project
Browse files Browse the repository at this point in the history
-Fix issue #33 by loading projects that are inside solution folders. the
Projects property only returns the top level projects
- Add protection against ActiveDocument possibly being null
- Fix a InvalidOperationException inside CommonHintView
  • Loading branch information
Dave McKeown authored and Dave McKeown committed Dec 16, 2013
1 parent 26d1da1 commit 8d69635
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
4 changes: 2 additions & 2 deletions SaveAllTheTime/DocumentMonitorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
39 changes: 29 additions & 10 deletions SaveAllTheTime/Extensions.cs
Original file line number Diff line number Diff line change
@@ -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<IVsWindowFrame> GetDocumentWindowFrames(this IVsUIShell vsShell)
Expand Down Expand Up @@ -45,21 +44,41 @@ internal static List<IVsWindowFrame> GetContents(this IEnumWindowFrames enumFram

internal static HashSet<string> GetProjectItemPaths(this Solution solution)
{
HashSet<string> items = new HashSet<string>();

var toAdd = solution.Projects
.Cast<Project>()
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<string>(projectItems);
}

static IEnumerable<Project> AllProjects(this Solution solution)
{
var mainProjects = solution.Projects.Cast<Project>();
var subProjects = solution.Projects.Cast<Project>().Where(x => x.Kind == ProjectKinds.vsProjectKindSolutionFolder).SolutionFolderProjects();

return items;
return mainProjects.Concat(subProjects);
}

static IEnumerable<Project> SolutionFolderProjects(this IEnumerable<Project> 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<Project> AsEnumerable(this Project project)
{
yield return project;
}

static IEnumerable<ProjectItem> AllProjectItems(Project project)
Expand Down
5 changes: 5 additions & 0 deletions SaveAllTheTime/SaveAllTheTime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<Reference Include="envdte, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="envdte80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<SpecificVersion>False</SpecificVersion>
<EmbedInteropTypes>False</EmbedInteropTypes>
<HintPath>..\..\..\Program Files (x86)\Common Files\microsoft shared\MSEnv\PublicAssemblies\envdte80.dll</HintPath>
</Reference>
<Reference Include="LibGit2Sharp">
<HintPath>..\packages\LibGit2Sharp.0.11.1.10\lib\net35\LibGit2Sharp.dll</HintPath>
</Reference>
Expand Down
3 changes: 3 additions & 0 deletions SaveAllTheTime/Views/CommitHintView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<MouseButtonEventHandler, MouseButtonEventArgs>(x => visualRoot.PreviewMouseUp += x, x => visualRoot.PreviewMouseUp += x)
Expand Down

0 comments on commit 8d69635

Please sign in to comment.