Page 1 of 1

Remove a ContextMenu from a TextEntry Object

Posted: Mon May 10, 2021 4:20 pm
by bitRocky
Hi,

I want a dynamic (created with moai.CreateObject()) Contextmenu shown for a TextEntry object.
This works for the first time, but if I want to change it, I first need to detach it, said moai.FreeObject().
But how?

Code: Select all

moai.set("strObj", "ContextMenu", "(none)")
Doesn't seem to be enough.

Code: Select all

moai.DoMethod(moai.get("menObj", "Parent"), "Remove", "menObj")
Also doesn't work.

So, how can I detach the contextmenu object (menObj) before using moai.FreeObject() and reusing the id for the new contextmenu?

Re: Remove a ContextMenu from a TextEntry Object

Posted: Mon May 10, 2021 11:59 pm
by bitRocky
Here is a little script for testing:

Code: Select all

/*
 * RapaGUI ContextMenu Test
*/
@VERSION 9,0

@REQUIRE "RapaGUI"

@APPTITLE "RapaContextMenuTest"

@OPTIONS {Encoding = #ENCODING_ISO8859_1}

Function p_CreateMenu()
	If menuCreated
		; how to detach the "cmenu"?
		; DebugPrint("Before Remove") moai.DoMethod("strObj", "Remove", "cmenu")

		moai.set("strObj", "ContextMenu", "(none)")
	
		DebugPrint("before FreeObject") moai.FreeObject("cmenu")
	EndIf 

	DebugPrint("Before CreateObject")
	moai.CreateObject([[
		<menu title="ContextMenu" id="cmenu">
			<item id="citem1"  >]]..Rnd(10)..[[</item>
			<item id="citem2"  >]]..Rnd(10)..[[</item>
			<item id="citem3"  >]]..Rnd(10)..[[</item>
		</menu>
	]])
	
	DebugPrint("Before Set")
	moai.set("strObj", "ContextMenu", "cmenu")
	menuCreated = True

EndFunction

/* Handles all incoming events */
Function p_EventFunc(msg)
	Switch msg.action
	Case "RapaGUI":
		Switch msg.id
		Case "citem1":
			DebugPrint("item 1 selected!")
		Case "citem2":
			DebugPrint("item 2 selected!")
		Case "citem3":
			DebugPrint("item 3 selected!")
		Case "butSetCMenu":
			p_CreateMenu()
		EndSwitch
	EndSwitch
EndFunction

InstallEventHandler({RapaGUI = p_EventFunc})

moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
	<Window id="winMain" title="Test" notify="closeRequest;" >
		<VGroup>
			<ColGroup columns="2">
				<Label>Press RMB:</Label>
				<Textentry id="strObj" notify="text"/>
			</ColGroup>
			<button id="butSetCMenu">Change ContextMenu</button>
		</VGroup>
	</Window>
</application>
]])

EscapeQuit(true)

menuCreated = False
p_CreateMenu()

Repeat WaitEvent() Forever

Re: Remove a ContextMenu from a TextEntry Object

Posted: Sun May 16, 2021 9:11 pm
by airsoftsoftwair
Looks like this is not possible yet. I'll fix this. Thanks for reporting!

Re: Remove a ContextMenu from a TextEntry Object

Posted: Sun May 30, 2021 5:52 pm
by airsoftsoftwair

Code: Select all

- Fix: moai.FreeObject() couldn't free menu objects that had previously been attached as a context menu  

Re: Remove a ContextMenu from a TextEntry Object

Posted: Sun May 30, 2021 6:16 pm
by bitRocky
Muchas gracias!