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);
            };
        }
Пример #2
0
        // ========================================
        // method
        // ========================================
        private ContextMenuStrip CreateNotifyIconContextMenu()
        {
            var items = new List <ToolStripItem>(16);

            var newMemo = new ToolStripMenuItem();

            newMemo.Text   = "ノートを作成(&N)";
            newMemo.Click += (sender, e) => {
                CreateMemo();
            };
            items.Add(newMemo);

            var newFusenMemo = new ToolStripMenuItem();

            newFusenMemo.Text   = "付箋ノートを作成(&F)";
            newFusenMemo.Click += (sender, e) => {
                CreateFusenMemo();
            };
            items.Add(newFusenMemo);

            var clipMemo = new ToolStripMenuItem();

            clipMemo.Text   = "ノートにクリップ(&C)";
            clipMemo.Click += (sender, e) => {
                var mainForm = _app.MainForm;
                var hWnd     = User32PI.GetWindow(
                    mainForm.Handle,
                    GetWindowCmd.GW_HWNDFIRST
                    );
                hWnd = User32Util.GetNextWindow(
                    hWnd,
                    handle => {
                    if (User32PI.IsWindowVisible(handle) && !User32Util.IsOwnedWindow(handle))
                    {
                        var cname = User32Util.GetWindowClassName(handle);
                        return
                        (!string.Equals(cname, "Shell_TrayWnd", StringComparison.OrdinalIgnoreCase) &&
                         !string.Equals(cname, "NotifyIconOverflowWindow", StringComparison.OrdinalIgnoreCase));
                    }
                    else
                    {
                        return(false);
                    }
                }
                    );

                var oldTopMost = mainForm.TopMost;
                mainForm.TopMost = false;
                if (hWnd != IntPtr.Zero)
                {
                    User32Util.ActivateWindow(hWnd);
                    Thread.Sleep(1000);
                }
                _app.ClipAndCreateMemo();
                mainForm.TopMost = oldTopMost;
            };
            items.Add(clipMemo);

            var capture = new ToolStripMenuItem();

            capture.Text   = "画面を取り込み(&D)";
            capture.Click += (sender, e) => {
                Thread.Sleep(500);
                _app.CaptureAndCreateMemo();
            };
            items.Add(capture);

            items.Add(new ToolStripSeparator());

            var searchMemo = new ToolStripMenuItem();

            searchMemo.Text   = "ノートを検索(&S)";
            searchMemo.Click += (sender, e) => {
                _app.ShowMainForm();
                _app.ActivateMainForm();
                var form = _app.MainForm;
                if (form != null)
                {
                    form.FocusConditionTextBox();
                }
            };
            items.Add(searchMemo);

            var activate = new ToolStripMenuItem();

            activate.Text   = "アクティブにする(&A)";
            activate.Click += (sender, e) => {
                ShowMainForm();
            };
            items.Add(activate);

            var showAllFusens = new ToolStripMenuItem();

            showAllFusens.Text   = "付箋ノートを表示(&F)";
            showAllFusens.Click += (sender, e) => {
                ShowFusenForms(false);
            };
            items.Add(showAllFusens);

            items.Add(new ToolStripSeparator());

            var action = new ToolStripMenuItem();

            action.Text = "アイコンの動作(&A)";
            items.Add(action);

            {
                var click = new ToolStripMenuItem();
                click.Text = "クリック(&C)";
                action.DropDown.Items.Add(click);
                InitClickSetting(click);
            }
            {
                var dclick = new ToolStripMenuItem();
                dclick.Text = "ダブルクリック(&D)";
                action.DropDown.Items.Add(dclick);

                InitDoubleClickSetting(dclick);
            }

            items.Add(new ToolStripSeparator());

            var exitItem = new ToolStripMenuItem();

            exitItem.Text   = "終了(&X)";
            exitItem.Click += (sender, e) => {
                _app.Exit();
            };
            items.Add(exitItem);

            var ret = new ContextMenuStrip();

            ret.SuspendLayout();
            ret.Items.AddRange(items.ToArray());
            ret.ResumeLayout();
            return(ret);
        }