Remove a ContextMenu from a TextEntry Object

Discuss GUI programming with the RapaGUI plugin here
Post Reply
bitRocky
Posts: 120
Joined: Fri Nov 14, 2014 6:01 pm

Remove a ContextMenu from a TextEntry Object

Post 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?
bitRocky
Posts: 120
Joined: Fri Nov 14, 2014 6:01 pm

Re: Remove a ContextMenu from a TextEntry Object

Post 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
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Remove a ContextMenu from a TextEntry Object

Post by airsoftsoftwair »

Looks like this is not possible yet. I'll fix this. Thanks for reporting!
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Remove a ContextMenu from a TextEntry Object

Post by airsoftsoftwair »

Code: Select all

- Fix: moai.FreeObject() couldn't free menu objects that had previously been attached as a context menu  
bitRocky
Posts: 120
Joined: Fri Nov 14, 2014 6:01 pm

Re: Remove a ContextMenu from a TextEntry Object

Post by bitRocky »

Muchas gracias!
Post Reply