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 TreeNode parentNode = null;
private BookmarkItem bookmarkItem; private BookmarkItem bookmarkItem;
private bool isWorking = false; private bool isWorking = false;
public BookmarkEditForm(ref TreeNode node) public BookmarkEditForm(ref TreeNode node)
{ {
@ -61,7 +61,7 @@ namespace bzit.bomg
if (this.IsWorking) if (this.IsWorking)
{ {
e.Cancel = true; e.Cancel = true;
} }
} }
public bool IsWorking public bool IsWorking
@ -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();
@ -154,7 +154,7 @@ namespace bzit.bomg
// don't replace with blank // don't replace with blank
if (!string.IsNullOrEmpty(sender.Description)) if (!string.IsNullOrEmpty(sender.Description))
{ {
bookmarkItem.Description = sender.Description; bookmarkItem.Description = sender.Description;
} }
} }
@ -171,15 +171,15 @@ namespace bzit.bomg
bookmarkItem.Description = sender.Description; bookmarkItem.Description = sender.Description;
} }
} }
// don't replace with blank // don't replace with blank
if (sender.IconData != null) if (sender.IconData != null)
{ {
bookmarkItem.IconData = sender.IconData; bookmarkItem.IconData = sender.IconData;
} }
tbxDescription.Text = bookmarkItem.Description; 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) if (hasError)
{ {

View File

@ -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);
tn.Tag = tag;
tn.ToolTipText = tag.SiteAddress + Environment.NewLine + tag.Description;
// load icon switch (e.KeyCode)
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;
} }
} }
} }

View File

