faqts : Computers : Programming : Languages : Tse : Menu

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

TSE: Menu: Character: Hotkey: Check: How to check if all hotkey characters are unique in menu block?

Nov 7th, 2006 16:37
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 07 November 2020 - 10:19 pm -------------------
TSE: Menu: Character: Hotkey: Check: How to check if all hotkey 
characters are unique in menu block?
Method: First collect all hotkeys, then check if the resulting string 
is unique
You collect all the hotkey menu characters in a block
by adding these to a string.
Finally you check if all the characters in
that string are unique.
--- cut here: begin --------------------------------------------------
// library: string: get: count (filenamemacro=getstgco.s) [kn, ri, we, 
08-11-2020 01:15:00]
INTEGER PROC FNStringGetCountI( STRING containS, STRING searchS )
 INTEGER I = 1 - 1
 INTEGER countI = 1 - 1
 INTEGER foundB = FALSE
 INTEGER beginI = 1
 INTEGER endI = Length( containS )
 INTEGER lengthSearchI = Length( searchS )
 REPEAT
  I = Pos( searchS, containS[beginI..endI] )
  foundB = ( I > 0 )
  IF foundB
   countI = countI + 1
   beginI = beginI + I + lengthSearchI - 1
  ENDIF
 UNTIL NOT foundB
 RETURN( countI )
END
INTEGER PROC FNStringCheckCharacterUniqueAllB( STRING s )
 INTEGER I = 0
 INTEGER lengthI = Length( s )
 INTEGER duplicateB = FALSE
 INTEGER countI = 0
 STRING cS[255] = ""
 I = 1 - 1
 REPEAT
  I = I + 1
  cS = SubStr( s, I, 1 )
  countI = FNStringGetCountI( s, cS )
  duplicateB = ( NOT ( countI == 1 ) )
 UNTIL ( duplicateB ) OR ( I >= lengthI )
 RETURN( NOT duplicateB )
END
// library: string: get: menu: block: character: hotkey: all 
(filenamemacro=getsthal.s) [kn, ho, tu, 07-11-2020 20:44:45]
STRING PROC FNStringGetMenuBlockCharacterHotkeyAllS()
 INTEGER downB = TRUE
 STRING s[255] = ""
 STRING menuLetterAllS[255] = ""
 STRING menuLetterS[255] = ""
 INTEGER foundI = 0
 IF NOT IsBlockMarked()
  Warn( "please mark a block" )
  RETURN( "" )
 ENDIF
 PushPosition()
 GotoBlockBegin()
 WHILE IsCursorInBlock() AND downB
  IF LFind( '^{[ ]@}{["].*["]}', "x" )
   s = GetFoundText( 2 )
   foundI = Pos( "&", s )
   IF ( foundI <> 0 )
    menuLetterS = SubStr( s, foundI + 1, 1 )
    menuLetterAllS = menuLetterAllS + menuLetterS
   ENDIF
  ENDIF
  downB = Down()
 ENDWHILE
 PopPosition()
 RETURN( menuLetterAllS )
END
// library: string: check: menu: block: character: hotkey: unique [kn, 
ri, tu, 07-11-2020 22:24:03]
INTEGER PROC FNStringCheckMenuBlockCharacterHotkeyUniqueB()
 STRING s[255] = ""
 s = FNStringGetMenuBlockCharacterHotkeyAllS()
 RETURN( FNStringCheckCharacterUniqueAllB( s ) )
END
PROC Main()
 Message( FNStringCheckMenuBlockCharacterHotkeyUniqueB() ) // gives 
TRUE when all the menu hotkey characters are unique in the given menu 
block
END
<F12> Main()
--- cut here: end ----------------------------------------------------
===
Method: While collecting all hotkeys, you check if the resulting 
string is unique
You collect all the hotkey menu characters in a block
by adding these to a string.
Each time you check if a new found hotkey character is already
present in that string.
If not found in the string then it is a unique hotkey character,
otherwise it is not unique or thus duplicate.
--- cut here: begin --------------------------------------------------
// library: string: check: menu: block: character: hotkey: unique [kn, 
ri, tu, 07-11-2020 22:24:03]
INTEGER PROC FNStringCheckMenuBlockCharacterHotkeyUniqueB()
 INTEGER duplicateB = TRUE
 INTEGER downB = TRUE
 STRING s[255] = ""
 STRING menuLetterAllS[255] = ""
 STRING menuLetterS[255] = ""
 INTEGER foundI = 0
 IF NOT IsBlockMarked()
  Warn( "please mark a block" )
  RETURN( FALSE )
 ENDIF
 PushPosition()
 GotoBlockBegin()
 WHILE IsCursorInBlock() AND downB AND NOT duplicateB
  IF LFind( '^{[ ]@}{["].*["]}', "x" )
   s = GetFoundText( 2 )
   foundI = Pos( "&", s )
   IF ( foundI <> 0 )
    menuLetterS = SubStr( s, foundI + 1, 1 )
    duplicateB = Pos( menuLetterS, menuLetterAllS ) <> 0
    menuLetterAllS = menuLetterAllS + menuLetterS
   ENDIF
  ENDIF
  downB = Down()
 ENDWHILE
 PopPosition()
 RETURN( NOT duplicateB )
END
PROC Main()
 Message( FNStringCheckMenuBlockCharacterHotkeyUniqueB() ) // gives 
TRUE when all the menu hotkey characters are unique in the given menu 
block
END
<F12> Main()
--- cut here: end ----------------------------------------------------
===
Internet: see also:
---
TSE: Menu: Character: Hotkey: Link: Overview: Can you give an overview 
of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/42905/fid/1571
----------------------------------------------------------------------