// ========================================
        // method
        // ========================================
        public override void ConfigureEditor(IEditor editor)
        {
            var facade = MemopadApplication.Instance;

            var editorHandle = new MemoShapeEditorHandle();

            editorHandle.KeyMap = facade.KeySchema.MemoContentEditorKeyMap;
            editor.InstallEditorHandle(editorHandle);

            editor.InstallHandle(new ResizeHandle(Directions.Left)
            {
                Cursor = Cursors.SizeWE
            });
            editor.InstallHandle(new ResizeHandle(Directions.Up)
            {
                Cursor = Cursors.SizeNS
            });
            editor.InstallHandle(new ResizeHandle(Directions.Right)
            {
                Cursor = Cursors.SizeWE
            });
            editor.InstallHandle(new ResizeHandle(Directions.Down)
            {
                Cursor = Cursors.SizeNS
            });
            editor.InstallHandle(new ResizeHandle(Directions.UpLeft)
            {
                Cursor = Cursors.SizeNWSE
            });
            editor.InstallHandle(new ResizeHandle(Directions.UpRight)
            {
                Cursor = Cursors.SizeNESW
            });
            editor.InstallHandle(new ResizeHandle(Directions.DownLeft)
            {
                Cursor = Cursors.SizeNESW
            });
            editor.InstallHandle(new ResizeHandle(Directions.DownRight)
            {
                Cursor = Cursors.SizeNWSE
            });

            editor.InstallRole(new SelectRole());
            editor.InstallRole(new FocusRole(InitFocus, CommitFocus));
            editor.InstallRole(new ResizeRole());
            editor.InstallRole(new RemoveRole());
            editor.InstallRole(new CopyRole());
            editor.InstallRole(new ReorderRole());
            editor.InstallRole(new SetStyledTextFontRole(() => Model.StyledText, FontModificationKinds.All));
            editor.InstallRole(new SetStyledTextColorRole(() => Model.StyledText));
            editor.InstallRole(new SetStyledTextAlignmentRole(() => Model.StyledText, AlignmentModificationKinds.All));

            var editorFocus = new MemoStyledTextFocus(Host, facade.Settings.KeyScheme == KeySchemeKind.Emacs, false);

            editorFocus.LinkClicked += (sender, e) => {
                LinkUtil.GoLink(e.Link);
            };

            editor.InstallFocus(editorFocus);
        }
        protected override void OnFigureMouseDown(MouseEventArgs e)
        {
            _startRowIndex = -1;
            _startColIndex = -1;
            _endRowIndex   = -1;
            _endColIndex   = -1;

            _isScenarioHandled = false;

            if (KeyUtil.IsShiftPressed())
            {
                var parent          = Host.Parent;
                var man             = Host.Site.SelectionManager;
                var selectedEditors = man.SelectedEditors;
                if (selectedEditors.Any() && selectedEditors.First().Parent == parent)
                {
                    var tableData   = GetParentTableData();
                    var firstEditor = selectedEditors.First();
                    _startRowIndex = tableData.GetRowIndex(firstEditor.Figure as TableCellFigure);
                    _startColIndex = tableData.GetColumnIndex(firstEditor.Figure as TableCellFigure);

                    _endRowIndex = tableData.GetRowIndex(Host.Figure as TableCellFigure);
                    _endColIndex = tableData.GetColumnIndex(Host.Figure as TableCellFigure);
                    SelectRange(_startRowIndex, _startColIndex, _endRowIndex, _endColIndex);
                }
            }
            else if (
                e.Button == MouseButtons.Left &&
                !KeyUtil.IsAltPressed() &&
                !KeyUtil.IsControlPressed() &&
                !KeyUtil.IsShiftPressed()
                )
            {
                var run = GetRun(e.Location);
                if (run != null && run.HasLink)
                {
                    LinkUtil.GoLink(run.Link);
                    _isScenarioHandled = true;
                }
                else
                {
                    _selectScenario.HandleMouseDown(this, e);
                }
            }
            else
            {
                _selectScenario.HandleMouseDown(this, e);
            }

            base.OnFigureMouseDown(e);
        }
