//-----------------------------------------------------------------------------// /// <summary> /// LoadChild nodes until the recurseCountdown reaches zero. /// </summary> /// <param name="recurseCountdown"></param> public void LoadNode(int recurseCountdown) { if (recurseCountdown <= 0) { return; } --recurseCountdown; if (!this.loaded) { this.loaded = true; try { DirectoryInfo[] subdirs = this.di.GetDirectories(); foreach (DirectoryInfo subdir in subdirs) { KExplorerNode subNode = new KExplorerNode(subdir); this.Nodes.Add(subNode); subNode.LoadNode(recurseCountdown); } } catch (Exception) { } } else { foreach (KExplorerNode node in this.Nodes) { node.LoadNode(recurseCountdown); } } }
/// <summary> /// Construct with the drive letter and a pointer to the main form /// </summary> /// <param name="newDriveLetter"></param> /// <param name="form1"></param> public DriveLoaderWorkUnit( KExplorerNode newCreatedDriveNode, string newDriveLetter, ISimpleKexplorerGUI form1, IWorkGUIFlagger flagger ) { this.createdNode = newCreatedDriveNode; this.driveLetter = newDriveLetter; this.form = form1; this.guiFlagger = flagger; }
/// <summary> /// Read the tree state of the GUI to figure out what is loaded, where it pointed, whats /// the name of the tab. /// </summary> /// <param name="kexplorerTab"></param> private void Initialize(ISimpleKexplorerGUI kexplorerTab) { if (kexplorerTab.TreeView1.Nodes[0] is KexplorerFtpNode) { var site = (KexplorerFtpNode)kexplorerTab.TreeView1.Nodes[0]; this.ftpSite = site.Site; } else { KExplorerNode selectedNode = (KExplorerNode)kexplorerTab.TreeView1.SelectedNode; if (selectedNode != null) { this.currentFolder = selectedNode.DirInfo.FullName; } else { this.currentFolder = ""; } ArrayList tdrives = new ArrayList(); foreach (KExplorerNode node in kexplorerTab.TreeView1.Nodes) { tdrives.Add(node.Text); } this.drives = (string[])tdrives.ToArray(typeof(string)); } }
public FolderFinderWorkUnit( string newPathToLookFor,KExplorerNode[] newStartNodes, ISimpleKexplorerGUI newForm, IKExplorerControl newFlagger ) { this.pathToLookFor = newPathToLookFor; this.startNodes = newStartNodes; this.form = newForm; this.controller = newFlagger; }
public IWorkUnit DoJob() { IWorkUnit moreWork = null; KExplorerNode[] tempNodes = this.startNodes; foreach (KExplorerNode node in tempNodes ) { if ( node.DirInfo != null && this.pathToLookFor.Equals( node.DirInfo.FullName ) ) { this.expandThisNode = node; this.form.MainForm.Invoke( new InvokeDelegate( this.ExpandNode )); break; } else if ( node.DirInfo != null && this.pathToLookFor.StartsWith( node.DirInfo.FullName )) { /// The node may or may not be loaded. If not, make sure to at least expand /// out to here. Then that will cause another job to get loaded to load it's /// sub nodes. Then, we just re-add this task. if ( node.Nodes.Count == 0 ) { this.expandThisNode = node; this.form.MainForm.Invoke(new InvokeDelegate( this.ExpandNode )); Pipeline drivePipeline = (Pipeline) this.controller.DrivePipelines[this.pathToLookFor.Substring(0,1)]; drivePipeline.AddJob( new FolderWorkUnit( node, this.form, (IWorkGUIFlagger)this.controller )); moreWork = this; } else { /// If the sub-nodes are already created. We re-add this job, but set it /// to look a the sub-nodes. KExplorerNode[] nextStartNodes = new KExplorerNode[ node.Nodes.Count ]; for (int i = 0; i < node.Nodes.Count; i++ ) { nextStartNodes[i] = (KExplorerNode)node.Nodes[ i ]; } this.startNodes = nextStartNodes; moreWork = this; } break; } } return moreWork; }
//-----------------------------------------------------------------------------// /// <summary> /// Called from form's invoke, actual treeview operations. /// </summary> private void AddSubSubNodes() { lock (this.form.TreeView1) { KExplorerNode[] nodes = new KExplorerNode[this.subDirs.Length]; for (int i = 0; i < nodes.Length; i++) { nodes[i] = new KExplorerNode(this.subDirs[i]); } this.currentSubFolderNode.Nodes.AddRange(nodes); } }
public IWorkUnit DoJob() { IWorkUnit moreWork = null; KExplorerNode[] tempNodes = this.startNodes; foreach (KExplorerNode node in tempNodes) { if (node.DirInfo != null && this.pathToLookFor.Equals(node.DirInfo.FullName)) { this.expandThisNode = node; this.form.MainForm.Invoke(new InvokeDelegate(this.ExpandNode)); break; } else if (node.DirInfo != null && this.pathToLookFor.StartsWith(node.DirInfo.FullName)) { /// The node may or may not be loaded. If not, make sure to at least expand /// out to here. Then that will cause another job to get loaded to load it's /// sub nodes. Then, we just re-add this task. if (node.Nodes.Count == 0) { this.expandThisNode = node; this.form.MainForm.Invoke(new InvokeDelegate(this.ExpandNode)); Pipeline drivePipeline = (Pipeline)this.controller.DrivePipelines[this.pathToLookFor.Substring(0, 1)]; drivePipeline.AddJob(new FolderWorkUnit(node, this.form, (IWorkGUIFlagger)this.controller)); moreWork = this; } else { /// If the sub-nodes are already created. We re-add this job, but set it /// to look a the sub-nodes. KExplorerNode[] nextStartNodes = new KExplorerNode[node.Nodes.Count]; for (int i = 0; i < node.Nodes.Count; i++) { nextStartNodes[i] = (KExplorerNode)node.Nodes[i]; } this.startNodes = nextStartNodes; moreWork = this; } break; } } return(moreWork); }
//-----------------------------------------------------------------------------// /// <summary> /// After Expanding a node, make sure two levels deeper are expanded. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TreeView1_AfterExpand(object sender, TreeViewEventArgs e) { if (!this.isGuiBeingChanged) { if (e.Node is KExplorerNode) { KExplorerNode kNode = (KExplorerNode)e.Node; string drive = kNode.DirInfo.FullName.Substring(0, 1); Pipeline drivePipeline = (Pipeline)this.drivePipelines[drive]; drivePipeline.AddJob(new FolderWorkUnit(kNode, this.form, this)); } else { KexplorerFtpNode ftpNode = (KexplorerFtpNode)e.Node; Pipeline ftppipeline = (Pipeline)this.drivePipelines[ftpNode.Site.host]; ftppipeline.AddJob(new FtpFolderWorkUnit(ftpNode, this.form, this)); } } }
//-----------------------------------------------------------------------------// /// <summary> /// When a node is selected. Start the job to load the datagrid. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e) { KExplorerNode kNode = (KExplorerNode)e.Node; if (kNode.Stale) { if (kNode.DirInfo == null) { string emptyDrive = kNode.Text.Substring(0, 1); Pipeline drivePipeline = (Pipeline)this.drivePipelines[emptyDrive]; if (drivePipeline == null) { drivePipeline = new Pipeline(this.form); this.drivePipelines[emptyDrive] = drivePipeline; drivePipeline.StartWork(); } drivePipeline.AddJob(new DriveLoaderWorkUnit(kNode, emptyDrive, this.form, this)); } else { // Refresh the node if it's stale... string drive = kNode.DirInfo.FullName.Substring(0, 1); Pipeline drivePipeline = (Pipeline)this.drivePipelines[drive]; if (drivePipeline == null) { drivePipeline = new Pipeline(this.form); this.drivePipelines[drive] = drivePipeline; drivePipeline.StartWork(); } drivePipeline.AddJob(new FolderWorkUnit(kNode, this.form, this)); } //this.pipeline.AddJob( new FolderWorkUnit( kNode, this.form, this ) ); } // File List always gets done in the main pipeline. this.pipeline.AddPriorityJob(new FileListWorkUnit(kNode, this.form, this)); }
//-----------------------------------------------------------------------------// /// <summary> /// Flags the most recently clicked node. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TreeView1_MouseDown(object sender, MouseEventArgs e) { this.clickedNode = (KExplorerNode)this.form.TreeView1.GetNodeAt(e.X, e.Y); }
//-----------------------------------------------------------------------------// /// <summary> /// LoadChild nodes until the recurseCountdown reaches zero. /// </summary> /// <param name="recurseCountdown"></param> public void LoadNode( int recurseCountdown ) { if ( recurseCountdown <= 0 ) { return; } --recurseCountdown; if ( !this.loaded ) { this.loaded = true; try { DirectoryInfo[] subdirs = this.di.GetDirectories(); foreach ( DirectoryInfo subdir in subdirs ) { KExplorerNode subNode = new KExplorerNode( subdir ); this.Nodes.Add( subNode ); subNode.LoadNode( recurseCountdown ); } } catch (Exception ) { } } else { foreach ( KExplorerNode node in this.Nodes ) { node.LoadNode( recurseCountdown ); } } }
//-----------------------------------------------------------------------------// /// <summary> /// Initialize with a Form1 /// </summary> /// <param name="newForm"></param> public void Initialize(ISimpleKexplorerGUI newForm, string currentFolderName, ArrayList onlyTheseDrives) { this.form = newForm; this.pipeline = new Pipeline(this.form); this.pipeline.StartWork(); this.drivePipelines = new Hashtable(); newForm.WatchingForFolder = currentFolderName; string[] drives = null; if (onlyTheseDrives != null && onlyTheseDrives.Count > 0) { drives = (string[])onlyTheseDrives.ToArray(typeof(string)); } else { drives = System.IO.Directory.GetLogicalDrives(); } foreach (string drive in drives) { //this.pipeline.AddJob( // new DriveLoaderWorkUnit( drive.Substring( 0, 1), this.form, this ) ); Pipeline drivePipeline = new Pipeline(this.form); this.drivePipelines[drive.Substring(0, 1)] = drivePipeline; drivePipeline.StartWork(); KExplorerNode createdNode = new KExplorerNode(drive.Substring(0, 1)); this.form.TreeView1.Nodes.Add(createdNode); drivePipeline.AddJob(new DriveLoaderWorkUnit(createdNode, drive.Substring(0, 1), this.form, this)); } this.launcher = new Launcher(); this.launcher.Initialize(); this.form.TreeView1.AfterExpand += new TreeViewEventHandler(TreeView1_AfterExpand); this.form.TreeView1.KeyDown += new KeyEventHandler(TreeView1_KeyDown); this.form.TreeView1.AfterSelect += new TreeViewEventHandler(TreeView1_AfterSelect); this.form.DataGridView1.KeyDown += new KeyEventHandler(DataGrid1_KeyDown); this.form.TreeView1.DoubleClick += new EventHandler(TreeView1_DoubleClick); this.form.DataGridView1.DoubleClick += new EventHandler(DataGrid1_DoubleClick); this.form.TreeView1.MouseDown += new MouseEventHandler(TreeView1_MouseDown); this.InitializeScriptManager(); this.form.TreeView1.ContextMenu.Popup += new EventHandler(ContextMenu_Popup); this.form.DataGridView1.ContextMenuStrip = this.form.FileGridMenuStrip; this.form.DataGridView1.ContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(ContextMenuStrip_Opening); if (currentFolderName != null && currentFolderName.Length > 0) { KExplorerNode driveNode = null; foreach (KExplorerNode node in this.form.TreeView1.Nodes) { if (currentFolderName.StartsWith(node.Text)) { driveNode = node; break; } } Pipeline drivePipeline = (Pipeline)this.drivePipelines[currentFolderName.Substring(0, 1)]; drivePipeline.AddJob(new FolderFinderWorkUnit( currentFolderName, new KExplorerNode[] { driveNode } , this.form , this )); } }
//-----------------------------------------------------------------------------// /// <summary> /// Add the found sub-directories to the current sub dir. /// </summary> private void AddSubDirsToSubDir() { lock( this.form.TreeView1 ) { KExplorerNode[] nodes = new KExplorerNode[ this.subDirs.Length ]; for ( int i = 0; i < nodes.Length; i++ ) { nodes[i] = new KExplorerNode( this.subDirs[ i ] ); nodes[i].Collapse(); } this.currentWorkingSubDir.Nodes.AddRange( nodes ); } }
//-----------------------------------------------------------------------------// /// <summary> /// Constructor with a node that is a folder. /// </summary> /// <param name="newFolderNode"></param> /// <param name="newForm"></param> public FolderWorkUnit(KExplorerNode newFolderNode, ISimpleKexplorerGUI newForm, IWorkGUIFlagger flagger) { this.folderNode = newFolderNode; this.form = newForm; this.guiFlagger = flagger; }
//-----------------------------------------------------------------------------// /// <summary> /// Constructor with a node that is a folder. /// </summary> /// <param name="newFolderNode"></param> /// <param name="newForm"></param> public FolderWorkUnit( KExplorerNode newFolderNode, ISimpleKexplorerGUI newForm, IWorkGUIFlagger flagger ) { this.folderNode = newFolderNode; this.form = newForm; this.guiFlagger = flagger; }
//-----------------------------------------------------------------------------// /// <summary> /// Job three is to load all directories beneath the first level of directories. /// After this, there is no more work created from this. /// </summary> /// <returns></returns> private IWorkUnit DoJobThree() { try { foreach ( KExplorerNode dirNode in this.createdNode.Nodes ) { if ( this.stop ) { break; } this.currentWorkingSubDir = dirNode; this.subDirs = null; try { this.subDirs = DirPerfStat.Instance().GetDirectories( dirNode.DirInfo ); } catch (Exception ) { } if ( this.subDirs != null && this.subDirs.Length > 0 && !this.stop ) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke( new InvokeDelegate( this.AddSubDirsToSubDir )); } finally { this.guiFlagger.SignalEndGUI(); } } } } finally { this.currentWorkingSubDir = null; this.subDirs = null; } return null; }
//------------------------------------------------------------------- /// <summary> /// Constructor. /// </summary> /// <param name="node"></param> /// <param name="newForm"></param> /// <param name="flagger"></param> public FileListWorkUnit(KExplorerNode node, ISimpleKexplorerGUI newForm, IWorkGUIFlagger flagger ) { this.kForm = newForm; this.kNode = node; this.guiFlagger = flagger; }
//-----------------------------------------------------------------------------// /// <summary> /// Initialize with a Form1 /// </summary> /// <param name="newForm"></param> public void Initialize(ISimpleKexplorerGUI newForm, string currentFolderName, ArrayList onlyTheseDrives ) { this.form = newForm; this.pipeline = new Pipeline( this.form); this.pipeline.StartWork(); this.drivePipelines = new Hashtable(); newForm.WatchingForFolder = currentFolderName; string[] drives = null; if ( onlyTheseDrives != null && onlyTheseDrives.Count > 0 ) { drives = (string[])onlyTheseDrives.ToArray(typeof(string)); } else { drives = System.IO.Directory.GetLogicalDrives(); } foreach( string drive in drives ) { //this.pipeline.AddJob( // new DriveLoaderWorkUnit( drive.Substring( 0, 1), this.form, this ) ); Pipeline drivePipeline = new Pipeline( this.form ); this.drivePipelines[ drive.Substring(0,1) ] = drivePipeline; drivePipeline.StartWork(); KExplorerNode createdNode = new KExplorerNode( drive.Substring( 0, 1) ); this.form.TreeView1.Nodes.Add( createdNode ); drivePipeline.AddJob(new DriveLoaderWorkUnit( createdNode, drive.Substring( 0, 1), this.form, this ) ); } this.launcher = new Launcher(); this.launcher.Initialize(); this.form.TreeView1.AfterExpand += new TreeViewEventHandler(TreeView1_AfterExpand); this.form.TreeView1.KeyDown += new KeyEventHandler(TreeView1_KeyDown); this.form.TreeView1.AfterSelect += new TreeViewEventHandler(TreeView1_AfterSelect); this.form.DataGridView1.KeyDown += new KeyEventHandler(DataGrid1_KeyDown); this.form.TreeView1.DoubleClick += new EventHandler(TreeView1_DoubleClick); this.form.DataGridView1.DoubleClick += new EventHandler(DataGrid1_DoubleClick); this.form.TreeView1.MouseDown += new MouseEventHandler(TreeView1_MouseDown); this.InitializeScriptManager(); this.form.TreeView1.ContextMenu.Popup +=new EventHandler(ContextMenu_Popup ); this.form.DataGridView1.ContextMenuStrip = this.form.FileGridMenuStrip; this.form.DataGridView1.ContextMenuStrip.Opening +=new System.ComponentModel.CancelEventHandler(ContextMenuStrip_Opening); if ( currentFolderName != null && currentFolderName.Length > 0 ) { KExplorerNode driveNode = null; foreach ( KExplorerNode node in this.form.TreeView1.Nodes ) { if ( currentFolderName.StartsWith( node.Text )) { driveNode = node; break; } } Pipeline drivePipeline = (Pipeline)this.drivePipelines[currentFolderName.Substring(0,1)]; drivePipeline.AddJob( new FolderFinderWorkUnit( currentFolderName, new KExplorerNode[]{driveNode} , this.form , this )); } }
//-----------------------------------------------------------------------------// /// <summary> /// Flags the most recently clicked node. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TreeView1_MouseDown(object sender, MouseEventArgs e) { this.clickedNode = (KExplorerNode)this.form.TreeView1.GetNodeAt(e.X,e.Y); }
//-----------------------------------------------------------------------------// /// <summary> /// Go through each sub-folder and load it's sub-folders. /// </summary> /// <returns></returns> private IWorkUnit DoJobTwo() { try { foreach ( KExplorerNode sNode in this.folderNode.Nodes ) { if ( this.stop ) { break; } this.currentSubFolderNode = sNode; if ( sNode.Nodes.Count > 0 && sNode.Stale ) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke( new InvokeDelegate( this.ClearSubNode )); } finally { this.guiFlagger.SignalEndGUI(); } sNode.Stale = false; } if ( sNode.Nodes.Count == 0 ) { try { this.subDirs = null; this.subDirs = DirPerfStat.Instance().GetDirectories( sNode.DirInfo ); if ( this.subDirs == null ) { this.YouWereAborted(); } if ( this.subDirs != null && this.subDirs.Length > 0 && !this.stop ) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke( new InvokeDelegate( this.AddSubSubNodes )); } finally { this.guiFlagger.SignalEndGUI(); } } } catch (Exception) { } } } } finally { this.subDirs = null; this.currentSubFolderNode = null; } return null; }
//-----------------------------------------------------------------------------// /// <summary> /// Go through each sub-folder and load it's sub-folders. /// </summary> /// <returns></returns> private IWorkUnit DoJobTwo() { try { foreach (KExplorerNode sNode in this.folderNode.Nodes) { if (this.stop) { break; } this.currentSubFolderNode = sNode; if (sNode.Nodes.Count > 0 && sNode.Stale) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke(new InvokeDelegate(this.ClearSubNode)); } finally { this.guiFlagger.SignalEndGUI(); } sNode.Stale = false; } if (sNode.Nodes.Count == 0) { try { this.subDirs = null; this.subDirs = DirPerfStat.Instance().GetDirectories(sNode.DirInfo); if (this.subDirs == null) { this.YouWereAborted(); } if (this.subDirs != null && this.subDirs.Length > 0 && !this.stop) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke(new InvokeDelegate(this.AddSubSubNodes)); } finally { this.guiFlagger.SignalEndGUI(); } } } catch (Exception) { } } } } finally { this.subDirs = null; this.currentSubFolderNode = null; } return(null); }
//-----------------------------------------------------------------------------// /// <summary> /// Add sub directories. /// </summary> private void AddSubNodes() { lock( this.form.TreeView1 ) { KExplorerNode[] nodes = new KExplorerNode[ this.subDirs.Length ]; for ( int i = 0; i < nodes.Length; i++ ) { nodes[i] = new KExplorerNode( this.subDirs[i] ); } this.folderNode.Nodes.AddRange( nodes ); } }
//------------------------------------------------------------------- /// <summary> /// Constructor. /// </summary> /// <param name="node"></param> /// <param name="newForm"></param> /// <param name="flagger"></param> public FileListWorkUnit(KExplorerNode node, ISimpleKexplorerGUI newForm, IWorkGUIFlagger flagger) { this.kForm = newForm; this.kNode = node; this.guiFlagger = flagger; }