Ejemplo n.º 1
0
        private async void ClassifyTree_Drop(object sender, DragEventArgs e)
        {
            ClassifyTree.AllowDrop = false;
            if (e.Data.GetDataPresent("classify"))
            {
                var from   = e.Data.GetData("classify") as string;
                var to     = "/";
                var iscopy = (e.AllowedEffects & DragDropEffects.Copy) != 0 && Keyboard.IsKeyDown(Key.LeftCtrl);

                lock (drop_lock)
                    if (drop_checker == true)
                    {
                        return;
                    }

                if (!iscopy && (from == to || from.Count(x => x == '/') == 1))
                {
                    var dialog = new BookmarkMessageOk($"같은 분류 또는 하위 분류로는 {(iscopy ? "복사할" : "옮길")} 수 없어요!");
                    await DialogHost.Show(dialog, "BookmarkDialog");

                    return;
                }

                await classify_move(from, to, iscopy);
            }
        }
Ejemplo n.º 2
0
        private async void Button_ClickAsync(object sender, RoutedEventArgs e)
        {
            var tag = (sender as Button).Tag.ToString();
            switch (tag)
            {
                case "Import":
                case "Export":
                    break;

                case "Dangling":
                    {
                        var classes = new HashSet<string>();
                        foreach (var rc in BookmarkModelManager.Instance.Model.root_classes)
                            classes.Add(rc);
                        foreach (var sc in BookmarkModelManager.Instance.Model.sub_classes)
                            classes.Add($"{sc.Item1}/{sc.Item2}");

                        var dangling_articles = new List<Tuple<string, BookmarkItemModel>>();
                        var dangling_artists = new List<Tuple<string, BookmarkItemModel>>();
                        var dangling_groups = new List<Tuple<string, BookmarkItemModel>>();
                        var dangling_etcs = new List<Tuple<string, BookmarkEtcItemModel>>();
                        foreach (var elem in BookmarkModelManager.Instance.Model.articles)
                            if (!classes.Contains(elem.Item1))
                                dangling_articles.Add(elem);
                        foreach (var elem in BookmarkModelManager.Instance.Model.artists)
                            if (!classes.Contains(elem.Item1))
                                dangling_artists.Add(elem);
                        foreach (var elem in BookmarkModelManager.Instance.Model.groups)
                            if (!classes.Contains(elem.Item1))
                                dangling_groups.Add(elem);
                        foreach (var elem in BookmarkModelManager.Instance.Model.etcs)
                            if (!classes.Contains(elem.Item1))
                                dangling_etcs.Add(elem);

                        var total_cnt = dangling_articles.Count + dangling_artists.Count + dangling_etcs.Count + dangling_groups.Count;
                        if (total_cnt > 0)
                        {
                            var builder = new StringBuilder();
                            builder.Append($"총 {total_cnt}개의 떠돌이 항목이 검색됨\r\n\r\n");
                            if (dangling_articles.Count > 0)
                            {
                                builder.Append($"작품 떠돌이 항목 {dangling_articles.Count}개\r\n");
                                foreach (var item in dangling_articles)
                                    builder.Append($"{item.Item1} - {item.Item2.content} {item.Item2.etc} {item.Item2.stamp}\r\n");
                                builder.Append("\r\n");
                            }
                            if (dangling_artists.Count > 0)
                            {
                                builder.Append($"작가 떠돌이 항목 {dangling_artists.Count}개\r\n");
                                foreach (var item in dangling_artists)
                                    builder.Append($"{item.Item1} - {item.Item2.content} {item.Item2.etc} {item.Item2.stamp}\r\n");
                                builder.Append("\r\n");
                            }
                            if (dangling_groups.Count > 0)
                            {
                                builder.Append($"그룹 떠돌이 항목 {dangling_groups.Count}개\r\n");
                                foreach (var item in dangling_groups)
                                    builder.Append($"{item.Item1} - {item.Item2.content} {item.Item2.etc} {item.Item2.stamp}\r\n");
                                builder.Append("\r\n");
                            }
                            if (dangling_etcs.Count > 0)
                            {
                                builder.Append($"기타 떠돌이 항목 {dangling_etcs.Count}개\r\n");
                                foreach (var item in dangling_etcs)
                                    builder.Append($"{item.Item1} - {item.Item2.content} {item.Item2.etc} {item.Item2.stamp}\r\n");
                                builder.Append("\r\n");
                            }

                            var dialog = new BookmarkToolDangling(builder.ToString());
                            if ((bool)(await DialogHost.Show(dialog, "ToolDialog")))
                            {
                                var n_classes = new HashSet<string>();

                                foreach (var ic in dangling_articles)
                                {
                                    n_classes.Add(ic.Item1);
                                    BookmarkModelManager.Instance.Model.articles.Remove(ic);
                                    BookmarkModelManager.Instance.Model.articles.Add(new Tuple<string, BookmarkItemModel>("/떠돌이 항목" + ic.Item1, ic.Item2));
                                }
                                foreach (var ic in dangling_artists)
                                {
                                    n_classes.Add(ic.Item1);
                                    BookmarkModelManager.Instance.Model.artists.Remove(ic);
                                    BookmarkModelManager.Instance.Model.artists.Add(new Tuple<string, BookmarkItemModel>("/떠돌이 항목" + ic.Item1, ic.Item2));
                                }
                                foreach (var ic in dangling_groups)
                                {
                                    n_classes.Add(ic.Item1);
                                    BookmarkModelManager.Instance.Model.groups.Remove(ic);
                                    BookmarkModelManager.Instance.Model.groups.Add(new Tuple<string, BookmarkItemModel>("/떠돌이 항목" + ic.Item1, ic.Item2));
                                }
                                foreach (var ic in dangling_etcs)
                                {
                                    n_classes.Add(ic.Item1);
                                    BookmarkModelManager.Instance.Model.etcs.Remove(ic);
                                    BookmarkModelManager.Instance.Model.etcs.Add(new Tuple<string, BookmarkEtcItemModel>("/떠돌이 항목" + ic.Item1, ic.Item2));
                                }

                                var used = new HashSet<string>();
                                var sub_classes = new List<Tuple<string, string>>();
                                foreach (var cc in n_classes)
                                {
                                    var nname = "/떠돌이 항목" + cc;
                                    if (classes.Contains(nname))
                                        continue;
                                    
                                    var ss = nname.Split('/');
                                    var root = "/" + ss[1];
                                    var parent = root;
                                    for (int i = 2; i < ss.Length; i++)
                                    {
                                        if (!used.Contains(parent + "/" + ss[i]))
                                        {
                                            used.Add(parent + "/" + ss[i]);
                                            sub_classes.Add(new Tuple<string, string>(parent, ss[i]));
                                        }
                                        parent += "/" + ss[i];
                                    }
                                }
                                if (!BookmarkModelManager.Instance.Model.root_classes.Contains("/떠돌이 항목"))
                                    BookmarkModelManager.Instance.Model.root_classes.Add("/떠돌이 항목");
                                BookmarkModelManager.Instance.Model.sub_classes.AddRange(sub_classes);
                                BookmarkModelManager.Instance.Save();
                            }
                        }
                        else
                        {
                            var dialog = new BookmarkMessageOk("떠돌이 항목이 없습니다!");
                            await DialogHost.Show(dialog, "ToolDialog");
                        }
                    }
                    break;
            }

        }