Beispiel #3
0
        public override void ConfigureEditor(IEditor editor)
        {
            var facade = MemopadApplication.Instance;

            var editorHandle = new MemoTableCellEditorHandle();

            editorHandle.KeyMap = facade.KeySchema.MemoTableCellEditorKeyMap;
            editor.InstallEditorHandle(editorHandle);

            editor.InstallHandle(new SelectionIndicatingHandle());

            editor.InstallRole(new SelectRole());
            editor.InstallRole(new FocusRole(InitFocus, CommitFocus));
            editor.InstallRole(new SetStyledTextFontRole(() => Model.StyledText, FontModificationKinds.All));
            editor.InstallRole(new SetStyledTextColorRole(() => Model.StyledText));
            editor.InstallRole(new SetStyledTextAlignmentRole(() => Model.StyledText, AlignmentModificationKinds.All));

            var editorFocus = new MemoStyledTextFocus(Host, facade.Settings.KeyScheme == KeySchemeKind.Emacs, false);

            editorFocus.IsConsiderHostBounds = true;
            editorFocus.LinkClicked         += (sender, e) => {
                LinkUtil.GoLink(e.Link);
            };
            editor.InstallFocus(editorFocus);

            editor.SelectionChanged += (sender, e) => {
                if (editor.IsSelected)
                {
                    var canvas = Host.Site.EditorCanvas;
                    var rect   = Figure.GetCharRect(0);
                    canvas.Caret.Position = rect.Location;

                    var loc = canvas.TranslateToControlPoint(rect.Location);
                    canvas.SetImePosition(loc);

                    canvas.EnsureVisible(editor);
                }
            };
        }
