Skip to content

Commit

Permalink
Merge pull request #24 from fdefelici/release_v0.1.0
Browse files Browse the repository at this point in the history
Release v0.1.0
  • Loading branch information
fdefelici committed Oct 25, 2023
2 parents 4eb15ac + 012a5cb commit 34dadfa
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 70 deletions.
59 changes: 36 additions & 23 deletions FUnreal/Sources/Core/VS/FUnrealDTE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.VisualStudio.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -42,7 +41,7 @@ public async Task InitializeAsync()
}

UENatvisPath = FindUENatvisPath();
await ReloadProjectAsync();
await ReloadProjectAsync();

if (UENatvisPath == null)
{
Expand Down Expand Up @@ -263,16 +262,26 @@ private string FindUENatvisPath()

//Microsoft.VisualStudio.CommonIDE.Solutions
//DteMiscProject
//NOTE: DTE Collections (ex. ProjectItems, FileNames) are 1-based (start index is 1 and not 0!!!)
if (project.Name.Equals("Visualizers", StringComparison.OrdinalIgnoreCase))
{
if (project.ProjectItems.Count != 1) return null;
ProjectItem item = project.ProjectItems.Item(1); //Collection 1-based (not starting from 0!!!)
if (project.ProjectItems.Count == 0) return null;

if (item.FileCount != 1) return null;
string absFilePath = item.FileNames[1]; //Collection 1-based (not starting from 0!!!)
Debug.Print(" Natvis file path: {0}", absFilePath);

return absFilePath;
foreach (ProjectItem item in project.ProjectItems)
{
string absFilePath = item.FileNames[1]; //Collection 1-based (not starting from 0!!!)
XDebug.Info("Visualizers file path: {0}", absFilePath);

if (!XFilesystem.HasExtension(absFilePath, ".natvis"))
{
continue;
}
else
{
XDebug.Info("Visualizers natvis file found: {0}", absFilePath);
return absFilePath;
}
}
}
}

Expand All @@ -287,15 +296,15 @@ private string FindUENatvisPath()

//Example of api, to select multiple elment (like shift+selection). Not useful now, but just to keep it.
//SolutionExplorerNode.SelectDown(vsUISelectionType.vsUISelectionTypeSetCaret, 1);
public async Task TryToSelectSolutionExplorerItemAsync(string[] relPathAfterProjectName)
public async Task TryToSelectSolutionExplorerItemAsync(string[] relPathAfterProjectName)
{
await XThread.SwitchToUIThreadIfItIsNotAsync();

XDebug.Info($"Selecting Subpath to project {XFilesystem.ToPath(relPathAfterProjectName)} ...");

//NOTE: GetItem works only if item is expanded on Solution Explorer View (otherwise throws exception)
//UIHierarchyItem foundItem = SolutionExplorerNode.GetItem(@"UENLOpt\Games\UENLOpt\Source\UENLOpt\MyActor.h");

//string[] parts = new string[] { "Source", "UENLOpt", "MyActor.h" };

UIHierarchyItem lastItem = GetProjectUIHierarchItem();
Expand All @@ -310,7 +319,7 @@ public async Task TryToSelectSolutionExplorerItemAsync(string[] relPathAfterProj
{
found = TryFindUIHierItemChild(lastItem, part, out UIHierarchyItem child);
if (!found) break;

child.UIHierarchyItems.Expanded = true;
lastItem = child;
}
Expand All @@ -336,7 +345,7 @@ private UIHierarchyItem GetProjectUIHierarchItem()
UIHierarchy SolutionExplorerNode = _DTE2.ToolWindows.SolutionExplorer;
if (!SolutionExplorerNode.UIHierarchyItems.Expanded) SolutionExplorerNode.UIHierarchyItems.Expanded = true;
if (SolutionExplorerNode.UIHierarchyItems.Count == 0) return null;

UIHierarchyItem solutionNode = SolutionExplorerNode.UIHierarchyItems.Item(1);
if (!solutionNode.UIHierarchyItems.Expanded) solutionNode.UIHierarchyItems.Expanded = true;
if (solutionNode.UIHierarchyItems.Count == 0) return null;
Expand Down Expand Up @@ -386,7 +395,8 @@ public async Task AddSubpathToProjectAsync(string[] relPathAfterProjectName)
}

lastItem = child;
} else
}
else
{
//Adding folder to the project item
var newPItem = GetProjectItemsFrom(lastItem.Object).AddFolder(part, VSConstants.ItemTypeGuid.VirtualFolder_string);
Expand All @@ -398,15 +408,16 @@ public async Task AddSubpathToProjectAsync(string[] relPathAfterProjectName)
if (childFound)
{
lastItem = newChild;
} else
}
else
{
//shold not happen
XDebug.Erro($"For the ProjectItem '{part}' just added, was not found the respective UIHierarchyItem!");
return;
}
}
}
}

if (firstNotExpanded != null)
{
//by the fact the only way to explor UIHierarchyItem is to expand them,
Expand Down Expand Up @@ -435,7 +446,7 @@ private bool TryFindUIHierItems(string[] relPathAfterProject, out List<UIHierarc
var uiItemParents = new List<UIHierarchyItem>();

bool found = false;
foreach(var part in relPathAfterProject)
foreach (var part in relPathAfterProject)
{
found = false;
bool originalExpanded = lastItem.UIHierarchyItems.Expanded;
Expand All @@ -452,21 +463,23 @@ private bool TryFindUIHierItems(string[] relPathAfterProject, out List<UIHierarc
lastItem = each;
found = true;
break;
; }
;
}
lastItem.UIHierarchyItems.Expanded = false;
}
}

//restore expansion
for(int i = uiItemParents.Count-1; i >=0; i--)
for (int i = uiItemParents.Count - 1; i >= 0; i--)
{
uiItemParents[i].UIHierarchyItems.Expanded = originalExpandState[i];
}

if (!found)
{
uiItems = null;
} else
}
else
{
uiItems = uiItemParents;
uiItems.Add(lastItem);
Expand Down Expand Up @@ -494,7 +507,7 @@ private bool TryFindUIHierItemChild(UIHierarchyItem parent, string childName, ou
return false;
}


//This method is needed just because Project and ProjectItem haven't a common interface, but object
private static ProjectItems GetProjectItemsFrom(object aProjectOrProjectItem)
{
Expand Down
Loading

0 comments on commit 34dadfa

Please sign in to comment.