Browse Source

fix #179: "navigate to file in project browser" does not work all the times

pull/516/head
Siegfried Pammer 11 years ago
parent
commit
f1894f80f5
  1. 74
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs
  2. 1
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/SolutionItemNode.cs

74
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs

@ -17,8 +17,11 @@ @@ -17,8 +17,11 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using ICSharpCode.Core;
@ -249,37 +252,58 @@ namespace ICSharpCode.SharpDevelop.Project @@ -249,37 +252,58 @@ namespace ICSharpCode.SharpDevelop.Project
try {
inSelectFile = true;
lastSelectionTarget = fileName;
TreeNode node = FindFileNode(fileName);
if (node != null) {
// Expand to node
TreeNode parent = node.Parent;
while (parent != null) {
parent.Expand();
parent = parent.Parent;
}
//node = FindFileNode(fileName);
treeView.SelectedNode = node;
} else {
// Node for this file does not exist yet (the tree view is lazy loaded)
SelectDeepestOpenNodeForPath(fileName);
}
LoadAndExpandToNode(new FileName(fileName));
} finally {
inSelectFile = false;
}
}
#region SelectDeepestOpenNode internals
//
// SolutionNode RootSolutionNode {
// get {
// if (treeView.Nodes != null && treeView.Nodes.Count>0) {
// return treeView.Nodes[0] as SolutionNode;
// }
// return null;
// }
// }
//
void LoadAndExpandToNode(FileName fileName)
{
IProject project = null;
if (!SD.ProjectService.IsSolutionOrProjectFile(fileName)) {
project = SD.ProjectService.FindProjectContainingFile(fileName);
}
Stack<ISolutionItem> itemsToExpand = new Stack<ISolutionItem>();
ISolutionItem item = project;
if (project == null) {
item = SD.ProjectService.CurrentSolution.AllItems
.OfType<ISolutionFileItem>().FirstOrDefault(i => i.FileName.Equals(fileName));
}
while (item != null) {
itemsToExpand.Push(item);
item = item.ParentFolder;
}
AbstractProjectBrowserTreeNode current = null;
var currentChildren = treeView.Nodes;
while (itemsToExpand.Any()) {
var currentItem = itemsToExpand.Pop();
current = currentChildren.OfType<AbstractProjectBrowserTreeNode>().FirstOrDefault(n => n.Tag == currentItem);
if (current == null) break;
current.Expand();
currentChildren = current.Nodes;
}
if (project != null) {
var fileItem = project.FindFile(fileName);
var virtualPath = fileItem.VirtualName;
if (!string.IsNullOrWhiteSpace(fileItem.DependentUpon)) {
int index = virtualPath.LastIndexOf('\\') + 1;
virtualPath = virtualPath.Insert(index, fileItem.DependentUpon + "\\");
}
string[] relativePath = virtualPath.Split('\\');
for (int i = 0; i < relativePath.Length; i++) {
current = currentChildren.OfType<AbstractProjectBrowserTreeNode>()
.FirstOrDefault(n => n.Text.Equals(relativePath[i], StringComparison.OrdinalIgnoreCase));
if (current == null) break;
current.Expand();
currentChildren = current.Nodes;
}
}
treeView.SelectedNode = current;
}
void SelectDeepestOpenNodeForPath(string fileName)
{
TreeNode node = FindDeepestOpenNodeForPath(fileName);

1
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/TreeNodes/SolutionItemNode.cs

@ -51,6 +51,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -51,6 +51,7 @@ namespace ICSharpCode.SharpDevelop.Project
this.solution = item.ParentSolution;
this.item = item;
this.Text = Path.GetFileName(FileName);
this.Tag = item;
SetIcon(IconService.GetImageForFile(FileName));
}

Loading…
Cancel
Save