WIP: rebuild with json, model and viewmodel
This commit is contained in:
parent
48416abccb
commit
050bff5a00
@ -136,7 +136,7 @@ namespace bzit.bomg
|
|||||||
BookmarkTreeView bookmarkTreeView = (BookmarkTreeView)parentNode.TreeView;
|
BookmarkTreeView bookmarkTreeView = (BookmarkTreeView)parentNode.TreeView;
|
||||||
if (bookmarkTreeView != null)
|
if (bookmarkTreeView != null)
|
||||||
{
|
{
|
||||||
parentNode.ImageIndex = parentNode.SelectedImageIndex = bookmarkTreeView.AddToIconList(bookmarkItem);
|
//##parentNode.ImageIndex = parentNode.SelectedImageIndex = bookmarkTreeView.AddToIconList(bookmarkItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Close();
|
this.Close();
|
||||||
|
@ -1,125 +1,219 @@
|
|||||||
|
using bzit.bomg.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace bzit.bomg
|
namespace bzit.bomg
|
||||||
{
|
{
|
||||||
public partial class BookmarkTreeView : RyzStudio.Windows.Forms.MovableTreeView
|
public partial class BookmarkTreeView : RyzStudio.Windows.Forms.MovableTreeView
|
||||||
{
|
{
|
||||||
protected ImageList iconList = null;
|
protected IconDatabase iconDatabase = null;
|
||||||
|
|
||||||
public BookmarkTreeView()
|
public BookmarkTreeView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
this.iconList = new ImageList();
|
if (this.ImageList == null)
|
||||||
this.iconList.ColorDepth = ColorDepth.Depth16Bit;
|
{
|
||||||
this.iconList.ImageSize = new Size(16, 16);
|
this.ImageList = new ImageList();
|
||||||
this.iconList.TransparentColor = Color.Transparent;
|
}
|
||||||
|
|
||||||
this.iconList.Images.Clear();
|
this.ImageList.ColorDepth = ColorDepth.Depth16Bit;
|
||||||
this.iconList.Images.Add(Properties.Resources.transmit_blue);
|
this.ImageList.ImageSize = new Size(16, 16);
|
||||||
this.iconList.Images.Add(Properties.Resources.folder);
|
this.ImageList.TransparentColor = Color.Transparent;
|
||||||
this.iconList.Images.Add(Properties.Resources.folder_explore);
|
|
||||||
//// this.iconList.Images.Add(Properties.Resources.page_white_gray_green);
|
|
||||||
this.iconList.Images.Add(Properties.Resources.page_white_world_bw);
|
|
||||||
|
|
||||||
this.ImageList = this.iconList;
|
this.ImageList.Images.Clear();
|
||||||
|
this.ImageList.Images.Add(Properties.Resources.transmit_blue);
|
||||||
|
this.ImageList.Images.Add(Properties.Resources.folder);
|
||||||
|
this.ImageList.Images.Add(Properties.Resources.folder_explore);
|
||||||
|
this.ImageList.Images.Add(Properties.Resources.page_white_world_bw);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region encapsulation
|
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||||
|
public new ImageList ImageList { get => base.ImageList; set => base.ImageList = value; }
|
||||||
|
|
||||||
[Browsable(false)]
|
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
|
||||||
public new ImageList ImageList
|
|
||||||
{
|
{
|
||||||
get { return base.ImageList; }
|
base.OnPreviewKeyDown(e);
|
||||||
set { base.ImageList = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
TreeNode tn = this.SelectedNode;
|
||||||
|
if (tn == null)
|
||||||
#region public properties
|
|
||||||
|
|
||||||
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(null)]
|
|
||||||
public IconDatabase IconDatabase { get; set; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region integrated behaviour
|
|
||||||
|
|
||||||
protected override void OnAddItemNode(TreeNode node)
|
|
||||||
{
|
|
||||||
base.OnAddItemNode(node);
|
|
||||||
|
|
||||||
BookmarkItem bi = new BookmarkItem();
|
|
||||||
node.Tag = bi;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public void AddBookmarkItem(string name, BookmarkItem tag)
|
|
||||||
{
|
|
||||||
if (this.Nodes.Count <= 0)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeNode tn = AddBookmarkPageFullPath(name.Trim(), 3);
|
switch (e.KeyCode)
|
||||||
tn.Tag = tag;
|
|
||||||
tn.ToolTipText = tag.SiteAddress + Environment.NewLine + tag.Description;
|
|
||||||
|
|
||||||
// load icon
|
|
||||||
if (this.IconDatabase.HasIcon(tag.SiteAddress))
|
|
||||||
{
|
{
|
||||||
try
|
case Keys.Insert:
|
||||||
{
|
if (e.Modifiers == Keys.Shift)
|
||||||
Image icon = this.IconDatabase.GetIcon(tag.SiteAddress);
|
|
||||||
if (icon != null)
|
|
||||||
{
|
{
|
||||||
tn.TreeView.ImageList.Images.Add(tag.SiteAddress, icon);
|
// do nothing
|
||||||
tn.ImageKey = tn.SelectedImageKey = tag.SiteAddress;
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
catch
|
{
|
||||||
{
|
MessageBox.Show("!");
|
||||||
// do nothing
|
//AddBookmarkPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int AddToIconList(BookmarkItem sender)
|
public bool InitialiseIconDatabase(out string message, string filename)
|
||||||
{
|
{
|
||||||
Image rs = null;
|
message = string.Empty;
|
||||||
if (this.IconDatabase.HasIcon(sender.SiteAddress))
|
|
||||||
|
if (string.IsNullOrWhiteSpace(filename))
|
||||||
{
|
{
|
||||||
rs = this.IconDatabase.GetIcon(sender.SiteAddress);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iconDatabase == null)
|
||||||
|
{
|
||||||
|
iconDatabase = new IconDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool rv = false;
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
rv = iconDatabase.LoadFile(filename);
|
||||||
|
if (!rv)
|
||||||
|
{
|
||||||
|
rv = iconDatabase.Create(filename, true, null, true);
|
||||||
|
if (!rv)
|
||||||
|
{
|
||||||
|
message = iconDatabase.LastError;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (this.IconDatabase.AddIcon(sender.SiteAddress, sender.IconData))
|
rv = iconDatabase.Create(filename, true, null, true);
|
||||||
|
if (!rv)
|
||||||
{
|
{
|
||||||
rs = sender.Icon;
|
message = iconDatabase.LastError;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rs != null)
|
return true;
|
||||||
{
|
|
||||||
this.ImageList.Images.Add(sender.SiteAddress, rs);
|
|
||||||
return this.ImageList.Images.IndexOfKey(sender.SiteAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddIcon(BookmarkItem sender)
|
public void AddItem(BookmarkItemViewModel viewModel)
|
||||||
{
|
{
|
||||||
if (this.IconDatabase.HasIcon(sender.SiteAddress))
|
int iconIndex = addIcon(viewModel);
|
||||||
|
|
||||||
|
TreeNode tn = new TreeNode(viewModel.SiteName, iconIndex, iconIndex);
|
||||||
|
tn.Tag = viewModel;
|
||||||
|
tn.ToolTipText = viewModel.ToString();
|
||||||
|
|
||||||
|
TreeNode tn2 = addFolderPath(viewModel.TreeviewPath);
|
||||||
|
|
||||||
|
tn2.Nodes.Add(tn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddItem_OnSelectedNode(BookmarkItemViewModel viewModel)
|
||||||
|
{
|
||||||
|
if (this.SelectedNode == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.IconDatabase.AddIcon(sender.SiteAddress, sender.IconData);
|
if (this.SelectedNode.Tag != null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int iconIndex = addIcon(viewModel);
|
||||||
|
|
||||||
|
TreeNode tn = new TreeNode(viewModel.SiteName, iconIndex, iconIndex);
|
||||||
|
tn.Tag = viewModel;
|
||||||
|
tn.ToolTipText = viewModel.ToString();
|
||||||
|
|
||||||
|
int n = this.SelectedNode.Nodes.Add(tn);
|
||||||
|
|
||||||
|
this.SelectedNode = this.SelectedNode.Nodes[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int addIcon(BookmarkItemViewModel viewModel) => addIcon(viewModel.ToModel());
|
||||||
|
|
||||||
|
protected int addIcon(BookmarkItemModel model)
|
||||||
|
{
|
||||||
|
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.ImageList.Images.Add(model.SiteAddress, rs);
|
||||||
|
|
||||||
|
return this.ImageList.Images.IndexOfKey(model.SiteAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap bmp = model.RetrieveFavicon();
|
||||||
|
if (bmp == null)
|
||||||
|
{
|
||||||
|
return (int)IconSet.Default;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ImageList.Images.Add(model.SiteAddress, bmp);
|
||||||
|
|
||||||
|
return this.ImageList.Images.IndexOfKey(model.SiteAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TreeNode addFolderPath(string path)
|
||||||
|
{
|
||||||
|
TreeNode tn = this.Nodes[0];
|
||||||
|
if (tn == null)
|
||||||
|
{
|
||||||
|
return tn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(path))
|
||||||
|
{
|
||||||
|
return tn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(path.Trim('\\')))
|
||||||
|
{
|
||||||
|
return tn;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] folderList = path.Trim('\\').Split('\\');
|
||||||
|
if (folderList.Length <= 0)
|
||||||
|
{
|
||||||
|
return tn;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string item in folderList)
|
||||||
|
{
|
||||||
|
if (tn.Nodes.ContainsKey(item))
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tn.Nodes.Add(item, item, (int)IconSet.Folder1, (int)IconSet.Folder2);
|
||||||
|
}
|
||||||
|
|
||||||
|
tn = tn.Nodes[item];
|
||||||
|
}
|
||||||
|
|
||||||
|
return tn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
1257
MainForm.Designer.cs
generated
1257
MainForm.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
74
MainForm.cs
74
MainForm.cs
@ -1,3 +1,4 @@
|
|||||||
|
using bzit.bomg.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -32,40 +33,19 @@ namespace bzit.bomg
|
|||||||
// toolbar
|
// toolbar
|
||||||
viewHelpHelpMenuItem.Enabled = File.Exists(Path.ChangeExtension(Application.ExecutablePath, ".chm"));
|
viewHelpHelpMenuItem.Enabled = File.Exists(Path.ChangeExtension(Application.ExecutablePath, ".chm"));
|
||||||
|
|
||||||
string iconDBPath = Path.ChangeExtension(Application.ExecutablePath, ".db");
|
|
||||||
|
|
||||||
bool rs = this.IconDatabase.Create(Path.ChangeExtension(Application.ExecutablePath, "db"), false, null, true);
|
|
||||||
if (!rs)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Can not find icon database. [" + this.IconDatabase.LastError + "]");
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
//bool rv = false;
|
bool rv = false;
|
||||||
// if (File.Exists(iconDBPath))
|
string iconDBFilename = Path.ChangeExtension(Application.ExecutablePath, ".db");
|
||||||
// {
|
|
||||||
// rv = this.IconDatabase.LoadFile(iconDBPath);
|
string errorMessage;
|
||||||
// if (!rv)
|
rv = treeView1.InitialiseIconDatabase(out errorMessage, iconDBFilename);
|
||||||
// {
|
if (!rv)
|
||||||
// rv = this.IconDatabase.CreateSpecial(iconDBPath, true);
|
{
|
||||||
// if (!rv)
|
MessageBox.Show("Can not find icon database. [" + this.IconDatabase.LastError + "]");
|
||||||
// {
|
this.Close();
|
||||||
// MessageBox.Show("Can not find icon database. [" + this.IconDatabase.LastError + "]");
|
}
|
||||||
// this.Close();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// rv = this.IconDatabase.CreateSpecial(iconDBPath, true);
|
|
||||||
// if (!rv)
|
|
||||||
// {
|
|
||||||
// MessageBox.Show("Can not find icon database. [" + this.IconDatabase.LastError + "]");
|
|
||||||
// this.Close();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
treeView1.IconDatabase = this.IconDatabase;
|
|
||||||
sessionFileFormat = new SessionFileFormat(this);
|
sessionFileFormat = new SessionFileFormat(this);
|
||||||
this.ApplicationMode = AppMode.Clear;
|
this.ApplicationMode = AppMode.Clear;
|
||||||
|
|
||||||
@ -521,10 +501,10 @@ namespace bzit.bomg
|
|||||||
/**
|
/**
|
||||||
* Node -> Delete
|
* Node -> Delete
|
||||||
*/
|
*/
|
||||||
private void toolStripMenuItem6_Click(object sender, EventArgs e)
|
private void toolStripMenuItem6_Click(object sender, EventArgs e) => treeView1.SNode.Delete();
|
||||||
{
|
//{
|
||||||
treeView1.DeleteNode();
|
// treeView1.DeleteNode();
|
||||||
}
|
//}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -533,12 +513,12 @@ namespace bzit.bomg
|
|||||||
/**
|
/**
|
||||||
* Add Page
|
* Add Page
|
||||||
*/
|
*/
|
||||||
private void toolStripMenuItem15_Click(object sender, EventArgs e) { treeView1.AddBookmarkPage(); }
|
//private void toolStripMenuItem15_Click(object sender, EventArgs e) { treeView1.AddBookmarkPage(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Folder
|
* Add Folder
|
||||||
*/
|
*/
|
||||||
private void toolStripMenuItem16_Click(object sender, EventArgs e) { treeView1.AddFolder(); }
|
//private void toolStripMenuItem16_Click(object sender, EventArgs e) => treeView1.SelectedNode = treeView1.SNode.AddFolder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open All
|
* Open All
|
||||||
@ -573,17 +553,17 @@ namespace bzit.bomg
|
|||||||
/**
|
/**
|
||||||
* Move Up
|
* Move Up
|
||||||
*/
|
*/
|
||||||
private void toolStripMenuItem12_Click(object sender, EventArgs e) { treeView1.MoveNodeUp(); }
|
private void toolStripMenuItem12_Click(object sender, EventArgs e) => treeView1.SNode.MoveUp();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move Down
|
* Move Down
|
||||||
*/
|
*/
|
||||||
private void toolStripMenuItem13_Click(object sender, EventArgs e) { treeView1.MoveNodeDown(); }
|
private void toolStripMenuItem13_Click(object sender, EventArgs e) => treeView1.SNode.MoveDown();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort
|
* Sort
|
||||||
*/
|
*/
|
||||||
private void sortToolStripMenuItem_Click(object sender, EventArgs e) { treeView1.SortNode(); }
|
private void sortToolStripMenuItem_Click(object sender, EventArgs e) => treeView1.SNode.Sort();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -844,5 +824,19 @@ namespace bzit.bomg
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toolStripButton1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
BookmarkItemModel model = new BookmarkItemModel()
|
||||||
|
{
|
||||||
|
SiteAddress = "http://www.hiimray.co.uk",
|
||||||
|
TreeviewPath = @"\hello\momo\"
|
||||||
|
};
|
||||||
|
model.Update();
|
||||||
|
|
||||||
|
treeView1.AddItem_OnSelectedNode(model.ToViewModel());
|
||||||
|
|
||||||
|
//MessageBox.Show(treeView1.Nodes.Count.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -131,7 +131,7 @@
|
|||||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
|
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
|
||||||
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
||||||
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADU
|
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADU
|
||||||
FwAAAk1TRnQBSQFMAgEBBwEAAWQBAgFkAQIBEAEAARABAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAFA
|
FwAAAk1TRnQBSQFMAgEBBwEAAWwBAgFsAQIBEAEAARABAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAFA
|
||||||
AwABIAMAAQEBAAEQBgABEBQAAZkBSgEYAS4BtwEdAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3
|
AwABIAMAAQEBAAEQBgABEBQAAZkBSgEYAS4BtwEdAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3
|
||||||
ARkBtwEdARcBLgGZAUoEAAGZAUoBGAEuAbcBHQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZ
|
ARkBtwEdARcBLgGZAUoEAAGZAUoBGAEuAbcBHQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZ
|
||||||
AbcBHQEXAS4BmQFKBAABmQFKARgBLgG3AR0BtwEZAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3
|
AbcBHQEXAS4BmQFKBAABmQFKARgBLgG3AR0BtwEZAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3
|
||||||
@ -268,15 +268,30 @@
|
|||||||
<data name="newMenuBarItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
<data name="newMenuBarItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
<value>
|
<value>
|
||||||
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||||
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHYSURBVDhPjZO7SxxRFMZNrPI/KKQShBDElS1FEAtBiwQt
|
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHZSURBVDhPjZM9SxxRFIaNqfIfIlgJQpDgypZBEAshFkpS
|
||||||
QiCQFAnY+cAiZcRKm7AsS5qQLpAiYJ9GJEQiOoOKL1DEYtd9ubM7j3vvzOiXcy7OOONuSA782GLO99vv
|
SECIhYJdolikjFiZJizLYiPpAikC6W1EQiQhM4tK/AAlWOy6X+7szse9d2b09ZxLZpxxNyQHHraY8z77
|
||||||
3p3tSkwPkSGy/+Ax8ZBom4zneZZhGNdhGKITUkrkcrmPtNtRkuWw4zhwXTem2Wyi0WigXC5rSalUQj6f
|
3ruzPYl5SGSI7D/oJ3qJjsl4nmcZhnEVhiG6IaVELpd7T7tdJVkOO44D13VjWq0Wms0mKpWKlpTLZeTz
|
||||||
b5M8ILK8IISAUkp/MrZtw7IsVCoVLaCW4C8pFAqRRI8WBE0T8mpLCyIJB1qtFqrVauo4DGd0mkYLxPEc
|
+Q7JPSLLC0IIKKX0J2PbNizLQrVa1QJqCf6SQqEQSfRoQdAqQl7+0IJIwoF2u41arZY6DsMZnabRAnH8
|
||||||
xMG7eCEIAn3u6Ci1Wk03KRaLd4Kbi9lH9t7LkZ3vo5/l4VvI3ReQZyvw6z8R+k5Kwk34Pur1+p1AHr35
|
GuLXQrwQBIE+d3SUer2um5RKpVvB9fmrB/b+i1Hj89imPJyH3JuBPFuH3/iK0HdSEm7C99FoNG4F8mhu
|
||||||
pI5mIE/m4Z+vQJ1+gNh5BmdjEGJvMdWEj8N3wqJYAEx3e7vP1+TJAglWSbAEz5yCZ7xGGCi9yPi+r++F
|
Qx0tQp4swf+9DnX6FsKYgrMzDLG/kmrCx+E7YVEsAJ7f9/amv8iTZRK8I8EqvOIzeOZLhIHSi4zv+/pe
|
||||||
JUws4LnannwqzAmosyWo4/dw1p/At/bjMMMtosvlNimB83tsXBiTcH8NwN7op/oZqMsfOhTBDRgOtws2
|
WMLEAp7Ln5NDovgU6mwV6vgNnO1H8K2DOMxwi+hyuU1K4HwfnxDmJNxvj2HvDFL9DNTFlg5FcAOGw52C
|
||||||
h18ZX/u+hLKGgBCHy5AX39rCSVICmvhFuk+yRRJ+xhmdptEC0zRv7gv+Bu1ec0anb2eIfh6XH3QKJOEd
|
3Sez5seBD6GsIyDE4Rrk+aeOcJKUgCZ+ke6SbJGEn3FGp2m0wDTN67uCv0G7V5zR6T8zQj+Pyw+6BZLw
|
||||||
ep1tyvC/N55eYohg6/9A4a7eP4kvnS+BaQv8AAAAAElFTkSuQmCC
|
Dr3ONmX43xtPHzFCsPV/oHBP3w1tip0dw+Y0hQAAAABJRU5ErkJggg==
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<data name="toolStripButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||||
|
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
|
||||||
|
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
|
||||||
|
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
|
||||||
|
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
|
||||||
|
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
|
||||||
|
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
|
||||||
|
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
|
||||||
|
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
|
||||||
|
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
|
||||||
|
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
|
||||||
</value>
|
</value>
|
||||||
</data>
|
</data>
|
||||||
<metadata name="treeMenuRoot.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="treeMenuRoot.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
314
Models/BookmarkItemModel.cs
Normal file
314
Models/BookmarkItemModel.cs
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
using bzit.bomg.Models;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using HtmlDocument = HtmlAgilityPack.HtmlDocument;
|
||||||
|
|
||||||
|
namespace bzit.bomg
|
||||||
|
{
|
||||||
|
public class BookmarkItemModel : BookmarkItemViewModel
|
||||||
|
{
|
||||||
|
public BookmarkItemModel()
|
||||||
|
{
|
||||||
|
this.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
this.SiteName = string.Empty;
|
||||||
|
this.SiteAddress = string.Empty;
|
||||||
|
this.SiteDescription = string.Empty;
|
||||||
|
this.FaviconAddress = string.Empty;
|
||||||
|
this.TreeviewPath = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public new string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("Name = ");
|
||||||
|
sb.Append(this.SiteName ?? string.Empty);
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
|
||||||
|
sb.Append("Address = ");
|
||||||
|
sb.Append(this.SiteAddress ?? string.Empty);
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
|
||||||
|
sb.Append("Description = ");
|
||||||
|
sb.Append(this.SiteDescription ?? string.Empty);
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookmarkItemViewModel ToViewModel()
|
||||||
|
{
|
||||||
|
return new BookmarkItemViewModel()
|
||||||
|
{
|
||||||
|
SiteName = this.SiteName,
|
||||||
|
SiteAddress = this.SiteAddress,
|
||||||
|
SiteDescription = this.SiteDescription,
|
||||||
|
FaviconAddress = this.FaviconAddress,
|
||||||
|
TreeviewPath = this.TreeviewPath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update()
|
||||||
|
{
|
||||||
|
string sourceCode = retrieveSourceCode();
|
||||||
|
if (string.IsNullOrWhiteSpace(sourceCode))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlDocument document = new HtmlDocument();
|
||||||
|
document.LoadHtml(sourceCode);
|
||||||
|
|
||||||
|
// title
|
||||||
|
this.SiteName = parseSiteTitle(document);
|
||||||
|
|
||||||
|
// description
|
||||||
|
this.SiteDescription = parseSiteDescription(document);
|
||||||
|
|
||||||
|
// favicon
|
||||||
|
this.FaviconAddress = parseSiteIcon(document);
|
||||||
|
if (!string.IsNullOrWhiteSpace(this.FaviconAddress))
|
||||||
|
{
|
||||||
|
Uri iconAddressURI;
|
||||||
|
bool rv = Uri.TryCreate(new Uri(this.SiteAddress), this.FaviconAddress, out iconAddressURI);
|
||||||
|
if (rv)
|
||||||
|
{
|
||||||
|
this.FaviconAddress = iconAddressURI.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap RetrieveFavicon()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(this.FaviconAddress))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] iconData = null;
|
||||||
|
WebClient webClient = new WebClient();
|
||||||
|
webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
iconData = webClient.DownloadData(this.FaviconAddress);
|
||||||
|
|
||||||
|
if (!RyzStudio.IO.FileType.IsImage(iconData))
|
||||||
|
{
|
||||||
|
throw new Exception("Not a supported image");
|
||||||
|
}
|
||||||
|
|
||||||
|
Image img = Image.FromStream(new MemoryStream(iconData));
|
||||||
|
return new Bitmap(img, 16, 16);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
iconData = null;
|
||||||
|
this.FaviconAddress = null;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string retrieveSourceCode()
|
||||||
|
{
|
||||||
|
WebClient webClient = new WebClient();
|
||||||
|
webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return webClient.DownloadString(this.SiteAddress);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//protected string encodePath(string text) => System.Web.HttpUtility.UrlEncode(text);
|
||||||
|
//protected string decodePath(string text) => System.Web.HttpUtility.UrlDecode(text);
|
||||||
|
|
||||||
|
protected string parseTagValue(HtmlDocument doc, string xpath, string defaultValue = "")
|
||||||
|
{
|
||||||
|
HtmlNodeCollection hnc = doc.DocumentNode.SelectNodes(xpath);
|
||||||
|
if (hnc == null)
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hnc.Count <= 0)
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (HtmlNode hn in hnc)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(hn.InnerHtml))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string rs = WebUtility.HtmlDecode(hn.InnerHtml)?.Replace("\r", "")?.Replace("\n", " ")?.Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string parseTagValue_Attr(HtmlDocument doc, string xpath, string attr, string defaultValue = "")
|
||||||
|
{
|
||||||
|
HtmlNodeCollection hnc = doc.DocumentNode.SelectNodes(xpath);
|
||||||
|
if (hnc == null)
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hnc.Count <= 0)
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (HtmlNode hn in hnc)
|
||||||
|
{
|
||||||
|
if (hn.Attributes[attr] == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(hn.Attributes[attr].Value))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return System.Web.HttpUtility.HtmlDecode(hn.Attributes[attr].Value?.Trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string parseSiteTitle(HtmlDocument doc)
|
||||||
|
{
|
||||||
|
string rs = null;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue(doc, "//title", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@property='og:title']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@name='twitter:title']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@property='og:site_name']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@itemprop='name']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string parseSiteDescription(HtmlDocument doc)
|
||||||
|
{
|
||||||
|
string rs = null;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@name='description']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@property='og:description']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@name='twitter:description']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@property='og:description']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@itemprop='description']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string parseSiteIcon(HtmlDocument doc)
|
||||||
|
{
|
||||||
|
string rs = null;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//link[@rel='shortcut icon']", "href", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//link[@rel='icon']", "href", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//link[@rel='apple-touch-icon']", "href", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//link[@rel='apple-touch-icon-precomposed']", "href", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@property='og:image']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@name='twitter:image']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@property='og:image']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rs))
|
||||||
|
{
|
||||||
|
rs = parseTagValue_Attr(doc, "//meta[@itemprop='image']", "content", string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,36 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace RyzStudio
|
|
||||||
{
|
|
||||||
public class String
|
|
||||||
{
|
|
||||||
public static string EncodeTo64(string value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(value);
|
|
||||||
return System.Convert.ToBase64String(toEncodeAsBytes);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string DecodeFrom64(string value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
byte[] encodedDataAsBytes = System.Convert.FromBase64String(value);
|
|
||||||
return System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,14 +7,24 @@ namespace RyzStudio.Windows.Forms
|
|||||||
{
|
{
|
||||||
public class MovableTreeView : System.Windows.Forms.TreeView
|
public class MovableTreeView : System.Windows.Forms.TreeView
|
||||||
{
|
{
|
||||||
|
public enum IconSet
|
||||||
|
{
|
||||||
|
Root = 0,
|
||||||
|
Folder1,
|
||||||
|
Folder2,
|
||||||
|
Default
|
||||||
|
}
|
||||||
|
|
||||||
|
public MovableTreeViewSelectedNode SNode { get; set; }
|
||||||
|
|
||||||
public delegate void NodeCountUpdated(ulong v);
|
public delegate void NodeCountUpdated(ulong v);
|
||||||
|
|
||||||
public EventHandler OnChanged = null;
|
public EventHandler OnChanged = null;
|
||||||
public NodeCountUpdated OnNodeCountUpdate = null;
|
public NodeCountUpdated OnNodeCountUpdate = null;
|
||||||
|
|
||||||
protected const char pathSeparator = '|';
|
protected const char pathSeparator = '|';
|
||||||
protected const int folderImageIndex = 1;
|
//protected const int folderImageIndex = 1;
|
||||||
protected const int folderSelectedImageIndex = 2;
|
//protected const int folderSelectedImageIndex = 2;
|
||||||
|
|
||||||
protected TreeNode draggingNode = null;
|
protected TreeNode draggingNode = null;
|
||||||
protected bool allowBeginEdit = false;
|
protected bool allowBeginEdit = false;
|
||||||
@ -24,6 +34,7 @@ namespace RyzStudio.Windows.Forms
|
|||||||
|
|
||||||
public MovableTreeView()
|
public MovableTreeView()
|
||||||
{
|
{
|
||||||
|
this.SNode = new MovableTreeViewSelectedNode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region public properties
|
#region public properties
|
||||||
@ -55,25 +66,25 @@ namespace RyzStudio.Windows.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Browsable(false)]
|
//[Browsable(false)]
|
||||||
public string[] NodeNameList
|
//public string[] NodeNameList
|
||||||
{
|
//{
|
||||||
get
|
// get
|
||||||
{
|
// {
|
||||||
string[] rv = new string[0];
|
// string[] rv = new string[0];
|
||||||
if (this.Nodes.Count <= 0)
|
// if (this.Nodes.Count <= 0)
|
||||||
{
|
// {
|
||||||
return rv;
|
// return rv;
|
||||||
}
|
// }
|
||||||
|
|
||||||
foreach (TreeNode tn in this.Nodes)
|
// foreach (TreeNode tn in this.Nodes)
|
||||||
{
|
// {
|
||||||
traverseNodeNameList(ref rv, tn);
|
// traverseNodeNameList(ref rv, tn);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return rv;
|
// return rv;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
[Browsable(false)]
|
[Browsable(false)]
|
||||||
public ulong NodeCount
|
public ulong NodeCount
|
||||||
@ -120,110 +131,110 @@ namespace RyzStudio.Windows.Forms
|
|||||||
|
|
||||||
#region public methods
|
#region public methods
|
||||||
|
|
||||||
public TreeNode AddFolder()
|
//public TreeNode AddFolder()
|
||||||
{
|
//{
|
||||||
return this.AddFolder("New Folder " + (new Random()).Next(10001, 99999).ToString());
|
// return this.AddFolder("New Folder " + (new Random()).Next(10001, 99999).ToString());
|
||||||
}
|
//}
|
||||||
|
|
||||||
public TreeNode AddFolder(string name)
|
//public TreeNode AddFolder(string name)
|
||||||
{
|
//{
|
||||||
if (this.SelectedNode == null)
|
// if (this.SelectedNode == null)
|
||||||
{
|
// {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (this.SelectedNode.Tag != null)
|
// if (this.SelectedNode.Tag != null)
|
||||||
{
|
// {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.HasChanged = true;
|
// this.HasChanged = true;
|
||||||
|
|
||||||
TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, folderImageIndex, folderSelectedImageIndex);
|
// TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, folderImageIndex, folderSelectedImageIndex);
|
||||||
this.SelectedNode = tn;
|
// this.SelectedNode = tn;
|
||||||
|
|
||||||
OnAddFolderNode(tn);
|
// OnAddFolderNode(tn);
|
||||||
|
|
||||||
return tn;
|
// return tn;
|
||||||
}
|
//}
|
||||||
|
|
||||||
public TreeNode AddBookmarkPage()
|
//public TreeNode AddBookmarkPage()
|
||||||
{
|
//{
|
||||||
return this.AddBookmarkPage("New Page " + (new Random()).Next(10001, 99999).ToString());
|
// return this.AddBookmarkPage("New Page " + (new Random()).Next(10001, 99999).ToString());
|
||||||
}
|
//}
|
||||||
|
|
||||||
public TreeNode AddBookmarkPage(string name, int icon = 3)
|
//public TreeNode AddBookmarkPage(string name, int icon = 3)
|
||||||
{
|
//{
|
||||||
if (this.SelectedNode == null)
|
// if (this.SelectedNode == null)
|
||||||
{
|
// {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (this.SelectedNode.Tag != null)
|
// if (this.SelectedNode.Tag != null)
|
||||||
{
|
// {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.HasChanged = true;
|
// this.HasChanged = true;
|
||||||
|
|
||||||
TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, icon, icon);
|
// TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, icon, icon);
|
||||||
tn.Tag = new object();
|
// tn.Tag = new object();
|
||||||
tn.ToolTipText = name;
|
// tn.ToolTipText = name;
|
||||||
|
|
||||||
nodeCount++;
|
// nodeCount++;
|
||||||
NodeCountUpdate(nodeCount);
|
// NodeCountUpdate(nodeCount);
|
||||||
|
|
||||||
this.SelectedNode = tn;
|
// this.SelectedNode = tn;
|
||||||
|
|
||||||
OnAddItemNode(tn);
|
// OnAddItemNode(tn);
|
||||||
return tn;
|
// return tn;
|
||||||
}
|
//}
|
||||||
|
|
||||||
public TreeNode AddBookmarkPageFullPath(string name, int icon = 3)
|
//public TreeNode AddBookmarkPageFullPath(string name, int icon = 3)
|
||||||
{
|
//{
|
||||||
if (this.Nodes.Count <= 0)
|
// if (this.Nodes.Count <= 0)
|
||||||
{
|
// {
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.HasChanged = true;
|
// this.HasChanged = true;
|
||||||
|
|
||||||
TreeNode tn2;
|
// TreeNode tn2;
|
||||||
if (!name.Contains(pathSeparator.ToString()))
|
// if (!name.Contains(pathSeparator.ToString()))
|
||||||
{
|
// {
|
||||||
tn2 = this.Nodes[0].Nodes.Add(name, PathDecode(name), icon, icon);
|
// tn2 = this.Nodes[0].Nodes.Add(name, PathDecode(name), icon, icon);
|
||||||
tn2.ToolTipText = name;
|
// tn2.ToolTipText = name;
|
||||||
nodeCount++;
|
// nodeCount++;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
tn2 = this.Nodes[0];
|
// tn2 = this.Nodes[0];
|
||||||
string[] folders = name.Split(pathSeparator);
|
// string[] folders = name.Split(pathSeparator);
|
||||||
for (int x = 0; x < (folders.Length - 1); x++)
|
// for (int x = 0; x < (folders.Length - 1); x++)
|
||||||
{
|
// {
|
||||||
string dr = folders[x].Trim();
|
// string dr = folders[x].Trim();
|
||||||
if (tn2.Nodes.ContainsKey(dr))
|
// if (tn2.Nodes.ContainsKey(dr))
|
||||||
{
|
// {
|
||||||
tn2 = tn2.Nodes[dr];
|
// tn2 = tn2.Nodes[dr];
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
tn2 = tn2.Nodes.Add(dr, PathDecode(dr), folderImageIndex, folderSelectedImageIndex);
|
// tn2 = tn2.Nodes.Add(dr, PathDecode(dr), folderImageIndex, folderSelectedImageIndex);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
string tm = folders[(folders.Length - 1)].Trim();
|
// string tm = folders[(folders.Length - 1)].Trim();
|
||||||
tn2 = tn2.Nodes.Add(tm, PathDecode(tm), icon, icon);
|
// tn2 = tn2.Nodes.Add(tm, PathDecode(tm), icon, icon);
|
||||||
tn2.Tag = new object();
|
// tn2.Tag = new object();
|
||||||
tn2.ToolTipText = tm;
|
// tn2.ToolTipText = tm;
|
||||||
|
|
||||||
nodeCount++;
|
// nodeCount++;
|
||||||
}
|
// }
|
||||||
|
|
||||||
NodeCountUpdate(nodeCount);
|
// NodeCountUpdate(nodeCount);
|
||||||
|
|
||||||
return tn2;
|
// return tn2;
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void EditNode()
|
public void EditNode()
|
||||||
{
|
{
|
||||||
@ -241,113 +252,113 @@ namespace RyzStudio.Windows.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteNode()
|
//public void DeleteNode()
|
||||||
{
|
//{
|
||||||
if (this.SelectedNode == null)
|
// if (this.SelectedNode == null)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (this.Nodes.Count <= 0)
|
// if (this.Nodes.Count <= 0)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (this.SelectedNode.Equals(this.Nodes[0]))
|
// if (this.SelectedNode.Equals(this.Nodes[0]))
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.HasChanged = true;
|
// this.HasChanged = true;
|
||||||
|
|
||||||
this.SelectedNode.Remove();
|
// this.SelectedNode.Remove();
|
||||||
|
|
||||||
if (this.SelectedNode.Tag == null)
|
// if (this.SelectedNode.Tag == null)
|
||||||
{
|
// {
|
||||||
nodeCount = this.NodeCountCalc;
|
// nodeCount = this.NodeCountCalc;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
nodeCount--;
|
// nodeCount--;
|
||||||
}
|
// }
|
||||||
|
|
||||||
NodeCountUpdate(nodeCount);
|
// NodeCountUpdate(nodeCount);
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void SortNode()
|
//public void SortNode()
|
||||||
{
|
//{
|
||||||
TreeNode tn = this.SelectedNode;
|
// TreeNode tn = this.SelectedNode;
|
||||||
string[] tnv = new string[0];
|
// string[] tnv = new string[0];
|
||||||
TreeNode[] tna = new TreeNode[0];
|
// TreeNode[] tna = new TreeNode[0];
|
||||||
|
|
||||||
this.HasChanged = true;
|
// this.HasChanged = true;
|
||||||
|
|
||||||
foreach (TreeNode tn2 in tn.Nodes)
|
// foreach (TreeNode tn2 in tn.Nodes)
|
||||||
{
|
// {
|
||||||
Array.Resize(ref tna, (tna.Length + 1));
|
// Array.Resize(ref tna, (tna.Length + 1));
|
||||||
tna[(tna.Length - 1)] = tn2;
|
// tna[(tna.Length - 1)] = tn2;
|
||||||
|
|
||||||
Array.Resize(ref tnv, (tnv.Length + 1));
|
// Array.Resize(ref tnv, (tnv.Length + 1));
|
||||||
tnv[(tnv.Length - 1)] = tn2.Text;
|
// tnv[(tnv.Length - 1)] = tn2.Text;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Array.Sort(tnv, tna);
|
// Array.Sort(tnv, tna);
|
||||||
|
|
||||||
tn.Nodes.Clear();
|
// tn.Nodes.Clear();
|
||||||
foreach (TreeNode tn2 in tna)
|
// foreach (TreeNode tn2 in tna)
|
||||||
{
|
// {
|
||||||
tn.Nodes.Add(tn2);
|
// tn.Nodes.Add(tn2);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void MoveNodeUp()
|
//public void MoveNodeUp()
|
||||||
{
|
//{
|
||||||
TreeNode tn = this.SelectedNode;
|
// TreeNode tn = this.SelectedNode;
|
||||||
if (tn.Parent == null)
|
// if (tn.Parent == null)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (tn.Index == 0)
|
// if (tn.Index == 0)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.HasChanged = true;
|
// this.HasChanged = true;
|
||||||
|
|
||||||
int n = tn.Index - 1;
|
// int n = tn.Index - 1;
|
||||||
|
|
||||||
TreeNode tn1 = tn.Parent;
|
// TreeNode tn1 = tn.Parent;
|
||||||
tn1.Nodes.Remove(tn);
|
// tn1.Nodes.Remove(tn);
|
||||||
tn1.Nodes.Insert(n, tn);
|
// tn1.Nodes.Insert(n, tn);
|
||||||
|
|
||||||
this.SelectedNode = tn;
|
// this.SelectedNode = tn;
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void MoveNodeDown()
|
//public void MoveNodeDown()
|
||||||
{
|
//{
|
||||||
TreeNode tn = this.SelectedNode;
|
// TreeNode tn = this.SelectedNode;
|
||||||
if (tn.Parent == null)
|
// if (tn.Parent == null)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
TreeNode tn1 = tn.Parent;
|
// TreeNode tn1 = tn.Parent;
|
||||||
|
|
||||||
this.HasChanged = true;
|
// this.HasChanged = true;
|
||||||
|
|
||||||
if (tn.Index >= (tn1.Nodes.Count - 1))
|
// if (tn.Index >= (tn1.Nodes.Count - 1))
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
int n = tn.Index + 1;
|
// int n = tn.Index + 1;
|
||||||
|
|
||||||
tn1.Nodes.Remove(tn);
|
// tn1.Nodes.Remove(tn);
|
||||||
tn1.Nodes.Insert(n, tn);
|
// tn1.Nodes.Insert(n, tn);
|
||||||
|
|
||||||
this.SelectedNode = tn;
|
// this.SelectedNode = tn;
|
||||||
}
|
//}
|
||||||
|
|
||||||
public string GetNodeFullPath(TreeNode node)
|
public string GetNodeFullPath(TreeNode node)
|
||||||
{
|
{
|
||||||
@ -480,7 +491,7 @@ namespace RyzStudio.Windows.Forms
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsNodeChild(draggingNode, en))
|
if (isNodeChild(draggingNode, en))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -589,18 +600,18 @@ namespace RyzStudio.Windows.Forms
|
|||||||
case Keys.Insert:
|
case Keys.Insert:
|
||||||
if (e.Modifiers == Keys.Shift)
|
if (e.Modifiers == Keys.Shift)
|
||||||
{
|
{
|
||||||
AddFolder();
|
this.SelectedNode = this.SNode.AddFolder();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddBookmarkPage();
|
//##AddBookmarkPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Keys.Delete:
|
case Keys.Delete:
|
||||||
if (!tn.IsEditing)
|
if (!tn.IsEditing)
|
||||||
{
|
{
|
||||||
this.DeleteNode();
|
this.SNode.Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -614,14 +625,14 @@ namespace RyzStudio.Windows.Forms
|
|||||||
case Keys.Up:
|
case Keys.Up:
|
||||||
if (e.Modifiers == Keys.Control)
|
if (e.Modifiers == Keys.Control)
|
||||||
{
|
{
|
||||||
this.MoveNodeUp();
|
this.SNode.MoveUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Keys.Down:
|
case Keys.Down:
|
||||||
if (e.Modifiers == Keys.Control)
|
if (e.Modifiers == Keys.Control)
|
||||||
{
|
{
|
||||||
this.MoveNodeDown();
|
this.SNode.MoveDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -638,9 +649,7 @@ namespace RyzStudio.Windows.Forms
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region internals
|
protected bool isNodeChild(TreeNode drag_node, TreeNode drop_node)
|
||||||
|
|
||||||
protected bool IsNodeChild(TreeNode drag_node, TreeNode drop_node)
|
|
||||||
{
|
{
|
||||||
TreeNode tn = drop_node;
|
TreeNode tn = drop_node;
|
||||||
while (true)
|
while (true)
|
||||||
@ -677,21 +686,21 @@ namespace RyzStudio.Windows.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void traverseNodeNameList(ref string[] results, TreeNode node)
|
//protected void traverseNodeNameList(ref string[] results, TreeNode node)
|
||||||
{
|
//{
|
||||||
foreach (TreeNode tn in node.Nodes)
|
// foreach (TreeNode tn in node.Nodes)
|
||||||
{
|
// {
|
||||||
if (tn.Tag == null)
|
// if (tn.Tag == null)
|
||||||
{
|
// {
|
||||||
traverseNodeNameList(ref results, tn);
|
// traverseNodeNameList(ref results, tn);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
Array.Resize(ref results, (results.Length + 1));
|
// Array.Resize(ref results, (results.Length + 1));
|
||||||
results[(results.Length - 1)] = this.GetNodeFullPath(tn);
|
// results[(results.Length - 1)] = this.GetNodeFullPath(tn);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
protected void traverseNodeCount(ref ulong results, TreeNode node)
|
protected void traverseNodeCount(ref ulong results, TreeNode node)
|
||||||
{
|
{
|
||||||
@ -708,19 +717,14 @@ namespace RyzStudio.Windows.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region public methods
|
|
||||||
|
|
||||||
protected virtual void OnAddFolderNode(TreeNode node) { }
|
protected virtual void OnAddFolderNode(TreeNode node) { }
|
||||||
|
|
||||||
protected virtual void OnAddItemNode(TreeNode node) { }
|
protected virtual void OnAddItemNode(TreeNode node) { }
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
////protected string PathEncode(string text) { return RyzStudio.String.EncodeTo64(text); }
|
////protected string PathEncode(string text) { return RyzStudio.String.EncodeTo64(text); }
|
||||||
//protected string PathDecode(string text) { return RyzStudio.String.DecodeFrom64(text); }
|
//protected string PathDecode(string text) { return RyzStudio.String.DecodeFrom64(text); }
|
||||||
protected string PathEncode(string text) { return System.Web.HttpUtility.UrlEncodeUnicode(text); }
|
protected string PathEncode(string text) { return System.Web.HttpUtility.UrlEncode(text); }
|
||||||
protected string PathDecode(string text) { return System.Web.HttpUtility.UrlDecode(text); }
|
protected string PathDecode(string text) { return System.Web.HttpUtility.UrlDecode(text); }
|
||||||
}
|
}
|
||||||
}
|
}
|
194
RyzStudio/Windows/Forms/MovableTreeViewSelectedNode.cs
Normal file
194
RyzStudio/Windows/Forms/MovableTreeViewSelectedNode.cs
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace RyzStudio.Windows.Forms
|
||||||
|
{
|
||||||
|
public class MovableTreeViewSelectedNode
|
||||||
|
{
|
||||||
|
protected MovableTreeView Treeview = null;
|
||||||
|
|
||||||
|
public MovableTreeViewSelectedNode(MovableTreeView treeview)
|
||||||
|
{
|
||||||
|
Treeview = treeview;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TreeNode SelectedNode { get => this.Treeview.SelectedNode; set => this.Treeview.SelectedNode = value; }
|
||||||
|
|
||||||
|
protected string encodeName(string name) => Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(name));
|
||||||
|
|
||||||
|
public TreeNode AddFolder()
|
||||||
|
{
|
||||||
|
//return this.AddFolder("New Folder " + (new Random()).Next(10001, 99999).ToString());
|
||||||
|
return this.AddFolder("New Folder (" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeNode AddFolder(string name)
|
||||||
|
{
|
||||||
|
if (this.SelectedNode == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.SelectedNode.Tag != null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.SelectedNode.Nodes.Add(encodeName(name), name, (int)MovableTreeView.IconSet.Folder1, (int)MovableTreeView.IconSet.Folder2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeNode AddItem(string name, object tag)
|
||||||
|
{
|
||||||
|
if (this.SelectedNode == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.SelectedNode.Tag != null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeNode tn = new TreeNode(name, (int)MovableTreeView.IconSet.Default, (int)MovableTreeView.IconSet.Default);
|
||||||
|
tn.Tag = tag;
|
||||||
|
|
||||||
|
this.SelectedNode.Nodes.Add(tn);
|
||||||
|
|
||||||
|
return tn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//public TreeNode AddPage() => this.AddPage("New Page (" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ")");
|
||||||
|
|
||||||
|
//public TreeNode AddPage(string name)
|
||||||
|
//{
|
||||||
|
// if (this.SelectedNode == null)
|
||||||
|
// {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (this.SelectedNode.Tag != null)
|
||||||
|
// {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// TreeNode tn = this.SelectedNode.Nodes.Add(encodeName(name), name, (int)MovableTreeView.IconSet.Default, (int)MovableTreeView.IconSet.Default);
|
||||||
|
// tn.Tag = new object();
|
||||||
|
// tn.ToolTipText = name;
|
||||||
|
|
||||||
|
// nodeCount++;
|
||||||
|
// NodeCountUpdate(nodeCount);
|
||||||
|
|
||||||
|
// this.SelectedNode = tn;
|
||||||
|
|
||||||
|
// OnAddItemNode(tn);
|
||||||
|
// return tn;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
public void Delete()
|
||||||
|
{
|
||||||
|
if (this.SelectedNode == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.Treeview.Nodes.Count <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.SelectedNode.Equals(this.Treeview.Nodes[0]))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.SelectedNode.Remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveDown()
|
||||||
|
{
|
||||||
|
if (this.SelectedNode == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeNode tn = this.SelectedNode;
|
||||||
|
if (tn.Parent == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeNode tn1 = tn.Parent;
|
||||||
|
|
||||||
|
if (tn.Index >= (tn1.Nodes.Count - 1))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int n = tn.Index + 1;
|
||||||
|
|
||||||
|
tn1.Nodes.Remove(tn);
|
||||||
|
tn1.Nodes.Insert(n, tn);
|
||||||
|
|
||||||
|
this.SelectedNode = tn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveUp()
|
||||||
|
{
|
||||||
|
if (this.SelectedNode == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TreeNode tn = this.SelectedNode;
|
||||||
|
if (tn.Parent == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tn.Index <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int n = tn.Index - 1;
|
||||||
|
|
||||||
|
TreeNode tn1 = tn.Parent;
|
||||||
|
tn1.Nodes.Remove(tn);
|
||||||
|
tn1.Nodes.Insert(n, tn);
|
||||||
|
|
||||||
|
this.SelectedNode = tn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Sort()
|
||||||
|
{
|
||||||
|
if (this.SelectedNode == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] tnv = new string[0];
|
||||||
|
TreeNode[] tna = new TreeNode[0];
|
||||||
|
|
||||||
|
foreach (TreeNode tn2 in this.SelectedNode.Nodes)
|
||||||
|
{
|
||||||
|
Array.Resize(ref tna, (tna.Length + 1));
|
||||||
|
tna[(tna.Length - 1)] = tn2;
|
||||||
|
|
||||||
|
Array.Resize(ref tnv, (tnv.Length + 1));
|
||||||
|
tnv[(tnv.Length - 1)] = tn2.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.Sort(tnv, tna);
|
||||||
|
|
||||||
|
this.SelectedNode.Nodes.Clear();
|
||||||
|
|
||||||
|
foreach (TreeNode tn2 in tna)
|
||||||
|
{
|
||||||
|
this.SelectedNode.Nodes.Add(tn2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -52,7 +52,7 @@ namespace bzit.bomg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parentForm.treeView1.AddBookmarkItem(bi.Fullpath, bi);
|
//##parentForm.treeView1.AddBookmarkItem(bi.Fullpath, bi);
|
||||||
}
|
}
|
||||||
|
|
||||||
tn.Expand();
|
tn.Expand();
|
||||||
|
@ -108,7 +108,7 @@ namespace bzit.bomg
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
parentForm.treeView1.AddIcon(bookmarkItem);
|
//##parentForm.treeView1.AddIcon(bookmarkItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
44
ViewModels/BookmarkItemViewModel.cs
Normal file
44
ViewModels/BookmarkItemViewModel.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace bzit.bomg.Models
|
||||||
|
{
|
||||||
|
public class BookmarkItemViewModel
|
||||||
|
{
|
||||||
|
public string SiteName { get; set; }
|
||||||
|
public string SiteAddress { get; set; }
|
||||||
|
public string SiteDescription { get; set; }
|
||||||
|
public string FaviconAddress { get; set; }
|
||||||
|
public string TreeviewPath { get; set; }
|
||||||
|
|
||||||
|
public BookmarkItemModel ToModel()
|
||||||
|
{
|
||||||
|
return new BookmarkItemModel()
|
||||||
|
{
|
||||||
|
SiteName = this.SiteName,
|
||||||
|
SiteAddress = this.SiteAddress,
|
||||||
|
SiteDescription = this.SiteDescription,
|
||||||
|
FaviconAddress = this.FaviconAddress,
|
||||||
|
TreeviewPath = this.TreeviewPath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public new string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("Name = ");
|
||||||
|
sb.Append(this.SiteName ?? string.Empty);
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
|
||||||
|
sb.Append("Address = ");
|
||||||
|
sb.Append(this.SiteAddress ?? string.Empty);
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
|
||||||
|
sb.Append("Description = ");
|
||||||
|
sb.Append(this.SiteDescription ?? string.Empty);
|
||||||
|
sb.Append(Environment.NewLine);
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -96,6 +96,9 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Models\BookmarkItemModel.cs" />
|
||||||
|
<Compile Include="RyzStudio\Windows\Forms\MovableTreeViewSelectedNode.cs" />
|
||||||
|
<Compile Include="ViewModels\BookmarkItemViewModel.cs" />
|
||||||
<Compile Include="RyzStudio\Data\SQLite\SQLiteDatabase2.cs" />
|
<Compile Include="RyzStudio\Data\SQLite\SQLiteDatabase2.cs" />
|
||||||
<Compile Include="UpdateIconForm.cs">
|
<Compile Include="UpdateIconForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
@ -142,7 +145,6 @@
|
|||||||
<Compile Include="RyzStudio\IO\FileType.cs" />
|
<Compile Include="RyzStudio\IO\FileType.cs" />
|
||||||
<Compile Include="RyzStudio\IO\SessionFileFormatBase.cs" />
|
<Compile Include="RyzStudio\IO\SessionFileFormatBase.cs" />
|
||||||
<Compile Include="RyzStudio\IO\SharpZipLib.cs" />
|
<Compile Include="RyzStudio\IO\SharpZipLib.cs" />
|
||||||
<Compile Include="RyzStudio\String.cs" />
|
|
||||||
<Compile Include="RyzStudio\Windows\Forms\BigButton.cs">
|
<Compile Include="RyzStudio\Windows\Forms\BigButton.cs">
|
||||||
<SubType>UserControl</SubType>
|
<SubType>UserControl</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -245,7 +247,9 @@
|
|||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<Folder Include="Data\" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="packages\System.Data.SQLite.Core.1.0.110.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('packages\System.Data.SQLite.Core.1.0.110.0\build\net46\System.Data.SQLite.Core.targets')" />
|
<Import Project="packages\System.Data.SQLite.Core.1.0.110.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('packages\System.Data.SQLite.Core.1.0.110.0\build\net46\System.Data.SQLite.Core.targets')" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
Reference in New Issue
Block a user