Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
Expand All @@ -7,6 +8,8 @@ namespace CodingWithCalvin.OpenInNotepadPlusPlus.Helpers
{
internal static class ProjectHelpers
{
private const string UnloadedProjectGuid = "{67294A52-A4F0-11D2-AA88-00C04F688DDE}";

public static string GetSelectedPath(DTE2 dte)
{
ThreadHelper.ThrowIfNotOnUIThread();
Expand All @@ -21,12 +24,38 @@ UIHierarchyItem selectedItem in (Array)
case ProjectItem projectItem:
return projectItem.FileNames[1];
case Project project:
return project.FullName;
return GetProjectPath(project, dte.Solution);
case Solution solution:
return solution.FullName;
}
}
return null;
}

private static string GetProjectPath(Project project, Solution solution)
{
ThreadHelper.ThrowIfNotOnUIThread();

bool isUnloaded = project.Kind.Equals(UnloadedProjectGuid, StringComparison.OrdinalIgnoreCase);

if (!isUnloaded)
{
return project.FullName;
}

// For unloaded projects, FullName is empty but UniqueName contains
// the relative path from the solution directory
if (!string.IsNullOrEmpty(project.UniqueName) && !string.IsNullOrEmpty(solution?.FullName))
{
var solutionDirectory = Path.GetDirectoryName(solution.FullName);
var projectPath = Path.Combine(solutionDirectory, project.UniqueName);
if (File.Exists(projectPath))
{
return projectPath;
}
}

return null;
}
}
}