private void diffShowInFileTreeToolStripMenuItem_Click(object sender, EventArgs e)
{
var diffGitItemStatus = DiffFiles.SelectedItems.First();
ExecuteCommand((int)Commands.FocusFileTree); // switch to view (and fills the first level of file tree data model if not already done)
var currentNodes = GitTree.Nodes;
TreeNode foundNode = null;
bool isIncompleteMatch = false;
var pathParts = UtilGetPathParts(diffGitItemStatus.Name);
for (int i = 0; i < pathParts.Length; i++)
{
string pathPart = pathParts[i];
string diffPathPart = pathPart.Replace("/", "\\");
var currentFoundNode = currentNodes.Cast<TreeNode>().FirstOrDefault(a =>
{
var treeGitItem = a.Tag as GitItem;
if (treeGitItem != null)
{
// TODO: what about case(in)sensitive handling?
return treeGitItem.Name == diffPathPart;
}
else
{
return false;
}
});
if (currentFoundNode == null)
{
isIncompleteMatch = true;
break;
}
foundNode = currentFoundNode;
if (i < pathParts.Length - 1) // if not the last path part...
{
foundNode.Expand(); // load more data
if (currentFoundNode.Nodes == null)
{
isIncompleteMatch = true;
break;
}
currentNodes = currentFoundNode.Nodes;
}
}
if (foundNode != null)
{
if (isIncompleteMatch)
{
MessageBox.Show(_nodeNotFoundNextAvailableParentSelected.Text);
}
GitTree.SelectedNode = foundNode;
GitTree.SelectedNode.EnsureVisible();
}
else
{
MessageBox.Show(_nodeNotFoundSelectionNotChanged.Text);
}
}