public void RedrawTreeView()
{
//Heff: if cancellation was requested, this was most likely called by a background thread, so don't try to interact with the form.
if (cts.IsCancellationRequested)
return;
if (MainTreeView.InvokeRequired)
this.Invoke(new Action(() =>
{
MainTreeView.BeginUpdate();
RedrawTreeView();
MainTreeView.EndUpdate();
}));
else
{
MainTreeView.BeginUpdate();
List<myTreeNode> nodes = new List<myTreeNode>();
ResetImageList();
for (int i = 0; i < LoadedTexes.Count; i++)
{
TPFTexInfo curr = LoadedTexes[i];
// KFreon: If analysed, add visual cues
string text = curr.FormatTexDetails(isAnalysed);
myTreeNode node = new myTreeNode(text);
node.TexInd = i;
// KFreon: Make tree dups obvious
if (curr.TreeDuplicates.Count != 0)
{
Font tempfont = node.NodeFont ?? MainTreeView.Font;
node.NodeFont = new Font(tempfont, FontStyle.Italic);
}
if (!curr.isDef)
{
// KFreon: Deal with File dups
if (curr.FileDuplicates.Count != 0)
for (int j = 0; j < curr.FileDuplicates.Count; j++)
{
TPFTexInfo trr = curr.FileDuplicates[j];
text = trr.FormatTexDetails(isAnalysed);
trr.ThumbInd = -1;
myTreeNode temp = new myTreeNode(text);
temp.TexInds.Add(i);
temp.TexInds.Add(j);
node.Nodes.Add(temp);
curr.FileDuplicates[j] = trr;
}
try
{
Bitmap bmp = new Bitmap(curr.Thumbnail);
bmp = UsefulThings.WinForms.Imaging.PadImageToSquare(bmp, 64);
curr.ThumbInd = MainTreeViewImageList.Images.Count;
MainTreeViewImageList.Images.Add(bmp);
}
catch
{
curr.ThumbInd = 2;
}
}
else
curr.ThumbInd = 1;
nodes.Add(node);
LoadedTexes[i] = curr;
}
MainTreeView.Nodes.Clear();
MainTreeView.Nodes.AddRange(nodes.ToArray());
SetTreeImages(MainTreeView);
MainTreeView.EndUpdate();
}
}