Ejemplo n.º 3
0
        private async Task classify_move(string from, string to, bool copy)
        {
            var name        = from.Split('/').Last();
            var from_parent = from.Remove(from.Length - name.Length);
            var warning     = false;
            var not_valid   = false;

            if (to == "/")
            {
                foreach (var ss in BookmarkModelManager.Instance.Model.root_classes)
                {
                    if (ss == "/" + name)
                    {
                        warning = true;
                    }
                }
            }
            else
            {
                foreach (var ss in BookmarkModelManager.Instance.Model.sub_classes)
                {
                    if (ss.Item1 == to && ss.Item2 == name)
                    {
                        warning = true;
                    }
                }
            }

            if (from.Remove(from.Length - from.Split('/').Last().Length - 1) == to)
            {
                not_valid = true;
            }

            if (warning || not_valid)
            {
                if (!not_valid)
                {
                    var dialog_error = new BookmarkMessage($"경고! {to}에 이미 {name}이 존재하기 때문에 {(copy ? "복사할" : "옮길")} 수 없어요!\r\n그래도 모든 경고를 무시하고 {(copy ? "복사를" : "이동을")} 진행할까요?\r\n하위 항목들은 자동으로 합쳐져요.");
                    if (!(bool)(await DialogHost.Show(dialog_error, "BookmarkDialog")))
                    {
                        return;
                    }
                }
                else
                {
                    var dialog_error = new BookmarkMessageOk($"부모로 바로 연결되는 상위 분류로는 {(copy ? "복사할" : "옮길")} 수 없어요!");
                    await DialogHost.Show(dialog_error, "BookmarkDialog");

                    return;
                }
            }

            if (to == "/")
            {
                to = "";
            }
            var dialog = new BookmarkMessage($"{name}을 {from_parent}에서 {to + "/"}로 {(copy ? "복사할" : "옮길")}까요?");

            if ((bool)(await DialogHost.Show(dialog, "BookmarkDialog")))
            {
                if (copy)
                {
                    copyto(from, to);
                }
                else
                {
                    moveto(from, to);
                }
                BookmarkModelManager.Instance.Save();
                init();
            }
        }
