94 lines
3.1 KiB
C#
94 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ProjectScannerP4V
|
|
{
|
|
public partial class FrmBrowseDepot : Form
|
|
{
|
|
public P4Tools p4t { get; set; }
|
|
public string InitialPath { get; set; }
|
|
public string SelectedPath { get; set; }
|
|
public FrmBrowseDepot()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FrmBrowseDepot_Load(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(InitialPath))
|
|
{
|
|
AddPathToTree(InitialPath);
|
|
}
|
|
}
|
|
|
|
void AddPathToTree(string path)
|
|
{
|
|
string[] splittedPath = path.Substring(2).Split('/');
|
|
TreeNodeCollection tnc = treeViewDepot.Nodes;
|
|
for(int i=0;i<splittedPath.Length;i++)
|
|
{
|
|
if (!string.IsNullOrEmpty(splittedPath[i]))
|
|
{
|
|
string Path2Search = "";// "/" + splittedPath[0];
|
|
for (int j = 0; j <= i; j++)
|
|
Path2Search += "/" + splittedPath[j];
|
|
|
|
TreeNode [] foundNodes = tnc.Find(Path2Search,true);
|
|
if ((foundNodes.Length == 0) || (foundNodes[0].Nodes.Count==0))
|
|
{
|
|
TreeNode tn;
|
|
if (foundNodes.Length > 0)
|
|
{
|
|
tn = foundNodes[0];
|
|
}
|
|
else
|
|
tn = tnc.Add(Path2Search, splittedPath[i]);
|
|
string[] dirs = p4t.GetDirectories("/" + Path2Search+"/");
|
|
if (dirs != null)
|
|
{
|
|
for (int k = 0; k < dirs.Length; k++)
|
|
{
|
|
TreeNode subNode = tn.Nodes.Add(Path2Search+"/"+dirs[k], dirs[k]);
|
|
subNode.Nodes.Add("");
|
|
}
|
|
}
|
|
tnc = tn.Nodes;
|
|
}
|
|
else
|
|
{
|
|
tnc = foundNodes[0].Nodes;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void treeViewDepot_BeforeExpand(object sender, TreeViewCancelEventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(e.Node.FirstNode.Name))
|
|
{
|
|
e.Node.Nodes.Clear();
|
|
AddPathToTree("/"+e.Node.Name);
|
|
}
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedPath = null;
|
|
if (treeViewDepot.SelectedNode != null)
|
|
{
|
|
SelectedPath = "/" + treeViewDepot.SelectedNode.Name + "/";
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Please select a folder first", "No folder selected");
|
|
}
|
|
}
|
|
}
|
|
}
|