public void DoCut(EditorCanvas editorCanvas) { if (editorCanvas == null) { return; } if (editorCanvas.FocusManager.IsEditorFocused) { var focus = editorCanvas.FocusManager.Focus as StyledTextFocus; if (focus != null) { focus.Cut(); } } else if (editorCanvas.CanCut()) { var targets = editorCanvas.SelectionManager.SelectedEditors; var req = new CopyRequest(targets); var bundle = new EditorBundle(targets); var copy = bundle.GetGroupCommand(req); if (copy == null) { return; } var remove = bundle.GetCompositeCommand(new RemoveRequest()); if (remove == null) { return; } var cmd = copy.Chain(remove); editorCanvas.CommandExecutor.Execute(cmd); } }
// ------------------------------ // private // ------------------------------ private static void Copy(IEnumerable <IEditor> targets, ICommandExecutor commandExecutor) { var req = new CopyRequest(targets); var list = new EditorBundle(targets); list.PerformGroupRequest(req, commandExecutor); }
public override bool HandleDragFinish(MouseEventArgs e) { using (_Host.RootFigure.DirtManager.BeginDirty()) { var delta = (Size)e.Location - (Size)_startPoint; var horizontal = Math.Abs(delta.Width) > Math.Abs(delta.Height); var content = _Host.RootEditor.Content; if (horizontal) { _moveRequest.MovingEditors = content.Children.Where(edi => edi.Figure.Left > _startPoint.X).ToArray(); } else { _moveRequest.MovingEditors = content.Children.Where(edi => edi.Figure.Top > _startPoint.Y).ToArray(); } _targets = new EditorBundle(_moveRequest.MovingEditors); var moveDelta = horizontal ? new Size(delta.Width, 0) : new Size(0, delta.Height); _moveRequest.MoveDelta = moveDelta; _targets.HideFeedback(_moveRequest); _targets.PerformCompositeRequest(_moveRequest, _Host.CommandExecutor); _Host.RootEditor.Content.HideFeedback(_spaceRequest); } _canvas.Tool = _toolOnFinished; return(true); }
private ICommand GetCutCommand(IEnumerable <IEditor> targets) { var bundle = new EditorBundle(targets); var req = new CopyRequest(targets); var copy = bundle.GetGroupCommand(req); var remove = bundle.GetCompositeCommand(new RemoveRequest()); return(copy.Chain(remove)); }
public virtual void HandleDragStart(object sender, MouseEventArgs e) { _startPoint = e.Location; _targets = new EditorBundle(Handle.Host.Site.SelectionManager.SelectedEditors); _moveRequest.MovingEditors = Handle.Host.Site.SelectionManager.SelectedEditors; _moveRequest.MoveDelta = Size.Empty; Handle.Host.ShowFeedback(_moveRequest); }
public void Create(string name, Dictionary <string, IBundle> bundles) { Dictionary <string, HashSet <string> > info = new Dictionary <string, HashSet <string> >(); BundleBuildRule.Instance.Collection(info); foreach (var kv in info) { EditorBundle bundle = new EditorBundle(kv.Key, kv.Value); bundles.Add(kv.Key, bundle); } }
protected void SetStyledTextAlignmentBase( AlignmentModificationKinds kinds, Mkamo.Common.DataType.HorizontalAlignment horizontaliAlign, VerticalAlignment verticalAlign ) { if (_EditorCanvas.FocusManager.IsEditorFocused) { /// Focusがある場合はその内容を変更する var focus = _EditorCanvas.FocusManager.Focus as StyledTextFocus; if (focus != null) { if ((kinds & AlignmentModificationKinds.Horizontal) == AlignmentModificationKinds.Horizontal) { focus.SetHorizontalAlignment(horizontaliAlign); } if ((kinds & AlignmentModificationKinds.Vertical) == AlignmentModificationKinds.Vertical) { focus.SetVerticalAlignment(verticalAlign); } } return; } var selecteds = _EditorCanvas.SelectionManager.SelectedEditors; if (selecteds.Any()) { var bundle = new EditorBundle(_EditorCanvas.SelectionManager.SelectedEditors); var executor = _EditorCanvas.CommandExecutor; //var nodeFig = selecteds.First().Figure as INode; //if (nodeFig != null) { // var req = new SetPlainTextFontRequest() { // Font = fontProvider(nodeFig.Font), // }; // bundle.PerformCompositeRequest(req, executor); //} var node = selecteds.First().Model as MemoStyledText; if (node != null) { var req = new SetStyledTextAlignmentRequest() { Kinds = kinds, HorizontalAlignment = horizontaliAlign, VerticalAlignment = verticalAlign, }; bundle.PerformCompositeRequest(req, executor); } } }
protected void SetFontBase(Func <FontDescription, FontDescription> fontProvider, FontModificationKinds kind) { if (_EditorCanvas == null) { return; } if (_EditorCanvas.FocusManager.IsEditorFocused) { /// Focusがある場合はその内容を変更する var focus = _EditorCanvas.FocusManager.Focus as StyledTextFocus; if (focus != null) { focus.SetFont((flow) => fontProvider(flow.Font)); } // todo: PlainTextのときの処理 } else { /// Focusがない場合はRequestを送る var selecteds = _EditorCanvas.SelectionManager.SelectedEditors; if (selecteds.Any()) { var bundle = new EditorBundle(_EditorCanvas.SelectionManager.SelectedEditors); var executor = _EditorCanvas.CommandExecutor; var nodeFig = selecteds.First().Figure as INode; if (nodeFig != null) { var req = new SetPlainTextFontRequest() { Font = fontProvider(nodeFig.Font), }; bundle.PerformCompositeRequest(req, executor); } var node = selecteds.First().Model as MemoStyledText; if (node != null) { var stext = node.StyledText; var stfont = stext.Inlines.First().Font; var req = new SetStyledTextFontRequest() { FontProvider = (flow) => fontProvider(stfont), }; bundle.PerformCompositeRequest(req, executor); } } } }
private ICommand GetCutCommand() { var targets = _owner.SelectionManager.SelectedEditors; var req = new CopyRequest(targets); var list = new EditorBundle(targets); var copy = list.GetGroupCommand(req); if (copy == null) { return(null); } var remove = list.GetCompositeCommand(new RemoveRequest()); if (remove == null) { return(null); } return(copy.Chain(remove)); }
public override bool HandleDragMove(MouseEventArgs e) { using (_Host.RootEditor.Figure.DirtManager.BeginDirty()) { if (_targets != null) { _targets.HideFeedback(_moveRequest); } var delta = (Size)e.Location - (Size)_startPoint; var horizontal = Math.Abs(delta.Width) > Math.Abs(delta.Height); horizontal = Math.Abs(delta.Width) < 40 && Math.Abs(delta.Height) < 40 ? false: horizontal; var content = _Host.RootEditor.Content; if (horizontal) { _moveRequest.MovingEditors = content.Children.Where(edi => edi.Figure.Left > _startPoint.X).ToArray(); } else { _moveRequest.MovingEditors = content.Children.Where(edi => edi.Figure.Top > _startPoint.Y).ToArray(); } _targets = new EditorBundle(_moveRequest.MovingEditors); var moveDelta = horizontal ? new Size(delta.Width, 0) : new Size(0, delta.Height); _moveRequest.MoveDelta = moveDelta; _targets.ShowFeedback(_moveRequest); _spaceRequest.Horizontal = horizontal; if (horizontal) { _spaceRequest.Bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, new Point(e.X, _startPoint.Y + 20)); } else { _spaceRequest.Bounds = RectUtil.GetRectangleFromDiagonalPoints(_startPoint, new Point(_startPoint.X + 20, e.Y)); } _Host.RootEditor.Content.ShowFeedback(_spaceRequest); } return(true); }
protected void SetTextColorBase(Color color) { if (_EditorCanvas == null) { return; } if (_EditorCanvas.FocusManager.IsEditorFocused) { /// Focusがある場合はその内容を変更する var focus = _EditorCanvas.FocusManager.Focus as StyledTextFocus; if (focus != null) { focus.SetColor(color); } // todo: PlainTextのときの処理 } else { /// Focusがない場合はRequestを送る var selecteds = _EditorCanvas.SelectionManager.SelectedEditors; if (selecteds.Any()) { var bundle = new EditorBundle(_EditorCanvas.SelectionManager.SelectedEditors); var executor = _EditorCanvas.CommandExecutor; //var nodeFig = selecteds.First().Figure as INode; //if (nodeFig != null) { // var req = new SetPlainTextFontRequest() { // Font = fontProvider(nodeFig.Font), // }; // bundle.PerformCompositeRequest(req, executor); //} var node = selecteds.First().Model as MemoStyledText; if (node != null) { var stext = node.StyledText; var req = new SetStyledTextColorRequest(color); bundle.PerformCompositeRequest(req, executor); } } } }
// ======================================== // method // ======================================== protected ToolStripMenuItem CreateCutInNewMemo() { var ret = new ToolStripMenuItem("切り出す(&C)"); ret.Click += (sender, ev) => { using (var form = new CreateMemoForm()) { var app = MemopadApplication.Instance; form.Font = app.Theme.CaptionFont; form.MemoTitle = "新しいノート"; form.ReplaceWithLinkRadioButton.Enabled = false; if (form.ShowDialog() == DialogResult.OK) { var site = _owner.Host.Site; var targets = GetCutInNewMemoTargets(); if (targets != null && targets.Any()) { var cloneds = site.EditorCanvas.CloneEditors(targets); app.ActivateMainForm(); var info = app.CreateMemo(form.MemoTitle); if (form.OriginalModification == CreateMemoForm.OriginalModificationKind.Remove) { var bundle = new EditorBundle(targets); var remove = bundle.GetCompositeCommand(new RemoveRequest()); site.CommandExecutor.Execute(remove); } var pageContent = app.MainForm.FindPageContent(info); var targetCanvas = pageContent.EditorCanvas; var target = targetCanvas.RootEditor.Children.First(); var command = new AddEditorsCommand(target, cloneds, Size.Empty); targetCanvas.CommandExecutor.Execute(command); } } } }; return(ret); }
public void DoDelete(EditorCanvas editorCanvas) { if (editorCanvas == null) { return; } if (editorCanvas.FocusManager.IsEditorFocused) { var focus = editorCanvas.FocusManager.Focus as StyledTextFocus; if (focus != null) { focus.RemoveForward(); } } else if (editorCanvas.CanDelete()) { var selecteds = editorCanvas.SelectionManager.SelectedEditors; var bundle = new EditorBundle(selecteds); var req = new RemoveRequest(); bundle.PerformCompositeRequest(req, editorCanvas.CommandExecutor); } }
public void DoCopy(EditorCanvas editorCanvas) { if (editorCanvas == null) { return; } if (editorCanvas.FocusManager.IsEditorFocused) { var focus = editorCanvas.FocusManager.Focus as StyledTextFocus; if (focus != null) { focus.Copy(); } } else if (editorCanvas.CanCopy()) { var targets = editorCanvas.SelectionManager.SelectedEditors; var bundle = new EditorBundle(targets); var copy = new CopyRequest(targets); bundle.PerformGroupRequest(copy, editorCanvas.CommandExecutor); } }
public void DoPaste(EditorCanvas editorCanvas) { if (editorCanvas == null) { return; } if (editorCanvas.FocusManager.IsEditorFocused) { var focus = editorCanvas.FocusManager.Focus as StyledTextFocus; if (focus != null) { focus.PasteInlinesOrText(false); } } else if (editorCanvas.CanPaste()) { var selecteds = editorCanvas.SelectionManager.SelectedEditors; var bundle = new EditorBundle(selecteds); var req = new PasteRequest(); req.Location = editorCanvas.Caret.Position; bundle.PerformCompositeRequest(req, editorCanvas.CommandExecutor); } }
protected internal void SetParagraphListKind(ListKind listKind) { if (_EditorCanvas == null) { return; } if (_EditorCanvas.FocusManager.IsEditorFocused) { var focus = _EditorCanvas.FocusManager.Focus as StyledTextFocus; focus.ToggleList(listKind); UpdateToolStrip(); return; } var selecteds = _EditorCanvas.SelectionManager.SelectedEditors; if (selecteds.Any()) { var bundle = new EditorBundle(_EditorCanvas.SelectionManager.SelectedEditors); var executor = _EditorCanvas.CommandExecutor; /// listKindでないParagraphがひとつでもあればon == true。そうでなければon == false。 var on = false; var node = default(MemoStyledText); foreach (var selected in selecteds) { var memoSText = selected.Model as MemoStyledText; if (memoSText != null) { var stext = memoSText.StyledText; foreach (var block in stext.Blocks) { var para = block as Paragraph; if (para != null && para.ListKind != listKind) { on = true; break; } } if (node == null) { node = memoSText; } } if (on) { break; } } if (node != null) { var req = new SetStyledTextListKindRequest() { ListKind = listKind, On = on, }; bundle.PerformCompositeRequest(req, executor); } } }
private void InitItems() { _remove = new ToolStripMenuItem(); _remove.Text = "削除(&R)"; _remove.Click += (sender, e) => { using (_owner.CommandExecutor.BeginChain()) { var req = new RemoveRequest(); var cmds = new CompositeCommand(); var parent = default(IEditor); foreach (var editor in _owner.SelectionManager.SelectedEditors) { if (parent == null) { parent = editor.Parent; } if (editor.CanUnderstand(req)) { cmds.Children.Add(editor.GetCommand(req)); } } _owner.CommandExecutor.Execute(cmds); if (parent != null) { parent.RequestSelect(SelectKind.True, true); } } }; _clone = new ToolStripMenuItem(); _clone.Text = "複製(&C)"; _clone.Click += (sender, e) => { var cloning = new List <IEditor>(_owner.SelectionManager.SelectedEditors); var req = new CloneRequest(cloning); req.MoveDelta = CloneMoveDelta; if (cloning.Any()) { var target = cloning.First().Parent; var cmd = target.PerformRequest(req) as CloneCommand; if (cmd != null && cmd.ClonedEditors != null) { _owner.SelectionManager.DeselectAll(); foreach (var cloned in cmd.ClonedEditors) { cloned.RequestSelect(SelectKind.True, false); } } } }; _cut = new ToolStripMenuItem(); _cut.Text = "切り取り(&X)"; _cut.Click += (sender, e) => { var cmd = GetCutCommand(); _owner.CommandExecutor.Execute(cmd); }; _copy = new ToolStripMenuItem(); _copy.Text = "コピー(&C)"; _copy.Click += (sender, e) => { var targets = _owner.SelectionManager.SelectedEditors; var req = new CopyRequest(targets); var list = new EditorBundle(targets); list.PerformGroupRequest(req, _owner.CommandExecutor); }; _copyAsImage = new ToolStripMenuItem(); _copyAsImage.Text = "画像としてコピー(&I)"; _copyAsImage.Click += (sender, e) => { _owner.CopySelectedAsImage(); }; _paste = new ToolStripMenuItem(); _paste.Text = "貼り付け(&P)"; _paste.Click += (sender, e) => { var found = _owner.RootEditor.FindEnabledEditor( _currentEvent.Location ); if (found != null) { var cmd = found.RequestPaste(_currentEvent.Location, null) as PasteCommand; if (cmd != null && cmd.PastedEditors != null) { _owner.SelectionManager.DeselectAll(); foreach (var editor in cmd.PastedEditors) { editor.RequestSelect(SelectKind.True, false); } } } }; _pasteInBlock = new ToolStripMenuItem(); _pasteInBlock.Text = "段落内に貼り付け(&P)"; _pasteInBlock.Click += (sender, e) => { var found = _owner.RootEditor.FindEnabledEditor( _currentEvent.Location ); if (found != null) { var cmd = found.RequestPaste( _currentEvent.Location, EditorConsts.InBlockPasteDescription ) as PasteCommand; if (cmd != null && cmd.PastedEditors != null) { _owner.SelectionManager.DeselectAll(); foreach (var editor in cmd.PastedEditors) { editor.RequestSelect(SelectKind.True, false); } } } }; _front = new ToolStripMenuItem(); _front.Text = "前面に移動(&F)"; _front.Click += (sender, e) => { var found = _owner.RootEditor.FindEnabledEditor( _currentEvent.Location ); if (found != null) { found.RequestReorder(ReorderKind.Front); } }; _frontMost = new ToolStripMenuItem(); _frontMost.Text = "最前面に移動(&F)"; _frontMost.Click += (sender, e) => { var found = _owner.RootEditor.FindEnabledEditor( _currentEvent.Location ); if (found != null) { found.RequestReorder(ReorderKind.FrontMost); } }; _back = new ToolStripMenuItem(); _back.Text = "背面に移動(&B)"; _back.Click += (sender, e) => { var found = _owner.RootEditor.FindEnabledEditor( _currentEvent.Location ); if (found != null) { found.RequestReorder(ReorderKind.Back); } }; _backMost = new ToolStripMenuItem(); _backMost.Text = "最背面に移動(&B)"; _backMost.Click += (sender, e) => { var found = _owner.RootEditor.FindEnabledEditor( _currentEvent.Location ); if (found != null) { found.RequestReorder(ReorderKind.BackMost); } }; _arrangeHLeft = new ToolStripMenuItem("左揃え(&L)"); _arrangeHLeft.Click += (sender, e) => { var editors = _owner.SelectionManager.SelectedEditors; var rect = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2)); using (_owner.CommandExecutor.BeginChain()) { foreach (var edi in editors) { var left = rect.Left; edi.RequestMove(new Size(left - edi.Figure.Left, 0)); } } }; _arrangeHCenter = new ToolStripMenuItem("左右中央揃え(&C)"); _arrangeHCenter.Click += (sender, e) => { var editors = _owner.SelectionManager.SelectedEditors; var rect = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2)); var center = RectUtil.GetCenter(rect); using (_owner.CommandExecutor.BeginChain()) { foreach (var edi in editors) { var left = center.X - edi.Figure.Width / 2; edi.RequestMove(new Size(left - edi.Figure.Left, 0)); } } }; _arrangeHRight = new ToolStripMenuItem("右揃え(&R)"); _arrangeHRight.Click += (sender, e) => { var editors = _owner.SelectionManager.SelectedEditors; var rect = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2)); using (_owner.CommandExecutor.BeginChain()) { foreach (var edi in editors) { var left = rect.Right - edi.Figure.Width; edi.RequestMove(new Size(left - edi.Figure.Left, 0)); } } }; _arrangeVTop = new ToolStripMenuItem("上揃え(&T)"); _arrangeVTop.Click += (sender, e) => { var editors = _owner.SelectionManager.SelectedEditors; var rect = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2)); using (_owner.CommandExecutor.BeginChain()) { foreach (var edi in editors) { var top = rect.Top; edi.RequestMove(new Size(0, top - edi.Figure.Top)); } } }; _arrangeVMiddle = new ToolStripMenuItem("上下中央揃え(&M)"); _arrangeVMiddle.Click += (sender, e) => { var editors = _owner.SelectionManager.SelectedEditors; var rect = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2)); var center = RectUtil.GetCenter(rect); using (_owner.CommandExecutor.BeginChain()) { foreach (var edi in editors) { var top = center.Y - edi.Figure.Height / 2; edi.RequestMove(new Size(0, top - edi.Figure.Top)); } } }; _arrangeVBottom = new ToolStripMenuItem("下揃え(&B)"); _arrangeVBottom.Click += (sender, e) => { var editors = _owner.SelectionManager.SelectedEditors; var rect = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2)); using (_owner.CommandExecutor.BeginChain()) { foreach (var edi in editors) { var top = rect.Bottom - edi.Figure.Height; edi.RequestMove(new Size(0, top - edi.Figure.Top)); } } }; _detailForm = new ToolStripMenuItem(); _detailForm.Text = "設定(&S)"; _detailForm.Click += (sender, e) => { var found = _owner.RootEditor.FindEnabledEditor( _currentEvent.Location ); if (found != null) { if (found.Controller != null && found.Controller.UIProvider != null) { var ui = found.Controller.UIProvider; var form = new DetailSettingsForm(); try { form.Size = _detailFormSize; form.Theme = _owner.Theme; ui.ConfigureDetailForm(form); if (form.ShowDialog() == DialogResult.OK) { var cmd = form.GetUpdateCommand(); if (cmd != null) { _owner.CommandExecutor.Execute(cmd); } } } finally { form.Dispose(); } } } }; }
public override ContextMenuStrip GetContextMenu(MouseEventArgs e) { if (_remove == null) { InitItems(); } _currentEvent = e; _ContextMenu.Items.Clear(); var selectedCount = _owner.SelectionManager.SelectedEditors.Count(); var target = _owner.RootEditor.FindEnabledEditor(e.Location); if (target == null) { return(_ContextMenu); } var sepaIndex = 0; var itemCount = 0; /// 削除,複製 if (UpdateItem(_remove, target, () => new RemoveRequest(), false)) { ++itemCount; } if (UpdateItem(_clone, target.Parent, () => new CloneRequest(_owner.SelectionManager.SelectedEditors) { MoveDelta = CloneMoveDelta }, false)) { ++itemCount; } /// separate sepaIndex = itemCount; /// クリップボード if (UpdateItem(_cut, target, GetCutCommand(), true)) { ++itemCount; } { var copyReq = new CopyRequest(_owner.SelectionManager.SelectedEditors); var copyBundle = new EditorBundle(copyReq.TargetEditors); var canCopy = copyBundle.CanUnderstandAll(copyReq); _copy.Enabled = canCopy; _ContextMenu.Items.Add(_copy); ++itemCount; } { _copyAsImage.Enabled = true; _ContextMenu.Items.Add(_copyAsImage); ++itemCount; } if (UpdateItem(_paste, target, () => new PasteRequest(), true)) { ++itemCount; } if (Clipboard.ContainsText()) { if (UpdateItem(_pasteInBlock, target, () => new PasteRequest(), false)) { ++itemCount; } } /// separate if (itemCount > sepaIndex && sepaIndex > 0) { _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator()); ++itemCount; sepaIndex = itemCount; } /// 前面,背面移動 if (selectedCount == 1 && !(target.Parent.Figure.Layout is ListLayout)) { /// Layoutが有効な場合は前面,背面移動の意味が違うことがあるので表示しない if (UpdateItem(_front, target, () => new ReorderRequest() { Kind = ReorderKind.Front }, false)) { ++itemCount; } if (UpdateItem(_frontMost, target, () => new ReorderRequest() { Kind = ReorderKind.FrontMost }, false)) { ++itemCount; } if (UpdateItem(_back, target, () => new ReorderRequest() { Kind = ReorderKind.Back }, false)) { ++itemCount; } if (UpdateItem(_backMost, target, () => new ReorderRequest() { Kind = ReorderKind.BackMost }, false)) { ++itemCount; } /// separate if (itemCount > sepaIndex && sepaIndex > 0) { _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator()); ++itemCount; sepaIndex = itemCount; } } var canMove = target.CanUnderstand(new ChangeBoundsRequest()); if (selectedCount > 1 && canMove) { /// 左揃え _ContextMenu.Items.Add(_arrangeHLeft); ++itemCount; /// 左右中央揃え _ContextMenu.Items.Add(_arrangeHCenter); ++itemCount; /// 右揃え _ContextMenu.Items.Add(_arrangeHRight); ++itemCount; /// separate _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator()); ++itemCount; sepaIndex = itemCount; /// 上揃え _ContextMenu.Items.Add(_arrangeVTop); ++itemCount; /// 上下中央揃え _ContextMenu.Items.Add(_arrangeVMiddle); ++itemCount; /// 下揃え _ContextMenu.Items.Add(_arrangeVBottom); ++itemCount; /// separate _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator()); ++itemCount; sepaIndex = itemCount; } /// 設定 if (selectedCount == 1 && target.Controller.UIProvider != null && target.Controller.UIProvider.SupportDetailForm) { var enabled = target.Controller.UIProvider.SupportDetailForm; _detailForm.Enabled = enabled; _ContextMenu.Items.Add(_detailForm); ++itemCount; } /// separate if (itemCount > sepaIndex && sepaIndex > 0) { _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator()); ++itemCount; sepaIndex = itemCount; } return(_ContextMenu); }