From 19264b388f068bbebfc8cbaa389544408bcfe62b Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 13 Nov 2020 15:26:48 -0600 Subject: [PATCH] Updated the code in the FileViewer to populate the main TreeVeiw with the Snapshot class object. --- .vs/DataOrganizer/v16/.suo | Bin 138240 -> 138240 bytes DataOrganizer/FileViewer.cs | 89 ++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 50 deletions(-) diff --git a/.vs/DataOrganizer/v16/.suo b/.vs/DataOrganizer/v16/.suo index 6a8e36997d838a847d675ff6aba5d82b0e14a751..a018daed40397f80642270bee0d19d8ba28f5b0e 100644 GIT binary patch delta 1727 zcmZqJ!O^gTV?z!TpMZGd7p7g;7&RFf7!H_Du41ZUJT&<$Q$3^N8>KW%w{wh$e`K^da@U6wVh5``o-1XRw(1n->ek+iW#R|RUM*Znlo{YWI*?bs(O?U8Q44J-%naN_h zk3ShK zDRTw}1`~{sc+S|sIQ`;FMv3XNj7+?f7x*YlzwnY#62uD-1m#4qUIyg@ZVU_zR@3Vk znGSA0@QSg4i6~7@3=9kwP)+X`8<>{cGchqvclgA3V7fgs)4}OJzZf~EbFwkr0ofW;IMg|5>Mg|5RMh1reQ1EXvW7v7d5cg7u6`Hh&eYXTmNa zTF=OMYICXhe?~^l$)%F@j2e@_N>(e%GB7a6F)%R5GcYhHFfcGEGB7YGF)%PFGcYiy zFfcHvf?Tcw^0f{F1A{ID1A`s|1A{&T0|Uq#hEUp=fq`N287T!8kl^MIQZ0;(2AfM| z{xdSFPcD`F&!{%JRKA&M64T~i^1ql^Z5S9Bo=*O$^qbLW^H=41)&X*t0XBC%fw{|+ zS&or&^Uq*mMzK?tesT4;70S5twVf8WscScu>d9WP-K-S)iW#R|E85Ox1 z7#JBC7+4q>7eSA(tVEA)mpCA)ldwA)WzU zwI@R!SZxJ^GeZVLB10ZSI@lBqhJ1!3hAgPL3Jk>zsZf zhIEEv1_g#x22dX11?2!J26^m9QlR}Y_RE43f*B6@FJ=NIc?QObiV~A$h2+IS3ZQDi zp}+*;OqX_KROLqmOa}u4gY$Gp2S#B=hRG9)bXgv}`~QFXhrf(A(+@Z@icIzi;hUaj z&nUzAZ2EskMq}PQhD3$}hGK>chJ1#S?e8IQnE4Mp%F*Y(zKj6XWI^E5K z@z*wA#siGgFMebcnLfdT(P4V+XGV+ZXFM7C7!f*U7VTl0zQL1Ge7d9$FZ= zpYmhevHd_WV_frS+z+m}e?q;u-|Ww5GF{4t@fmWQKWA)UoIc-!(Qy0br;J>Tf+CP~ z4k}y^fQnPW>F0tNO|~C+#n`|ERyTdKKchXP%jAVV^3&@+GD=R*4`SqI(sD)-@Dl_T z4q&4iY!T)dZ$I!3WR5@(qZBBCmQJ4-%&0%T{v)I63f41x!A=HfXkZc|6ej5oWAZeBl~pskBmR3i+eI|_s~fzg3+ zI%6>7en$U^i7LEYj0_Cij0_Asj0_C_HZz8uXXK1_NiEJy&x`dzI5yx5BlmQ^FN`zT z86a|#7x;)WF)~bl_?b~@`n;EnGNAI0VS3&dMjZ*41B@_(PDbTS4NHLjh>7W%l>1RGL za!lv=%eZ5@<4Z;dh^HH0GUgKWFAuVRr?D_eaI!NpFmOQqcb{?k!Ox6O+34ww?Hrs; eOsw0zB$&1_Pgmk)a+|CWE3#dRi|GS1L=XV+gn7*X diff --git a/DataOrganizer/FileViewer.cs b/DataOrganizer/FileViewer.cs index d659eb4..9be3da7 100644 --- a/DataOrganizer/FileViewer.cs +++ b/DataOrganizer/FileViewer.cs @@ -16,7 +16,8 @@ namespace DataOrganizer { private Dictionary Profiles { get; } = new Dictionary(); private Dictionary FolderGroups { get; } = new Dictionary(); - //private Dictionary Folders { get; } = new Dictionary(); + private string CurrentNamingPattern { get; set; } = string.Empty; + private ContextMenu PrimaryTreeContextMenu { get; set; } = new ContextMenu(); //Copy to default new content location, set new naming rules etc.. public FileViewer() { @@ -39,64 +40,52 @@ namespace DataOrganizer private void SelectedFolderComboBox_SelectedIndexChanged(object sender, EventArgs e) { - var folder = FolderGroups[RootFolderComboBox.Text]; - var rootDepth = folder.Path.Split(new char[] { Path.DirectorySeparatorChar }).Length; - var profile = Profiles[ProfileComboBox.Text]; - var includedFolders = new Dictionary(); var db = new DB(); + var folderGroup = FolderGroups[RootFolderComboBox.Text]; + CurrentNamingPattern = db.GetNamingPatternById(folderGroup.PatternId); + var profile = Profiles[ProfileComboBox.Text]; + PrimaryFilesTreeView.Nodes.Clear(); - var files = db.GetFilesForProfileByFolderGroup(profile.Id, folder.Id); - var d = new Snapshot(files, profile, folder); + var files = db.GetFilesForProfileByFolderGroup(profile.Id, folderGroup.Id); + var snapshot = new Snapshot(files, profile, folderGroup); - var currentShowNode = new TreeNode(); - - foreach (var file in files) + foreach(var folder in snapshot.Root.Folders) { - var folders = file.FullPath.Split(new char[] { Path.DirectorySeparatorChar }); - var currentPath = folder.Path; - - if(folders.Length == rootDepth + 1) - { - PrimaryFilesTreeView.Nodes.Add(new TreeNode(folders[rootDepth]) { Name = Path.Combine(currentPath, folders[rootDepth]), ToolTipText = Path.Combine(currentPath, folders[rootDepth]) }); - continue; - } - - var previousPath = string.Empty; - - if (folders.Length >= rootDepth + 1) - { - if (currentShowNode.Text != folders[rootDepth]) - { - currentShowNode = new TreeNode(folders[rootDepth]) { Name = Path.Combine(currentPath, folders[rootDepth]), ToolTipText = Path.Combine(currentPath, folders[rootDepth]) }; - includedFolders.Add(Path.Combine(currentPath, folders[rootDepth]), currentShowNode); - PrimaryFilesTreeView.Nodes.Add(currentShowNode); - } - } - - for(var i = rootDepth; i < folders.Length - 1; i++) - { - previousPath = currentPath; - currentPath = Path.Combine(currentPath, folders[i]); - - if(!includedFolders.ContainsKey(currentPath)) - { - var newNode = new TreeNode(folders[i]) { Name = currentPath, ToolTipText = currentPath }; - - if (includedFolders.ContainsKey(previousPath)) - { - includedFolders[previousPath].Nodes.Add(newNode); - includedFolders.Add(currentPath, newNode); - } - } - } - - var node = includedFolders[currentPath]; - node.Nodes.Add(new TreeNode(folders[folders.Length - 1]) { Name = Path.Combine(currentPath, folders[folders.Length - 1]), ToolTipText = Path.Combine(currentPath, folders[folders.Length - 1]) }); + PrimaryFilesTreeView.Nodes.Add(GetNodeFromSnapshot(folder)); } } + private TreeNode GetNodeFromSnapshot(KeyValuePair folder) + { + var node = new TreeNode(folder.Value.Name) { Name = folder.Key, ToolTipText = folder.Key }; + var regex = new Regex(CurrentNamingPattern); + + foreach(var f in folder.Value.Folders) + { + var folderNode = GetNodeFromSnapshot(f); + node.Nodes.Add(folderNode); + if (folderNode.ForeColor == Color.Orange) + { + node.ForeColor = folderNode.ForeColor; + node.ToolTipText = "Naming violations found!"; + } + } + + foreach(var file in folder.Value.Files) + { + var fileNode = new TreeNode(file.Value.Name) { Name = file.Key, ToolTipText = file.Key }; + + if (!regex.IsMatch(file.Value.Name)) fileNode.ForeColor = Color.Orange; + + node.Nodes.Add(fileNode); + node.ForeColor = fileNode.ForeColor; + } + + return node; + } + private void ProfileComboBox_SelectedIndexChanged(object sender, EventArgs e) { var profile = Profiles[ProfileComboBox.Text];