Exemplo n.º 1
0
        private void InitMarkDefCheckListBox()
        {
            var defs = MemoMarkUtil.GetMemoMarkDefinitions();

            foreach (var def in defs)
            {
                var item = new KryptonListItem();
                item.ShortText = def.Name;
                item.Image     = def.Image;
                item.Tag       = def;
                _markDefinitionCheckedListBox.Items.Add(item);
            }
        }
Exemplo n.º 2
0
        protected void SavePageContent(PageContent pageContent)
        {
            var info   = pageContent.MemoInfo;
            var canvas = pageContent.EditorCanvas;

            if (pageContent.IsModified)
            {
                MemoSerializeUtil.SaveEditor(info.MementoId, canvas);
                var memo = canvas.EditorContent as Memo;

                _facade.Container.SaveExtendedTextData(memo, "FullText", canvas.GetFullText());
                _facade.Container.SaveExtendedTextData(memo, "SummaryText", MemoTextUtil.GetSummaryText(canvas));
                MemoMarkUtil.SaveMarkIdsCache(memo, MemoMarkUtil.GetMemoMarkIds(memo));
                MemoOutlineUtil.SaveOutline(pageContent.EditorCanvas);

                pageContent.IsModified = false;
            }
        }
Exemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var g           = e.Graphics;
            var borderColor = SystemColors.ControlDark;
            var backColor   = SystemColors.Window;

            if (_isCompact)
            {
                ControlPaint.DrawBorder(g, ClientRectangle, borderColor, ButtonBorderStyle.Solid);
                return;
            }

            var y  = _editorCanvas.Top - 1;
            var y2 = _titleTextBox.Top - ItemPadding;
            var r  = new Rectangle(0, 0, Width, y);

            using (var brush = new SolidBrush(_theme.DarkBackColor))
                using (var pen = new Pen(Color.FromArgb(160, 170, 200), 1)) {
                    //g.FillRectangle(brush1, r1);
                    //g.FillRectangle(brush2, r2);
                    g.FillRectangle(brush, r);
                    g.DrawLine(pen, new Point(0, y), new Point(Width, y));
                }
            if (_inMemoSearcher.Visible)
            {
                using (var pen = new Pen(_borderColor)) {
                    g.DrawLine(pen, new Point(0, _inMemoSearcher.Top - 1), new Point(Width, _inMemoSearcher.Top - 1));
                }
            }

            ControlPaintUtil.DrawBorder(g, _titleTextBox, borderColor, backColor, ItemPadding);
            ControlPaintUtil.DrawBorder(g, _tagTextBox, borderColor, backColor, ItemPadding);

            if (_isSubInfoShown)
            {
                using (var pen = new Pen(Color.Silver)) {
                    pen.DashStyle = DashStyle.Dash;
                    var lineY = (_tagTextBox.Top + _sourceTextBox.Bottom) / 2;
                    g.DrawLine(pen, new Point(ItemSpace, lineY), new Point(Width - ItemSpace - 1, lineY));
                }
                ControlPaintUtil.DrawBorder(g, _sourceTextBox, borderColor, backColor, ItemPadding);

                /// mark
                if (_memo != null)
                {
                    var marks      = _memo.Marks;
                    var markCount  = marks.Count;
                    var markImages = new List <Image>();
                    for (int i = 0; i < markCount; ++i)
                    {
                        var def = MemoMarkUtil.GetMarkDefinition(marks[i]);
                        markImages.Add(def.Image);
                    }

                    if (markImages.Count > 0)
                    {
                        var top   = _sourceLabel.Bottom + ItemPadding + ((y - (_sourceLabel.Bottom + ItemPadding)) - markImages[0].Height) / 2;
                        var cLeft = _titleTextBox.Left - ItemPadding;
                        for (int i = 0; i < markCount; ++i)
                        {
                            var image = markImages[i];
                            g.DrawImage(image, new Point(cLeft, top));
                            cLeft += image.Width + ItemPadding;
                        }
                    }
                }
            }

            ControlPaint.DrawBorder(g, ClientRectangle, _borderColor, ButtonBorderStyle.Solid);
        }
