protected override void saveToXmlTextWriter(ref XmlTextWriter writer) { if (parentForm.treeView1.Nodes.Count <= 0) { 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.Address); writer.WriteElementString("description", bi.Description); writer.WriteElementString("created", bi.Created.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); }
public void AddBookmarkItem(string name, BookmarkItem tag) { if (this.Nodes.Count <= 0) { return; } TreeNode tn = AddBookmarkPageFullPath(name.Trim(), 3); tn.Tag = tag; tn.ToolTipText = tag.Address + Environment.NewLine + tag.Description; // load icon if (this.IconDatabase.HasIcon(tag.Address)) { try { Image icon = this.IconDatabase.GetIcon(tag.Address); if (icon != null) { tn.TreeView.ImageList.Images.Add(tag.Address, icon); tn.ImageKey = tn.SelectedImageKey = tag.Address; } } catch { // do nothing } } }
protected override void OnShown(EventArgs e) { base.OnShown(e); if (parentNode.Tag != null) { if (parentNode.Tag is BookmarkItem) { bookmarkItem = (BookmarkItem)parentNode.Tag; tbxName.Text = bookmarkItem.GetName(); tbxAddress.Text = bookmarkItem.Address; tbxDescription.Text = bookmarkItem.Description; if (parentNode.TreeView.ImageList != null) { if (parentNode.ImageIndex >= 0) { pbxIcon.Image = parentNode.TreeView.ImageList.Images[parentNode.ImageIndex]; } else { pbxIcon.Image = parentNode.TreeView.ImageList.Images[parentNode.ImageKey]; } } } } }
private void btnSave_Click(object sender, EventArgs e) { if (this.IsWorking) { return; } if (bookmarkItem == null) { bookmarkItem = new BookmarkItem(); } bookmarkItem.ChangeName(tbxName.Text.Trim()); bookmarkItem.Address = tbxAddress.Text.Trim(); bookmarkItem.Description = tbxDescription.Text.Trim(); parentNode.Text = tbxName.Text.Trim(); //// parentNode.ImageIndex = parentNode.SelectedImageIndex = 3; parentNode.ToolTipText = string.Concat(bookmarkItem.Address, Environment.NewLine, bookmarkItem.Description).Trim(); parentNode.Tag = bookmarkItem; BookmarkTreeView bookmarkTreeView = (BookmarkTreeView)parentNode.TreeView; if (bookmarkTreeView != null) { parentNode.ImageIndex = parentNode.SelectedImageIndex = bookmarkTreeView.AddToIconList(bookmarkItem); } this.Close(); }
protected override void OnAddItemNode(TreeNode node) { base.OnAddItemNode(node); BookmarkItem bi = new BookmarkItem(); node.Tag = bi; }
public void AddIcon(BookmarkItem sender) { if (this.IconDatabase.HasIcon(sender.Address)) { return; } this.IconDatabase.AddIcon(sender.Address, sender.IconData); }
private void mainThread_DoWork(object sender, DoWorkEventArgs e) { TreeNode[] nodeList = parentForm.treeView1.NodeList; for (int i = 0; i < nodeList.Length; i++) { if (progressBar1.InvokeRequired) { progressBar1.Invoke(new Action(() => progressBar1.Value = (i + 1))); } else { progressBar1.Value = (i + 1); } if (label2.InvokeRequired) { label2.Invoke(new Action(() => label2.Text = string.Concat((i + 1).ToString(), "/", progressBar1.Maximum.ToString()))); } else { label2.Text = string.Concat((i + 1).ToString(), "/", progressBar1.Maximum.ToString()); } TreeNode node = nodeList[i]; if (node == null) { continue; } if (node.Tag == null) { continue; } if (!(node.Tag is BookmarkItem)) { continue; } BookmarkItem bookmarkItem = (BookmarkItem)node.Tag; if (bookmarkItem == null) { continue; } bookmarkItem.GetFaviconAddress(); if (bookmarkItem.IconData == null) { continue; } parentForm.treeView1.AddIcon(bookmarkItem); } }
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node == null) { return; } if (e.Node.Text.Equals("")) { return; } // view ui expandAllViewMenuItem.Enabled = false; collapseAllViewMenuItem.Enabled = false; if (e.Node != null) { if (e.Node.Tag == null) { expandAllViewMenuItem.Enabled = true; collapseAllViewMenuItem.Enabled = true; } } if (e.Button == MouseButtons.Right) { // folder if (e.Node.Tag == null) { if (e.Node.Equals(e.Node.TreeView.Nodes[0])) { treeMenuRoot.Show(Cursor.Position); } else { treeMenuFolder.Show(Cursor.Position); } } else { if (!(e.Node.Tag is BookmarkItem)) { return; } BookmarkItem bi = (BookmarkItem)e.Node.Tag; treeMenuItem.Show(Cursor.Position); } } }
protected override void loadFromXmlDocument(ref XmlDocument xml_doc) { XmlNodeList xnl = xml_doc.SelectNodes("bomg/b/g"); if (xnl.Count <= 0) { 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); foreach (XmlNode xn in xnl.Item(0)) { BookmarkItem bi = new BookmarkItem(); foreach (XmlNode xn2 in xn.ChildNodes) { switch (xn2.LocalName) { case "name": bi.Fullpath = xn2.InnerText?.Trim(); break; case "address": bi.Address = xn2.InnerText?.Trim(); break; case "description": bi.Description = xn2.InnerText?.Trim(); break; case "created": bi.Created = xn2.InnerText?.Trim(); break; default: break; } } parentForm.treeView1.AddBookmarkItem(bi.Fullpath, bi); } tn.Expand(); }
protected void bookmarkItem_OnRetrieveCompleted(BookmarkItem sender, bool hasError, string message) { if (string.IsNullOrEmpty(sender.TempName)) { if (MessageBox.Show("The page could not be retrieved or the title is blank. Do you want to keep your original title?", "Keep original?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { bookmarkItem.TempName = sender.TempName; tbxName.Text = bookmarkItem.TempName; // don't replace with blank if (!string.IsNullOrEmpty(sender.Description)) { bookmarkItem.Description = sender.Description; } } } else { bookmarkItem.TempName = sender.TempName; tbxName.Text = bookmarkItem.TempName; // don't replace with blank if (!string.IsNullOrEmpty(sender.Description)) { 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; if (hasError) { oToolTip.SetToolTip(pictureBox1, message); } this.IsWorking = false; }
private void btnRetrievePage_Click(object sender, EventArgs e) { if (this.IsWorking) { return; } if (string.IsNullOrWhiteSpace(tbxAddress.Text)) { return; } this.IsWorking = true; oToolTip.SetToolTip(pictureBox1, ""); BookmarkItem bi = new BookmarkItem(); bi.OnRetrieveCompleted += bookmarkItem_OnRetrieveCompleted; bi.RetrieveAsync(tbxAddress.Text.Trim()); }
public int AddToIconList(BookmarkItem sender) { Image rs = null; if (this.IconDatabase.HasIcon(sender.Address)) { rs = this.IconDatabase.GetIcon(sender.Address); } else { if (this.IconDatabase.AddIcon(sender.Address, sender.IconData)) { rs = sender.Icon; } } if (rs != null) { this.ImageList.Images.Add(sender.Address, rs); return(this.ImageList.Images.IndexOfKey(sender.Address)); } return(3); }
protected void openBookmark(TreeNode node) { if (node == null) { return; } if (node.Tag == null) { return; } if (!(node.Tag is BookmarkItem)) { return; } BookmarkItem item = (BookmarkItem)node.Tag; if (item == null) { return; } if (string.IsNullOrEmpty(item.Address)) { return; } int bookmarkAction; if (!int.TryParse(this.IconDatabase.GetConfig("core.bookmark.action", string.Empty), out bookmarkAction)) { bookmarkAction = 0; } string bookmarkCustom1 = this.IconDatabase.GetConfig("core.bookmark.customcommand1", string.Empty).Trim(); string bookmarkCustom2 = this.IconDatabase.GetConfig("core.bookmark.customcommand2", string.Empty).Trim(); switch (bookmarkAction) { case 1: if (string.IsNullOrEmpty(bookmarkCustom1)) { return; } bookmarkCustom1 = bookmarkCustom1.Replace("%1", item.Address); bookmarkCustom2 = bookmarkCustom2.Replace("%1", item.Address); try { System.Diagnostics.Process.Start(bookmarkCustom1, bookmarkCustom2); } catch { // do nothing } break; default: try { System.Diagnostics.Process.Start(item.Address); } catch { // do nothing } break; } }
private void treeView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { TreeNode tn = treeView1.SelectedNode; if (tn == null) { return; } switch (e.KeyCode) { case Keys.Apps: treeView1_NodeMouseClick(sender, new TreeNodeMouseClickEventArgs(tn, MouseButtons.Right, 1, tn.Bounds.X, tn.Bounds.Y)); return; case Keys.F2: if (tn.Tag == null) { return; } if (!(tn.Tag is BookmarkItem)) { return; } toolStripMenuItem8_Click(sender, null); break; case Keys.F3: if (tn.Tag == null) { return; } if (!(tn.Tag is BookmarkItem)) { return; } BookmarkItem bookmarkItem = (BookmarkItem)tn.Tag; if (bookmarkItem == null) { return; } if (string.IsNullOrEmpty(bookmarkItem.Address)) { return; } try { Clipboard.SetText(bookmarkItem.Address.Trim()); } catch { // do nothing } break; case Keys.Enter: openBookmark(tn); break; default: break; } }