//显示编辑框 public void ShowEdit(Canvas c, TagBox brother) { if (c == null || brother == null) { return; } ComplateEdit(); Parent = c; NoEdit = brother; //设置好编辑框的各种属性 Edit.Text = brother.Text; Edit.Width = Math.Max(500, brother.Width + 10); Thickness m = brother.Margin; Edit.Margin = new Thickness(m.Left + 20, m.Top + 5, 0, 0); Edit.FontFamily = brother.txt.FontFamily; Edit.FontSize = brother.txt.FontSize; Edit.FontStretch = brother.txt.FontStretch; Edit.FontStyle = brother.txt.FontStyle; //显示该编辑框 Parent.Children.Add(Edit); Edit.Focus(); Edit.SelectAll(); }
public void ClearSongControls() { UniqueIdBox.Text = "(No song selected)"; TitleBox.Clear(); SubtitleBox.Clear(); BackgroundBox.Clear(); ComposerBox.Clear(); ArrangerBox.Clear(); CopyrightBox.Clear(); LicenseBox.Clear(); MadeFamousByBox.Clear(); DifficultyBox.Value = 0; RatingBox.Value = 0; FingerHintBox.Clear(); HandsBox.Clear(); TagBox.Clear(); TagList.Items.Clear(); BookmarkMeasureBox.Value = 1; BookmarkDescriptionBox.Clear(); BookmarkList.Items.Clear(); PropertiesGroup.Enabled = false; }
private void canvas_KeyDown(object sender, KeyEventArgs e) { System.Diagnostics.Debug.WriteLine("canvas_KeyDown {0}-{1}", e.Key, e.ImeProcessedKey); if (!FloatTextBox.Ins.IsVisible) { if (e.Key == Key.Up || e.Key == Key.Down || e.Key == Key.Left || e.Key == Key.Right) { NavigateTagBox(e.Key); e.Handled = true; } else if (e.Key == Key.Enter) { NewBrotherTag(); e.Handled = true; } else if (e.Key == Key.F2) { TagBox t = FindTagBox(SelectedTag); if (t != null) { FloatTextBox.Ins.ShowEdit(canvas, t); e.Handled = true; } } } }
private void CancelEdit() { if (Parent != null) { Parent.Children.Remove(Edit); } Parent = null; NoEdit = null; }
private void UpdateCurrentTagByContextMenu() { TagBox t = TagAreaMenu.PlacementTarget as TagBox; if (t != null && t.GUTag != null) { SetCurrentTag(t.GUTag, true); } }
//public void ShowGraph(ITagDB tagDB, string root) //{ // Logger.I("ShowGraph at " + root); // this.tagDB = tagDB; // this.rootTag = root; // canvas.Children.Clear(); // canvasRecentTags.Children.Clear(); // //计算有向图布局 // ITagLayout tagLayout = TagLayoutFactory.CreateLayout(); // tagLayout.Layout(tagDB, root); // //将有向图中的元素显示在界面上 // IEnumerable<UIElement> lines = tagLayout.Lines; // IEnumerable<UIElement> allTxt = tagLayout.TagArea; // canvas.Width = tagLayout.Size.Width; // layoutHeight = tagLayout.Size.Height; // SetHeight(); // foreach (UIElement l in lines) // { // canvas.Children.Add(l); // } // foreach (TagBox t in allTxt) // { // //设置每一个tag的上下文菜单和事件响应钩子 // t.ContextMenu = TagAreaMenu; // t.MouseLeftButtonDown += Tag_MouseLeftButtonDown; // t.MouseDoubleClick += Tag_MouseDoubleClick; // canvas.Children.Add(t); // } // UpdateRecentTags(root); // //SetCurrentTag(root); // SetCurrentTag(); //} //双击tag,以该tag为根显示有向图 private void Tag_MouseDoubleClick(object sender, MouseButtonEventArgs e) { TagBox b = sender as TagBox; if (b != null) { ChangeRoot(b.GUTag, b.GUTag); } }
private void ModifyTag_Executed(object sender, ExecutedRoutedEventArgs e) { TagBox t = TagAreaMenu.PlacementTarget as TagBox; if (t != null && t.GUTag != null) { SetCurrentTag(t.GUTag); FloatTextBox.Ins.ShowEdit(canvas, t); } }
private void ShowRootPath() { //如果配置不需要显示,则直接返回 if (!NeedShowRootPath()) { return; } if (RootTag == null) { return; } connectCanvas.Children.Clear(); //需要显示从全局根到当前视图根节点之间的路径 //查找出所有从当前视图根节点到全局根节点之间的中间节点 List <GUTag> connect = new List <GUTag>(); GUTag from = RootTag; GUTag tmp = from; connect.Add(from); while (connect.Count < 20 && tmp != null) { List <GUTag> ps = TagDB.QueryTagParent(tmp); if (ps.Count > 0) { tmp = ps[0]; connect.Add(tmp); } else { break; } } connect.Reverse(); //显示所有中间节点 double X = 0; foreach (GUTag u in connect) { GTagBox gt = new GTagBox(5, u, X, 0, 1); TagBox tx = UIElementFactory.CreateTagBox(gt, null); tx.HideCircle(); X += gt.OutterBox.Width; if (tx.ContextMenu == null) { tx.ContextMenu = TagAreaMenu; tx.MouseLeftButtonDown += Tag_MouseLeftButtonDown; tx.MouseDoubleClick += Tag_MouseDoubleClick; } connectCanvas.Children.Add(tx); } }
public TagBox ChangeSelectd(GUTag tag) { DbgShowTagBox(); TagBox target = FindTagBox(tag); if (target != null) { SetCurrentTag(tag); } return(target); }
public ImageListItem(DenshaImage dImage) { _dImage = dImage; if(File.Exists(_dImage.ThumbnailFullPath)) _image = Image.FromFile(_dImage.ThumbnailFullPath); initImageAttributes(); initStringFormat(); _tagBox = new TagBox(this); }
//在当前图中的所有tag查找,看看当前是否已经显示,如果已经显示,直接切换节点 //如果没有显示,返回null public TagBox ChangeSelectedByTxt(AutoCompleteTipsItem txt) { DbgShowTagBox(); TagBox target = FindTagBoxByTxt(txt); if (target != null) { SetCurrentTag(target.GUTag); } return(target); }
public void ClearSelected() { foreach (UIElement u in allTagBox) { TagBox tb = u as TagBox; if (tb != null) { tb.Stat = (tb.GUTag == SelectedTag)? TagBox.Status.SelectedLostFocus : TagBox.Status.None; } } }
private bool Match(TagBox t, AutoCompleteTipsItem aItem) { GUTag tag = aItem.Data as GUTag; if (tag != null) { return(tag == t.GUTag); } else { return(t.Text == aItem.Content); } }
private void ComplateEdit() { if (!IsVisible) { return; } //合法性检查 string err = CfgPath.CheckTagFormat(Edit.Text); if (err != null) { MessageBox.Show(err, "标签不合法,请重新输入", MessageBoxButton.OK, MessageBoxImage.Error); return; } //第一步,先将编辑器隐藏起来,否则后面有TextChangedCallback导致业务流程处理后, //会有很多意想不到的流程发生,导致多次递归调用本函数(HideEdit)。 //比如:HideEdit=>lostfocus=>HideEdit GUTag tag = NoEdit.GUTag; string oldTitle = NoEdit.Text; string newTitle = Edit.Text; Canvas parentBak = Parent; //将这两个置空,表示该编辑器不可见了(IsVisible = false)。 Parent = null; NoEdit = null; try { //隐藏编辑框 parentBak.Children.Remove(Edit); System.Diagnostics.Debug.WriteLine("HideFloat1"); //如果文本内容发生修改,通知观察者 if (oldTitle != newTitle && oldTitle != null && newTitle != null) { TextChangedCallback?.Invoke(parentBak, tag, newTitle); System.Diagnostics.Debug.WriteLine("HideFloat2"); } } finally { parentBak?.Focus(); //因为编辑框失去焦点时会有相应的处理,所以这儿设置焦点的处理必须放在所有处理完成之后 //否则可能形成递归调用 } }
private void DbgShowTagBox() { Logger.D("\r\n\r\n BeginDbgShowTagBox {0}=====================", MyCanvasType); foreach (UIElement u in canvas.Children) { TagBox t = u as TagBox; if (t != null) { Logger.D("DbgShowTagBox:{0} - POS:{1}-{2},Visibility={3}", t.GUTag, t.Margin.Left, t.Margin.Top, t.Visibility); } } Logger.D("EndDbgShowTagBox {0}=====================\r\n\r\n ", MyCanvasType); }
private TagBox FindTagBoxByTxt(AutoCompleteTipsItem tag) { foreach (UIElement u in allTagBox)//此处不能在Canvas.Children中查找,因为为了性能做了特殊优化,一些不可见的tagbox仍然存在于Canvas.Children中。 { TagBox t = u as TagBox; if (t != null) { if (Match(t, tag)) { Logger.D("FindTagBox:{0} - POS:{1}-{2}", tag, t.Margin.Left, t.Margin.Top); return(t); } } } return(null); }
public TagBox New(GTagBox g) { if (TagBoxGarbage.Count > 0) { sttReuseTag++; TagBox b = TagBoxGarbage[0] as TagBox; TagBoxGarbage.RemoveAt(0); b.Visibility = System.Windows.Visibility.Visible; return(b); } else { sttNewTag++; return(new TagBox(g)); } }
private void UpdateSelectedStatus(GUTag tag, TagBox.Status stat) { foreach (UIElement u in allTagBox) { TagBox tb = u as TagBox; if (tb != null) { tb.Stat = TagBox.Status.None; if (tb.GUTag == tag) { tb.Stat = stat; } } } }
public static TagBox CreateTagBox(GTagBox g, TreeLayoutEnv env) { TagBox b = (env == null)?new TagBox(g): env.New(g); b.FontFamily = StaticCfg.Ins.GFontF; b.FontSize = g.FontSize; b.Height1 = g.InnerBox.Height; b.Width1 = g.InnerBox.Width; b.Margin = new Thickness(g.InnerBox.X - 10, g.InnerBox.Y, 0, 0); b.TextAlignment = TextAlignment.Center; b.GUTag = g.Tag; b.Background1 = g.Distance;//new SolidColorBrush(GetColor(g.Distance,g.Level)); //if (g.Distance >= 5) b.Foreground1 = g.Distance;// new SolidColorBrush(Colors.White); b.Foreground1 = g.Distance; return(b); }
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); } }
private void miNewTag_Click(object sender, RoutedEventArgs e) { UpdateCurrentTagByContextMenu(); if (SelectedTag == null) { return; } //TODO 如果有多个创建子标签如何正确处理? GUTag newTag = TagDB.NewTag(StaticCfg.Ins.DefaultNewTag); TagDB.SetParent(SelectedTag, newTag); //完善:如果新建Tag不在可见范围内,更新根节点。 //RedrawGraph(); EnsureVisible(newTag, RootTag); //BUG20171031: 子标签如果没有在图中显示出来(比如mainCanvas中因为深度的限制,并没有将其显示出来,下面b可能为null TagBox b = ChangeSelectd(newTag); FloatTextBox.Ins.ShowEdit(canvas, b); }
protected void Rebuild() { this.isDirty = true; this.tags.Sort(); this.boxen.Clear(); if (this.Window == null) { return; } var cr = Gdk.CairoHelper.Create(this.Window); cr.SetFontSize(FONT_HEIGHT); cr.SelectFontFace("Mono", FontSlant.Normal, FontWeight.Normal); int left = ENTRY_PADDING; int top = ENTRY_PADDING; foreach (string rawTag in this.tags) { var tag = rawTag.Replace('_', ' '); var box = new TagBox(); box.Extents = cr.TextExtents(tag); box.Tag = tag; box.Rect = new Rectangle(left, top, box.Extents.Width + 3 * TAGBOX_PADDING + TAGBOX_XSIZE, FONT_HEIGHT + 2 * TAGBOX_PADDING); this.boxen.Add(box); left += (int)(TAGBOX_SEPARATION + box.Rect.Width); } cr.Dispose(); this.isDirty = false; this.QueueDraw(); }
private void NewBrotherTag() { UpdateCurrentTagByContextMenu(); if (SelectedTag == null) { return; } List <GUTag> ps = TagDB.QueryTagParent(SelectedTag); if (ps.Count == 0) { return; } GUTag parent = ps[0]; GUTag newTag = TagDB.NewTag(StaticCfg.Ins.DefaultNewTag); TagDB.SetParent(parent, newTag);//TODO 如果有多个创建子标签如何正确处理? RedrawGraph(); TagBox b = ChangeSelectd(newTag); FloatTextBox.Ins.ShowEdit(canvas, b); }
void ReleaseDesignerOutlets() { if (AddTagButton != null) { AddTagButton.Dispose(); AddTagButton = null; } if (ArrangerBox != null) { ArrangerBox.Dispose(); ArrangerBox = null; } if (BackgroundBox != null) { BackgroundBox.Dispose(); BackgroundBox = null; } if (BookmarkLabelBox != null) { BookmarkLabelBox.Dispose(); BookmarkLabelBox = null; } if (BookmarkList != null) { BookmarkList.Dispose(); BookmarkList = null; } if (BookmarkMeasureBox != null) { BookmarkMeasureBox.Dispose(); BookmarkMeasureBox = null; } if (ComposerBox != null) { ComposerBox.Dispose(); ComposerBox = null; } if (CopyrightBox != null) { CopyrightBox.Dispose(); CopyrightBox = null; } if (DifficultyBox != null) { DifficultyBox.Dispose(); DifficultyBox = null; } if (FingerHintBox != null) { FingerHintBox.Dispose(); FingerHintBox = null; } if (HandsBox != null) { HandsBox.Dispose(); HandsBox = null; } if (LicenseBox != null) { LicenseBox.Dispose(); LicenseBox = null; } if (MadeFamousByBox != null) { MadeFamousByBox.Dispose(); MadeFamousByBox = null; } if (PartsBox != null) { PartsBox.Dispose(); PartsBox = null; } if (PropertiesGroup != null) { PropertiesGroup.Dispose(); PropertiesGroup = null; } if (RatingBox != null) { RatingBox.Dispose(); RatingBox = null; } if (RemoveBookmarkButton != null) { RemoveBookmarkButton.Dispose(); RemoveBookmarkButton = null; } if (RemoveTagButton != null) { RemoveTagButton.Dispose(); RemoveTagButton = null; } if (RetargetButton != null) { RetargetButton.Dispose(); RetargetButton = null; } if (SongList != null) { SongList.Dispose(); SongList = null; } if (SubtitleBox != null) { SubtitleBox.Dispose(); SubtitleBox = null; } if (TagBox != null) { TagBox.Dispose(); TagBox = null; } if (TagList != null) { TagList.Dispose(); TagList = null; } if (TitleBox != null) { TitleBox.Dispose(); TitleBox = null; } if (UniqueIdBox != null) { UniqueIdBox.Dispose(); UniqueIdBox = null; } }
public TagItem(Tag t, TagBox box) { this.Tag = t; _tagBox = box; }
private void AddTag_Click(object sender, EventArgs e) { c.AddTag(TagBox.Text); TagBox.Clear(); }
private GUTag NavigateTagBox(Key direction) { //先找到当前选择的节点 TagBox curB = null; foreach (UIElement b in allTagBox)//Bug:不能使用Children,Children中有些事不可见的(为了性能优化,没有将所有无用的TagBox从Canvas.Children中删除 { TagBox tmp = b as TagBox; if (tmp != null && tmp.GUTag == SelectedTag) { curB = tmp; break; } } double xyRadio = 0.1; if (direction == Key.Left || direction == Key.Right) { xyRadio = 1 / xyRadio; } double mimDistance = double.MaxValue; double mimDistanceBetter = double.MaxValue; GUTag result = null; GUTag resultBetter = null; //在移动当前节点 if (curB != null) { foreach (UIElement tmp in allTagBox) { TagBox b = tmp as TagBox; //过滤掉不满足条件的所有元素 if (b == null) { continue; } if (b == curB) { continue; } switch (direction) { case Key.Up: if (curB.Margin.Top <= b.Margin.Top + b.Height1) { continue; } break; case Key.Down: if (curB.Margin.Top + curB.Height1 >= b.Margin.Top) { continue; } break; case Key.Left: if (curB.Margin.Left <= b.Margin.Left + b.Width1) { continue; } break; case Key.Right: if (curB.Margin.Left + curB.Width1 >= b.Margin.Left) { continue; } break; default: break; } double x1 = curB.Margin.Left + curB.Width1 / 2; double y1 = curB.Margin.Top + curB.Height1 / 2; double x2 = b.Margin.Left + b.Width1 / 2; double y2 = b.Margin.Top + b.Height1 / 2; double dis = double.MaxValue; double delta = 0.2; //左右移动时,如果两个矩形在水平方向上有交集,优先采用 //采用的标准是看水平方向的距离 if (direction == Key.Left || direction == Key.Right) { double top1 = b.Margin.Top - delta; double bottom1 = top1 + b.Height1 + delta; double top2 = curB.Margin.Top - delta; double bottom2 = top2 + curB.Height1 + delta; if (!(top1 > bottom2 || bottom1 < top2)) { dis = (x1 - x2) * (x1 - x2); dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } } //上下移动时,如果两个矩形在垂直方向上有交集,优先采用 //采用的标准是看垂直方向的距离 else if (direction == Key.Up || direction == Key.Down) { double left1 = b.Margin.Left - delta; double right1 = left1 + b.Width1 + delta; double left2 = curB.Margin.Left - delta; double right2 = left2 + curB.Width1 + delta; if (!(left1 > right2 || right1 < left2)) { dis = (y1 - y2) * (y1 - y2); dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } } //记录下优选中的佼佼者 if (dis < mimDistanceBetter) { mimDistanceBetter = dis; resultBetter = b.GUTag; } //如果都没有交集,就直接看距离 dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); if (dis < mimDistance) { mimDistance = dis; result = b.GUTag; } } } if (resultBetter != null) { SetCurrentTag(resultBetter, true); } else if (result != null) { SetCurrentTag(result, true); } //如果当前节点时根节点,则向上退一级 else if ((direction == Key.Left || direction == Key.Up) && SelectedTag == RootTag) { UpTag(); } return(result); }