Archived
Fixed save icons not always working
This commit is contained in:
1 parent
ce54eb7ce4
commit
b17ba5665b
3 files changed
+72
-49
No files matched your search
@@ -1,5 +1,7 @@
|
||||
using System.ComponentModel;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using bzit.bomg.Models;
|
||||
using FizzyLauncher;
|
||||
@@ -125,6 +127,8 @@ namespace RyzStudio.Windows.Forms
|
||||
if (MessageBox.Show("Delete?", "Delete?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
this.DeleteNode();
|
||||
|
||||
this.HasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +247,8 @@ namespace RyzStudio.Windows.Forms
|
||||
this.EditNode(treeNode);
|
||||
}
|
||||
|
||||
this.HasChanged = true;
|
||||
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
@@ -272,6 +278,8 @@ namespace RyzStudio.Windows.Forms
|
||||
|
||||
this.SelectedNode = newNode;
|
||||
|
||||
this.HasChanged = true;
|
||||
|
||||
return newNode;
|
||||
}
|
||||
}
|
||||
@@ -282,29 +290,11 @@ namespace RyzStudio.Windows.Forms
|
||||
public TreeNode AddNode(BookmarkModel model)
|
||||
{
|
||||
var parentNode = this.CreateNodePath(model?.Path?.Trim() ?? string.Empty, (int)NodeIcon.Folder1, (int)NodeIcon.Folder2);
|
||||
int iconIndex = (int)NodeIcon.Default;
|
||||
|
||||
// Add custom favicon
|
||||
if (model.Icon != null)
|
||||
{
|
||||
var iconKey = model.Id.ToString();
|
||||
if (!string.IsNullOrWhiteSpace(iconKey))
|
||||
{
|
||||
if (this.ImageList.Images.ContainsKey(iconKey))
|
||||
{
|
||||
this.ImageList.Images.RemoveByKey(iconKey);
|
||||
}
|
||||
var n = AddImage(model.Id.ToString(), model.Icon);
|
||||
|
||||
UIControl.Invoke(this, (x) =>
|
||||
{
|
||||
this.ImageList.Images.Add(iconKey, model.Icon);
|
||||
});
|
||||
|
||||
iconIndex = this.ImageList.Images.IndexOfKey(iconKey);
|
||||
}
|
||||
}
|
||||
|
||||
TreeNode newNode = new TreeNode(model?.Title?.Trim() ?? string.Empty, iconIndex, iconIndex);
|
||||
TreeNode newNode = new TreeNode(model?.Title?.Trim() ?? string.Empty, n, n);
|
||||
newNode.Tag = model;
|
||||
newNode.ToolTipText = model.ToString();
|
||||
|
||||
@@ -404,10 +394,6 @@ namespace RyzStudio.Windows.Forms
|
||||
if (node == null)
|
||||
{
|
||||
node = this.SelectedNode;
|
||||
}
|
||||
|
||||
if (node == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -416,28 +402,18 @@ namespace RyzStudio.Windows.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
var iconKey = "default";
|
||||
if (model.Id == Guid.Empty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update custom favicon
|
||||
var key = model.Id.ToString();
|
||||
if (!string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
if (model.Icon != null)
|
||||
{
|
||||
UIControl.Invoke(this, (x) =>
|
||||
{
|
||||
this.ImageList.Images.Add(key, model.Icon);
|
||||
});
|
||||
|
||||
iconKey = key;
|
||||
}
|
||||
}
|
||||
var n = AddImage(model.Id.ToString(), model.Icon);
|
||||
|
||||
UIControl.Invoke(this, (x) =>
|
||||
{
|
||||
node.Text = model.Title;
|
||||
node.ImageKey = iconKey;
|
||||
node.SelectedImageKey = iconKey;
|
||||
node.ImageIndex = node.SelectedImageIndex = n;
|
||||
node.Tag = model;
|
||||
node.ToolTipText = model.ToString();
|
||||
});
|
||||
@@ -458,5 +434,39 @@ namespace RyzStudio.Windows.Forms
|
||||
});
|
||||
}
|
||||
|
||||
private int AddImage(string key, Image image)
|
||||
{
|
||||
if (image == null)
|
||||
{
|
||||
return (int)NodeIcon.Default;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (image.Width <= 0)
|
||||
{
|
||||
return (int)NodeIcon.Default;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return (int)NodeIcon.Default;
|
||||
}
|
||||
|
||||
UIControl.Invoke(this, (x) =>
|
||||
{
|
||||
if (this.ImageList.Images.ContainsKey(key))
|
||||
{
|
||||
var n = this.ImageList.Images.IndexOfKey(key);
|
||||
|
||||
this.ImageList.Images.SetKeyName(n, ".deleted");
|
||||
}
|
||||
|
||||
this.ImageList.Images.Add(key, image);
|
||||
});
|
||||
|
||||
return this.ImageList.Images.IndexOfKey(key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user