Example #1
0
        private void LoadDirectory(DirectoryInfo dirInfo)
        {
            ShowLoading();

            form.SuspendLayout();

            var loadedTags = (Settings.Default.Tags != null) ? Settings.Default.Tags : new List <string>();

            form.tagPanel.ReorderButtons = false;

            // Remove all tags that aren't included in the loaded tags.
            Tags.RemoveRange(Tags.Where(t => !loadedTags.Contains(t)));

            // Add all tags that are in loaded tags but not in current tags.
            //Tags.AddRange(loadedTags.Where(t => !Tags.Contains(t)).ToList());
            for (int i = 0; i < loadedTags.Count; i++)
            {
                if (!Tags.Contains(loadedTags[i]))
                {
                    Tags.Add(loadedTags[i]);
                }
            }

            form.tagPanel.ReorderButtons = true;
            form.tagPanel.ReorderTagButtons();

            // Empty all Subfolders and load custom ones from settings.
            //while (Subfolders.Count > 0)
            //Subfolders.RemoveAt(0);
            Subfolders.Clear();

            var sfnames       = Settings.Default.SubfolderNames ?? new List <string>();
            var sfdirectories = Settings.Default.SubfolderDirectories ?? new List <string>();

            for (int i = 0; i < Math.Min(sfnames.Count, sfdirectories.Count); i++)
            {
                Subfolders.Add(new SubfolderInfo(sfnames[i], sfdirectories[i], true));
            }

            // Load info specific to chosen directory.

            if (dirInfo == null)
            {
                Logs.Log("Directory open cancelled.");
                this.files = new List <string>();
            }
            else
            {
                this.directory = dirInfo.FullName;
                this.files     = dirInfo.GetFileNamesList();

                string[] folders = dirInfo.GetFolderNames();
                for (int i = 0; i < folders.Length; i++)
                {
                    Subfolders.Add(new SubfolderInfo(folders[i], Path.Combine(directory, folders[i]), false));
                }

                fileIndex = 0;

                Logs.Log($"Opened '{directory}' and found {files.Count} files and {folders.Length} subdirectories.");
            }

            form.ResumeLayout();

            HideLoading();
        }