by Steegy » Sat Apr 29, 2006 4:55 pm
Current code (as autoscript)
Current issues:
- how should it work??
- double-clicking a button (unexpectedly) goes to the "first occurence" instead of the "next occurence"
Buttons:
%: for symbols
0: for digits 0 - 9
A - Z: for letters A - Z
<-: go to parent node
<x: go to parent node and close it
How to install scripts:
http://faq.mediamonkey.com/index.php?ac ... artlang=en
Code: Select all
' Copy anything you want, but I like the credit :-)
Option Explicit
Dim SDB : Set SDB = CreateObject("SongsDB.SDBApplication")
Dim BorderlessButton : BorderlessButton = False
Dim IgnorePrefixes : IgnorePrefixes = True
Dim Prefixes : Prefixes = Array("the") ' Prefixes to ignore (the character ' is always ignored if not in the "Title" tree node)
Dim CurrentNode
Sub OnStartUp
Call CreatePanel
End Sub
Sub CreatePanel
Dim Panel : Set Panel = InitialisePanel
Dim MI : Set MI = SDB.UI.AddMenuItem(SDB.UI.Menu_View, 1, -3)
MI.Caption = "Library Buttons"
MI.Checked = Panel.Common.Visible = True
MI.Hint = "Show the library buttons panel"
Script.RegisterEvent MI, "OnClick", "MIClick"
Set SDB.Objects("NodeFromFirstCharacter_MenuItem") = MI
Dim BW : BW = 16 ' button width
Dim BH : BH = 20 ' button height
MakeTheButton Panel, "%", BW, 0, BW, BH, "ActionSymbol"
MakeTheButton Panel, "0", 2*BW, 0, BW, BH, "Action0"
Dim i
For i = 0 To 12
MakeTheButton Panel, Chr(65 + i), 3*BW + i*BW, 0, BW, BH, "Action" & Chr(65 + i)
Next
For i = 13 To 25
MakeTheButton Panel, Chr(65 + i), 3*BW + (i-13)*BW, BH, BW, 20, "Action" & Chr(65 + i)
Next
MakeTheButton Panel, "<-", 0, BH+3, 20, BH-3, "GotoParentNode"
MakeTheButton Panel, "<x", 20, BH+3, 20, BH-3, "GotoParentNodeAndClose"
End Sub
Function InitialisePanel
Set InitialisePanel = SDB.UI.NewDockablePersistentPanel("NodeFromFirstCharacter")
If InitialisePanel.IsNew Then
InitialisePanel.DockedTo = 1
InitialisePanel.Common.Height = 100
End If
InitialisePanel.Caption = ""
If SDB.IniFile.StringValue("NodeFromFirstCharacter", "PanelVisible") = "False" Then
InitialisePanel.Common.Visible = False
Else
InitialisePanel.Common.Visible = True
End If
Set SDB.Objects("NodeFromFirstCharacter_Panel") = InitialisePanel
Script.RegisterEvent InitialisePanel, "OnClose", "PanelClosed"
End Function
Sub MIClick(MI)
MI.Checked = Not MI.Checked
If SDB.Objects("NodeFromFirstCharacter_Panel") Is Nothing And MI.Checked Then
Call InitialisePanel
End If
SDB.Objects("NodeFromFirstCharacter_Panel").Common.Visible = MI.Checked
SDB.IniFile.StringValue("NodeFromFirstCharacter", "PanelVisible") = MI.Checked
End Sub
Sub PanelClosed(Panel)
SDB.Objects("NodeFromFirstCharacter_MenuItem").Checked = False
Set SDB.Objects("NodeFromFirstCharacter_Panel") = Nothing
SDB.IniFile.StringValue("NodeFromFirstCharacter", "PanelVisible") = "False"
End Sub
Function MakeTheButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
If BorderlessButton Then
Call CreateBorderlessButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
Else
Call CreateButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
End If
End Function
Function CreateBorderlessButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
Set CreateBorderlessButton = SDB.UI.NewLabel(Owner)
CreateBorderlessButton.Caption = Caption
CreateBorderlessButton.Common.SetRect X, Y, Width, Height
Script.RegisterEvent CreateBorderlessButton.Common, "OnClick", OnClickFunc
End Function
Function CreateButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
Set CreateButton = SDB.UI.NewButton(Owner)
CreateButton.Caption = Caption
CreateButton.Common.SetRect X, Y, Width, Height
Script.RegisterEvent CreateButton.Common, "OnClick", OnClickFunc
End Function
Sub ActionSymbol(Button) : NodeFromFirstCharacter "%" : End Sub
Sub Action0(Button) : NodeFromFirstCharacter "0" : End Sub
'Because dynamically created methods (using Execute or ExecuteGlobal) can't be executed from the default button event handlers, I had to implement them all at compile-time.
Sub ActionA(Button) : NodeFromFirstCharacter "A" : End Sub
Sub ActionB(Button) : NodeFromFirstCharacter "B" : End Sub
Sub ActionC(Button) : NodeFromFirstCharacter "C" : End Sub
Sub ActionD(Button) : NodeFromFirstCharacter "D" : End Sub
Sub ActionE(Button) : NodeFromFirstCharacter "E" : End Sub
Sub ActionF(Button) : NodeFromFirstCharacter "F" : End Sub
Sub ActionG(Button) : NodeFromFirstCharacter "G" : End Sub
Sub ActionH(Button) : NodeFromFirstCharacter "H" : End Sub
Sub ActionI(Button) : NodeFromFirstCharacter "I" : End Sub
Sub ActionJ(Button) : NodeFromFirstCharacter "J" : End Sub
Sub ActionK(Button) : NodeFromFirstCharacter "K" : End Sub
Sub ActionL(Button) : NodeFromFirstCharacter "L" : End Sub
Sub ActionM(Button) : NodeFromFirstCharacter "M" : End Sub
Sub ActionN(Button) : NodeFromFirstCharacter "N" : End Sub
Sub ActionO(Button) : NodeFromFirstCharacter "O" : End Sub
Sub ActionP(Button) : NodeFromFirstCharacter "P" : End Sub
Sub ActionQ(Button) : NodeFromFirstCharacter "Q" : End Sub
Sub ActionR(Button) : NodeFromFirstCharacter "R" : End Sub
Sub ActionS(Button) : NodeFromFirstCharacter "S" : End Sub
Sub ActionT(Button) : NodeFromFirstCharacter "T" : End Sub
Sub ActionU(Button) : NodeFromFirstCharacter "U" : End Sub
Sub ActionV(Button) : NodeFromFirstCharacter "V" : End Sub
Sub ActionW(Button) : NodeFromFirstCharacter "W" : End Sub
Sub ActionX(Button) : NodeFromFirstCharacter "X" : End Sub
Sub ActionY(Button) : NodeFromFirstCharacter "Y" : End Sub
Sub ActionZ(Button) : NodeFromFirstCharacter "Z" : End Sub
Sub GotoParentNodeAndClose(Button)
On Error Resume Next
Dim ParentNode : Set ParentNode = SDB.MainTree.ParentNode(SDB.MainTree.CurrentNode)
Set SDB.MainTree.CurrentNode = ParentNode
ParentNode.Expanded = False
End Sub
Sub GotoParentNode(Button)
On Error Resume Next
Dim ParentNode : Set ParentNode = SDB.MainTree.ParentNode(SDB.MainTree.CurrentNode)
Set SDB.MainTree.CurrentNode = ParentNode
End Sub
Function FindNodeToStartWith(Character, IgnoreIt)
Set FindNodeToStartWith = Nothing
Dim PreviousNode : Set PreviousNode = SDB.Objects("PreviousFirstCharNode")
If Not PreviousNode Is Nothing Then
Dim FirstChar : FirstChar = GetFirstCorrectCharacter(PreviousNode.Caption, IgnoreIt)
If IsAMatch(FirstChar, Character) Then
If EqualNodes(PreviousNode, CurrentNode) Then
Set FindNodeToStartWith = CurrentNode
Exit Function
End If
End If
End If
Select Case SDB.MainTree.CurrentNode.NodeType
Case 9, 1, 2, 4: 'Title, Artist, Album, Genre main nodes
Set FindNodeToStartWith = CurrentNode
FindNodeToStartWith.Expanded = True
Set FindNodeToStartWith = SDB.MainTree.FirstChildNode(FindNodeToStartWith)
Case 150, 60, 151, 50, 152, 52, 153, 53: 'Title, Artist, Album, Genre child nodes
Set FindNodeToStartWith = CurrentNode
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
FindNodeToStartWith.Expanded = True
Set FindNodeToStartWith = SDB.MainTree.FirstChildNode(FindNodeToStartWith)
Case 51, 54: 'ArtistAlbum, GenreArtist nodes
Set FindNodeToStartWith = CurrentNode
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
FindNodeToStartWith.Expanded = True
Set FindNodeToStartWith = SDB.MainTree.FirstChildNode(FindNodeToStartWith)
Case 55: 'GenreArtistAlbum nodes
Set FindNodeToStartWith = CurrentNode
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
FindNodeToStartWith.Expanded = True
Set FindNodeToStartWith = SDB.MainTree.FirstChildNode(FindNodeToStartWith)
End Select
End Function
Function NodeFromFirstCharacter(Character)
' If SDB.Objects("NodeFromFirstCharacter_Busy") Is Nothing Then
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = SDB
' Else
' Exit Function
' MsgBox "2"
' End If
Set CurrentNode = SDB.MainTree.CurrentNode
If CurrentNode Is Nothing Then
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = Nothing
Exit Function
End If
Dim NodeType : NodeType = CurrentNode.NodeType
Dim IgnoreIt : IgnoreIt = Not (NodeType = 9 Or NodeType = 150 Or NodeType = 60)
Dim StartNode : Set StartNode = FindNodeToStartWith(Character, IgnoreIt)
If StartNode Is Nothing Then
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = Nothing
Exit Function
End If
On Error Resume Next
Dim FirstChar
Dim ChildNode : Set ChildNode = StartNode
Do
Set ChildNode = SDB.MainTree.NextSiblingNode(ChildNode)
If Err <> 0 Or (ChildNode Is Nothing) Then
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = Nothing
Exit Function
End If
FirstChar = GetFirstCorrectCharacter(ChildNode.Caption, IgnoreIt)
If IsAMatch(FirstChar, Character) Then
Exit Do
End If
Loop While True
Set SDB.MainTree.CurrentNode = ChildNode
Set SDB.Objects("PreviousFirstCharNode") = ChildNode
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = Nothing
End Function
Function IsAMatch(FirstChar, Character)
IsAMatch = False
If StrComp(FirstChar, Character, 1) = 0 Then
IsAMatch = True
ElseIf Character = "0" Then
If IsNumber(FirstChar) Then
IsAMatch = True
End If
ElseIf Character = "%" Then
If IsNoNumberOrLetter(FirstChar) Then
IsAMatch = True
End If
End If
End Function
Function IsNoNumberOrLetter(InputChar)
Dim InputCharCode : InputCharCode = Asc(InputChar)
IsNoNumberOrLetter = (InputCharCode < 48 Or (InputCharCode > 57 And InputCharCode < 65) Or (InputCharCode > 90 And InputCharCode < 97) Or InputCharCode > 122)
End Function
Function IsNumber(InputChar)
Dim InputCharCode : InputCharCode = Asc(InputChar)
IsNumber = (InputCharCode > 47 And InputCharCode < 58)
End Function
Function EqualNodes(Node1, Node2)
EqualNodes = False
If Node1.NodeType = Node2.NodeType Then
If Node1.Caption = Node2.Caption Then
EqualNodes = True
End If
End If
End Function
Function GetFirstCorrectCharacter(ByVal InputText, IgnoreIt)
Dim TextToChar : TextToChar = InputText
If IgnorePrefixes Then
TextToChar = RemovePrefix(TextToChar)
End If
If IgnoreIt And Left(TextToChar, 1) = "'" Then
TextToChar = Mid(TextToChar, 2, 1)
Else
TextToChar = Left(TextToChar, 1)
End If
GetFirstCorrectCharacter = TextToChar
End Function
Function RemovePrefix(ByVal InputText)
RemovePrefix = InputText
Dim i, Prefix, PrefixLength
For i = 0 To UBound(Prefixes)
Prefix = Prefixes(i) & " "
PrefixLength = Len(Prefix)
If Len(InputText) > PrefixLength Then
If StrComp(Left(InputText, PrefixLength), Prefix, 1) = 0 Then
RemovePrefix = Mid(RemovePrefix, PrefixLength + 1)
Exit For ' stop when a prefix has been removed
End If
End If
Next
End Function
The panel with the buttons has a title bar that isn't shown.
With borderless buttons (fits better on some skins, like this one):
Showing/hiding the panel can be done through the "View" menu.
Borderless buttons are now possible too (yes fellow coders... how did I do that
). You can choose for borderless if you set BorderlessButton to True.
BTW: Code cleanup is on the todo list.
Cheers
Steegy
[i][u][b]Current code (as autoscript)[/b][/u][/i]
[u]Current issues:[/u]
- how should it work??
- double-clicking a button (unexpectedly) goes to the "first occurence" instead of the "next occurence"
[u]Buttons:[/u]
%: for symbols
0: for digits 0 - 9
A - Z: for letters A - Z
<-: go to parent node
<x: go to parent node and close it
How to install scripts: http://faq.mediamonkey.com/index.php?action=artikel&cat=373734&id=8&artlang=en
[code]' Copy anything you want, but I like the credit :-)
Option Explicit
Dim SDB : Set SDB = CreateObject("SongsDB.SDBApplication")
Dim BorderlessButton : BorderlessButton = False
Dim IgnorePrefixes : IgnorePrefixes = True
Dim Prefixes : Prefixes = Array("the") ' Prefixes to ignore (the character ' is always ignored if not in the "Title" tree node)
Dim CurrentNode
Sub OnStartUp
Call CreatePanel
End Sub
Sub CreatePanel
Dim Panel : Set Panel = InitialisePanel
Dim MI : Set MI = SDB.UI.AddMenuItem(SDB.UI.Menu_View, 1, -3)
MI.Caption = "Library Buttons"
MI.Checked = Panel.Common.Visible = True
MI.Hint = "Show the library buttons panel"
Script.RegisterEvent MI, "OnClick", "MIClick"
Set SDB.Objects("NodeFromFirstCharacter_MenuItem") = MI
Dim BW : BW = 16 ' button width
Dim BH : BH = 20 ' button height
MakeTheButton Panel, "%", BW, 0, BW, BH, "ActionSymbol"
MakeTheButton Panel, "0", 2*BW, 0, BW, BH, "Action0"
Dim i
For i = 0 To 12
MakeTheButton Panel, Chr(65 + i), 3*BW + i*BW, 0, BW, BH, "Action" & Chr(65 + i)
Next
For i = 13 To 25
MakeTheButton Panel, Chr(65 + i), 3*BW + (i-13)*BW, BH, BW, 20, "Action" & Chr(65 + i)
Next
MakeTheButton Panel, "<-", 0, BH+3, 20, BH-3, "GotoParentNode"
MakeTheButton Panel, "<x", 20, BH+3, 20, BH-3, "GotoParentNodeAndClose"
End Sub
Function InitialisePanel
Set InitialisePanel = SDB.UI.NewDockablePersistentPanel("NodeFromFirstCharacter")
If InitialisePanel.IsNew Then
InitialisePanel.DockedTo = 1
InitialisePanel.Common.Height = 100
End If
InitialisePanel.Caption = ""
If SDB.IniFile.StringValue("NodeFromFirstCharacter", "PanelVisible") = "False" Then
InitialisePanel.Common.Visible = False
Else
InitialisePanel.Common.Visible = True
End If
Set SDB.Objects("NodeFromFirstCharacter_Panel") = InitialisePanel
Script.RegisterEvent InitialisePanel, "OnClose", "PanelClosed"
End Function
Sub MIClick(MI)
MI.Checked = Not MI.Checked
If SDB.Objects("NodeFromFirstCharacter_Panel") Is Nothing And MI.Checked Then
Call InitialisePanel
End If
SDB.Objects("NodeFromFirstCharacter_Panel").Common.Visible = MI.Checked
SDB.IniFile.StringValue("NodeFromFirstCharacter", "PanelVisible") = MI.Checked
End Sub
Sub PanelClosed(Panel)
SDB.Objects("NodeFromFirstCharacter_MenuItem").Checked = False
Set SDB.Objects("NodeFromFirstCharacter_Panel") = Nothing
SDB.IniFile.StringValue("NodeFromFirstCharacter", "PanelVisible") = "False"
End Sub
Function MakeTheButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
If BorderlessButton Then
Call CreateBorderlessButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
Else
Call CreateButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
End If
End Function
Function CreateBorderlessButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
Set CreateBorderlessButton = SDB.UI.NewLabel(Owner)
CreateBorderlessButton.Caption = Caption
CreateBorderlessButton.Common.SetRect X, Y, Width, Height
Script.RegisterEvent CreateBorderlessButton.Common, "OnClick", OnClickFunc
End Function
Function CreateButton(Owner, Caption, X, Y, Width, Height, OnClickFunc)
Set CreateButton = SDB.UI.NewButton(Owner)
CreateButton.Caption = Caption
CreateButton.Common.SetRect X, Y, Width, Height
Script.RegisterEvent CreateButton.Common, "OnClick", OnClickFunc
End Function
Sub ActionSymbol(Button) : NodeFromFirstCharacter "%" : End Sub
Sub Action0(Button) : NodeFromFirstCharacter "0" : End Sub
'Because dynamically created methods (using Execute or ExecuteGlobal) can't be executed from the default button event handlers, I had to implement them all at compile-time.
Sub ActionA(Button) : NodeFromFirstCharacter "A" : End Sub
Sub ActionB(Button) : NodeFromFirstCharacter "B" : End Sub
Sub ActionC(Button) : NodeFromFirstCharacter "C" : End Sub
Sub ActionD(Button) : NodeFromFirstCharacter "D" : End Sub
Sub ActionE(Button) : NodeFromFirstCharacter "E" : End Sub
Sub ActionF(Button) : NodeFromFirstCharacter "F" : End Sub
Sub ActionG(Button) : NodeFromFirstCharacter "G" : End Sub
Sub ActionH(Button) : NodeFromFirstCharacter "H" : End Sub
Sub ActionI(Button) : NodeFromFirstCharacter "I" : End Sub
Sub ActionJ(Button) : NodeFromFirstCharacter "J" : End Sub
Sub ActionK(Button) : NodeFromFirstCharacter "K" : End Sub
Sub ActionL(Button) : NodeFromFirstCharacter "L" : End Sub
Sub ActionM(Button) : NodeFromFirstCharacter "M" : End Sub
Sub ActionN(Button) : NodeFromFirstCharacter "N" : End Sub
Sub ActionO(Button) : NodeFromFirstCharacter "O" : End Sub
Sub ActionP(Button) : NodeFromFirstCharacter "P" : End Sub
Sub ActionQ(Button) : NodeFromFirstCharacter "Q" : End Sub
Sub ActionR(Button) : NodeFromFirstCharacter "R" : End Sub
Sub ActionS(Button) : NodeFromFirstCharacter "S" : End Sub
Sub ActionT(Button) : NodeFromFirstCharacter "T" : End Sub
Sub ActionU(Button) : NodeFromFirstCharacter "U" : End Sub
Sub ActionV(Button) : NodeFromFirstCharacter "V" : End Sub
Sub ActionW(Button) : NodeFromFirstCharacter "W" : End Sub
Sub ActionX(Button) : NodeFromFirstCharacter "X" : End Sub
Sub ActionY(Button) : NodeFromFirstCharacter "Y" : End Sub
Sub ActionZ(Button) : NodeFromFirstCharacter "Z" : End Sub
Sub GotoParentNodeAndClose(Button)
On Error Resume Next
Dim ParentNode : Set ParentNode = SDB.MainTree.ParentNode(SDB.MainTree.CurrentNode)
Set SDB.MainTree.CurrentNode = ParentNode
ParentNode.Expanded = False
End Sub
Sub GotoParentNode(Button)
On Error Resume Next
Dim ParentNode : Set ParentNode = SDB.MainTree.ParentNode(SDB.MainTree.CurrentNode)
Set SDB.MainTree.CurrentNode = ParentNode
End Sub
Function FindNodeToStartWith(Character, IgnoreIt)
Set FindNodeToStartWith = Nothing
Dim PreviousNode : Set PreviousNode = SDB.Objects("PreviousFirstCharNode")
If Not PreviousNode Is Nothing Then
Dim FirstChar : FirstChar = GetFirstCorrectCharacter(PreviousNode.Caption, IgnoreIt)
If IsAMatch(FirstChar, Character) Then
If EqualNodes(PreviousNode, CurrentNode) Then
Set FindNodeToStartWith = CurrentNode
Exit Function
End If
End If
End If
Select Case SDB.MainTree.CurrentNode.NodeType
Case 9, 1, 2, 4: 'Title, Artist, Album, Genre main nodes
Set FindNodeToStartWith = CurrentNode
FindNodeToStartWith.Expanded = True
Set FindNodeToStartWith = SDB.MainTree.FirstChildNode(FindNodeToStartWith)
Case 150, 60, 151, 50, 152, 52, 153, 53: 'Title, Artist, Album, Genre child nodes
Set FindNodeToStartWith = CurrentNode
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
FindNodeToStartWith.Expanded = True
Set FindNodeToStartWith = SDB.MainTree.FirstChildNode(FindNodeToStartWith)
Case 51, 54: 'ArtistAlbum, GenreArtist nodes
Set FindNodeToStartWith = CurrentNode
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
FindNodeToStartWith.Expanded = True
Set FindNodeToStartWith = SDB.MainTree.FirstChildNode(FindNodeToStartWith)
Case 55: 'GenreArtistAlbum nodes
Set FindNodeToStartWith = CurrentNode
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
Set FindNodeToStartWith = SDB.MainTree.ParentNode(FindNodeToStartWith)
FindNodeToStartWith.Expanded = True
Set FindNodeToStartWith = SDB.MainTree.FirstChildNode(FindNodeToStartWith)
End Select
End Function
Function NodeFromFirstCharacter(Character)
' If SDB.Objects("NodeFromFirstCharacter_Busy") Is Nothing Then
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = SDB
' Else
' Exit Function
' MsgBox "2"
' End If
Set CurrentNode = SDB.MainTree.CurrentNode
If CurrentNode Is Nothing Then
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = Nothing
Exit Function
End If
Dim NodeType : NodeType = CurrentNode.NodeType
Dim IgnoreIt : IgnoreIt = Not (NodeType = 9 Or NodeType = 150 Or NodeType = 60)
Dim StartNode : Set StartNode = FindNodeToStartWith(Character, IgnoreIt)
If StartNode Is Nothing Then
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = Nothing
Exit Function
End If
On Error Resume Next
Dim FirstChar
Dim ChildNode : Set ChildNode = StartNode
Do
Set ChildNode = SDB.MainTree.NextSiblingNode(ChildNode)
If Err <> 0 Or (ChildNode Is Nothing) Then
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = Nothing
Exit Function
End If
FirstChar = GetFirstCorrectCharacter(ChildNode.Caption, IgnoreIt)
If IsAMatch(FirstChar, Character) Then
Exit Do
End If
Loop While True
Set SDB.MainTree.CurrentNode = ChildNode
Set SDB.Objects("PreviousFirstCharNode") = ChildNode
' Set SDB.Objects("NodeFromFirstCharacter_Busy") = Nothing
End Function
Function IsAMatch(FirstChar, Character)
IsAMatch = False
If StrComp(FirstChar, Character, 1) = 0 Then
IsAMatch = True
ElseIf Character = "0" Then
If IsNumber(FirstChar) Then
IsAMatch = True
End If
ElseIf Character = "%" Then
If IsNoNumberOrLetter(FirstChar) Then
IsAMatch = True
End If
End If
End Function
Function IsNoNumberOrLetter(InputChar)
Dim InputCharCode : InputCharCode = Asc(InputChar)
IsNoNumberOrLetter = (InputCharCode < 48 Or (InputCharCode > 57 And InputCharCode < 65) Or (InputCharCode > 90 And InputCharCode < 97) Or InputCharCode > 122)
End Function
Function IsNumber(InputChar)
Dim InputCharCode : InputCharCode = Asc(InputChar)
IsNumber = (InputCharCode > 47 And InputCharCode < 58)
End Function
Function EqualNodes(Node1, Node2)
EqualNodes = False
If Node1.NodeType = Node2.NodeType Then
If Node1.Caption = Node2.Caption Then
EqualNodes = True
End If
End If
End Function
Function GetFirstCorrectCharacter(ByVal InputText, IgnoreIt)
Dim TextToChar : TextToChar = InputText
If IgnorePrefixes Then
TextToChar = RemovePrefix(TextToChar)
End If
If IgnoreIt And Left(TextToChar, 1) = "'" Then
TextToChar = Mid(TextToChar, 2, 1)
Else
TextToChar = Left(TextToChar, 1)
End If
GetFirstCorrectCharacter = TextToChar
End Function
Function RemovePrefix(ByVal InputText)
RemovePrefix = InputText
Dim i, Prefix, PrefixLength
For i = 0 To UBound(Prefixes)
Prefix = Prefixes(i) & " "
PrefixLength = Len(Prefix)
If Len(InputText) > PrefixLength Then
If StrComp(Left(InputText, PrefixLength), Prefix, 1) = 0 Then
RemovePrefix = Mid(RemovePrefix, PrefixLength + 1)
Exit For ' stop when a prefix has been removed
End If
End If
Next
End Function
[/code]
[img]http://home.scarlet.be/ruben.castelein/MM/LibraryButtons.gif[/img]
The panel with the buttons has a title bar that isn't shown.
With borderless buttons (fits better on some skins, like this one):
[img]http://home.scarlet.be/ruben.castelein/MM/LibraryBorderlessButtons.gif[/img]
Showing/hiding the panel can be done through the "View" menu.
Borderless buttons are now possible too (yes fellow coders... how did I do that :lol: ). You can choose for borderless if you set BorderlessButton to True.
BTW: Code cleanup is on the todo list.
Cheers
Steegy