| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Csimbi I post too much
 
  Reputation: 97 
 Joined: 14 Jul 2007
 Posts: 3327
 
 
 | 
			
				|  Posted: Sat Aug 10, 2024 7:31 am    Post subject: Extending Context Menu of Data Dissect Structure Entry |   |  
				| 
 |  
				| Hi all, I am seeking LUA expert support to extend the Context Menu that appears when you right-click on an entry in the Data Dissect Window.
 
 Here's the pseudo-code I am thinking about - if that makes any sense
   
 
  	  | Code: |  	  | // The means to register the menu item and register a function to invoke
 MyRightMenuItem ("Section Name", "Get entry info...", &GetEntryInfo())
 
 // The function to register
 GetEntryInfo()
 {
 if IsValid(address) HandleValidEntry(); // We check if all is good and do something about it
 else HandleInValidEntry(); // We log it, pop an error or something
 }
 
 | 
 
 I have really no clue how to get this done - if, at all, possible.
 Thank you!
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| ParkourPenguin I post too much
 
  Reputation: 152 
 Joined: 06 Jul 2014
 Posts: 4706
 
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| AylinCE Grandmaster Cheater Supreme
 
  Reputation: 37 
 Joined: 16 Feb 2017
 Posts: 1527
 
 
 | 
			
				|  Posted: Sat Aug 10, 2024 4:32 pm    Post subject: |   |  
				| 
 |  
				| Just an example targeting adding a right click menu to the relevant section. 
 I hope you have the codes you will use in the click ready.
 
 
  	  | Code: |  	  | function popupblaclick1(sender) showMessage('Menu 1 was clicked')
 end
 
 function popupblaclick2(sender)
 showMessage('Menu 2 was clicked')
 end
 
 -----------------------------------------------
 local exFrm1 = ""
 
 function addPPMn11()
 for i=0,getFormCount()-1 do
 local formClassName = getForm(i).ClassName
 if formClassName=='TfrmStructures2' then
 aa4 = getForm(i).pmStructureView
 exFrm1 = getForm(i)
 pmenu_items=menu_getItems(aa4)
 if mi1 then mi1.Destroy() end
 mi1=createMenuItem(aa4)
 menuItem_setCaption(mi1,'Menu i1')
 menuItem_onClick(mi1,popupblaclick1)
 menuItem_add(pmenu_items, mi1)
 
 if mi2 then mi2.Destroy() end
 mi2=createMenuItem(aa4)
 menuItem_setCaption(mi2,'Menu i2')
 menuItem_onClick(mi2,popupblaclick2)
 menuItem_add(pmenu_items, mi2)
 end
 end
 end
 
 registerFormAddNotification(function(exFrm1)
 local t=createTimer()
 t.Interval = 1
 t.OnTimer = function (timer)
 timer.destroy()
 addPPMn11()
 end
 end)
 | 
 _________________
 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Csimbi I post too much
 
  Reputation: 97 
 Joined: 14 Jul 2007
 Posts: 3327
 
 
 | 
			
				|  Posted: Sun Aug 25, 2024 12:53 pm    Post subject: |   |  
				| 
 |  
				| Thank you both! 
 
  	  | AylinCE wrote: |  	  | Just an example targeting adding a right click menu to the relevant section. 
 | 
 I added an [ENABLE] and a [DISABLE] section, assigned to Cheat Table.
 I enable it, and it appears to be doing nothing - at least, there are no new menu items appearing in the popup.
 Am I using it wrong?
 Thanks!
 
 Edit
 Managed to fix it.
 Next question is, how do I get the value right-clicked from the sender - so I can do something with it...
 
 Final code (for posterity):
 
  	  | Code: |  	  | [ENABLE] {$lua}
 function getFormStructureDissect()
 for k,v in ipairs(enumStructureForms()) do if v.ClassName=="TfrmStructures2" then return v end end
 return nil
 end
 
 function popupLookupNameIDClick(sender)
 showMessage('popupLookupNameIDClick!')
 end
 
 local frmDissect
 
 function fn_AddPopupMenuItems()
 if miNameIDLookup then miNameIDLookup.destroy() end
 frmDissect=getFormStructureDissect()
 if frmDissect~=nil then
 local pmDissect = frmDissect.pmStructureView  -- pmDissect = TfrmStructures2.PopupMenu
 local mnItemDissect=pmDissect.getItems()      -- mnItemDissect = main MenuItem of TfrmStructures2.PopupMenu
 
 miNameIDLookup=createMenuItem(pmDissect)
 miNameIDLookup.setCaption('Find Name from ID')
 miNameIDLookup.setOnClick(popupLookupNameIDClick)
 mnItemDissect.Add(miNameIDLookup)
 end
 end
 
 local function pmRegTimer_tick(thisTimer) ---- Timer callback
 thisTimer.Active = false
 fn_AddPopupMenuItems()
 print('Registered popupLookupNameIDClick.')
 thisTimer.destroy()
 thisTimer=nil
 end
 
 objPopupMenuNotification= registerFormAddNotification(function(frmDissect)
 local t=createTimer(getMainForm())
 t.Interval = 200
 t.OnTimer = pmRegTimer_tick
 end
 end)
 
 [DISABLE]
 {$lua}
 if syntaxcheck then return end
 
 unregisterFormAddNotification(objPopupMenuNotification)
 
 if miNameIDLookup then
 miNameIDLookup.destroy()
 print('Destroyed popupLookupNameIDClick.')
 end
 
 | 
 
 Last edited by Csimbi on Mon Aug 26, 2024 10:44 am; edited 3 times in total
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Csimbi I post too much
 
  Reputation: 97 
 Joined: 14 Jul 2007
 Posts: 3327
 
 
 | 
			
				|  Posted: Mon Aug 26, 2024 10:39 am    Post subject: |   |  
				| 
 |  
				| Okay, this works for the most part - however, the popup menu item keeps disappearing. For example, when I add a new column, the popup menu item disappears.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| LeFiXER Grandmaster Cheater Supreme
 
 ![]() Reputation: 20 
 Joined: 02 Sep 2011
 Posts: 1069
 Location: 0x90
 
 | 
			
				|  Posted: Fri Aug 30, 2024 2:31 pm    Post subject: |   |  
				| 
 |  
				| Save this as a Lua file within the autorun directory. It will add the respective item to the popupmenu of the Structure Dissect form. The function attached to that particular object returns the index  of the menu item. 
  	  | Code: |  	  | local function addItemToPopupMenu(form)
 if form.findComponentByName('miNameIDLookup') then miNameIDLookup.destroy(); miNameIDLookup = nil end
 
 local miNameIDLookup = createMenuItem(form.pmStructureView)
 local miSep = createMenuItem(form.pmStructureview)
 miSep.Name = 'miNewSep1'
 miSep.Caption = '-'
 form.pmStructureView.Items.add(miSep)
 
 miNameIDLookup.Name = 'miNameIDLookup'
 miNameIDLookup.Caption = 'Find Name from ID'
 miNameIDLookup.OnClick = function (sender)
 print('popupLookupNameIDClick! with index: ' .. sender.MenuIndex)
 end
 form.pmStructureView.Items.add(miNameIDLookup)
 end
 
 local function formCreateNotify(form)
 if form.ClassName ~= 'TfrmStructures2' then return end
 
 local timer = createTimer(MainForm)
 timer.Interval = 15
 timer.OnTimer = function(t)
 addItemToPopupMenu(form)
 t.destroy()
 end
 end
 
 registerFormAddNotification(formCreateNotify)
 
 | 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Csimbi I post too much
 
  Reputation: 97 
 Joined: 14 Jul 2007
 Posts: 3327
 
 
 | 
			
				|  Posted: Tue Sep 17, 2024 1:17 pm    Post subject: |   |  
				| 
 |  
				| It would appear new windows do not get the new popup menu item. How would I make it so that the popup menu is registered for each dissect window that is opened?
 Thank you!
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Tue Sep 17, 2024 2:40 pm    Post subject: |   |  
				| 
 |  
				| registerFormAddNotification should have done that _________________
 
 Do not ask me about online cheats. I don't know any and wont help finding them.
 Like my help? Join me on Patreon so i can keep helping
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Csimbi I post too much
 
  Reputation: 97 
 Joined: 14 Jul 2007
 Posts: 3327
 
 
 | 
			
				|  Posted: Wed Sep 18, 2024 8:46 am    Post subject: |   |  
				| 
 |  
				| For some reason, it's the first dissect window only. 
 
  	  | Code: |  	  | objPopupMenuNotification=registerFormAddNotification(function(frmDissect) local t=createTimer(getMainForm())
 t.Interval = 200
 t.OnTimer = pmRegTimer_tick
 end)
 
 | 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Wed Sep 18, 2024 2:35 pm    Post subject: |   |  
				| 
 |  
				| How does pmRegTimer_tick get the frmDissect  parameter passed to the callback? _________________
 
 Do not ask me about online cheats. I don't know any and wont help finding them.
 Like my help? Join me on Patreon so i can keep helping
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Csimbi I post too much
 
  Reputation: 97 
 Joined: 14 Jul 2007
 Posts: 3327
 
 
 | 
			
				|  Posted: Wed Sep 18, 2024 3:34 pm    Post subject: |   |  
				| 
 |  
				|  	  | Code: |  	  | local frmDissect => this is a global in scope of the script (I think :D)
 
 local function pmRegTimer_tick(thisTimer) ---- Timer callback
 thisTimer.Active = false
 fn_AddPopupMenuItems()
 --print('Registered popupLookupNameIDClick.')
 thisTimer.destroy()
 thisTimer=nil
 end
 
 | 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Wed Sep 18, 2024 4:35 pm    Post subject: |   |  
				| 
 |  
				| you do need to assign the parameter given to the function to that local var though.  And since they have the same name that's going to be problematic 
 change objPopupMenuNotification=registerFormAddNotification(function(frmDissect) to objPopupMenuNotification=registerFormAddNotification(function(newfrmDissect)
 
 and then in the function assign do a frmDissect=newfrmDissect
 _________________
 
 Do not ask me about online cheats. I don't know any and wont help finding them.
 Like my help? Join me on Patreon so i can keep helping
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Csimbi I post too much
 
  Reputation: 97 
 Joined: 14 Jul 2007
 Posts: 3327
 
 
 | 
			
				|  Posted: Thu Sep 19, 2024 4:29 am    Post subject: |   |  
				| 
 |  
				| Thank you!
 
 No luck though - the new popup menuitems are still missing in a new window
 
  	  | Code: |  	  | objPopupMenuNotification=registerFormAddNotification(function(newfrmDissect) frmDissect=newfrmDissect
 local t=createTimer(getMainForm())
 t.Interval = 200
 t.OnTimer = pmRegTimer_tick
 end)
 
 | 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| ParkourPenguin I post too much
 
  Reputation: 152 
 Joined: 06 Jul 2014
 Posts: 4706
 
 
 | 
			
				|  Posted: Thu Sep 19, 2024 10:40 am    Post subject: |   |  
				| 
 |  
				| registerFormAddNotification gets called for every form. Check the class name 
 
  	  | Code: |  	  | function forEachAndFutureForm(classname, func) local i
 for i=0,getFormCount()-1 do
 local f = getForm(i)
 if f.ClassName==classname then
 func(f)
 end
 end
 
 registerFormAddNotification(function(f)
 if classname==f.ClassName then
 f.registerFirstShowCallback(func)
 end
 end)
 end
 
 forEachAndFutureForm('TfrmStructures2',function(f)
 local mi = createMenuItem(f.pmStructureView)
 mi.Name = 'miHelloWorld'
 mi.Caption = 'Hello'
 mi.OnClick = function() print'Hello' end
 
 f.pmStructureView.Items.add(mi)
 end)
 | 
 _________________
 
 I don't know where I'm going, but I'll figure it out when I get there. |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Csimbi I post too much
 
  Reputation: 97 
 Joined: 14 Jul 2007
 Posts: 3327
 
 
 | 
			
				|  Posted: Sat Sep 21, 2024 2:24 pm    Post subject: |   |  
				| 
 |  
				|  	  | ParkourPenguin wrote: |  	  | registerFormAddNotification gets called for every form. Check the class name | 
 
 I'll say, okay and admit I am not sure what am I looking at.
 Is this something I should be building into my code or it this built into CE?
 I am not very good with LUA - thank you for your patience!
 
 Last edited by Csimbi on Sun Sep 22, 2024 8:16 am; edited 1 time in total
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  |