Fixed: wrong icon on second load

This commit is contained in:
Ray 2021-09-30 23:09:55 +01:00
parent 01cb902536
commit d4c3870732
3 changed files with 61 additions and 161 deletions

View File

@ -1197,17 +1197,22 @@ namespace FizzyLauncher
Image icon = null;
// retrieve icon from DB
if (!string.IsNullOrWhiteSpace(model.SiteAddress))
{
string iconID = model?.ToHash();
string iconID = model?.ToHash();
icon = iconDatabase.FindIcon(iconID);
}
icon = iconDatabase.FindIcon(iconID);
//if (!string.IsNullOrWhiteSpace(model.SiteAddress))
//{
// string iconID = model?.ToHash();
// icon = iconDatabase.FindIcon(iconID);
//}
BookmarkForm bookmarkForm = new BookmarkForm(model, icon);
if (bookmarkForm.ShowDialog() == DialogResult.OK)
{
string iconID = bookmarkForm.Model.Item?.ToHash();
//string iconID = bookmarkForm.Model.Item?.ToHash();
iconID = bookmarkForm.Model.Item?.ToHash();
if (!string.IsNullOrWhiteSpace(iconID))
{
iconDatabase.AddIcon(iconID, bookmarkForm.Model.Icon);

View File

@ -217,6 +217,20 @@ namespace RyzStudio.Windows.Forms
return rv;
}
public static void Add(TreeView parentControl, ImageList control, Image value)
{
if (parentControl.InvokeRequired)
{
parentControl.Invoke(new MethodInvoker(() => {
control.Images.Add(value);
}));
}
else
{
control.Images.Add(value);
}
}
public static void Add(Control parentControl, ImageList control, string key, Image value)
{
if (parentControl.InvokeRequired)
@ -260,6 +274,20 @@ namespace RyzStudio.Windows.Forms
}
}
public static void Clear(TreeView parentControl, ImageList control)
{
if (parentControl.InvokeRequired)
{
parentControl.Invoke(new MethodInvoker(() => {
control.Images.Clear();
}));
}
else
{
control.Images.Clear();
}
}
public static void Clear(FlowLayoutPanel control)
{
if (control.InvokeRequired)

View File

@ -1,5 +1,4 @@
using BookmarkManager;
using bzit.bomg;
using bzit.bomg.Models;
using System;
using System.Collections.Generic;
@ -230,11 +229,8 @@ namespace RyzStudio.Windows.Forms
this.ImageList.ColorDepth = ColorDepth.Depth32Bit;
this.ImageList.ImageSize = new Size(16, 16);
this.ImageList.TransparentColor = Color.Transparent;
this.ImageList.Images.Clear();
this.ImageList.Images.Add(Resources.hexagon);
this.ImageList.Images.Add(Resources.folder);
this.ImageList.Images.Add(Resources.folder_explore);
this.ImageList.Images.Add(Resources.file_text);
ResetImageList();
}
@ -596,23 +592,6 @@ namespace RyzStudio.Windows.Forms
return node.Nodes.Add(EncodePath(name), name, (int)IconSet.Folder1, (int)IconSet.Folder2);
}
//public void AddItem(List<BookmarkItemViewModel> viewModelList)
//{
// this.Clear();
// if (viewModelList == null)
// {
// return;
// }
// foreach (BookmarkItemViewModel item in viewModelList)
// {
// AddItem(item);
// }
// this.HasChanged = false;
//}
public TreeNode AddItem(BookmarkItem item)
{
int iconIndex = FindIcon(item);
@ -649,24 +628,10 @@ namespace RyzStudio.Windows.Forms
return tn;
}
//public void AddOrUpdateItem(TreeNode treeNode, BookmarkItemViewModel viewModel)
//{
// switch (GetNodeType(treeNode))
// {
// case NodeType.Root:
// case NodeType.Folder:
// AddItem(treeNode, viewModel);
// break;
// case NodeType.Page:
// UpdateItem(treeNode, viewModel);
// break;
// default:
// break;
// }
//}
public void Clear()
{
ResetImageList();
ThreadControl.Clear(this);
this.HasChanged = false;
@ -674,6 +639,11 @@ namespace RyzStudio.Windows.Forms
public void Clear(string name)
{
ResetImageList();
var tt1 = this.ImageList;
ThreadControl.Clear(this);
ThreadControl.Add(this, this.Nodes, "", name?.Trim(), (int)IconSet.Root, (int)IconSet.Root);
@ -685,23 +655,6 @@ namespace RyzStudio.Windows.Forms
//iconDatabase.Close();
}
//public int CountBookmarkItem()
//{
// int itemCount = 0;
// if (this.Nodes.Count <= 0)
// {
// return itemCount;
// }
// foreach (TreeNode item in this.Nodes)
// {
// TraverseBookmarkList(ref itemCount, item);
// }
// return itemCount;
//}
public void DeleteNode() => DeleteNode(this.SelectedNode);
public void EditNode()
@ -759,23 +712,6 @@ namespace RyzStudio.Windows.Forms
return rs;
}
//public List<TreeNode> GetBookmarkNodeList()
//{
// List<TreeNode> rs = new List<TreeNode>();
// if (this.Nodes.Count <= 0)
// {
// return rs;
// }
// foreach (TreeNode item in this.Nodes)
// {
// traverseBookmarkList(rs, item);
// }
// return rs;
//}
public bool FindTextNode(TreeNode node, string term)
{
if (node == null)
@ -888,54 +824,16 @@ namespace RyzStudio.Windows.Forms
return (int)IconSet.Default;
}
if (this.ImageList.Images.ContainsKey(iconID)) this.ImageList.Images.RemoveByKey(iconID);
if (this.ImageList.Images.ContainsKey(iconID))
{
this.ImageList.Images.RemoveByKey(iconID);
}
ThreadControl.Add(this, this.ImageList, iconID, image);
return this.ImageList.Images.IndexOfKey(iconID);
}
//protected int addIcon(BookmarkItemViewModel viewModel) => addIcon(viewModel.ToModel());
//protected int addIcon(BookmarkItemModel model)
//{
// return (int)IconSet.Default;
// if (this.ImageList.Images.ContainsKey(model.SiteAddress))
// {
// return this.ImageList.Images.IndexOfKey(model.SiteAddress);
// }
// //if (iconDatabase.HasIcon(model.SiteAddress))
// //{
// // Image rs = iconDatabase.GetIcon(model.SiteAddress);
// // if (rs == null)
// // {
// // return (int)IconSet.Default;
// // }
// // else
// // {
// // this.Add(this.ImageList, model.SiteAddress, rs);
// // return this.ImageList.Images.IndexOfKey(model.SiteAddress);
// // }
// //}
// byte[] rawData;
// Bitmap bmp = model.RetrieveFavicon(out rawData);
// if (bmp == null)
// {
// return (int)IconSet.Default;
// }
// ThreadControl.Add(this, this.ImageList, model.SiteAddress, bmp);
// //iconDatabase.AddIcon(model.SiteAddress, rawData);
// return this.ImageList.Images.IndexOfKey(model.SiteAddress);
//}
protected TreeNode AddFolderPath(string path)
{
TreeNode tn = null;
@ -988,6 +886,15 @@ namespace RyzStudio.Windows.Forms
return tn;
}
protected void ResetImageList()
{
ThreadControl.Clear(this, this.ImageList);
ThreadControl.Add(this, this.ImageList, Resources.hexagon);
ThreadControl.Add(this, this.ImageList, Resources.folder);
ThreadControl.Add(this, this.ImageList, Resources.folder_explore);
ThreadControl.Add(this, this.ImageList, Resources.file_text);
}
protected void TraverseBookmarkList(List<BookmarkItem> rs, TreeNode node)
{
foreach (TreeNode tn in node.Nodes)
@ -1010,45 +917,5 @@ namespace RyzStudio.Windows.Forms
}
}
//protected void TraverseBookmarkList(List<TreeNode> rs, TreeNode node)
//{
// foreach (TreeNode tn in node.Nodes)
// {
// NodeType nodeType = GetNodeType(tn);
// if (nodeType == NodeType.Folder)
// {
// TraverseBookmarkList(rs, tn);
// }
// else if (nodeType == NodeType.Page)
// {
// BookmarkItemViewModel nodeTag = GetNodeModel(tn);
// nodeTag.TreeviewPath = GetNodePath(tn);
// if (nodeTag != null)
// {
// rs.Add(tn);
// }
// }
// }
//}
//protected void TraverseBookmarkList(ref int itemCount, TreeNode node)
//{
// foreach (TreeNode tn in node.Nodes)
// {
// NodeType nodeType = GetNodeType(tn);
// if (nodeType == NodeType.Folder)
// {
// TraverseBookmarkList(ref itemCount, tn);
// }
// else if (nodeType == NodeType.Page)
// {
// itemCount++;
// }
// }
//}
}
}