Getting the Gui to show gits files.
[Widgit.git] / Form1.cs
blob1b677ef6b4cfa107c54cc1f8e47b62e8058b6149
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.Diagnostics;
9 using System.IO;
10 using Git;
12 namespace Gitrdone
14 public partial class Form1 : Form
16 protected List<Git.File> m_files;
17 protected OutputTextWriter m_outputWriter;
18 public Form1()
20 InitializeComponent();
21 OutputTextWriter m_outputWriter = new OutputTextWriter(m_outputArea);
22 System.Console.SetOut(m_outputWriter);
24 Git.Repo r = new Git.Repo("/home/govind/Projects/testme");
25 ResetRepoTree(r);
28 protected bool ResetRepoTree(Repo repo)
30 m_files = repo.ListFiles();
31 m_workspaceTree.BeginUpdate();
32 m_workspaceTree.Nodes.Clear();
33 TreeNode root = new TreeNode("root");
34 root.Tag = "";
35 m_workspaceTree.Nodes.Add(root);
36 Stack<TreeNode> nodeStack = new Stack<TreeNode>();
37 nodeStack.Push(root);
38 m_files.Sort();
39 foreach (Git.File f in m_files)
41 TreeNode n = new TreeNode(f.Name);
42 n.Tag = f;
43 System.Console.WriteLine("filepath: " + f.RelativePath + " nodepath: " + nodeStack.Peek().Tag.ToString());
44 if (f.RelativePath == "")
46 root.Nodes.Add(n);
48 else if (f.RelativePath == nodeStack.Peek().Tag.ToString())
50 nodeStack.Peek().Nodes.Add(n);
52 else
54 bool bDone = false;
55 while (nodeStack.Count > 1 && !bDone)
57 string stackPath = nodeStack.Peek().Tag.ToString();
58 if (f.RelativePath == stackPath)
60 nodeStack.Peek().Nodes.Add(n);
61 bDone = true;
63 else
65 string[] pathParts = f.RelativePath.Split(System.IO.Path.DirectorySeparatorChar);
66 int idx = pathParts.Length - 1;
67 while (idx > -1 && !bDone)
69 string subPath = string.Join(System.IO.Path.DirectorySeparatorChar.ToString(), pathParts, 0, idx);
70 if (stackPath.Length > subPath.Length)
72 break;
74 if (subPath == stackPath)
76 for (int newPartsIdx = idx + 1; newPartsIdx < pathParts.Length; ++newPartsIdx)
78 subPath = subPath + System.IO.Path.DirectorySeparatorChar + pathParts[newPartsIdx];
79 TreeNode pathNode = new TreeNode(pathParts[newPartsIdx]);
80 pathNode.Tag = subPath;
81 nodeStack.Peek().Nodes.Add(pathNode);
82 nodeStack.Push(pathNode);
84 nodeStack.Peek().Nodes.Add(n);
85 bDone = true;
87 --idx;
90 nodeStack.Pop();
94 m_workspaceTree.EndUpdate();
95 return true;