Example #1
0
 public static void Uncomment()
 {
     ModifyCode.CommentLines(false);
 }
Example #2
0
    bool _WndProc(wnd w, int msg, nint wparam, nint lparam, ref nint lresult)
    {
        switch (msg)
        {
        case Api.WM_SETFOCUS:
            if (!_noModelEnsureCurrentSelected)
            {
                App.Model.EnsureCurrentSelected();
            }
            break;

        case Api.WM_CHAR: {
            int c = (int)wparam;
            if (c < 32)
            {
                if (c is not(9 or 10 or 13))
                {
                    return(true);
                }
            }
            else
            {
                if (CodeInfo.SciBeforeCharAdded(this, (char)c))
                {
                    return(true);
                }
            }
        }
        break;

        case Api.WM_MBUTTONDOWN:
            Api.SetFocus(w);
            return(true);

        case Api.WM_RBUTTONDOWN: {
            //workaround for Scintilla bug: when right-clicked a margin, if caret or selection start is at that line, goes to the start of line
            POINT p      = Math2.NintToPOINT(lparam);
            int   margin = zMarginFromPoint(p, false);
            if (margin >= 0)
            {
                var selStart = zSelectionStart8;
                var(_, start, end) = zLineStartEndFromPos(false, zPosFromXY(false, p, false));
                if (selStart >= start && selStart <= end)
                {
                    return(true);
                }
                //do vice versa if the end of non-empty selection is at the start of the right-clicked line, to avoid comment/uncomment wrong lines
                if (margin == c_marginLineNumbers || margin == c_marginMarkers)
                {
                    if (zSelectionEnd8 == start)
                    {
                        zGoToPos(false, start);                                              //clear selection above start
                    }
                }
            }
        }
        break;

        case Api.WM_CONTEXTMENU: {
            bool kbd    = (int)lparam == -1;
            int  margin = kbd ? -1 : zMarginFromPoint(Math2.NintToPOINT(lparam), true);
            switch (margin)
            {
            case -1:
                var m = new KWpfMenu();
                App.Commands[nameof(Menus.Edit)].CopyToMenu(m);
                m.Show(this, byCaret: kbd);
                break;

            case c_marginLineNumbers or c_marginMarkers or c_marginImages or c_marginChanges:
                ModifyCode.CommentLines(null, notSlashStar: true);
                break;

            case c_marginFold:
                int fold = popupMenu.showSimple("Folding: hide all|Folding: show all", owner: Hwnd) - 1;                 //note: no "toggle", it's not useful
                if (fold >= 0)
                {
                    Call(SCI_FOLDALL, fold);
                }
                break;
            }
            return(true);
        }
            //case Api.WM_PAINT:
            //	_Paint(false);
            //	break;
            //case Api.WM_PAINT: {
            //		using var p1 = perf.local();
            //		Call(msg, wparam, lparam);
            //		return true;
            //	}
        }

        //Call(msg, wparam, lparam);

        //in winforms version this was after base.WndProc. Now in hook cannot do it, therefore using async.
        //SHOULDDO: superclass and use normal wndproc instead of hook. Now possible various anomalies because of async.
        switch (msg)
        {
        //case Api.WM_MOUSEMOVE:
        //	CodeInfo.SciMouseMoved(this, Math2.LoShort(m.LParam), Math2.HiShort(m.LParam));
        //	break;
        case Api.WM_KILLFOCUS:
            //Dispatcher.InvokeAsync(() => CodeInfo.SciKillFocus(this));//no, dangerous
            CodeInfo.SciKillFocus(this);
            break;
            //case Api.WM_LBUTTONUP:
            //	//rejected. Sometimes I accidentally Ctrl+click and then wonder why it shows eg the github search dialog.
            //	if (Keyboard.Modifiers == ModifierKeys.Control && !zIsSelection) {
            //		Dispatcher.InvokeAsync(() => CiGoTo.GoToSymbolFromPos());
            //	}
            //	break;
        }

        return(false);
    }
Example #3
0
 public static void Comment()
 {
     ModifyCode.CommentLines(true);
 }