CodeQuickTester icon indicating copy to clipboard operation
CodeQuickTester copied to clipboard

The Contextmenu Doesn't Work Properly.

Open nperovic opened this issue 1 year ago • 0 comments

https://github.com/G33kDude/RichCode.ahk/blob/9a54252d193dbafeccb86b9e751cb36c8c8f5548/RichCode.ahk#L207-L241

I apologise for not being able to point out exactly where the problem is, but this is what I have done so far to fix it. I'm sure you'll understand as soon as you see it.

; Create the right click menu
this.menu := Menu()
for Index, Entry in RichCode.MenuItems
	this.menu.Add(Entry?, IsSet(Entry) ? RightClickMenu : unset)

; Get the ITextDocument object
bufpIRichEditOle := Buffer(A_PtrSize, 0)
this.SendMsg(0x43C, 0, bufpIRichEditOle) ; EM_GETOLEINTERFACE
this.pIRichEditOle := NumGet(bufpIRichEditOle, "UPtr")
this.IRichEditOle := ComValue(9, this.pIRichEditOle, 1)
; ObjAddRef(this.pIRichEditOle)
this.pITextDocument := ComObjQuery(this.IRichEditOle, RichCode.IID_ITextDocument)
this.ITextDocument := ComValue(9, this.pITextDocument, 1)
; ObjAddRef(this.pITextDocument)

RightClickMenu(ItemName, ItemPos, MenuName)
{
	Switch ItemName {
	case "Cut"       : A_Clipboard := this.SelectedText, this.SelectedText := ""
	case "Copy"      : A_Clipboard := this.SelectedText
	case "Paste"     : this.SelectedText := A_Clipboard
	case "Delete"    : this.SelectedText := ""
	case "Select All": this.Selection    := [0, -1]
	case "UPPERCASE" : this.SelectedText := Format("{:U}", this.SelectedText)
	case "lowercase" : this.SelectedText := Format("{:L}", this.SelectedText)
	case "TitleCase" : this.SelectedText := Format("{:T}", this.SelectedText)
	}
}

nperovic avatar Aug 10 '23 13:08 nperovic