Skip to content

Commit a40fb1c

Browse files
authored
Merge pull request #17 from ukos-git/add_menus
include Menus
2 parents 475fba6 + 624a1cd commit a40fb1c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

procedures/CodeBrowser.ipf

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ StrConstant macroMarker = "\\W519"
1919
StrConstant windowMarker = "\\W520"
2020
StrConstant procMarker = "\\W521"
2121
StrConstant structureMarker = "\\W522"
22+
StrConstant menuMarker = "\\W523"
2223

2324
// the idea here: static functions have less intense colors
2425
StrConstant plainColor = "0,0,0" // black
@@ -239,6 +240,9 @@ Function/S createMarkerForType(type)
239240
marker = constantMarker
240241
elseif(strsearch(type, "structure", 0) != -1)
241242
marker = structureMarker
243+
elseif(strsearch(type, "menu", 0) != -1)
244+
marker = menuMarker
245+
return getColorDef(plainColor) + marker
242246
endif
243247

244248
// plain definitions
@@ -480,6 +484,56 @@ Function addDecoratedStructure(module, procedureWithoutModule, declWave, lineWav
480484
WaveClear wavStructureStart, wavStructureEnd
481485
End
482486

487+
Function addDecoratedMenu(module, procedureWithoutModule, declWave, lineWave)
488+
String module, procedureWithoutModule
489+
WAVE/T declWave
490+
WAVE/D lineWave
491+
492+
Variable numLines, idx, numEntries, numMatches
493+
String procText, re, def, name, type
494+
String currentMenu = ""
495+
496+
// get procedure code
497+
procText = getProcedureText(module, procedureWithoutModule)
498+
numLines = ItemsInList(procText, "\r")
499+
500+
// search code and return wavLineNumber
501+
Make/FREE/N=(numLines)/T text = StringFromList(p, procText, "\r")
502+
// regexp: match case insensitive (?i) spaces don't matter. search for menu or submenu with a name in double quotes.
503+
// help for regex on https://regex101.com/
504+
re = "^(?i)[[:space:]]*(menu|submenu)[[:space:]]+\"((?:[^\"\\\\]|\\\\.)+)\"(?:[[:space:]]*[,][[:space:]]*(hideable|dynamic|contextualmenu))?"
505+
Grep/Q/INDX/E=re text
506+
numMatches = !!V_Value
507+
Wave W_Index
508+
Duplicate/FREE W_Index wavLineNumber
509+
KillWaves/Z W_Index
510+
if(!numMatches)
511+
return 0
512+
endif
513+
514+
numMatches = DimSize(wavLineNumber, 0)
515+
numEntries = DimSize(declWave, 0)
516+
Redimension/N=(numEntries + numMatches, -1) declWave, lineWave
517+
518+
for(idx = numEntries; idx < (numEntries + numMatches); idx += 1)
519+
SplitString/E=re text[wavLineNumber[(idx - numEntries)]], def, name, type
520+
def = LowerStr(def)
521+
if(!cmpstr(def, "menu"))
522+
currentMenu = name
523+
endif
524+
declWave[idx][0] = createMarkerForType(def)
525+
declWave[idx][1] = "Menu " + currentMenu
526+
if(!cmpstr(def, "submenu"))
527+
declWave[idx][1] += ":" + name
528+
endif
529+
if(cmpstr(type, ""))
530+
declWave[idx][1] += "(" + type + ")"
531+
endif
532+
533+
lineWave[idx] = wavLineNumber[(idx - numEntries)]
534+
endfor
535+
End
536+
483537
// input wave (wavStructure) contains text of Structure lineseparated.
484538
// wavStructure begins with "Structure" definition in first line and ends with "EndStructure" in last line.
485539
Function/S getStructureElements(wavStructure)
@@ -615,6 +669,7 @@ Function/S parseProcedure(procedure, [checksumIsCalculated])
615669
addDecoratedConstants(procedure.module, procedure.name, decls, lines)
616670
addDecoratedMacros(procedure.module, procedure.name, decls, lines)
617671
addDecoratedStructure(procedure.module, procedure.name, decls, lines)
672+
addDecoratedMenu(procedure.module, procedure.name, decls, lines)
618673

619674
// stop timer
620675
setParsingTime(timerStop(timer))

0 commit comments

Comments
 (0)