Added support for directories

This commit is contained in:
Ray 2024-12-31 17:47:25 +00:00
parent de42bc7f66
commit 49223ba8f0
3 changed files with 85 additions and 13 deletions

View File

@ -6,6 +6,7 @@ using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using BookmarkManager; using BookmarkManager;
@ -748,9 +749,21 @@ namespace FizzyLauncher
InvalidateOptions(); InvalidateOptions();
// Load items // Clear treeview
treeView1.Clear("New Session"); treeView1.Clear("New Session");
// Load directories
foreach (var item in this.CurrentSession.Directories ?? new List<string>())
{
if (string.IsNullOrWhiteSpace(item))
{
continue;
}
treeView1.CreateNodePath(item, (int)NodeIcon.Folder1, (int)NodeIcon.Folder2);
}
// Load bookmarks
foreach (var item in this.CurrentSession.Items ?? new List<BookmarkModel>()) foreach (var item in this.CurrentSession.Items ?? new List<BookmarkModel>())
{ {
treeView1.AddNode(item); treeView1.AddNode(item);
@ -798,18 +811,11 @@ namespace FizzyLauncher
this.CurrentSession.Width = this.Width; this.CurrentSession.Width = this.Width;
this.CurrentSession.Height = this.Height; this.CurrentSession.Height = this.Height;
var nodeList = treeView1.ToNodeList<BookmarkModel>() ?? new List<KeyValuePair<TreeNode, BookmarkModel>>(); var directoryList = treeView1.GetAllDirectories();
foreach (var node in nodeList) var bookmarkList = treeView1.GetAllNodes();
{
node.Value.Path = treeView1.GetNodePath(node.Key);
if (node.Value.Path.Contains('\n')) this.CurrentSession.Directories = directoryList ?? new List<string>();
{ this.CurrentSession.Items = bookmarkList.Select(x => x.Value)?.ToList() ?? new List<BookmarkModel>();
node.Value.Path = node.Value.Path.Substring(0, node.Value.Path.LastIndexOf('\n'));
}
}
this.CurrentSession.Items = nodeList.Select(x => x.Value).ToList();
var result = GenericResult.Create(); var result = GenericResult.Create();
@ -825,7 +831,7 @@ namespace FizzyLauncher
if (result.IsSuccess) if (result.IsSuccess)
{ {
// Add icons to save file // Add icons to save file
var result2 = AddImagesToZipFile(filename, nodeList); var result2 = AddImagesToZipFile(filename, bookmarkList);
if (!result2.IsSuccess) if (!result2.IsSuccess)
{ {
if (showNotices) if (showNotices)

View File

@ -20,6 +20,8 @@ namespace FizzyLauncher.Models
public int Height { get; set; } = 0; public int Height { get; set; } = 0;
public List<string> Directories { get; set; } = new List<string>();
public List<BookmarkModel> Items { get; set; } = new List<BookmarkModel>(); public List<BookmarkModel> Items { get; set; } = new List<BookmarkModel>();
} }

View File

@ -1,10 +1,14 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using bzit.bomg.Models; using bzit.bomg.Models;
using FizzyLauncher; using FizzyLauncher;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Resources = BookmarkManager.AppResource; using Resources = BookmarkManager.AppResource;
namespace RyzStudio.Windows.Forms namespace RyzStudio.Windows.Forms
@ -421,6 +425,53 @@ namespace RyzStudio.Windows.Forms
this.HasChanged = true; this.HasChanged = true;
} }
public List<string> GetAllDirectories()
{
var nodes = GetAllTreeNodes();
nodes = nodes.Where(x => this.GetNodeType(x) == NodeType.Folder)?.ToList() ?? new List<TreeNode>();
var result = new List<string>();
foreach (var item in nodes)
{
result.Add(this.GetNodePath(item));
}
return result;
}
public List<KeyValuePair<TreeNode, BookmarkModel>> GetAllNodes()
{
var result = this.ToNodeList<BookmarkModel>() ?? new List<KeyValuePair<TreeNode, BookmarkModel>>();
foreach (var node in result)
{
node.Value.Path = this.GetNodePath(node.Key);
if (node.Value.Path.Contains('\n'))
{
node.Value.Path = node.Value.Path.Substring(0, node.Value.Path.LastIndexOf('\n'));
}
}
return result;
}
public List<TreeNode> GetAllTreeNodes()
{
var result = new List<TreeNode>();
if (this.Nodes.Count <= 0)
{
return result;
}
foreach (TreeNode node in this.Nodes)
{
TraverseNodeTree(result, node);
}
return result;
}
private void ClearImageList() private void ClearImageList()
{ {
@ -468,5 +519,18 @@ namespace RyzStudio.Windows.Forms
return this.ImageList.Images.IndexOfKey(key); return this.ImageList.Images.IndexOfKey(key);
} }
protected void TraverseNodeTree(List<TreeNode> result, TreeNode node)
{
foreach (TreeNode node2 in node.Nodes)
{
result.Add(node2);
foreach (TreeNode node3 in node2.Nodes)
{
result.Add(node3);
}
}
}
} }
} }