/// <summary> /// Show folders and files hierarchically on the TreeView /// </summary> /// <param name="rootFolders"></param> public void SetFileHierarchies(FileHierarchies fileHierarchies) { SortedDictionary <string, Folder> _rootFolders = fileHierarchies.GetRootFolders(); if (_rootFolders == null) { return; } // remove all existing nodes in tree view _tvwFolders.Nodes.Clear(); foreach (var pair in _rootFolders) { Folder rootFolder = pair.Value; TreeNode rootNode = new TreeNode(rootFolder.Name); rootNode.Tag = rootFolder; // bind a folder information to the node SetCheckState(rootNode, rootFolder.CheckState); ConstructTreeRecursively(rootFolder, rootNode); _tvwFolders.Nodes.Add(rootNode); } }
/// <summary> /// Initialize this program /// </summary> /// <param name="e"></param> protected override void OnShown(EventArgs e) { base.OnShown(e); EventHandlerManager.AddEventHandler(tvwFolders, "AfterCheck", this, "tvwFolders_AfterCheck"); EventHandlerManager.AddEventHandler(tvwFolders, "AfterSelect", this, "tvwFolders_AfterSelect"); EventHandlerManager.AddEventHandler(lvwFiles, "ItemChecked", this, "lvwFiles_ItemChecked"); EventHandlerManager.AddEventHandler(chkSelectAll, "CheckedChanged", this, "chkSelectAll_CheckedChanged"); tvwFoldersManager = new FolderTreeViewManager(tvwFolders); lvwFilesManager = new FileListViewManager(lvwFiles, colName, colType, colSize); // initialize the title message of the form _defaultMainFormText = Text; SetMessageToMainFormText(""); // initialize the status strip bar lblStatusStrip.Text = ""; // restrict file types that this app can open dlgOpenFile.Filter = "SpaceSniffer export file|*." + _txtExtention + "|FileListExporter File|*." + _fileListExtention; // show file open dialog DialogResult result = dlgOpenFile.ShowDialog(); // if a file is selected: if (result == DialogResult.OK) { fileListExporterFile.SetFilePath(dlgOpenFile.FileName); // if a txt file(SpaceSniffer export filer) is selected: if (fileListExporterFile.FileExtention == _txtExtention) { SetStatusLoading(dlgOpenFile.FileName); // try to load the selected txt file _fileHierarchies = spaceSnifferFile.LoadTxtFile(dlgOpenFile.FileName); // if the file hierarchies are successfully loaded: if (_fileHierarchies != null) { SetStatusLoaded(dlgOpenFile.FileName); // show FileListExporter file save dialog if (ShowSaveFileDialog(fileListExporterFile.FileDirectory, fileListExporterFile.FileNameBody)) { SetStatusSaving(fileListExporterFile.FilePath); fileListExporterFile.SaveFile(_fileHierarchies.GetRootFolders()); SetMessageToMainFormText(fileListExporterFile.FilePath); SetStatusSaved(fileListExporterFile.FilePath); SetStatusFoldersLoading(); EventHandlerManager.PauseAllEventHandlers(); { tvwFoldersManager.SetFileHierarchies(_fileHierarchies); } EventHandlerManager.ResumeAllEventHandlers(); SetStatusFoldersLoaded(); } // if a user gave up to proceed: else { // close the program Dispose(); } } else { // close the program Dispose(); } } // if a FileListExporter file is selected: else if (fileListExporterFile.FileExtention == _fileListExtention) { fileListExporterFile.SetFilePath(dlgOpenFile.FileName); SetStatusLoading(fileListExporterFile.FilePath); _fileHierarchies = fileListExporterFile.LoadFile(); // if the file hierarchies are successfully loaded: if (_fileHierarchies != null) { SetStatusLoaded(fileListExporterFile.FilePath); SetMessageToMainFormText(fileListExporterFile.FilePath); tvwFoldersManager.SetFileHierarchies(_fileHierarchies); } else { // close the program Dispose(); } } else { // close the program MessageBox.Show("Please select a file with these types only: " + dlgOpenFile.Filter); Dispose(); } } // if canceled: else { // close the app Dispose(); } }
protected void btnSave_Click(object sender, EventArgs e) { fileListExporterFile.SaveFile(_fileHierarchies.GetRootFolders()); }