@ -18,7 +18,7 @@ namespace bzit.bomg
{ {
return false; return false;
} }
return this.DoNonQuery(@" return this.DoNonQuery(@"
CREATE TABLE bzt_app_bomg_icons CREATE TABLE bzt_app_bomg_icons
( (
@ -29,7 +29,7 @@ namespace bzit.bomg
) )
") >= 0; ") >= 0;
} }
#region public methods #region public methods
public bool HasIcon(string url) public bool HasIcon(string url)
@ -48,7 +48,7 @@ namespace bzit.bomg
{ {
return false; return false;
} }
if (this.HasIcon(url)) if (this.HasIcon(url))
{ {
return this.DoNonQuery("UPDATE bzt_app_bomg_icons SET='" + imageToSQLString(image) + "' WHERE ico_key='" + SQLiteDatabase2.escapeValue(url) + "';") >= 0; 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; return false;
} }
if (this.HasIcon(url)) if (this.HasIcon(url))
{ {
return this.DoNonQuery("UPDATE bzt_app_bomg_icons SET='" + bytesToSQLString(image) + "' WHERE ico_key='" + escapeValue(url) + "';") >= 0; 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; return null;
} }
string rs = this.DoQuerySingle("SELECT ico_content FROM bzt_app_bomg_icons WHERE ico_key='" + escapeValue(url) + "'"); string rs = this.DoQuerySingle("SELECT ico_content FROM bzt_app_bomg_icons WHERE ico_key='" + escapeValue(url) + "'");
return sqlStringToImage(rs); return sqlStringToImage(rs);
} }
@ -98,20 +98,20 @@ namespace bzit.bomg
{ {
return; return;
} }
this.DoNonQuery("DELETE FROM bzt_app_bomg_icons WHERE ico_key='" + escapeValue(url) + "';"); this.DoNonQuery("DELETE FROM bzt_app_bomg_icons WHERE ico_key='" + escapeValue(url) + "';");
} }
#endregion #endregion
protected string imageToSQLString(Image image) protected string imageToSQLString(Image image)
{ {
MemoryStream stream = new MemoryStream(); MemoryStream stream = new MemoryStream();
image.Save(stream, new System.Drawing.Imaging.ImageFormat(image.RawFormat.Guid)); image.Save(stream, new System.Drawing.Imaging.ImageFormat(image.RawFormat.Guid));
stream.Close(); stream.Close();
byte[] byteArray = stream.ToArray(); byte[] byteArray = stream.ToArray();
return bytesToSQLString(byteArray); return bytesToSQLString(byteArray);
} }
@ -121,12 +121,12 @@ namespace bzit.bomg
} }
protected Image sqlStringToImage(string base64_string) protected Image sqlStringToImage(string base64_string)
{ {
byte[] byteArray2 = Convert.FromBase64String(base64_string); byte[] byteArray2 = Convert.FromBase64String(base64_string);
MemoryStream stream2 = new MemoryStream(); MemoryStream stream2 = new MemoryStream();
stream2.Write(byteArray2, 0, byteArray2.Length); stream2.Write(byteArray2, 0, byteArray2.Length);
Image displayImage = Image.FromStream(stream2); Image displayImage = Image.FromStream(stream2);
return displayImage; 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;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
@ -32,41 +33,20 @@ 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);
// 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();
// }
// }
treeView1.IconDatabase = this.IconDatabase; string errorMessage;
sessionFileFormat = new SessionFileFormat(this); 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; this.ApplicationMode = AppMode.Clear;
treeView1.OnNodeCountUpdate = delegate (ulong v) { treeView1.OnNodeCountUpdate = delegate (ulong v) {
@ -88,7 +68,7 @@ namespace bzit.bomg
protected override void OnShown(EventArgs e) protected override void OnShown(EventArgs e)
{ {
base.OnShown(e); base.OnShown(e);
this.Height = Screen.PrimaryScreen.WorkingArea.Height; this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.Location = Screen.PrimaryScreen.WorkingArea.Location; this.Location = Screen.PrimaryScreen.WorkingArea.Location;
@ -215,7 +195,7 @@ namespace bzit.bomg
} }
} }
} }
#region public properties #region public properties
public AppMode ApplicationMode public AppMode ApplicationMode
@ -237,7 +217,7 @@ namespace bzit.bomg
closeFileMenuItem.Enabled = false; closeFileMenuItem.Enabled = false;
saveFileMenuItem.Enabled = saveMenuBarItem.Enabled = false; saveFileMenuItem.Enabled = saveMenuBarItem.Enabled = false;
saveAsFileMenuItem.Enabled = false; saveAsFileMenuItem.Enabled = false;
updateIconsToolMenuItem.Enabled = false; updateIconsToolMenuItem.Enabled = false;
break; break;
case AppMode.Open: case AppMode.Open:
@ -265,9 +245,9 @@ namespace bzit.bomg
[DefaultValue(null)] [DefaultValue(null)]
public IconDatabase IconDatabase { get; set; } public IconDatabase IconDatabase { get; set; }
#endregion #endregion
#region Toolbar #1 #region Toolbar #1
/** /**
@ -307,7 +287,7 @@ namespace bzit.bomg
ApplicationMode = AppMode.Clear; ApplicationMode = AppMode.Clear;
return; return;
} }
if (ApplicationMode == AppMode.Open) if (ApplicationMode == AppMode.Open)
{ {
if (string.IsNullOrEmpty(sessionFilename)) 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; 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; ApplicationMode = AppMode.Clear;
} }
else if (ApplicationMode == AppMode.New) else if (ApplicationMode == AppMode.New)
@ -488,7 +468,7 @@ namespace bzit.bomg
{ {
this.TopMost = !this.TopMost; this.TopMost = !this.TopMost;
} }
#endregion #endregion
#region TreeView Menu - item #region TreeView Menu - item
@ -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
@ -549,14 +529,14 @@ namespace bzit.bomg
{ {
return; return;
} }
foreach (TreeNode tn in treeView1.SelectedNode.Nodes) foreach (TreeNode tn in treeView1.SelectedNode.Nodes)
{ {
if (tn.Tag == null) if (tn.Tag == null)
{ {
continue; continue;
} }
openBookmark(tn); openBookmark(tn);
} }
} }
@ -573,20 +553,20 @@ 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
protected void OpenBookmarkFile(string filename) protected void OpenBookmarkFile(string filename)
{ {
treeView1.HasChanged = false; treeView1.HasChanged = false;
@ -618,7 +598,7 @@ namespace bzit.bomg
protected bool SaveBookmarkFile() protected bool SaveBookmarkFile()
{ {
bool rv = false; bool rv = false;
if (saveFileDialog.ShowDialog() == DialogResult.OK) if (saveFileDialog.ShowDialog() == DialogResult.OK)
{ {
switch (saveFileDialog.FilterIndex) switch (saveFileDialog.FilterIndex)
@ -641,9 +621,9 @@ namespace bzit.bomg
break; break;
default: break; default: break;
} }
} }
if (rv) if (rv)
{ {
ApplicationMode = AppMode.Open; ApplicationMode = AppMode.Open;
@ -677,7 +657,7 @@ namespace bzit.bomg
collapseAllViewMenuItem.Enabled = true; collapseAllViewMenuItem.Enabled = true;
} }
} }
if (e.Button == MouseButtons.Right) if (e.Button == MouseButtons.Right)
{ {
// folder // folder
@ -714,7 +694,7 @@ namespace bzit.bomg
{ {
return; return;
} }
switch (e.KeyCode) switch (e.KeyCode)
{ {
case Keys.Apps: case Keys.Apps:
@ -772,7 +752,7 @@ namespace bzit.bomg
default: break; default: break;
} }
} }
protected void openBookmark(TreeNode node) protected void openBookmark(TreeNode node)
{ {
if (node == null) if (node == null)
@ -789,13 +769,13 @@ namespace bzit.bomg
{ {
return; return;
} }
BookmarkItem item = (BookmarkItem)node.Tag; BookmarkItem item = (BookmarkItem)node.Tag;
if (item == null) if (item == null)
{ {
return; return;
} }
if (string.IsNullOrEmpty(item.SiteAddress)) if (string.IsNullOrEmpty(item.SiteAddress))
{ {
return; return;
@ -843,6 +823,20 @@ 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());
}
} }
} }

View File

@ -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
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 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;
//// public int[] folderImageIndex = { 1, 2 }; //// public int[] folderImageIndex = { 1, 2 };
protected ulong nodeCount = 0; protected ulong nodeCount = 0;
protected bool hasChanged = false; protected bool hasChanged = false;
public MovableTreeView() public MovableTreeView()
{ {
this.SNode = new MovableTreeViewSelectedNode(this);
} }
#region public properties #region public properties
/* [Category("Data")] /* [Category("Data")]
@ -45,35 +56,35 @@ namespace RyzStudio.Windows.Forms
{ {
return rv; return rv;
} }
foreach (TreeNode tn in this.Nodes) foreach (TreeNode tn in this.Nodes)
{ {
traverseNodeList(ref rv, tn); traverseNodeList(ref rv, tn);
} }
return rv; return rv;
} }
} }
[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
@ -94,12 +105,12 @@ namespace RyzStudio.Windows.Forms
{ {
return rv; return rv;
} }
foreach (TreeNode tn in this.Nodes) foreach (TreeNode tn in this.Nodes)
{ {
traverseNodeCount(ref rv, tn); traverseNodeCount(ref rv, tn);
} }
return rv; return rv;
} }
} }
@ -112,119 +123,119 @@ namespace RyzStudio.Windows.Forms
{ {
hasChanged = value; hasChanged = value;
OnChanged?.Invoke(null, null); OnChanged?.Invoke(null, null);
} }
} }
#endregion #endregion
#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;
TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, folderImageIndex, folderSelectedImageIndex);
this.SelectedNode = tn;
OnAddFolderNode(tn);
return tn; // this.HasChanged = true;
}
public TreeNode AddBookmarkPage() // TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, folderImageIndex, folderSelectedImageIndex);
{ // this.SelectedNode = tn;
return this.AddBookmarkPage("New Page " + (new Random()).Next(10001, 99999).ToString());
}
public TreeNode AddBookmarkPage(string name, int icon = 3) // OnAddFolderNode(tn);
{
if (this.SelectedNode == null)
{
return null;
}
if (this.SelectedNode.Tag != null) // return tn;
{ //}
return null;
}
this.HasChanged = true; //public TreeNode AddBookmarkPage()
//{
TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, icon, icon); // return this.AddBookmarkPage("New Page " + (new Random()).Next(10001, 99999).ToString());
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) //public TreeNode AddBookmarkPage(string name, int icon = 3)
{ //{
if (this.Nodes.Count <= 0) // if (this.SelectedNode == null)
{ // {
return 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() public void EditNode()
{ {
this.HasChanged = true; this.HasChanged = true;
@ -233,7 +244,7 @@ namespace RyzStudio.Windows.Forms
{ {
return; return;
} }
if (!this.SelectedNode.IsEditing) if (!this.SelectedNode.IsEditing)
{ {
allowBeginEdit = true; allowBeginEdit = true;
@ -241,114 +252,114 @@ 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();
if (this.SelectedNode.Tag == null)
{
nodeCount = this.NodeCountCalc;
}
else
{
nodeCount--;
}
NodeCountUpdate(nodeCount); // this.SelectedNode.Remove();
}
public void SortNode() // if (this.SelectedNode.Tag == null)
{ // {
TreeNode tn = this.SelectedNode; // nodeCount = this.NodeCountCalc;
string[] tnv = new string[0]; // }
TreeNode[] tna = new TreeNode[0]; // else
// {
// nodeCount--;
// }
this.HasChanged = true; // NodeCountUpdate(nodeCount);
//}
foreach (TreeNode tn2 in tn.Nodes)
{
Array.Resize(ref tna, (tna.Length + 1));
tna[(tna.Length - 1)] = tn2;
Array.Resize(ref tnv, (tnv.Length + 1)); //public void SortNode()
tnv[(tnv.Length - 1)] = tn2.Text; //{
} // TreeNode tn = this.SelectedNode;
// string[] tnv = new string[0];
// TreeNode[] tna = new TreeNode[0];
Array.Sort(tnv, tna); // this.HasChanged = true;
tn.Nodes.Clear();
foreach (TreeNode tn2 in tna)
{
tn.Nodes.Add(tn2);
}
}
public void MoveNodeUp() // foreach (TreeNode tn2 in tn.Nodes)
{ // {
TreeNode tn = this.SelectedNode; // Array.Resize(ref tna, (tna.Length + 1));
if (tn.Parent == null) // tna[(tna.Length - 1)] = tn2;
{
return;
}
if (tn.Index == 0) // Array.Resize(ref tnv, (tnv.Length + 1));
{ // tnv[(tnv.Length - 1)] = tn2.Text;
return; // }
}
this.HasChanged = true; // Array.Sort(tnv, tna);
int n = tn.Index - 1;
TreeNode tn1 = tn.Parent; // tn.Nodes.Clear();
tn1.Nodes.Remove(tn); // foreach (TreeNode tn2 in tna)
tn1.Nodes.Insert(n, tn); // {
// tn.Nodes.Add(tn2);
this.SelectedNode = tn; // }
} //}
public void MoveNodeDown() //public void MoveNodeUp()
{ //{
TreeNode tn = this.SelectedNode; // TreeNode tn = this.SelectedNode;
if (tn.Parent == null) // if (tn.Parent == null)
{ // {
return; // return;
} // }
TreeNode tn1 = tn.Parent; // if (tn.Index == 0)
// {
// return;
// }
this.HasChanged = true; // this.HasChanged = true;
if (tn.Index >= (tn1.Nodes.Count - 1)) // int n = tn.Index - 1;
{
return; // TreeNode tn1 = tn.Parent;
} // tn1.Nodes.Remove(tn);
// tn1.Nodes.Insert(n, tn);
int n = tn.Index + 1;
// 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) public string GetNodeFullPath(TreeNode node)
{ {
string rv = PathEncode(node.Text); string rv = PathEncode(node.Text);
@ -367,10 +378,10 @@ namespace RyzStudio.Windows.Forms
{ {
break; break;
} }
rv = PathEncode(tn.Text) + pathSeparator.ToString() + rv; rv = PathEncode(tn.Text) + pathSeparator.ToString() + rv;
} }
return rv; return rv;
} }
@ -385,7 +396,7 @@ namespace RyzStudio.Windows.Forms
{ {
return false; return false;
} }
bool rt = false; bool rt = false;
bool inclusive = false; bool inclusive = false;
TreeNode tn = node; TreeNode tn = node;
@ -395,7 +406,7 @@ namespace RyzStudio.Windows.Forms
{ {
break; break;
} }
if (inclusive) if (inclusive)
{ {
if (tn.Text.ToLower().Contains(term.ToLower())) if (tn.Text.ToLower().Contains(term.ToLower()))
@ -406,7 +417,7 @@ namespace RyzStudio.Windows.Forms
break; break;
} }
} }
if (tn.Nodes.Count > 0) if (tn.Nodes.Count > 0)
{ {
tn = tn.Nodes[0]; tn = tn.Nodes[0];
@ -440,7 +451,7 @@ namespace RyzStudio.Windows.Forms
} }
} }
} }
return rt; return rt;
} }
@ -454,13 +465,13 @@ namespace RyzStudio.Windows.Forms
} }
#endregion #endregion
#region integrated behaviour #region integrated behaviour
protected override void OnItemDrag(ItemDragEventArgs e) protected override void OnItemDrag(ItemDragEventArgs e)
{ {
base.OnItemDrag(e); base.OnItemDrag(e);
draggingNode = (TreeNode)e.Item; draggingNode = (TreeNode)e.Item;
DoDragDrop(e.Item, DragDropEffects.Move); DoDragDrop(e.Item, DragDropEffects.Move);
} }
@ -480,7 +491,7 @@ namespace RyzStudio.Windows.Forms
return; return;
} }
if (IsNodeChild(draggingNode, en)) if (isNodeChild(draggingNode, en))
{ {
return; return;
} }
@ -503,21 +514,21 @@ namespace RyzStudio.Windows.Forms
protected override void OnDragEnter(DragEventArgs e) protected override void OnDragEnter(DragEventArgs e)
{ {
base.OnDragEnter(e); base.OnDragEnter(e);
e.Effect = DragDropEffects.Move; e.Effect = DragDropEffects.Move;
} }
protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseDown(MouseEventArgs e)
{ {
base.OnMouseDown(e); base.OnMouseDown(e);
this.SelectedNode = this.GetNodeAt(e.Location); this.SelectedNode = this.GetNodeAt(e.Location);
} }
protected override void OnDragOver(DragEventArgs e) protected override void OnDragOver(DragEventArgs e)
{ {
base.OnDragOver(e); base.OnDragOver(e);
this.SelectedNode = this.GetNodeAt(this.PointToClient(new Point(e.X, e.Y))); this.SelectedNode = this.GetNodeAt(this.PointToClient(new Point(e.X, e.Y)));
} }
@ -530,9 +541,9 @@ namespace RyzStudio.Windows.Forms
} }
this.HasChanged = true; this.HasChanged = true;
base.OnBeforeLabelEdit(e); base.OnBeforeLabelEdit(e);
if (e.Node == null) if (e.Node == null)
{ {
e.CancelEdit = true; e.CancelEdit = true;
@ -553,7 +564,7 @@ namespace RyzStudio.Windows.Forms
protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e) protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e)
{ {
base.OnAfterLabelEdit(e); base.OnAfterLabelEdit(e);
if (e.Node.Tag == null) if (e.Node.Tag == null)
{ {
if (e.Label == null) if (e.Label == null)
@ -572,7 +583,7 @@ namespace RyzStudio.Windows.Forms
{ {
e.CancelEdit = true; e.CancelEdit = true;
} }
allowBeginEdit = false; allowBeginEdit = false;
} }
@ -583,24 +594,24 @@ namespace RyzStudio.Windows.Forms
{ {
return; return;
} }
switch (e.KeyCode) switch (e.KeyCode)
{ {
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)
{ {
@ -707,20 +716,15 @@ 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); }
} }
} }

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

View File

@ -108,7 +108,7 @@ namespace bzit.bomg
continue; 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" /> <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">