WIP: rebuild with json, model and viewmodel

This commit is contained in:
Ray 2019-04-16 21:57:31 +01:00
parent 48416abccb
commit 050bff5a00
14 changed files with 1741 additions and 1105 deletions

View File

@ -8,7 +8,7 @@ namespace bzit.bomg
{
private TreeNode parentNode = null;
private BookmarkItem bookmarkItem;
private bool isWorking = false;
private bool isWorking = false;
public BookmarkEditForm(ref TreeNode node)
{
@ -61,7 +61,7 @@ namespace bzit.bomg
if (this.IsWorking)
{
e.Cancel = true;
}
}
}
public bool IsWorking
@ -136,7 +136,7 @@ namespace bzit.bomg
BookmarkTreeView bookmarkTreeView = (BookmarkTreeView)parentNode.TreeView;
if (bookmarkTreeView != null)
{
parentNode.ImageIndex = parentNode.SelectedImageIndex = bookmarkTreeView.AddToIconList(bookmarkItem);
//##parentNode.ImageIndex = parentNode.SelectedImageIndex = bookmarkTreeView.AddToIconList(bookmarkItem);
}
this.Close();
@ -154,7 +154,7 @@ namespace bzit.bomg
// don't replace with blank
if (!string.IsNullOrEmpty(sender.Description))
{
{
bookmarkItem.Description = sender.Description;
}
}
@ -171,15 +171,15 @@ namespace bzit.bomg
bookmarkItem.Description = sender.Description;
}
}
// don't replace with blank
if (sender.IconData != null)
{
bookmarkItem.IconData = sender.IconData;
}
tbxDescription.Text = bookmarkItem.Description;
pbxIcon.Image = (bookmarkItem.Icon == null) ? parentNode.TreeView.ImageList.Images[3] : bookmarkItem.Icon;
pbxIcon.Image = (bookmarkItem.Icon == null) ? parentNode.TreeView.ImageList.Images[3] : bookmarkItem.Icon;
if (hasError)
{

View File

@ -1,125 +1,219 @@
using bzit.bomg.Models;
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace bzit.bomg
{
public partial class BookmarkTreeView : RyzStudio.Windows.Forms.MovableTreeView
{
protected ImageList iconList = null;
protected IconDatabase iconDatabase = null;
public BookmarkTreeView()
{
InitializeComponent();
this.iconList = new ImageList();
this.iconList.ColorDepth = ColorDepth.Depth16Bit;
this.iconList.ImageSize = new Size(16, 16);
this.iconList.TransparentColor = Color.Transparent;
if (this.ImageList == null)
{
this.ImageList = new ImageList();
}
this.iconList.Images.Clear();
this.iconList.Images.Add(Properties.Resources.transmit_blue);
this.iconList.Images.Add(Properties.Resources.folder);
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.ColorDepth = ColorDepth.Depth16Bit;
this.ImageList.ImageSize = new Size(16, 16);
this.ImageList.TransparentColor = Color.Transparent;
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)]
public new ImageList ImageList
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
{
get { return base.ImageList; }
set { base.ImageList = value; }
}
base.OnPreviewKeyDown(e);
#endregion
#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)
TreeNode tn = this.SelectedNode;
if (tn == null)
{
return;
}
TreeNode tn = AddBookmarkPageFullPath(name.Trim(), 3);
tn.Tag = tag;
tn.ToolTipText = tag.SiteAddress + Environment.NewLine + tag.Description;
// load icon
if (this.IconDatabase.HasIcon(tag.SiteAddress))
switch (e.KeyCode)
{
try
{
Image icon = this.IconDatabase.GetIcon(tag.SiteAddress);
if (icon != null)
case Keys.Insert:
if (e.Modifiers == Keys.Shift)
{
tn.TreeView.ImageList.Images.Add(tag.SiteAddress, icon);
tn.ImageKey = tn.SelectedImageKey = tag.SiteAddress;
// do nothing
}
}
catch
{
// do nothing
}
else
{
MessageBox.Show("!");
//AddBookmarkPage();
}
break;
default: break;
}
}
public int AddToIconList(BookmarkItem sender)
public bool InitialiseIconDatabase(out string message, string filename)
{
Image rs = null;
if (this.IconDatabase.HasIcon(sender.SiteAddress))
message = string.Empty;
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
{
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)
{
this.ImageList.Images.Add(sender.SiteAddress, rs);
return this.ImageList.Images.IndexOfKey(sender.SiteAddress);
}
return 3;
return true;
}
public void AddIcon(BookmarkItem sender)
{
if (this.IconDatabase.HasIcon(sender.SiteAddress))
public void AddItem(BookmarkItemViewModel viewModel)
{
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;
}
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;
}
}
}