Ejemplo n.º 4
0
        private async void Tvi_DropAsync(object sender, DragEventArgs e)
        {
            // Drop 이벤트에선 Bubbling이 일어나기 때문에 e.Handled를 true로 조작하거나
            // lock을 사용하여 처리해줄 필요가 있음
            // 단, lock을 사용할경우 unlock처리 지연을 위한 루틴이 하나이상 있어야함
            ClassifyTree.AllowDrop = false;
            var iscopy = (e.AllowedEffects & DragDropEffects.Copy) != 0 && Keyboard.IsKeyDown(Key.LeftCtrl);

            if (e.Data.GetDataPresent("registries"))
            {
                var tt = e.Data.GetData("registries") as Tuple <string, List <BookmarkPageDataGridItemViewModel> >;

                lock (drop_lock)
                    if (drop_checker == true)
                    {
                        var tvi = sender as TreeViewItem;
                        tvi.Foreground = Brushes.Black;
                        return;
                    }
                lock (drop_lock)
                    drop_checker = true;

                var message = $"{tt.Item2.Count}개 항목을 {tt.Item1}에서 {(sender as TreeViewItem).Tag}로 {(iscopy ? "복사할" : "옮길")}까요?";
                var dialog  = new BookmarkMessage(message);
                if ((bool)(await DialogHost.Show(dialog, "BookmarkDialog")))
                {
                    if (iscopy == false)
                    {
                        // 기존항목들 삭제
                        foreach (var ll in tt.Item2)
                        {
                            List <Tuple <string, BookmarkItemModel> > rl;
                            if (ll.형 == "작가")
                            {
                                rl = BookmarkModelManager.Instance.Model.artists;
                            }
                            else if (ll.형 == "그룹")
                            {
                                rl = BookmarkModelManager.Instance.Model.groups;
                            }
                            else
                            {
                                rl = BookmarkModelManager.Instance.Model.articles;
                            }

                            for (int i = 0; i < rl.Count; i++)
                            {
                                if (rl[i].Item1 == tt.Item1 && rl[i].Item2.Equals(ll.BIM))
                                {
                                    rl.RemoveAt(i);
                                    break;
                                }
                            }
                        }
                    }

                    // 추가
                    foreach (var ll in tt.Item2)
                    {
                        List <Tuple <string, BookmarkItemModel> > rl;
                        if (ll.형 == "작가")
                        {
                            rl = BookmarkModelManager.Instance.Model.artists;
                        }
                        else if (ll.형 == "그룹")
                        {
                            rl = BookmarkModelManager.Instance.Model.groups;
                        }
                        else
                        {
                            rl = BookmarkModelManager.Instance.Model.articles;
                        }

                        rl.Add(new Tuple <string, BookmarkItemModel>((sender as TreeViewItem).Tag.ToString(), ll.BIM));
                    }

                    BookmarkModelManager.Instance.Save();
                    refresh();
                }
            }
            else if (e.Data.GetDataPresent("classify"))
            {
                var from = e.Data.GetData("classify") as string;
                var to   = (sender as TreeViewItem).Tag as string;

                lock (drop_lock)
                    if (drop_checker == true)
                    {
                        var tvi = sender as TreeViewItem;
                        tvi.Foreground = Brushes.Black;
                        return;
                    }
                lock (drop_lock)
                    drop_checker = true;

                if (from == to || (to.StartsWith(from) && !iscopy))
                {
                    var dialog = new BookmarkMessageOk($"같은 분류 또는 하위 분류로는 {(iscopy ? "복사할" : "옮길")} 수 없어요!");
                    await DialogHost.Show(dialog, "BookmarkDialog");

                    goto END;
                }

                await classify_move(from, to, iscopy);
            }
END:
            lock (drop_lock)
                drop_checker = false;
            var tvi2 = sender as TreeViewItem;

            tvi2.Foreground = Brushes.Black;
        }