Exemplo n.º 4
0
        // --- mark ---
        protected void HandleMemoMarkToolStripSplitButtonDropDownOpening(object sender, EventArgs e)
        {
            var button = (ToolStripSplitButton)sender;
            var items  = button.DropDownItems;

            items.Clear();

            if (_EditorCanvas == null)
            {
                return;
            }

            var memo  = _EditorCanvas.EditorContent as Memo;
            var marks = memo.Marks;

            var item = default(ToolStripMenuItem);
            var defs = MemoMarkUtil.GetMemoMarkDefinitions();

            item        = new ToolStripMenuItem("すべてクリア");
            item.Click += (s, ev) => MemoMarkDropDownClearMenuItemClick();
            items.Add(item);
            items.Add(new ToolStripSeparator());

            foreach (var def in defs)
            {
                var kind  = def.Kind;
                var image = def.Image;
                item         = new ToolStripMenuItem(def.Name, image);
                item.Click  += (s, ev) => MemoMarkDropDownMenuItemClick(button, kind, image);
                item.Checked = marks.Any(mark => mark.Kind == kind);
                items.Add(item);
            }

            /// 選択中のノートのマーク表示
            //var targets = _EditorCanvas.SelectionManager.SelectedEditors;
            //if (!targets.Any(
            //    editor => {
            //        var content = editor.Model as MemoContent;
            //        return content != null && content.IsMarkable;
            //    }
            //)) {
            //    return;
            //}

            //var first = targets.First(
            //    editor => {
            //        var content = editor.Model as MemoContent;
            //        return content != null && content.IsMarkable;
            //    }
            //);
            //var firstContent = first.Model as MemoContent;
            //if (firstContent == null) {
            //    return;
            //}
            //var firstMarks = firstContent.Marks;

            //var item = default(ToolStripMenuItem);
            //var defs = MemoMarkUtil.GetMemoMarkDefinitions();

            //foreach (var def in defs) {
            //    var kind = def.Kind;
            //    var image = def.Image;
            //    item = new ToolStripMenuItem(def.Name, image);
            //    item.Click += (s, ev) => MemoMarkDropDownMenuItemClick(button, kind, image);
            //    item.Checked = firstMarks.Any(mark => mark.Kind == kind);
            //    items.Add(item);
            //}
        }