View File

@ -18,7 +18,7 @@ namespace bzit.bomg
{
return false;
}
return this.DoNonQuery(@"
CREATE TABLE bzt_app_bomg_icons
(
@ -29,7 +29,7 @@ namespace bzit.bomg
)
") >= 0;
}
#region public methods
public bool HasIcon(string url)
@ -48,7 +48,7 @@ namespace bzit.bomg
{
return false;
}
if (this.HasIcon(url))
{
return this.DoNonQuery("UPDATE bzt_app_bomg_icons SET='" + imageToSQLString(image) + "' WHERE ico_key='" + SQLiteDatabase2.escapeValue(url) + "';") >= 0;
@ -70,7 +70,7 @@ namespace bzit.bomg
{
return false;
}
if (this.HasIcon(url))
{
return this.DoNonQuery("UPDATE bzt_app_bomg_icons SET='" + bytesToSQLString(image) + "' WHERE ico_key='" + escapeValue(url) + "';") >= 0;
@ -87,7 +87,7 @@ namespace bzit.bomg
{
return null;
}
string rs = this.DoQuerySingle("SELECT ico_content FROM bzt_app_bomg_icons WHERE ico_key='" + escapeValue(url) + "'");
return sqlStringToImage(rs);
}
@ -98,20 +98,20 @@ namespace bzit.bomg
{
return;
}
this.DoNonQuery("DELETE FROM bzt_app_bomg_icons WHERE ico_key='" + escapeValue(url) + "';");
}
#endregion
protected string imageToSQLString(Image image)
{
MemoryStream stream = new MemoryStream();
image.Save(stream, new System.Drawing.Imaging.ImageFormat(image.RawFormat.Guid));
stream.Close();
byte[] byteArray = stream.ToArray();
return bytesToSQLString(byteArray);
}
@ -121,12 +121,12 @@ namespace bzit.bomg
}
protected Image sqlStringToImage(string base64_string)
{
{
byte[] byteArray2 = Convert.FromBase64String(base64_string);
MemoryStream stream2 = new MemoryStream();
stream2.Write(byteArray2, 0, byteArray2.Length);
Image displayImage = Image.FromStream(stream2);
return displayImage;
}

1257
MainForm.Designer.cs generated

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
using bzit.bomg.Models;
using System;
using System.ComponentModel;
using System.IO;
@ -32,41 +33,20 @@ namespace bzit.bomg
// toolbar
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;
// if (File.Exists(iconDBPath))
// {
// rv = this.IconDatabase.LoadFile(iconDBPath);
// if (!rv)
// {
// rv = this.IconDatabase.CreateSpecial(iconDBPath, true);
// if (!rv)
// {
// 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();
// }
// }
bool rv = false;
string iconDBFilename = Path.ChangeExtension(Application.ExecutablePath, ".db");
treeView1.IconDatabase = this.IconDatabase;
sessionFileFormat = new SessionFileFormat(this);
string errorMessage;
rv = treeView1.InitialiseIconDatabase(out errorMessage, iconDBFilename);
if (!rv)
{
MessageBox.Show("Can not find icon database. [" + this.IconDatabase.LastError + "]");
this.Close();
}
sessionFileFormat = new SessionFileFormat(this);
this.ApplicationMode = AppMode.Clear;
treeView1.OnNodeCountUpdate = delegate (ulong v) {
@ -88,7 +68,7 @@ namespace bzit.bomg
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.Location = Screen.PrimaryScreen.WorkingArea.Location;
@ -215,7 +195,7 @@ namespace bzit.bomg
}
}
}
#region public properties
public AppMode ApplicationMode
@ -237,7 +217,7 @@ namespace bzit.bomg
closeFileMenuItem.Enabled = false;
saveFileMenuItem.Enabled = saveMenuBarItem.Enabled = false;
saveAsFileMenuItem.Enabled = false;
updateIconsToolMenuItem.Enabled = false;
updateIconsToolMenuItem.Enabled = false;
break;
case AppMode.Open:
@ -265,9 +245,9 @@ namespace bzit.bomg
[DefaultValue(null)]
public IconDatabase IconDatabase { get; set; }
#endregion
#region Toolbar #1
/**
@ -307,7 +287,7 @@ namespace bzit.bomg
ApplicationMode = AppMode.Clear;
return;
}
if (ApplicationMode == AppMode.Open)
{
if (string.IsNullOrEmpty(sessionFilename))
@ -327,7 +307,7 @@ namespace bzit.bomg
{
if (MessageBox.Show("There was a problem saving bookmarks. Bookmarks are not saved", "Not Saved", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) return;
}
ApplicationMode = AppMode.Clear;
}
else if (ApplicationMode == AppMode.New)
@ -488,7 +468,7 @@ namespace bzit.bomg
{
this.TopMost = !this.TopMost;
}
#endregion
#region TreeView Menu - item
@ -521,10 +501,10 @@ namespace bzit.bomg
/**
* Node -> Delete
*/
private void toolStripMenuItem6_Click(object sender, EventArgs e)
{
treeView1.DeleteNode();
}
private void toolStripMenuItem6_Click(object sender, EventArgs e) => treeView1.SNode.Delete();
//{
// treeView1.DeleteNode();
//}
#endregion
@ -533,12 +513,12 @@ namespace bzit.bomg
/**
* Add Page
*/
private void toolStripMenuItem15_Click(object sender, EventArgs e) { treeView1.AddBookmarkPage(); }
//private void toolStripMenuItem15_Click(object sender, EventArgs e) { treeView1.AddBookmarkPage(); }
/**
* 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
@ -549,14 +529,14 @@ namespace bzit.bomg
{
return;
}
foreach (TreeNode tn in treeView1.SelectedNode.Nodes)
{
if (tn.Tag == null)
{
continue;
}
openBookmark(tn);
}
}
@ -573,20 +553,20 @@ namespace bzit.bomg
/**
* 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
*/
private void toolStripMenuItem13_Click(object sender, EventArgs e) { treeView1.MoveNodeDown(); }
private void toolStripMenuItem13_Click(object sender, EventArgs e) => treeView1.SNode.MoveDown();
/**
* Sort
*/
private void sortToolStripMenuItem_Click(object sender, EventArgs e) { treeView1.SortNode(); }
private void sortToolStripMenuItem_Click(object sender, EventArgs e) => treeView1.SNode.Sort();
#endregion
protected void OpenBookmarkFile(string filename)
{
treeView1.HasChanged = false;
@ -618,7 +598,7 @@ namespace bzit.bomg
protected bool SaveBookmarkFile()
{
bool rv = false;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
switch (saveFileDialog.FilterIndex)
@ -641,9 +621,9 @@ namespace bzit.bomg
break;
default: break;
}
}
if (rv)
{
ApplicationMode = AppMode.Open;
@ -677,7 +657,7 @@ namespace bzit.bomg
collapseAllViewMenuItem.Enabled = true;
}
}
if (e.Button == MouseButtons.Right)
{
// folder
@ -714,7 +694,7 @@ namespace bzit.bomg
{
return;
}
switch (e.KeyCode)
{
case Keys.Apps:
@ -772,7 +752,7 @@ namespace bzit.bomg
default: break;
}
}
protected void openBookmark(TreeNode node)
{
if (node == null)
@ -789,13 +769,13 @@ namespace bzit.bomg
{
return;
}
BookmarkItem item = (BookmarkItem)node.Tag;
if (item == null)
{
return;
}
if (string.IsNullOrEmpty(item.SiteAddress))
{
return;
@ -843,6 +823,20 @@ namespace bzit.bomg
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());
}
}
}

