WBStudio.ListMenuTitles
;------------------------------------------------------------------------------------------------------------------------------------------
; WBStudio Utility for use within WinBatch Studio debug mode.
;------------------------------------------------------------------------------------------------------------------------------------------
; Working on WSPOPUP.MNU - ReadOnly -
; Working on WSP-USER.MNU - ReadOnly -
;
; Create a list of Menu title lines. Menu level 1 to 4 is adjustable.
; Adjustable supress of comments.
;
; Running script can be terminated by pressing [Shift] key.
;
; (c)Detlev Dalitz.20051215.20100211.
;------------------------------------------------------------------------------------------------------------------------------------------
Terminate (RtStatus () != 10, IntControl (1004, 0, 0, 0, 0), "Terminated. Script runs only in WinBatch Studio debug mode.")
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
; ****** Options - Tweak Section ******
;
;strWorkFile = StrCat (DirHome (), "Wspopup.mnu")
strWorkFile = DirHome () : "wsp-user.mnu"
;
;intMenuLevel = 1           ; Allowed: 1..4
;intMenuLevel = 2           ; Allowed: 1..4
;intMenuLevel = 3           ; Allowed: 1..4
intMenuLevel = 4            ; Allowed: 1..4
;
blnSupressComment = @FALSE  ; Do not supress special menu title lines.
;blnSupressComment = @TRUE  ; Supress special menu title lines, display only menu titles.
;
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
wFileOpen (strWorkFile)
wTopOfFile ()
intLineCount = wLineCount ()
;------------------------------------------------------------------------------------------------------------------------------------------
SendKey ("!wh") ; Tile horizontal MDI windows in WBStudio editor. ; Function wWinTile() does not fit here.
;------------------------------------------------------------------------------------------------------------------------------------------
strHeader = TimeYmdHms () : " - WSPOPUP.MNU - Menu structure - Level 1-" : intMenuLevel
strHeader = strHeader : @LF : "  Line   Level   Contents" : @LF
strExitMsg = "Ready."
;------------------------------------------------------------------------------------------------------------------------------------------
; Search within WSPOPUP.MNU for menu title lines.
;   wf_sPattern   = "^.+\^.+\^.*\^.*$" ; Pattern for menu title lines.
wf_sPattern = ArrDimension (5) ; Element 0 is not used.
wf_sPattern[1] = "^[^ \;].+"
wf_sPattern[2] = "^[^ \;].+|^ [^ ].+"
wf_sPattern[3] = "^[^ \;].+|^ [^ ].+|^  [^ ].+"
wf_sPattern[4] = "^[^ \;].+|^ [^ ].+|^  [^ ].+|^   [^ ].+"
wf_iForward = @TRUE
wf_iMatchCase = @TRUE
wf_iRegExp = @TRUE
wf_iWrap = @FALSE
;------------------------------------------------------------------------------------------------------------------------------------------
intCountTitles = 0
strOut = ""
While @TRUE
   wClearSel ()
   wf_iResult = wFind (wf_sPattern[intMenuLevel], wf_iForward, wf_iMatchCase, wf_iRegExp, wf_iWrap)
   If !wf_iResult Then Break
   strPopLine = wGetWord ()
   intCountTitles = intCountTitles + 1

   If blnSupressComment Then strPopLine = ItemExtract (1, strPopLine, ";") ; Assumes that there is no other prior ";" in line.

   intLevel = 2 + StrLen (strPopLine) - StrLen (StrTrim (strPopLine : @LF))

   strLevelNum = StrFixLeft (intLevel, " ", intLevel + 1)
   strLevelNum = StrFix (strLevelNum, " ", 4 + 1)

   intLine = wGetLineNo ()
   strLineNum = StrFixLeft (intLine, " ", 6)

   strPopLine = strLineNum : "   " : strLevelNum : "  |" : strPopLine
   strOut = ItemInsert (strPopLine, -1, strOut, @LF)

   strStatusMsg = intLineCount : "/" : strPopLine
   wStatusMsg (strStatusMsg)

   If IsKeyDown (@SHIFT) ; Shift can stop the loop.
      strExitMsg = "Aborted."
      Break
   EndIf
EndWhile
wTopOfFile ()
;------------------------------------------------------------------------------------------------------------------------------------------
strOut = ItemInsert ("", -1, strOut, @LF)  ; Add Footer.
strOut = ItemInsert (TimeYmdHms () : " - Line " : intLineCount : "/" : intLine, -1, strOut, @LF)
strOut = ItemInsert (" - Menu Titles: " : intCountTitles, -1, strOut, @LF)
strOut = ItemInsert (strExitMsg, -1, strOut, @LF)
strOut = ItemInsert (strHeader, 0, strOut, @LF)  ; Add Header.
strOut = StrReplace (strOut, @LF, @CRLF)
;------------------------------------------------------------------------------------------------------------------------------------------
:CANCEL
ClipPut (strOut)
wFileNew ()
wPaste ()
;------------------------------------------------------------------------------------------------------------------------------------------
wWinMaximize ()  ; SendKey("!-x") ; Maximize MDI window in WBStudio editor.
;------------------------------------------------------------------------------------------------------------------------------------------
Exit
;------------------------------------------------------------------------------------------------------------------------------------------