Beispiel #4
0
        protected override void OnFigureMouseClick(MouseEventArgs e)
        {
            var handled = false;

            if (
                e.Button == MouseButtons.Left &&
                !KeyUtil.IsAltPressed() &&
                !KeyUtil.IsControlPressed() &&
                !KeyUtil.IsShiftPressed()
                )
            {
                var run = GetRun(e.Location);
                if (run != null && run.HasLink)
                {
                    LinkUtil.GoLink(run.Link);
                    handled = true;
                }
            }

            if (!handled)
            {
                base.OnFigureMouseClick(e);
            }
        }
        private void InitMenuItems()
        {
            _cutInNewMemo        = new ToolStripMenuItem("切り出す(&C)");
            _cutInNewMemo.Click += (sender, e) => {
                using (var form = new CreateMemoForm()) {
                    form.Font      = _app.Theme.CaptionFont;
                    form.MemoTitle = "新しいノート";
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        var copied = Owner.Referer.Target.CopyBlocksAndInlines(Owner.Referer.Selection.Range);

                        _app.ShowMainForm();
                        _app.ActivateMainForm();
                        var info = _app.CreateMemo(form.MemoTitle);

                        if (form.OriginalModification == CreateMemoForm.OriginalModificationKind.Remove)
                        {
                            Owner.RemoveForward();
                        }
                        else if (form.OriginalModification == CreateMemoForm.OriginalModificationKind.ReplaceWithLink)
                        {
                            Owner.RemoveForward();
                            Owner.InsertLink(info.Title, new Link(UriUtil.GetUri(info)));
                            if (copied.Last() is BlockBreak)
                            {
                                Owner.InsertBlockBreak();
                            }
                        }

                        var pageContent = _app.MainForm.FindPageContent(info);
                        var canvas      = pageContent.EditorCanvas;
                        var caret       = canvas.Caret;
                        var loc         = CaretUtil.GetExpectedMemoTextPosition(caret.Position);
                        MemoEditorHelper.AddBlocksAndInlines(canvas.RootEditor.Children.First(), loc, copied, false);
                    }
                }
            };


            _splitThisParagraph        = new ToolStripMenuItem("この行で分割(&S)");
            _splitThisParagraph.Click += (sender, e) => {
                using (_editor.Site.CommandExecutor.BeginChain()) {
                    var referer = Owner.Referer;
                    var stext   = referer.Target;

                    var lineIndex = stext.GetLineIndex(referer.CaretIndex);
                    var lineStart = stext.GetLineStartCharIndex(lineIndex);
                    var flows     = stext.CopyBlocksAndInlines(lineStart);

                    var rect = Rectangle.Empty;
                    rect = _focus.Figure.GetCharRect(lineStart);

                    Owner.Selection.Range = Range.FromStartAndEnd(lineStart - 1, stext.Length - 2);
                    Owner.RemoveForward();
                    _editor.RequestFocus(FocusKind.Commit, null);

                    var loc        = new Point(_editor.Figure.Left, rect.Bottom + 16);
                    var memoEditor = _editor.Parent;
                    var created    = MemoEditorHelper.AddBlocksAndInlines(memoEditor, loc, flows, true);
                    created.RequestFocusCommit(true);
                }
            };

            _splitParagraphs        = new ToolStripMenuItem("段落ごとに分割(&P)");
            _splitParagraphs.Click += (sender, e) => {
                using (_editor.Figure.Root.DirtManager.BeginDirty())
                    using (_editor.Site.CommandExecutor.BeginChain()) {
                        var referer    = Owner.Referer;
                        var stext      = referer.Target;
                        var memoEditor = _editor.Parent;

                        var created  = default(IEditor);
                        var createds = new List <IEditor>();
                        var cTop     = _editor.Figure.Top;
                        foreach (var block in stext.Blocks)
                        {
                            var flows = new Flow[] { block.CloneDeeply() as Block, };
                            var loc   = new Point(_editor.Figure.Left, cTop);
                            created = MemoEditorHelper.AddBlocksAndInlines(memoEditor, loc, flows, true);
                            createds.Add(created);
                            cTop += created.Figure.Height + 16;
                        }
                        created.RequestFocusCommit(true);

                        _editor.RequestRemove();

                        var cmd = new SelectMultiCommand(createds, SelectKind.True, true);
                        cmd.Execute();
                    }
            };


            _openLink        = new ToolStripMenuItem("リンクを開く(&O)");
            _openLink.Click += (sender, e) => {
                var run = Owner.GetInlineAtCaretIndex() as Run;
                if (run != null && run.HasLink)
                {
                    LinkUtil.GoLink(run.Link);
                }
            };

            _removeLink        = new ToolStripMenuItem("リンクを削除(&R)");
            _removeLink.Click += (sender, e) => {
                Owner.UnsetLink();
            };

            _setLink        = new ToolStripMenuItem("リンクを設定(&L)");
            _setLink.Click += (sender, e) => {
                if (Owner.Selection.IsEmpty)
                {
                    var run = Owner.GetInlineAtCaretIndex() as Run;
                    if (run != null)
                    {
                        var oldUri = default(string);
                        if (run != null && run.HasLink)
                        {
                            oldUri = run.Link.Uri;
                        }

                        var oldText = run.Text;
                        var dialog  = new LinkSelectForm();
                        if (dialog.ShowDialog(_app.MainForm, oldUri, run.Text) == DialogResult.OK)
                        {
                            var uri     = dialog.Uri;
                            var newText = dialog.TitleText;
                            if (newText != oldText)
                            {
                                Owner.SetRunText(run, newText);
                            }
                            if (uri != oldUri)
                            {
                                Owner.SetLink(uri, null);
                            }
                        }
                    }
                }
                else
                {
                    var range   = Owner.Selection.Range;
                    var oldText = Owner.Referer.Target.Text.Substring(range.Offset, range.Length);

                    var dialog = new LinkSelectForm();
                    dialog.TitleTextTextBoxEnabled = false;
                    if (dialog.ShowDialog(_app.MainForm, null, oldText) == DialogResult.OK)
                    {
                        Owner.SetLink(dialog.Uri, null);
                    }
                }
            };


            _addComment        = new ToolStripMenuItem("コメントを追加(&C)");
            _addComment.Click += (sender, e) => {
                MemoEditorHelper.AddCommentForMemoText(Owner);
            };
        }
        // ------------------------------
        // private
        // ------------------------------
        private void InitEditorFocus(IEditor editor)
        {
            var app         = MemopadApplication.Instance;
            var editorFocus = new MemoStyledTextFocus(editor, app.Settings.KeyScheme == KeySchemeKind.Emacs, true);

            editorFocus.IsCurrentLineBackgroundEnable = true;
            editorFocus.IsConsiderImeWindowSize       = true;
            editorFocus.IsConsiderHostBounds          = true;
            editorFocus.Figure.Padding    = DefaultPadding;
            editorFocus.Figure.DragTarget = CreateFocusFigureDragTarget();
            editorFocus.Figure.DragSource = CreateFocusFigureDragSource();

            /// キー入力時にテキストがemptyなら削除
            editorFocus.ShortcutKeyProcess += (sender, e) => {
                RemoveIfEmpty(editorFocus, e.KeyData);
            };
            editorFocus.KeyDown += (sender, e) => {
                RemoveIfEmpty(editorFocus, e.KeyData);
            };
            //editorFocus.KeyDown += (sender, e) => {
            //    var mtext = Host.Model as MemoText;
            //    if (mtext.IsSticky) {
            //        /// stickyなら何もしない
            //        return;
            //    }

            //    var editorCanvas = Host.Site.EditorCanvas;
            //    if (
            //        editorFocus.StyledText.IsEmpty &&
            //        e.KeyData != Keys.ProcessKey &&
            //        editorCanvas.GetImeString().Length == 0
            //    ) {
            //        var parent = Host.Parent;
            //        Host.RequestFocus(FocusKind.Rollback, null);
            //        Host.RequestRemove();
            //        parent.RequestSelect(SelectKind.True, true);
            //    }
            //};
            editorFocus.LinkClicked += (sender, e) => {
                LinkUtil.GoLink(e.Link);
            };

            editor.InstallFocus(editorFocus);

            /// コミット時にStyledTextがemptyなら削除
            editor.FocusChanged += (sender, e) => {
                var mtext = Host.Model as MemoText;
                if (mtext.IsSticky)
                {
                    /// stickyなら何もしない
                    return;
                }

                if (!editor.IsFocused)
                {
                    var styledText = Model.StyledText;
                    if (styledText.IsEmpty)
                    {
                        var parent = editor.Parent;
                        editor.RequestRemove();
                        parent.RequestSelect(SelectKind.True, true);
                    }
                }
            };
        }
        protected override void OnFigureMouseDown(MouseEventArgs e)
        {
            var handled = false;

            if (
                (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle) &&
                !KeyUtil.IsAltPressed() &&
                !KeyUtil.IsControlPressed() &&
                !KeyUtil.IsShiftPressed()
                )
            {
                var run = GetRun(e.Location);
                if (run != null && run.HasLink)
                {
                    LinkUtil.GoLink(run.Link);
                    handled = true;
                }
            }

            /// checkbox
            if (e.Button == MouseButtons.Left)
            {
                var node = _Figure as INode;
                if (node != null)
                {
                    var bulcmd = node.GetProcessCheckBoxBulletCommand(e.Location);
                    if (bulcmd != null)
                    {
                        /// bulcmdはFigureのStyledTextを変更するだけ
                        /// ModelのStyledTextを変えないといけない
                        bulcmd.Execute();

                        var model    = Host.Model as MemoText;
                        var oldStext = model.StyledText;
                        var newStext = node.StyledText.CloneDeeply() as StyledText.Core.StyledText;
                        var cmd      = new DelegatingCommand(
                            () => {
                            model.StyledText = newStext;
                        },
                            () => {
                            model.StyledText = oldStext;
                        }
                            );
                        Host.Site.CommandExecutor.Execute(cmd);
                        handled = true;
                    }
                }
            }


            if (!handled)
            {
                _isSelectedOnMouseDown = Host.IsSelected;
                _toggle = KeyUtil.IsControlPressed();

                /// EditorがFocusされていたらCommitしておく
                var focused = Host.Site.FocusManager.FocusedEditor;
                if (focused != null)
                {
                    focused.RequestFocusCommit(true);
                }

                Host.RequestSelect(SelectKind.True, !_toggle && !Host.IsSelected);
                if (e.Button == MouseButtons.Left && !KeyUtil.IsControlPressed())
                {
                    Host.RequestFocus(FocusKind.Begin, e.Location);
                    Host.Site.EditorCanvas.EventDispatcher.SetDnDTarget(Host.Focus.Figure);
                }
                base.OnFigureMouseDown(e);
            }
        }