public void addURLTag() { bool checkURL_AlreadyHave = false; //检查这个标签是否存在 for (int i = 0; i < treeView1.Nodes.Count; i++) { if (treeView1.Nodes[i].Text == ItemTitle.Text) { checkURL_AlreadyHave = true; break; } if (((nTreeNode)treeView1.Nodes[i]).Type == "FaviFolder") { for (int l = 0; l < ((nTreeNode)treeView1.Nodes[i]).Nodes.Count; l++) { if (((nTreeNode)treeView1.Nodes[i]).Nodes[l].Text == ItemTitle.Text || ((nTreeNode)(((nTreeNode)treeView1.Nodes[i]).Nodes[l])).URL == ItemURL.Text) { checkURL_AlreadyHave = true; break; } } } } if (checkURL_AlreadyHave == false) //如果没有重复就增加URL标签 { if (ItemTitle.Text.Length > 1 && ItemURL.Text.Length > 4) { nTreeNode treeNode = new nTreeNode(); treeNode.Text = treeNode.Name = treeNode.Title = ItemTitle.Text; treeNode.URL = ItemURL.Text; treeNode.Date_Added = DateTime.Now.ToString("yyyyMMddHHmmssffff"); iconImageList.Images.Add(treeNode.Date_Added, iconImage); treeNode.Last_Visited = DateTime.Now.ToString("yyyyMMddHHmmssffff"); treeNode.Layer = "0"; treeNode.ID = DateTime.Now.ToString("yyyyMMddHHmmssffff"); treeNode.FatherID = "0"; treeNode.Type = "URL"; treeNode.SelectedImageIndex = treeNode.ImageIndex = iconImageList.Images.IndexOfKey(treeNode.Date_Added); treeNode.IconBase64str = IamgeToBase64(iconImage); treeView1.Nodes.Add(treeNode); treeView1.SelectedNode = treeNode; } } else { MessageBox.Show(this, "标签重复,不能添加!", "CefiBrowser", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.Close(); GC.Collect(); } }
private void treeView1_DragDrop(object sender, DragEventArgs e) { nTreeNode myNode = null; if (e.Data.GetDataPresent(typeof(nTreeNode))) { myNode = (nTreeNode)(e.Data.GetData(typeof(nTreeNode))); } else { MessageBox.Show("error"); } Position.X = e.X; Position.Y = e.Y; Position = treeView1.PointToClient(Position); nTreeNode DropNode = (nTreeNode)this.treeView1.GetNodeAt(Position); // 1.目标节点不是空。2.目标节点不是被拖拽接点的字节点。3.目标节点不是被拖拽节点本身 if (DropNode != null && DropNode.Parent != myNode && DropNode != myNode && DropNode.Type == "FaviFolder") { nTreeNode DragNode = myNode; // 将被拖拽节点从原来位置删除。 myNode.Remove(); // 在目标节点下增加被拖拽节点 DragNode.Layer = "1"; DragNode.FatherID = DropNode.ID; DropNode.Nodes.Add(DragNode); itemTagChanged = true; //标记有变动 } // 如果目标节点不存在,即拖拽的位置不存在节点,那么就将被拖拽节点放在根节点之下 else if (myNode.Layer == "1") { myNode.FatherID = ""; myNode.Layer = "0"; nTreeNode DragNode = myNode; myNode.Remove(); treeView1.Nodes.Add(DragNode); itemTagChanged = true; //标记有变动 } else if (myNode.Type == "FaviFolder") { nTreeNode DragNode = myNode; myNode.Remove(); treeView1.Nodes.Add(DragNode); itemTagChanged = true; //标记有变动 } }
public bool itemTagChanged = false; //所有标签是否有变动 private void NewFavi_Folder_Click(object sender, EventArgs e) { FavirteButton favirte = new FavirteButton(); favirte.Height = 23; favirte.Title = "快捷收藏夹"; favirte.ItemIcon = CefiBrowser.Properties.Resources.FileFolderIcon; Font sf = new Font("Tahoma", 8.25f, FontStyle.Regular); Graphics g = this.CreateGraphics(); //单位为mm g.PageUnit = GraphicsUnit.Millimeter; //测量字符串长度 Size sif = TextRenderer.MeasureText(g, favirte.Title, sf, new Size(0, 0), TextFormatFlags.NoPadding); favirte.TitleWidth = sif.Width; favirte.Width = 26 + favirte.TitleWidth; if (favirte.Width > 140) { favirte.Width = 140; } favirte.Left = MainForm.Instance.FavPanel.Left + 6; if (MainForm.Instance.FavPanel.Controls.Count > 0) { int nFavPoint = 0; nFavPoint = MainForm.Instance.FavPanel.Left + 6; for (int i = 0; i < MainForm.Instance.FavPanel.Controls.Count; i++) { //if (((FavirteButton)FavPanel.Controls[i]).URL == "" || // ((FavirteButton)FavPanel.Controls[i]).Title == favirte.Title) // return; nFavPoint = MainForm.Instance.FavPanel.Controls[i].Width + 2 + nFavPoint; } favirte.Left = nFavPoint; } MainForm.Instance.Invoke(new Action(() => { MainForm.Instance.FavPanel.Controls.Add(favirte); } )); nTreeNode yTreeNode = new nTreeNode(); yTreeNode.Date_Added = DateTime.Now.ToString("yyyyMMddHHmmssffff"); iconImageList.Images.Add(yTreeNode.Date_Added, favirte.ItemIcon); yTreeNode.Last_Visited = DateTime.Now.ToString("yyyyMMddHHmmssffff"); yTreeNode.Layer = "0"; yTreeNode.ID = DateTime.Now.ToString("yyyyMMddHHmmssffff"); yTreeNode.FatherID = "0"; yTreeNode.Type = "FaviFolder"; yTreeNode.URL = ""; yTreeNode.Text = favirte.Title; yTreeNode.Title = yTreeNode.Name = favirte.Title; yTreeNode.SelectedImageIndex = yTreeNode.StateImageIndex = yTreeNode.ImageIndex = iconImageList.Images.IndexOfKey(yTreeNode.Date_Added); yTreeNode.IconBase64str = IamgeToBase64(CefiBrowser.Properties.Resources.FileFolderIcon); treeView1.Nodes.Add(yTreeNode); itemTagChanged = true; sf = null; favirte = null; yTreeNode = null; GC.Collect(); }
/// <summary> /// 保存整理后的收藏夹 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Favi_Save_Click(object sender, EventArgs e) { // string currDirectiory = Environment.CurrentDirectory.ToString(); nBookmarks.nCheckFiles(@"Bookmarks"); //检查 string jsonStr = ""; try { for (int i = 0; i < treeView1.Nodes.Count; i++) { JObject jsonObject1 = new JObject(); nTreeNode tTreeNode = new nTreeNode(); tTreeNode = (nTreeNode)treeView1.Nodes[i]; jsonObject1.Add("Date_Added", tTreeNode.Date_Added); jsonObject1.Add("Last_Visited", tTreeNode.Last_Visited); jsonObject1.Add("Title", tTreeNode.Text); jsonObject1.Add("URL", tTreeNode.URL); jsonObject1.Add("Layer", tTreeNode.Layer); jsonObject1.Add("ID", tTreeNode.ID); jsonObject1.Add("FatherID", tTreeNode.FatherID); jsonObject1.Add("Type", tTreeNode.Type); jsonObject1.Add("IconBase64str", tTreeNode.IconBase64str); jsonStr = jsonStr.Replace("[", ""); jsonStr = jsonStr.Replace("]", ""); jsonStr = jsonStr + ","; jsonStr = "[" + jsonStr + jsonObject1.ToString() + "]"; jsonStr = jsonStr.Replace(",,", ","); if (tTreeNode.Type == "FaviFolder") { for (int k = 0; k < tTreeNode.Nodes.Count; k++) { JObject jsonObject = new JObject(); nTreeNode yTreeNode = new nTreeNode(); yTreeNode = (nTreeNode)tTreeNode.Nodes[k]; jsonObject.Add("Date_Added", yTreeNode.Date_Added); jsonObject.Add("Last_Visited", yTreeNode.Last_Visited); jsonObject.Add("Title", yTreeNode.Text); jsonObject.Add("URL", yTreeNode.URL); jsonObject.Add("Layer", yTreeNode.Layer); jsonObject.Add("ID", yTreeNode.ID); jsonObject.Add("FatherID", yTreeNode.FatherID); jsonObject.Add("Type", yTreeNode.Type); jsonObject.Add("IconBase64str", yTreeNode.IconBase64str); jsonStr = jsonStr.Replace("[", ""); jsonStr = jsonStr.Replace("]", ""); jsonStr = jsonStr + ","; jsonStr = "[" + jsonStr + jsonObject.ToString() + "]"; jsonStr = jsonStr.Replace(",,", ","); } } } jsonStr = "[" + jsonStr.Substring(2, jsonStr.Length - 2); File.WriteAllText(PublicClass.currDirectiory + @"\UserData\Bookmarks", jsonStr); } catch (Exception e1) { MessageBox.Show(e1.Message); } // nCheckFiles("Bookmarks"); //备份 MainForm.Instance.Invoke(new Action(() => { MainForm.Instance.FavPanel.Controls.Clear(); MainForm.Instance.LoadFav_Bar_Info(); //删除后重新加载,哈哈,有点傻傻的 } )); itemTagChanged = false;// 当保存改动后标记为False ItemTitle = null; ItemURL = null; iconImage = null; jsonStr = null; // currDirectiory = null; GC.Collect(); //MainForm.Instance.RefreshActiveTab(); }
//程序启动时加载收藏夹上的信息 public void LoadFav_Bar_Info() { // string currDirectiory = Environment.CurrentDirectory.ToString(); string jsonStr = File.ReadAllText(PublicClass.currDirectiory + @"\UserData\Bookmarks"); Font sf = new Font("Tahoma", 8.25f, FontStyle.Regular); Graphics g = this.CreateGraphics(); try { var jobInfoList = JsonConvert.DeserializeObject <List <FavireBT> >(jsonStr); if (jobInfoList.Count > 0) { favireBTs = jobInfoList; foreach (FavireBT jobInfo in favireBTs) { iconImageList.Images.Add(jobInfo.Date_Added, Base64ToImage(jobInfo.IconBase64str)); nTreeNode tNode = new nTreeNode(); tNode.Name = jobInfo.Title; tNode.URL = jobInfo.URL; tNode.Title = jobInfo.Title; tNode.Date_Added = jobInfo.Date_Added; tNode.Last_Visited = jobInfo.Last_Visited; tNode.Layer = jobInfo.Layer; tNode.Type = jobInfo.Type; tNode.ID = jobInfo.ID; tNode.FatherID = jobInfo.FatherID; tNode.Text = jobInfo.Title; tNode.ToolTipText = jobInfo.Title; tNode.Type = jobInfo.Type; tNode.IconBase64str = jobInfo.IconBase64str; tNode.SelectedImageIndex = tNode.ImageIndex = iconImageList.Images.IndexOfKey(jobInfo.Date_Added); if (jobInfo.Layer == "0") { treeView1.Nodes.Add(tNode); tNode = null; GC.Collect(); } else { for (int i = 0; i < treeView1.Nodes.Count; i++) { if (((nTreeNode)treeView1.Nodes[i]).ID == tNode.FatherID) { ((nTreeNode)treeView1.Nodes[i]).Nodes.Add(tNode); } } tNode = null; GC.Collect(); } } } } catch (Exception e) { MessageBox.Show(e.Message); } // currDirectiory = null; jsonStr = null; sf = null; g = null; favireBTs = null; GC.Collect(); }