private void deleteToolStripMenuItem1_Click(object sender, EventArgs e) { //Delete file or folder from fileView ListViewItem currFile = fileView.SelectedItems[0]; TreeNode currFolder = folderView.SelectedNode; if (currFile.ImageKey != "Folder_Documents.png" && currFile.ImageKey != "Folder_Downloads.png") //can't delete downloads or documents folder { int numFolders = currFolder.Nodes.Count; if (currFile.SubItems[1].Text == "Text Document") { int fileIndex = currFile.Index - numFolders; FolderFiles[currFolder].Items[fileIndex].Remove(); //delete from dictionary currFile.Remove(); //delete from fileview } else if (currFile.SubItems[1].Text == "File Folder") { int fileIndex = currFile.Index; //get index of what is selected in fileview FolderFiles.Remove(currFolder.Nodes[fileIndex]); //delete selected folder from dictionary currFolder.Nodes[fileIndex].Remove(); //delete from folderview Class_FileManager.refreshFileView(fileView, currFolder); //refresh to disappear from fileview } } }
private void folderView_AfterSelect(object sender, TreeViewEventArgs e) { //Click on folder in treeview, show folders and files in listView TreeNode currFolder = folderView.SelectedNode; Class_FileManager.refreshFileView(fileView, currFolder); //populate files }
private void renameToolStripMenuItem_Click(object sender, System.EventArgs e) { // Rename folder from Right Click menu TreeNode currFolder = folderView.SelectedNode; currFolder.BeginEdit(); Class_FileManager.refreshFileView(fileView, currFolder); //populate files }
private void fileView_DoubleClick(object sender, EventArgs e) { //Allow user to change folders from clicking on a folder in FileView ListViewItem currFile = fileView.SelectedItems[0]; TreeNode currFolder = folderView.SelectedNode; //current folder int index = fileView.SelectedItems[0].Index; if (currFile.SubItems[1].Text == "File Folder") { folderView.SelectedNode = currFolder.Nodes[index]; Class_FileManager.refreshFileView(fileView, folderView.SelectedNode); } }
/************************************************************************************************ * * Folder Stuff * * **********************************************************************************************/ private void folderView_AfterSelect(object sender, TreeViewEventArgs e) { //Click on folder in treeview, show folders and files in listView TreeNode currFolder = folderView.SelectedNode; // if folder is "ThisPC", don't allow creation of new text document if (currFolder.Parent == null) //PC has null parent { fileToolStripMenuItem.Visible = false; //do not allow new files to be created } else { fileToolStripMenuItem.Visible = true; //allow new files to be created } Class_FileManager.refreshFileView(fileView, currFolder); //populate files filePathComboBox.Text = Class_FileManager.getFilePath(folderView.SelectedNode); //update combobox to display current path }
private void folderView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { // Validate folder name, no empty name, no invalid characters //Code Attribution: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.treeview.afterlabeledit?view=netframework-4.7.2 if (e.Label != null) { if (e.Label.Length > 0) { foreach (TreeNode folder in e.Node.Parent.Nodes) // check that there are no other similar named folders within current level { if (!folder.Equals(e.Node) && folder.Text == e.Label) { MessageBox.Show("This destination already contains a folder named '" + e.Label + "'"); e.CancelEdit = true; } } if (e.Label.IndexOfAny(new char[] { '\\', '/', ':', '*', '?', '"', '<', '>', '|' }) == -1) //does not contain any invalid characters { e.Node.EndEdit(false); // Stop editing without canceling the label change. if (!IsHandleCreated) { CreateHandle(); } BeginInvoke(new Action(() => Class_FileManager.refreshFileView(fileView, folderView.SelectedNode))); //update all files' tags AFTER label has finished editing } else { // Cancel the label edit action, inform the user, and place the node in edit mode again e.CancelEdit = true; MessageBox.Show("A file name can't contain any of the following characters:\n \\ / : * ? \" < > |"); //mimicing windows invalid characters message e.Node.BeginEdit(); } } else { // Cancel the label edit action, inform the user, and place the node in edit mode again e.CancelEdit = true; MessageBox.Show("A file name can't be blank"); //cannot be blank name e.Node.BeginEdit(); } } }
private void folderToolStripMenuItem_Click(object sender, EventArgs e) { // Create New Folder from right click menu in LISTVIEW Class_FileManager.CreateFolder(fileView, folderView.SelectedNode); }
private void newFolderButton_Click(object sender, EventArgs e) { // Create New Folder Button from icon/toolbar Class_FileManager.CreateFolder(fileView, folderView.SelectedNode); }