Exemplo n.º 5
0
        /// <summary>
        /// infos内からqueryに適合するものだけを返す。
        /// </summary>
        public IEnumerable <MemoInfo> Search(IEnumerable <MemoInfo> infos, MemoQuery query)
        {
            if (query == null || query.IsEmptyQuery)
            {
                return(new List <MemoInfo>());
            }

            var matched = infos;

            /// タイトル
            if (query.NarrowByTitle)
            {
                matched = matched.Where(
                    info => info.Title.IndexOf(query.Title, StringComparison.OrdinalIgnoreCase) > -1
                    );
            }

            /// タグ
            if (query.NarrowByTagIds)
            {
                var tags     = GetTags(query);
                var noTag    = query.NoTag;
                var compKind = query.TagCompoundKind;
                Func <MemoInfo, bool> tagFilter = info => {
                    var memo = _facade.Container.Find <Memo>(info.MemoId);
                    return
                        /// noTagかつ「allでタグを指定」を満たすことはあり得ないので,noTagは常にorでつなぐだけにしておく
                        ((noTag && !memo.Tags.Any()) ||
                         (compKind == MemoConditionCompoundKind.Any && memo.Tags.ContainsAny(tags)) ||
                         (compKind == MemoConditionCompoundKind.All && memo.Tags.ContainsAll(tags)));
                };
                matched = matched.Where(tagFilter);
            }

            /// 重要度
            if (query.NarrowByImportanceKind)
            {
                var importances = query.ImportanceKinds;
                Func <MemoInfo, bool> importanceFilter = info => {
                    var memo = _facade.Container.Find <Memo>(info.MemoId);
                    return(importances.Contains(memo.Importance));
                };
                matched = matched.Where(importanceFilter);
            }


            /// recent
            if (query.NarrowByRecentTimeSpan)
            {
                var recent = query.RecentTimeSpan;
                var filter = default(Func <MemoInfo, bool>);
                switch (recent.DateKind)
                {
                case MemoDateKind.Created: {
                    filter = info => {
                        var memo = _facade.Container.Find <Memo>(info.MemoId);
                        return
                            (memo.CreatedDate >= recent.FromDate &&
                             memo.CreatedDate < recent.ToDate);
                    };
                    break;
                }

                case MemoDateKind.Modified: {
                    filter = info => {
                        var memo = _facade.Container.Find <Memo>(info.MemoId);
                        return
                            (memo.ModifiedDate >= recent.FromDate &&
                             memo.ModifiedDate < recent.ToDate);
                    };
                    break;
                }

                case MemoDateKind.Accessed: {
                    filter = info => {
                        var memo = _facade.Container.Find <Memo>(info.MemoId);
                        return
                            (memo.AccessedDate >= recent.FromDate &&
                             memo.AccessedDate < recent.ToDate);
                    };
                    break;
                }
                }
                matched = matched.Where(filter);
            }

            /// 期間
            if (query.NarrowByTimeSpan)
            {
                var timeSpan = query.TimeSpan;
                var filter   = default(Func <MemoInfo, bool>);
                switch (timeSpan.DateKind)
                {
                case MemoDateKind.Created: {
                    filter = info => {
                        var memo = _facade.Container.Find <Memo>(info.MemoId);
                        return
                            (memo.CreatedDate >= timeSpan.FromDate &&
                             memo.CreatedDate < timeSpan.ToDate);
                    };
                    break;
                }

                case MemoDateKind.Modified: {
                    filter = info => {
                        var memo = _facade.Container.Find <Memo>(info.MemoId);
                        return
                            (memo.ModifiedDate >= timeSpan.FromDate &&
                             memo.ModifiedDate < timeSpan.ToDate);
                    };
                    break;
                }

                case MemoDateKind.Accessed: {
                    filter = info => {
                        var memo = _facade.Container.Find <Memo>(info.MemoId);
                        return
                            (memo.AccessedDate >= timeSpan.FromDate &&
                             memo.AccessedDate < timeSpan.ToDate);
                    };
                    break;
                }
                }
                matched = matched.Where(filter);
            }

            /// マーク
            if (query.NarrowByMarkKinds)
            {
                var noMarkKind = query.NoMarkKind;
                Func <MemoInfo, bool> markFilter = info => {
                    var memo   = _facade.Container.Find <Memo>(info.MemoId);
                    var opened = _facade.FindPageContent(info);

                    var markIds = default(IEnumerable <string>);
                    if (opened == null)
                    {
                        /// 開かれていなければキャッシュを見る
                        markIds = MemoMarkUtil.LoadMarkIdsCache(memo);
                        if (markIds == null)
                        {
                            markIds = MemoMarkUtil.GetMemoMarkIds(memo);
                            MemoMarkUtil.SaveMarkIdsCache(memo, markIds);
                        }
                    }
                    else
                    {
                        markIds = MemoMarkUtil.GetMemoMarkIds(memo);
                    }

                    if (noMarkKind && !markIds.Any())
                    {
                        return(true);
                    }
                    var marks     = MemoMarkUtil.GetMarks(markIds);
                    var markKinds = marks.Select(mark => mark.Kind).ToArray();
                    var compKind  = query.MarkCompoundKind;
                    return
                        ((compKind == MemoConditionCompoundKind.Any && query.MarkKinds.Any(kind => markKinds.Contains(kind))) ||
                         (compKind == MemoConditionCompoundKind.All && query.MarkKinds.All(kind => markKinds.Contains(kind))));
                };
                matched = matched.Where(markFilter);
            }


            /// 全文検索
            if (!query.NarrowByKeywords)
            {
                return(matched);
            }
            else
            {
                var ret = new List <MemoInfo>();

                var keywords = query.Condition.Split(' ');

                foreach (var info in matched.ToArray())
                {
                    /// MemoInfoのFullTextを取得
                    var fullText = default(string);
                    var opened   = _facade.FindPageContent(info);

                    if (opened == null)
                    {
                        fullText = _facade.Container.LoadExtendedTextData(typeof(Memo), info.MemoId, "FullText");

                        if (fullText == null)
                        {
                            /// 見つからなかった場合はノートをロードしてGetText()できるようにしておく
                            _facade.LoadMemo(info, true);
                            opened = _facade.FindPageContent(info);
                            if (opened != null)
                            {
                                var canvas = opened.EditorCanvas;
                                _facade.Container.SaveExtendedTextData(
                                    canvas.EditorContent, "FullText", canvas.GetFullText()
                                    );
                            }
                        }
                    }

                    if (opened != null && fullText == null)
                    {
                        var canvas = opened.EditorCanvas;
                        fullText = canvas.GetFullText();
                    }

                    if (fullText != null)
                    {
                        var matchFailed = false;
                        foreach (var keyword in keywords)
                        {
                            //if (Regex.IsMatch(fullText, keyword, RegexOptions.IgnoreCase | RegexOptions.Multiline)) {
                            if (keyword.StartsWith("-"))
                            {
                                /// "-"で始まる場合は除外キーワード
                                var realKeyword = keyword.Substring(1); /// "-"を除去
                                if (fullText.IndexOf(realKeyword, StringComparison.OrdinalIgnoreCase) > -1)
                                {
                                    matchFailed = true;
                                    break;
                                }
                            }
                            else
                            {
                                /// "-"で始まらなければ普通のキーワード
                                if (fullText.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) < 0)
                                {
                                    matchFailed = true;
                                    break;
                                }
                            }
                        }
                        if (!matchFailed)
                        {
                            ret.Add(info);
                        }
                    }
                }

                return(ret);
            }
        }