public void ITagDB_Test_Reopen()//关闭后重新打开 { GUTag p1 = db.NewTag("p1"); GUTag c1 = db.NewTag("c1"); db.SetParent(p1, c1); List <string> alias = db.QueryTagAlias(p1); foreach (string a in alias) { Logger.D(a); } Assert.AreEqual(1, alias.Count); Assert.AreEqual("p1", alias[0]); Logger.D("end test reopen"); IDisposableFactory.DisposeAll(); db = null; db = TagDBFactory.CreateTagDB("sql"); List <GUTag> p1new = db.QueryTags("p1"); alias = db.QueryTagAlias(p1new[0]); Assert.AreEqual(1, alias.Count); Assert.AreEqual("p1", alias[0]); }
public void SearchByTxt(AutoCompleteTipsItem aItem) { //先在main中查找,如果有,切换焦点后返回 if (MainCanvas.ChangeSelectedByTxt(aItem) != null) { return; } //再在sub中查找,如果有,切换焦点后返回 if (SubCanvas.ChangeSelectedByTxt(aItem) != null) { MainCanvas.ClearSelected(); return; } //如果item精确对应到一个GUTag,直接使用该GUTag GUTag tag = aItem.Data as GUTag; if (tag == null) { List <GUTag> tags = TagDB.QueryTags(aItem.Content); if (tags.Count > 0) { tag = tags[0]; } } //如果不在视图中,但数据库中存在,TODO:如何有效的切换??是一个需要考虑的问题 if (tag != null) { GUTag mainRoot = TagDB.GetTag(StaticCfg.Ins.DefaultTagID); GUTag subRoot = mainRoot; GUTag subSel = subRoot; List <GUTag> parents = QueryParentHistory(tag); int cnt = parents.Count; if (cnt > 0) { subSel = parents[0]; subRoot = parents[Math.Min(3, cnt - 1)]; mainRoot = parents[Math.Min(6, cnt - 1)]; } ChangeRoot(mainRoot, subRoot, subSel); } //不存在精确匹配的tag else { } }
private void miDeleteTag_Click(object sender, RoutedEventArgs e) { UpdateCurrentTagByContextMenu(); if (TagDB.QueryTagChildren(SelectedTag).Count == 0) { GUTag oldCurrentTag, newCurrentTag; GetNextTag(out oldCurrentTag, out newCurrentTag); TagDB.RemoveTag(oldCurrentTag); //如果新选出来的当前节点在视图中,直接选中该tag foreach (UIElement u in allTagBox) { TagBox t = u as TagBox; if (t != null && t.GUTag == newCurrentTag) { SetCurrentTag(newCurrentTag, true); } } //当新选出来的tag不再视图中时,才需要切换视图的根节点 if (SelectedTag != newCurrentTag) { ChangeRoot(newCurrentTag, newCurrentTag); } else { RedrawGraph(); } //如果该title的所有tag全部被删除,则需要删除Tag所在目录: //这个调用之所以放在这儿,而不放在TagDB.RemoveTag时调用, //是因为在彻底删除该tag后(转到其他tag后),程序打开的标签笔记才会被关闭。 //这个时候才能删除tag的目录(否则会有文件正在使用无法移动目录) if (TagDB.QueryTags(oldCurrentTag.Title).Count == 0) //确保没有同名标签,才要删除目录,否则不要删除目录 { BackTask.Ins.Add(new DelTagTaskInf(oldCurrentTag.Title)); } } else { MessageBox.Show(string.Format("[{0}]下还有其他子节点,如果确实需要删除该标签,请先删除所有子节点", SelectedTag), "提示:", MessageBoxButton.OK, MessageBoxImage.Warning); } }