View previous topic :: View next topic |
Author |
Message |
Csimbi I post too much Reputation: 96
Joined: 14 Jul 2007 Posts: 3180
|
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: 146
Joined: 06 Jul 2014 Posts: 4469
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 34
Joined: 16 Feb 2017 Posts: 1402
|
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: 96
Joined: 14 Jul 2007 Posts: 3180
|
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: 96
Joined: 14 Jul 2007 Posts: 3180
|
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: 1058 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 |
|
|
|