protected void MemoMarkDropDownMenuItemClick(ToolStripSplitButton button, MemoMarkKind kind, Image image) { if (_EditorCanvas == null) { return; } var memo = _EditorCanvas.EditorContent as Memo; var marks = memo.Marks; var isAdding = !marks.Any(mark => mark.Kind == kind); if (memo.Marks.Any(mark => mark.Kind == kind)) { ICollectionUtil.Remove(memo.Marks, mark => mark.Kind == kind); } else { var newMark = MemoFactory.CreateMark(); newMark.Kind = kind; memo.Marks.Add(newMark); } /// ToolStripSplitButtonを選択されたkindに変更 button.Tag = kind; button.Image = image; if (_facade.IsMainFormLoaded) { var info = _PageContent.MemoInfo; _facade.MainForm.InvalidateMemoListBox(new [] { info }); } _PageContent.IsModified = true; /// 選択中のノートのマーク設定 //var targets = _EditorCanvas.SelectionManager.SelectedEditors; //if (!targets.Any( // editor => { // var content = editor.Model as MemoContent; // return content != null && content.IsMarkable; // } //)) { // return; //} ///// markの追加か削除かの判定,最初のIsMarkableなeditorで判断する //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 isAdding = !firstMarks.Any(mark => mark.Kind == kind); ///// markの変更 //foreach (var target in targets) { // var content = target.Model as MemoContent; // if (content == null || !content.IsMarkable) { // continue; // } // if (isAdding && !content.Marks.Any(mark => mark.Kind == kind)) { // var newMark = MemoFactory.CreateMark(); // newMark.Kind = kind; // content.Marks.Add(newMark); // } else if (!isAdding && content.Marks.Any(mark => mark.Kind == kind)) { // ICollectionUtil.Remove(content.Marks, mark => mark.Kind == kind); // } //} ///// ToolStripSplitButtonを選択されたkindに変更 //button.Tag = kind; //button.Image = image; }
protected void UpdateMemoMarkHandles(TModel model) { if (!model.IsMarkable) { return; } /// MarkのHandleを更新 if (model.Marks.Count > 0) { var markHandle = _compositeMemoMarkHandle.Value; /// いらないmark handleを削除 ICollectionUtil.Remove( markHandle.Children, handle => { var mh = handle as MemoMarkHandle; if (mh != null) { return(!model.Marks.Contains(mh.Mark)); } return(true); } ); /// mark handleを追加 foreach (var mark in model.Marks) { var contained = markHandle.Children.Any( handle => { var mh = handle as MemoMarkHandle; if (mh != null) { return(mh.Mark == mark); } return(false); } ); if (!contained) { var handle = new MemoMarkHandle(); handle.Mark = mark; markHandle.Children.Add(handle); } } if (Host != null && Host.Figure != null) { markHandle.Relocate(Host.Figure); } } else { if (_compositeMemoMarkHandle.IsValueCreated && _compositeMemoMarkHandle.Value.Children.Count > 0) { /// いらないmark handleを削除 var markHandle = _compositeMemoMarkHandle.Value; ICollectionUtil.Remove( markHandle.Children, handle => { var mh = handle as MemoMarkHandle; if (mh != null) { return(!model.Marks.Contains(mh.Mark)); } return(true); } ); } } }