View File

@ -131,7 +131,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADU
FwAAAk1TRnQBSQFMAgEBBwEAAWQBAgFkAQIBEAEAARABAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAFA
FwAAAk1TRnQBSQFMAgEBBwEAAWwBAgFsAQIBEAEAARABAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAFA
AwABIAMAAQEBAAEQBgABEBQAAZkBSgEYAS4BtwEdAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3
ARkBtwEdARcBLgGZAUoEAAGZAUoBGAEuAbcBHQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZ
AbcBHQEXAS4BmQFKBAABmQFKARgBLgG3AR0BtwEZAbcBGQG3ARkBtwEZAbcBGQG3ARkBtwEZAbcBGQG3
@ -268,15 +268,30 @@
<data name="newMenuBarItem.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHYSURBVDhPjZO7SxxRFMZNrPI/KKQShBDElS1FEAtBiwQt
QiCQFAnY+cAiZcRKm7AsS5qQLpAiYJ9GJEQiOoOKL1DEYtd9ubM7j3vvzOiXcy7OOONuSA782GLO99vv
3p3tSkwPkSGy/+Ax8ZBom4zneZZhGNdhGKITUkrkcrmPtNtRkuWw4zhwXTem2Wyi0WigXC5rSalUQj6f
b5M8ILK8IISAUkp/MrZtw7IsVCoVLaCW4C8pFAqRRI8WBE0T8mpLCyIJB1qtFqrVauo4DGd0mkYLxPEc
xMG7eCEIAn3u6Ci1Wk03KRaLd4Kbi9lH9t7LkZ3vo5/l4VvI3ReQZyvw6z8R+k5Kwk34Pur1+p1AHr35
pI5mIE/m4Z+vQJ1+gNh5BmdjEGJvMdWEj8N3wqJYAEx3e7vP1+TJAglWSbAEz5yCZ7xGGCi9yPi+r++F
JUws4LnannwqzAmosyWo4/dw1p/At/bjMMMtosvlNimB83tsXBiTcH8NwN7op/oZqMsfOhTBDRgOtws2
h18ZX/u+hLKGgBCHy5AX39rCSVICmvhFuk+yRRJ+xhmdptEC0zRv7gv+Bu1ec0anb2eIfh6XH3QKJOEd
ep1tyvC/N55eYohg6/9A4a7eP4kvnS+BaQv8AAAAAElFTkSuQmCC
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAHZSURBVDhPjZM9SxxRFIaNqfIfIlgJQpDgypZBEAshFkpS
SECIhYJdolikjFiZJizLYiPpAikC6W1EQiQhM4tK/AAlWOy6X+7szse9d2b09ZxLZpxxNyQHHraY8z77
3ruzPYl5SGSI7D/oJ3qJjsl4nmcZhnEVhiG6IaVELpd7T7tdJVkOO44D13VjWq0Wms0mKpWKlpTLZeTz
+Q7JPSLLC0IIKKX0J2PbNizLQrVa1QJqCf6SQqEQSfRoQdAqQl7+0IJIwoF2u41arZY6DsMZnabRAnH8
GuLXQrwQBIE+d3SUer2um5RKpVvB9fmrB/b+i1Hj89imPJyH3JuBPFuH3/iK0HdSEm7C99FoNG4F8mhu
Qx0tQp4swf+9DnX6FsKYgrMzDLG/kmrCx+E7YVEsAJ7f9/amv8iTZRK8I8EqvOIzeOZLhIHSi4zv+/pe
WMLEAp7Ln5NDovgU6mwV6vgNnO1H8K2DOMxwi+hyuU1K4HwfnxDmJNxvj2HvDFL9DNTFlg5FcAOGw52C
3Sez5seBD6GsIyDE4Rrk+aeOcJKUgCZ+ke6SbJGEn3FGp2m0wDTN67uCv0G7V5zR6T8zQj+Pyw+6BZLw
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>
</data>
<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
View 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;
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -7,25 +7,36 @@ namespace RyzStudio.Windows.Forms
{
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 EventHandler OnChanged = null;
public NodeCountUpdated OnNodeCountUpdate = null;
protected const char pathSeparator = '|';
protected const int folderImageIndex = 1;
protected const int folderSelectedImageIndex = 2;
//protected const int folderImageIndex = 1;
//protected const int folderSelectedImageIndex = 2;
protected TreeNode draggingNode = null;
protected TreeNode draggingNode = null;
protected bool allowBeginEdit = false;
//// public int[] folderImageIndex = { 1, 2 };
protected ulong nodeCount = 0;
protected bool hasChanged = false;
public MovableTreeView()
{
this.SNode = new MovableTreeViewSelectedNode(this);
}
#region public properties
/* [Category("Data")]
@ -45,35 +56,35 @@ namespace RyzStudio.Windows.Forms
{
return rv;
}
foreach (TreeNode tn in this.Nodes)
{
traverseNodeList(ref rv, tn);
}
return rv;
}
}
[Browsable(false)]
public string[] NodeNameList
{
get
{
string[] rv = new string[0];
if (this.Nodes.Count <= 0)
{
return rv;
}
foreach (TreeNode tn in this.Nodes)
{
traverseNodeNameList(ref rv, tn);
}
return rv;
}
}
//[Browsable(false)]
//public string[] NodeNameList
//{
// get
// {
// string[] rv = new string[0];
// if (this.Nodes.Count <= 0)
// {
// return rv;
// }
// foreach (TreeNode tn in this.Nodes)
// {
// traverseNodeNameList(ref rv, tn);
// }
// return rv;
// }
//}
[Browsable(false)]
public ulong NodeCount
@ -94,12 +105,12 @@ namespace RyzStudio.Windows.Forms
{
return rv;
}
foreach (TreeNode tn in this.Nodes)
{
traverseNodeCount(ref rv, tn);
}
return rv;
}
}
@ -112,119 +123,119 @@ namespace RyzStudio.Windows.Forms
{
hasChanged = value;
OnChanged?.Invoke(null, null);
OnChanged?.Invoke(null, null);
}
}
#endregion
#region public methods
public TreeNode AddFolder()
{
return this.AddFolder("New Folder " + (new Random()).Next(10001, 99999).ToString());
}
//public TreeNode AddFolder()
//{
// return this.AddFolder("New Folder " + (new Random()).Next(10001, 99999).ToString());
//}
public TreeNode AddFolder(string name)
{
if (this.SelectedNode == null)
{
return null;
}
//public TreeNode AddFolder(string name)
//{
// if (this.SelectedNode == null)
// {
// return null;
// }
if (this.SelectedNode.Tag != null)
{
return null;
}
this.HasChanged = true;
TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, folderImageIndex, folderSelectedImageIndex);
this.SelectedNode = tn;
OnAddFolderNode(tn);
// if (this.SelectedNode.Tag != null)
// {
// return null;
// }
return tn;
}
// this.HasChanged = true;
public TreeNode AddBookmarkPage()
{
return this.AddBookmarkPage("New Page " + (new Random()).Next(10001, 99999).ToString());
}
// TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, folderImageIndex, folderSelectedImageIndex);
// this.SelectedNode = tn;
public TreeNode AddBookmarkPage(string name, int icon = 3)
{
if (this.SelectedNode == null)
{
return null;
}
// OnAddFolderNode(tn);
if (this.SelectedNode.Tag != null)
{
return null;
}
// return tn;
//}
this.HasChanged = true;
TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, icon, icon);
tn.Tag = new object();
tn.ToolTipText = name;
nodeCount++;
NodeCountUpdate(nodeCount);
this.SelectedNode = tn;
OnAddItemNode(tn);
return tn;
}
//public TreeNode AddBookmarkPage()
//{
// return this.AddBookmarkPage("New Page " + (new Random()).Next(10001, 99999).ToString());
//}
public TreeNode AddBookmarkPageFullPath(string name, int icon = 3)
{
if (this.Nodes.Count <= 0)
{
return null;
}
//public TreeNode AddBookmarkPage(string name, int icon = 3)
//{
// if (this.SelectedNode == null)
// {
// return null;
// }
// if (this.SelectedNode.Tag != null)
// {
// return null;
// }
// this.HasChanged = true;
// TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, icon, icon);
// tn.Tag = new object();
// tn.ToolTipText = name;
// nodeCount++;
// NodeCountUpdate(nodeCount);
// this.SelectedNode = tn;
// OnAddItemNode(tn);
// return tn;
//}
//public TreeNode AddBookmarkPageFullPath(string name, int icon = 3)
//{
// if (this.Nodes.Count <= 0)
// {
// return null;
// }
// this.HasChanged = true;
// TreeNode tn2;
// if (!name.Contains(pathSeparator.ToString()))
// {
// tn2 = this.Nodes[0].Nodes.Add(name, PathDecode(name), icon, icon);
// tn2.ToolTipText = name;
// nodeCount++;
// }
// else
// {
// tn2 = this.Nodes[0];
// string[] folders = name.Split(pathSeparator);
// for (int x = 0; x < (folders.Length - 1); x++)
// {
// string dr = folders[x].Trim();
// if (tn2.Nodes.ContainsKey(dr))
// {
// tn2 = tn2.Nodes[dr];
// }
// else
// {
// tn2 = tn2.Nodes.Add(dr, PathDecode(dr), folderImageIndex, folderSelectedImageIndex);
// }
// }
// string tm = folders[(folders.Length - 1)].Trim();
// tn2 = tn2.Nodes.Add(tm, PathDecode(tm), icon, icon);
// tn2.Tag = new object();
// tn2.ToolTipText = tm;
// nodeCount++;
// }
// NodeCountUpdate(nodeCount);
// return tn2;
//}
this.HasChanged = true;
TreeNode tn2;
if (!name.Contains(pathSeparator.ToString()))
{
tn2 = this.Nodes[0].Nodes.Add(name, PathDecode(name), icon, icon);
tn2.ToolTipText = name;
nodeCount++;
}
else
{
tn2 = this.Nodes[0];
string[] folders = name.Split(pathSeparator);
for (int x = 0; x < (folders.Length - 1); x++)
{
string dr = folders[x].Trim();
if (tn2.Nodes.ContainsKey(dr))
{
tn2 = tn2.Nodes[dr];
}
else
{
tn2 = tn2.Nodes.Add(dr, PathDecode(dr), folderImageIndex, folderSelectedImageIndex);
}
}
string tm = folders[(folders.Length - 1)].Trim();
tn2 = tn2.Nodes.Add(tm, PathDecode(tm), icon, icon);
tn2.Tag = new object();
tn2.ToolTipText = tm;
nodeCount++;
}
NodeCountUpdate(nodeCount);
return tn2;
}
public void EditNode()
{
this.HasChanged = true;
@ -233,7 +244,7 @@ namespace RyzStudio.Windows.Forms
{
return;
}
if (!this.SelectedNode.IsEditing)
{
allowBeginEdit = true;
@ -241,114 +252,114 @@ namespace RyzStudio.Windows.Forms
}
}
public void DeleteNode()
{
if (this.SelectedNode == null)
{
return;
}
//public void DeleteNode()
//{
// if (this.SelectedNode == null)
// {
// return;
// }
if (this.Nodes.Count <= 0)
{
return;
}
// if (this.Nodes.Count <= 0)
// {
// return;
// }
if (this.SelectedNode.Equals(this.Nodes[0]))
{
return;
}
// if (this.SelectedNode.Equals(this.Nodes[0]))
// {
// return;
// }
this.HasChanged = true;
this.SelectedNode.Remove();
if (this.SelectedNode.Tag == null)
{
nodeCount = this.NodeCountCalc;
}
else
{
nodeCount--;
}
// this.HasChanged = true;
NodeCountUpdate(nodeCount);
}
// this.SelectedNode.Remove();
public void SortNode()
{
TreeNode tn = this.SelectedNode;
string[] tnv = new string[0];
TreeNode[] tna = new TreeNode[0];
// if (this.SelectedNode.Tag == null)
// {
// nodeCount = this.NodeCountCalc;
// }
// else
// {
// nodeCount--;
// }
this.HasChanged = true;
foreach (TreeNode tn2 in tn.Nodes)
{
Array.Resize(ref tna, (tna.Length + 1));
tna[(tna.Length - 1)] = tn2;
// NodeCountUpdate(nodeCount);
//}
Array.Resize(ref tnv, (tnv.Length + 1));
tnv[(tnv.Length - 1)] = tn2.Text;
}
//public void SortNode()
//{
// TreeNode tn = this.SelectedNode;
// string[] tnv = new string[0];
// TreeNode[] tna = new TreeNode[0];
Array.Sort(tnv, tna);
tn.Nodes.Clear();
foreach (TreeNode tn2 in tna)
{
tn.Nodes.Add(tn2);
}
}
// this.HasChanged = true;
public void MoveNodeUp()
{
TreeNode tn = this.SelectedNode;
if (tn.Parent == null)
{
return;
}
// foreach (TreeNode tn2 in tn.Nodes)
// {
// Array.Resize(ref tna, (tna.Length + 1));
// tna[(tna.Length - 1)] = tn2;
if (tn.Index == 0)
{
return;
}
// Array.Resize(ref tnv, (tnv.Length + 1));
// tnv[(tnv.Length - 1)] = tn2.Text;
// }
this.HasChanged = true;
int n = tn.Index - 1;
// Array.Sort(tnv, tna);
TreeNode tn1 = tn.Parent;
tn1.Nodes.Remove(tn);
tn1.Nodes.Insert(n, tn);
this.SelectedNode = tn;
}
// tn.Nodes.Clear();
// foreach (TreeNode tn2 in tna)
// {
// tn.Nodes.Add(tn2);
// }
//}
public void MoveNodeDown()
{
TreeNode tn = this.SelectedNode;
if (tn.Parent == null)
{
return;
}
//public void MoveNodeUp()
//{
// TreeNode tn = this.SelectedNode;
// if (tn.Parent == null)
// {
// return;
// }
TreeNode tn1 = tn.Parent;
// if (tn.Index == 0)
// {
// return;
// }
this.HasChanged = true;
// this.HasChanged = true;
if (tn.Index >= (tn1.Nodes.Count - 1))
{
return;
}
int n = tn.Index + 1;
// int n = tn.Index - 1;
// TreeNode tn1 = tn.Parent;
// tn1.Nodes.Remove(tn);
// tn1.Nodes.Insert(n, tn);
// this.SelectedNode = tn;
//}
//public void MoveNodeDown()
//{
// TreeNode tn = this.SelectedNode;
// if (tn.Parent == null)
// {
// return;
// }
// TreeNode tn1 = tn.Parent;
// this.HasChanged = true;
// 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;
//}
tn1.Nodes.Remove(tn);
tn1.Nodes.Insert(n, tn);
this.SelectedNode = tn;
}
public string GetNodeFullPath(TreeNode node)
{
string rv = PathEncode(node.Text);
@ -367,10 +378,10 @@ namespace RyzStudio.Windows.Forms
{
break;
}
rv = PathEncode(tn.Text) + pathSeparator.ToString() + rv;
}
return rv;
}
@ -385,7 +396,7 @@ namespace RyzStudio.Windows.Forms
{
return false;
}
bool rt = false;
bool inclusive = false;
TreeNode tn = node;
@ -395,7 +406,7 @@ namespace RyzStudio.Windows.Forms
{
break;
}
if (inclusive)
{
if (tn.Text.ToLower().Contains(term.ToLower()))
@ -406,7 +417,7 @@ namespace RyzStudio.Windows.Forms
break;
}
}
if (tn.Nodes.Count > 0)
{
tn = tn.Nodes[0];
@ -440,7 +451,7 @@ namespace RyzStudio.Windows.Forms
}
}
}
return rt;
}
@ -454,13 +465,13 @@ namespace RyzStudio.Windows.Forms
}
#endregion
#region integrated behaviour
protected override void OnItemDrag(ItemDragEventArgs e)
{
base.OnItemDrag(e);
draggingNode = (TreeNode)e.Item;
DoDragDrop(e.Item, DragDropEffects.Move);
}
@ -480,7 +491,7 @@ namespace RyzStudio.Windows.Forms
return;
}
if (IsNodeChild(draggingNode, en))
if (isNodeChild(draggingNode, en))
{
return;
}
@ -503,21 +514,21 @@ namespace RyzStudio.Windows.Forms
protected override void OnDragEnter(DragEventArgs e)
{
base.OnDragEnter(e);
e.Effect = DragDropEffects.Move;
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
this.SelectedNode = this.GetNodeAt(e.Location);
}
protected override void OnDragOver(DragEventArgs e)
{
base.OnDragOver(e);
this.SelectedNode = this.GetNodeAt(this.PointToClient(new Point(e.X, e.Y)));
}
@ -530,9 +541,9 @@ namespace RyzStudio.Windows.Forms
}
this.HasChanged = true;
base.OnBeforeLabelEdit(e);
if (e.Node == null)
{
e.CancelEdit = true;
@ -553,7 +564,7 @@ namespace RyzStudio.Windows.Forms
protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e)
{
base.OnAfterLabelEdit(e);
if (e.Node.Tag == null)
{
if (e.Label == null)
@ -572,7 +583,7 @@ namespace RyzStudio.Windows.Forms
{
e.CancelEdit = true;
}
allowBeginEdit = false;
}
@ -583,24 +594,24 @@ namespace RyzStudio.Windows.Forms
{
return;
}
switch (e.KeyCode)
{
case Keys.Insert:
if (e.Modifiers == Keys.Shift)
{
AddFolder();
this.SelectedNode = this.SNode.AddFolder();
}
else
{
AddBookmarkPage();
//##AddBookmarkPage();
}
break;
case Keys.Delete:
if (!tn.IsEditing)
{
this.DeleteNode();
this.SNode.Delete();
}
break;
@ -614,14 +625,14 @@ namespace RyzStudio.Windows.Forms
case Keys.Up:
if (e.Modifiers == Keys.Control)
{
this.MoveNodeUp();
this.SNode.MoveUp();
}
break;
case Keys.Down:
if (e.Modifiers == Keys.Control)
{
this.MoveNodeDown();
this.SNode.MoveDown();
}
break;
@ -638,9 +649,7 @@ namespace RyzStudio.Windows.Forms
#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;
while (true)
@ -677,21 +686,21 @@ namespace RyzStudio.Windows.Forms
}
}
protected void traverseNodeNameList(ref string[] results, TreeNode node)
{
foreach (TreeNode tn in node.Nodes)
{
if (tn.Tag == null)
{
traverseNodeNameList(ref results, tn);
}
else
{
Array.Resize(ref results, (results.Length + 1));
results[(results.Length - 1)] = this.GetNodeFullPath(tn);
}
}
}
//protected void traverseNodeNameList(ref string[] results, TreeNode node)
//{
// foreach (TreeNode tn in node.Nodes)
// {
// if (tn.Tag == null)
// {
// traverseNodeNameList(ref results, tn);
// }
// else
// {
// Array.Resize(ref results, (results.Length + 1));
// results[(results.Length - 1)] = this.GetNodeFullPath(tn);
// }
// }
//}
protected void traverseNodeCount(ref ulong results, TreeNode node)
{
@ -707,20 +716,15 @@ namespace RyzStudio.Windows.Forms
}
}
}
#endregion
#region public methods
protected virtual void OnAddFolderNode(TreeNode node) { }
protected virtual void OnAddItemNode(TreeNode node) { }
#endregion
////protected string PathEncode(string text) { return RyzStudio.String.EncodeTo64(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); }
}
}

View 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);
}
}
}
}

View File

@ -13,10 +13,10 @@ namespace bzit.bomg
base.CONST_STREAM_FILE_NAME = "bookmarks.xml";
base.CONST_KEYPASS = "";
base.enableErrorReporting = true;
parentForm = parent_form;
}
protected override void loadFromXmlDocument(ref XmlDocument xml_doc)
{
XmlNodeList xnl = xml_doc.SelectNodes("bomg/b/g");
@ -25,13 +25,13 @@ namespace bzit.bomg
MessageBox.Show("No bookmarks found.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
parentForm.treeView1.Clear();
TreeNode tn = parentForm.treeView1.Nodes.Add("", xnl.Item(0).Attributes["name"].InnerText, 0, 0);
TreeNode tn = parentForm.treeView1.Nodes.Add("", xnl.Item(0).Attributes["name"].InnerText, 0, 0);
foreach (XmlNode xn in xnl.Item(0))
{
BookmarkItem bi = new BookmarkItem();
foreach (XmlNode xn2 in xn.ChildNodes)
{
switch (xn2.LocalName)
@ -51,10 +51,10 @@ namespace bzit.bomg
default: break;
}
}
parentForm.treeView1.AddBookmarkItem(bi.Fullpath, bi);
//##parentForm.treeView1.AddBookmarkItem(bi.Fullpath, bi);
}
tn.Expand();
}
@ -64,18 +64,18 @@ namespace bzit.bomg
{
return;
}
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement(CONST_PRODUCT);
writer.WriteStartElement("b");
writer.WriteStartElement("g");
writer.WriteAttributeString("name", parentForm.treeView1.Nodes[0].Text);
foreach (TreeNode tn in parentForm.treeView1.NodeList)
{
BookmarkItem bi = (BookmarkItem)tn.Tag;
writer.WriteStartElement("m");
writer.WriteElementString("name", parentForm.treeView1.GetNodeFullPath(tn));
writer.WriteElementString("address", bi.SiteAddress);
@ -83,7 +83,7 @@ namespace bzit.bomg
writer.WriteElementString("created", bi.Created.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();

View File

@ -108,7 +108,7 @@ namespace bzit.bomg
continue;
}
parentForm.treeView1.AddIcon(bookmarkItem);
//##parentForm.treeView1.AddIcon(bookmarkItem);
}
}

View 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();
}
}
}

View File

@ -96,6 +96,9 @@
<Reference Include="System.Xml" />
</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="UpdateIconForm.cs">
<SubType>Form</SubType>
@ -142,7 +145,6 @@
<Compile Include="RyzStudio\IO\FileType.cs" />
<Compile Include="RyzStudio\IO\SessionFileFormatBase.cs" />
<Compile Include="RyzStudio\IO\SharpZipLib.cs" />
<Compile Include="RyzStudio\String.cs" />
<Compile Include="RyzStudio\Windows\Forms\BigButton.cs">
<SubType>UserControl</SubType>
</Compile>
@ -245,7 +247,9 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Data\" />
</ItemGroup>
<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')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">