Added: icon database support

This commit is contained in:
Ray committed 2021-09-21 14:53:18 +01:00
1 parent 4dd399f537
commit 253365d25e
3 files changed
+80 -80

No files matched your search

+36 -39
View File
@@ -207,10 +207,8 @@ namespace RyzStudio.Windows.Forms
protected const string DEFAULT_NEW_FOLDER_NAME = "New Folder";
protected const string PATH_SEPARATOR = "\n";
public event EventHandler OnNodeChanged = null;
//protected IconDatabase iconDatabase = null;
protected TreeNode draggingNode = null;
protected bool hasChanged = false;
@@ -616,9 +614,9 @@ namespace RyzStudio.Windows.Forms
// this.HasChanged = false;
//}
public void AddItem(BookmarkItem item)
public TreeNode AddItem(BookmarkItem item)
{
int iconIndex = addIcon(item);
int iconIndex = FindIcon(item);
TreeNode tn = new TreeNode(item.SiteName, iconIndex, iconIndex);
tn.Tag = item;
@@ -629,22 +627,23 @@ namespace RyzStudio.Windows.Forms
ThreadControl.Add(tn2, tn);
this.HasChanged = true;
return tn;
}
public TreeNode AddItem(TreeNode treeNode, BookmarkItem item)
{
if (treeNode == null)
{
return null;
}
if (treeNode == null) return null;
if (item == null) return null;
int iconIndex = addIcon(item);
int iconIndex = FindIcon(item);
TreeNode tn = new TreeNode(item.SiteName, iconIndex, iconIndex);
tn.Tag = item;
tn.ToolTipText = item.ToString();
treeNode.Nodes.Add(tn);
//treeNode.Nodes.Add(tn);
ThreadControl.Add(treeNode, tn);
this.HasChanged = true;
@@ -859,14 +858,12 @@ namespace RyzStudio.Windows.Forms
public new void Sort() => Sort(this.SelectedNode);
public void UpdateItem(TreeNode treeNode, BookmarkItem item, Image image)
public void UpdateItem(TreeNode treeNode, BookmarkItem item)
{
if (treeNode == null)
{
return;
}
if (treeNode == null) return;
if (item == null) return;
int iconIndex = addIcon(item);
int iconIndex = FindIcon(item);
treeNode.Text = item.SiteName;
treeNode.ImageIndex = iconIndex;
@@ -878,9 +875,30 @@ namespace RyzStudio.Windows.Forms
}
protected int addIcon(BookmarkItem viewModel)
protected int FindIcon(BookmarkItem item)
{
return (int)IconSet.Default;
if (this.IconDatabase == null) return (int)IconSet.Default;
if (item == null) return (int)IconSet.Default;
if (string.IsNullOrWhiteSpace(item.SiteName)) return (int)IconSet.Default;
string iconID = Crypto.GetSHA256Hash(item?.SiteName);
Image image = this.IconDatabase.FindIcon(iconID);
if (image == null)
{
return (int)IconSet.Default;
}
if (this.ImageList.Images.ContainsKey(iconID))
{
this.ImageList.Images.RemoveByKey(iconID);
}
ThreadControl.Add(this, this.ImageList, iconID, image);
return this.ImageList.Images.IndexOfKey(iconID);
//return (int)IconSet.Default;
}
//protected int addIcon(BookmarkItemViewModel viewModel) => addIcon(viewModel.ToModel());
@@ -976,27 +994,6 @@ namespace RyzStudio.Windows.Forms
return tn;
}
//protected bool IsNodeChild(TreeNode dragNode, TreeNode dropNode)
//{
// TreeNode tn = dropNode;
// while (true)
// {
// if (tn.Parent == null)
// {
// break;
// }
// if (tn.Equals(dragNode))
// {
// return true;
// }
// tn = tn.Parent;
// }
// return false;
//}
protected void TraverseBookmarkList(List<BookmarkItem> rs, TreeNode node)
{
foreach (TreeNode tn in node.Nodes)