Skip to content

Commit 23e08b1

Browse files
committed
Modularise right click menu
1 parent 632b971 commit 23e08b1

File tree

5 files changed

+279
-268
lines changed

5 files changed

+279
-268
lines changed

lua/blobsprofiler/client/cl_blobsprofiler.lua

Lines changed: 14 additions & 265 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ net.Receive("blobsProfiler:sendSourceChunk", function()
241241
end
242242
end)
243243

244-
blobsProfiler.Menu.RCFunctions = {} -- TODO: modularisation?
245-
blobsProfiler.Menu.RCFunctions["Globals"] = {
244+
blobsProfiler.Menu.RCFunctions = {}
245+
blobsProfiler.Menu.RCFunctions_DEFAULT = {
246246
["string"] = {
247247
{
248248
name = "Print",
@@ -341,261 +341,6 @@ blobsProfiler.Menu.RCFunctions["Globals"] = {
341341
}
342342
}
343343
}
344-
blobsProfiler.Menu.RCFunctions["Hooks"] = blobsProfiler.Menu.RCFunctions["Globals"]
345-
blobsProfiler.Menu.RCFunctions["ConCommands"] = blobsProfiler.Menu.RCFunctions["Globals"]
346-
blobsProfiler.Menu.RCFunctions["Files"] = {
347-
["table"] = {
348-
{
349-
name = "Print path",
350-
func = function(ref, node)
351-
local path = ""
352-
local function apparentParentDir(child)
353-
if child.parentNode then
354-
path = child.Label:GetText() .. (path ~= "" and "/" or "") .. path
355-
apparentParentDir(child.parentNode)
356-
else
357-
path = child:GetText() .. "/" .. path
358-
end
359-
end
360-
361-
apparentParentDir(node)
362-
363-
print(path)
364-
end,
365-
icon = "icon16/application_osx_terminal.png"
366-
},
367-
{
368-
name = "Copy path",
369-
func = function(ref, node)
370-
local path = ""
371-
local function apparentParentDir(child)
372-
if child.parentNode then
373-
path = child.Label:GetText() .. (path ~= "" and "/" or "") .. path
374-
apparentParentDir(child.parentNode)
375-
else
376-
path = child:GetText() .. "/" .. path
377-
end
378-
end
379-
380-
apparentParentDir(node)
381-
382-
SetClipboardText(path)
383-
end,
384-
icon = "icon16/page_copy.png"
385-
}
386-
},
387-
["string"] = {
388-
{
389-
name = "View source",
390-
func = function(ref, node)
391-
local path = ""
392-
local function apparentParentDir(child)
393-
if child.parentNode then
394-
path = child.Label:GetText() .. (path ~= "" and "/" or "") .. path
395-
apparentParentDir(child.parentNode)
396-
else
397-
path = child:GetText() .. "/" .. path
398-
end
399-
end
400-
401-
apparentParentDir(node)
402-
403-
net.Start("blobsProfiler:requestSource")
404-
net.WriteString(path)
405-
net.SendToServer()
406-
end,
407-
icon = "icon16/script_code.png"
408-
},
409-
{
410-
name = "Print path",
411-
func = function(ref, node)
412-
local path = ""
413-
local function apparentParentDir(child)
414-
if child.parentNode then
415-
path = child.Label:GetText() .. (path ~= "" and "/" or "") .. path
416-
apparentParentDir(child.parentNode)
417-
else
418-
path = child:GetText() .. "/" .. path
419-
end
420-
end
421-
422-
apparentParentDir(node)
423-
424-
print(path)
425-
end,
426-
icon = "icon16/application_osx_terminal.png"
427-
},
428-
{
429-
name = "Copy path",
430-
func = function(ref, node)
431-
local path = ""
432-
local function apparentParentDir(child)
433-
if child.parentNode then
434-
path = child.Label:GetText() .. (path ~= "" and "/" or "") .. path
435-
apparentParentDir(child.parentNode)
436-
else
437-
path = child:GetText() .. "/" .. path
438-
end
439-
end
440-
441-
apparentParentDir(node)
442-
443-
SetClipboardText(path)
444-
end,
445-
icon = "icon16/page_copy.png"
446-
}
447-
}
448-
}
449-
blobsProfiler.Menu.RCFunctions["Network"] = blobsProfiler.Menu.RCFunctions["Globals"]
450-
blobsProfiler.Menu.RCFunctions["Timers"] = {
451-
["table"] = { -- root node, timer identifier
452-
{
453-
name = "Print",
454-
func = function(ref, node)
455-
print(ref.value)
456-
print(node.GlobalPath)
457-
end,
458-
icon = "icon16/application_osx_terminal.png",
459-
requiredAccess = "Read"
460-
},
461-
{ -- Pause/Resume timer
462-
name = function(ref, node)
463-
if not timer.Exists(node.GlobalPath) then return end
464-
local timeLeft = timer.TimeLeft(node.GlobalPath)
465-
if timeLeft < 0 then
466-
return "Resume"
467-
else
468-
return "Pause"
469-
end
470-
end,
471-
func = function(ref, node)
472-
if not timer.Exists(node.GlobalPath) then return end
473-
local timeLeft = timer.TimeLeft(node.GlobalPath)
474-
if timeLeft < 0 then
475-
timer.UnPause(node.GlobalPath)
476-
node.Icon:SetImage("icon16/clock_stop.png")
477-
else
478-
timer.Pause(node.GlobalPath)
479-
node.Icon:SetImage("icon16/clock_play.png")
480-
end
481-
end,
482-
onLoad = function(ref, node)
483-
if not timer.Exists(node.GlobalPath) then return end
484-
local timeLeft = timer.TimeLeft(node.GlobalPath)
485-
if timeLeft < 0 then
486-
node.Icon:SetImage("icon16/clock_stop.png")
487-
else
488-
node.Icon:SetImage("icon16/clock_play.png")
489-
end
490-
end,
491-
icon = function(ref, node)
492-
if not timer.Exists(node.GlobalPath) then return end
493-
local timeLeft = timer.TimeLeft(node.GlobalPath)
494-
if timeLeft < 0 then
495-
return "icon16/clock_stop.png"
496-
else
497-
return "icon16/clock_play.png"
498-
end
499-
end,
500-
requiredAccess = "Write"
501-
},
502-
{ -- Delete timer
503-
name = function(ref, node)
504-
if not timer.Exists(node.GlobalPath) then node.Label:SetTextColor(Color(255,0,0)) return end
505-
return "Delete"
506-
end,
507-
func = function(ref, node)
508-
timer.Remove(node.GlobalPath)
509-
node.Label:SetTextColor(Color(255,0,0))
510-
node.Icon:SetImage("icon16/clock_delete.png")
511-
end,
512-
onLoad = function(ref, node)
513-
if not timer.Exists(node.GlobalPath) then
514-
node.Label:SetTextColor(Color(255,0,0))
515-
node.Icon:SetImage("icon16/clock_delete.png")
516-
end
517-
end,
518-
icon = "icon16/clock_delete.png",
519-
requiredAccess = "Delete"
520-
},
521-
{ -- Remove timer reference
522-
name = function(ref, node)
523-
if not timer.Exists(node.GlobalPath) then return "Remove reference" end
524-
end,
525-
func = function(ref, node)
526-
blobsProfiler.createdTimers[node.GlobalPath] = nil
527-
node:Remove()
528-
end,
529-
icon = "icon16/clock_red.png",
530-
requiredAccess = "Delete"
531-
}
532-
}
533-
}
534-
blobsProfiler.Menu.RCFunctions["SQLite.Schema"] = { -- TODO: make submodules work with this
535-
["table"] = {
536-
{
537-
name = "SQL Create statement",
538-
submenu = {
539-
{
540-
name = "Print",
541-
func = function(ref, node)
542-
local grabSQLCreate = sql.QueryValue("SELECT sql FROM sqlite_master WHERE name = ".. sql.SQLStr(ref.key) .." LIMIT 1;")
543-
print(grabSQLCreate)
544-
end,
545-
icon = "icon16/application_osx_terminal.png"
546-
},
547-
{
548-
name = "Copy to clipboard",
549-
func = function(ref, node)
550-
local grabSQLCreate = sql.QueryValue("SELECT sql FROM sqlite_master WHERE name = ".. sql.SQLStr(ref.key) .." LIMIT 1;")
551-
SetClipboardText(grabSQLCreate)
552-
end,
553-
icon = "icon16/page_copy.png"
554-
}
555-
},
556-
icon = "icon16/table_lightning.png",
557-
condition = function(ref, node, realm)
558-
if not blobsProfiler[realm].SQLite.Schema.Tables then return false end
559-
560-
return blobsProfiler[realm].SQLite.Schema.Tables[ref.key]
561-
end
562-
}
563-
--[[{
564-
name = "Expand children",
565-
func = function(ref, node)
566-
local function expandChildren(panel)
567-
if panel.Expander and (panel.GetExpanded and not panel:GetExpanded()) then
568-
panel.Expander:DoClick()
569-
end
570-
571-
for k, v in pairs(panel:GetChildren()) do
572-
expandChildren(v)
573-
end
574-
end
575-
576-
expandChildren(node)
577-
end,
578-
icon = "icon16/table_multiple.png"
579-
},
580-
{
581-
name = "Collapse children",
582-
func = function(ref, node)
583-
local function expandChildren(panel)
584-
if panel.Expander and (panel.GetExpanded and panel:GetExpanded()) then
585-
panel.Expander:DoClick()
586-
end
587-
588-
for k, v in pairs(panel:GetChildren()) do
589-
expandChildren(v)
590-
end
591-
end
592-
593-
expandChildren(node)
594-
end,
595-
icon = "icon16/table_multiple.png"
596-
},]]
597-
}
598-
}
599344

600345
blobsProfiler.Menu.TypeFolders = {}
601346
blobsProfiler.Menu.TypeFolders.Client = {}
@@ -689,8 +434,9 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
689434
childNode.LazyLoaded = true
690435
end
691436

692-
if blobsProfiler.Menu.RCFunctions[varType] and blobsProfiler.Menu.RCFunctions[varType][dataType] then
693-
for k,v in ipairs(blobsProfiler.Menu.RCFunctions[varType][dataType]) do
437+
local RCTable = blobsProfiler.GetRCFunctionsTable(varType)
438+
if RCTable and RCTable[dataType] then
439+
for k,v in ipairs(RCTable[dataType]) do
694440
if v.requiredAccess and childNode.Restrictions[v.requiredAccess] then
695441
continue
696442
end
@@ -769,11 +515,12 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
769515
childNode.DoRightClick = function()
770516
childNode:InternalDoClick()
771517

772-
if blobsProfiler.Menu.RCFunctions[varType] and blobsProfiler.Menu.RCFunctions[varType][visualDataType] then
518+
local RCTable = blobsProfiler.GetRCFunctionsTable(varType)
519+
if RCTable and RCTable[visualDataType] then
773520
blobsProfiler.Menu.RCMenu = DermaMenu()
774521
local RCMenu = blobsProfiler.Menu.RCMenu
775522

776-
for _, rcM in ipairs(blobsProfiler.Menu.RCFunctions[varType][visualDataType]) do
523+
for _, rcM in ipairs(RCTable[visualDataType]) do
777524
if rcM.requiredAccess and childNode.Restrictions[rcM.requiredAccess] then
778525
continue
779526
end
@@ -843,8 +590,9 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
843590
end
844591
end
845592

846-
if blobsProfiler.Menu.RCFunctions[varType] and blobsProfiler.Menu.RCFunctions[varType][visualDataType] then
847-
for k,v in ipairs(blobsProfiler.Menu.RCFunctions[varType][visualDataType]) do
593+
local RCTable = blobsProfiler.GetRCFunctionsTable(varType)
594+
if RCTable and RCTable[visualDataType] then
595+
for k,v in ipairs(RCTable[visualDataType]) do
848596
if v.requiredAccess and childNode.Restrictions[v.requiredAccess] then
849597
continue
850598
end
@@ -901,10 +649,11 @@ local function addDTreeNode(parentNode, nodeData, specialType, isRoot, varType,
901649
visualDataType = nodeValue.fakeVarType -- every day we stray further away from god
902650
end
903651

652+
local RCTable = blobsProfiler.GetRCFunctionsTable(varType)
904653
if dataType == "table" and childNode.Expander and childNode.Expander.SetExpanded then
905654
childNode:SetExpanded(not childNode:GetExpanded())
906-
elseif blobsProfiler.Menu.RCFunctions[varType] and blobsProfiler.Menu.RCFunctions[varType][visualDataType] then
907-
for _, rcM in ipairs(blobsProfiler.Menu.RCFunctions[varType][visualDataType]) do
655+
elseif RCTable and RCTable[visualDataType] then
656+
for _, rcM in ipairs(RCTable[visualDataType]) do
908657
if rcM.requiredAccess and childNode.Restrictions[rcM.requiredAccess] then
909658
continue
910659
end

0 commit comments

Comments
 (0)