Description:
The FavouriteNodes script adds a submenu to the standard toolbar with favourite nodes (with custom names and shortcut keys) you can specify.
To add a tree node to the favourite nodes list, right click the node and choose "Add to favourite nodes".
The script needs MediaMonkey version 2.5.2 or above.
Installing automaticly:
Installer for version 1.2 (latest, updated 31.03.2006): http://home.scarlet.be/ruben.castelein/ ... des1.2.exe
Just run the exe and follow the instructions.
Installing manually:
For people that have an older version of the script:
In this new version, the script is standalone. That means that you don't need the StoreStartupAndFavouriteNodes anymore.
Because you can now add shortcut keys, the storage format for the favourites has been changed. This means you will have to (remove and readd your favourites, or) change the FavouriteNodes saved favourites specification in the MediaMonkey.ini settings file. See at the end of the post for more info.
This newer version uses new built in functionality in MediaMonkey, so it will work faster.
The script consists of 1 standalone script file ("FavouriteNodes.vbs")
FavouriteNodes.vbs (for the Scripts\Auto folder)
Code: Select all
'==========================================================================
'
' MediaMonkey Script
'
' NAME: FavouriteNodes v1.1
' DESCRIPTION:
' Adds a submenu to the standard toolbar with favourite nodes you can specify.
'
' AUTHOR: Steegy aka RC (Ruben Castelein)
' DATE : 20.01.2006
' UPDATE: 31.03.2006
'
' INSTALL:
' - Copy script to MediaMonkey's "Scripts\Auto" folder
'
' The script needs MediaMonkey version 2.5.2 or above.
'
' The script's settings in the "Variable Configuration" section can be modified
'
'==========================================================================
'>> ForumURL: http://www.mediamonkey.com/forum/viewtopic.php?t=7656
'>> ScriptName: FavouriteNodes
'>> VersionNumber: 1.1
'>> Author: Steegy aka RC (Ruben Castelein)
'>>>>EndOfProperties
'##############################################################################################
'%%%%%%%%%%%%%%%%%%%%%
' Script declarations:
'%%%%%%%%%%%%%%%%%%%%%
Option Explicit
Dim splitString
splitString = "§$§$§"
Dim FavouriteNodes
Set FavouriteNodes = CreateObject("Scripting.Dictionary")
Dim MessageHeader
MessageHeader = "FavouriteNodes:" & vbNewline & vbNewline
'Imports
'Script.Include(SDB.ApplicationPath & "Scripts\Utility_General.vbs")
'##############################################################################################
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Variable Configuration: (HERE YOU CAN MAKE SOME CHANGES IF YOU WANT)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
Dim Error_BrowseToNode
Error_BrowseToNode = "An error occured while auto-opening the specified node. "_
& "Possibly, the node specification is incorrect."_
& vbNewline & "The node has been opened as far as possible."
Dim isStartupNodeExpanded ' Expand (True) or don't expand (False) the favourite node
isStartupNodeExpanded = True
'##############################################################################################
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' The subroutines and functions that make this text file a "program":
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub OnStartup
InitialiseFavouriteNodes
Dim i
Dim FavouriteNodesKeys
FavouriteNodesKeys = FavouriteNodes.Keys
' Adds toolbar button (home icon) MyFavNodesTBB submenu to the standard toolbar
SDB.UI.AddMenuItemSep SDB.UI.Menu_TbStandard,0,0
Dim MyFavNodesTBB
Set MyFavNodesTBB = SDB.UI.AddMenuItemSub(SDB.UI.Menu_TbStandard,0,0)
MyFavNodesTBB.Caption = SDB.Localize("Favourite nodes")
MyFavNodesTBB.IconIndex = 61
Dim miFavouriteNode
For i = 0 To FavouriteNodes.Count - 1
Set miFavouriteNode = SDB.UI.AddMenuItem(MyFavNodesTBB,0,0)
With miFavouriteNode
.Caption = FavouriteNodesKeys(i)
.Hint = ArrayToPathString(FavouriteNodes(FavouriteNodesKeys(i)))
.OnClickFunc = "BrowseIt"
.UseScript = Script.ScriptPath
.ShortCut = FavouriteNodes(FavouriteNodesKeys(i))(UBound(FavouriteNodes(FavouriteNodesKeys(i))))
End With
Set SDB.Objects("FavouriteNodes_" & FavouriteNodesKeys(i)) = miFavouriteNode
Next
Set SDB.Objects("MyFavNodesTBB") = MyFavNodesTBB
' Adds item miAddToFavouriteNodes to the tree node popup menu
SDB.UI.AddMenuItemSep SDB.UI.Menu_Pop_Tree,0,0
Dim miAddToFavouriteNodes
Set miAddToFavouriteNodes = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,0)
With miAddToFavouriteNodes
.Caption = "Add to favourite nodes"
.OnClickFunc = "addToFavouriteNodes"
.UseScript = Script.ScriptPath
.IconIndex = 61
End With
' Adds the mRemoveFavouriteNodes submenu
SDB.UI.AddMenuItemSep SDB.UI.Menu_Edit,0,0
Dim mRemoveFavouriteNodes
Set mRemoveFavouriteNodes = SDB.UI.addMenuItemSub(SDB.UI.Menu_Edit,0,0)
With mRemoveFavouriteNodes
.Caption = "Remove nodes from favourites"
.Hint = "Remove a node from the favourite nodes list"
.IconIndex = 61
.useScript = Script.ScriptPath
End With
Set SDB.Objects("FavouriteNodesRemoveMenu") = mRemoveFavouriteNodes
If Not FavouriteNodes Is Nothing Then
Dim miFavouriteNodeRemove
For i = 0 To FavouriteNodes.Count - 1
Set miFavouriteNodeRemove = SDB.UI.AddMenuItem(mRemoveFavouriteNodes,0,0)
With miFavouriteNodeRemove
.Caption = FavouriteNodesKeys(i)
.Hint = ArrayToPathString(FavouriteNodes(FavouriteNodesKeys(i)))
.IconIndex = 8
.OnClickFunc = "deleteNodeFromFavourites"
.UseScript = Script.ScriptPath
End With
Next
End If
End Sub
Function InitialiseFavouriteNodes
InitialiseFavouriteNodes = False
Set SDB.Objects("FavouriteNodes") = FavouriteNodes
Dim FavouriteNodesCountINI
FavouriteNodesCountINI = SDB.IniFile.StringValue("FavouriteNodes", "Count")
If FavouriteNodesCountINI = "" Then Exit Function
Dim i, PathToNode, PathToNodeArray
For i = 1 To FavouriteNodesCountINI
PathToNode = SDB.IniFile.StringValue("FavouriteNodes", "Fav" & i)
PathToNodeArray = Split(PathToNode, splitString)
FavouriteNodes.Add PathToNodeArray(0), PathToNodeArray
Next
InitialiseFavouriteNodes = True
End Function
Sub BrowseIt(arg)
Dim FavouriteNodes
Set FavouriteNodes = SDB.Objects("FavouriteNodes")
Dim Result
Result = BrowseToNode(FavouriteNodes.Item(arg.Caption))
If Result = False Then
SDB.MessageBox MessageHeader & Error_BrowseToNode , mtError, Array(mbOk)
End If
End Sub
Function BrowseToNode(FullPathToNode)
' Browses to the specified node and returns True on success.
On Error Resume Next
Dim Node2B
Set Node2B = SDB.MainTree.Node_NowPlaying
Dim i
For i = 1 To UBound(FullPathToNode) - 1
If i > 1 Then
Node2B.Expanded = True
Set Node2B = SDB.MainTree.FirstChildNode(Node2B)
End If
If Not Node2B.Caption = FullPathToNode(i) Then
Do
Set Node2B = SDB.MainTree.NextSiblingNode(Node2B)
If Err <> 0 Then Exit Function
Loop While Node2B.Caption <> FullPathToNode(i)
End If
Next
SDB.MainTree.CurrentNode = Node2B
Node2B.Expanded = isStartupNodeExpanded
BrowseToNode = True
End Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Remove a chosen favourite node
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
Sub deleteNodeFromFavourites(Item)
Dim FavouriteNodes
Set FavouriteNodes = SDB.Objects("FavouriteNodes")
' Remove from toolbar submenu
Dim NodeItemToBeDeleted
Set NodeItemToBeDeleted = SDB.Objects("FavouriteNodes_" & Item.Caption)
NodeItemToBeDeleted.Visible = False
Set SDB.Objects("FavouriteNodes_" & Item.Caption) = Nothing
' Remove from dictionary
FavouriteNodes.Remove(Item.Caption)
' Reorder Ini entries
ReorderFavouriteNodesIni
' Remove from menu submenu
Item.Visible = False
End Sub
Sub ReorderFavouriteNodesIni
Dim FavouriteNodes
Set FavouriteNodes = SDB.Objects("FavouriteNodes")
If FavouriteNodes Is Nothing Then Exit Sub
Dim FavouriteNodesKeys
FavouriteNodesKeys = FavouriteNodes.Keys
SDB.IniFile.StringValue("FavouriteNodes", "Count") = FavouriteNodes.Count
Dim i
For i = 0 To FavouriteNodes.Count - 1
SDB.IniFile.StringValue("FavouriteNodes", "Fav" & (i + 1)) = ArrayToSplittedString(FavouriteNodes(FavouriteNodesKeys(i)))
Next
SDB.IniFile.DeleteKey "FavouriteNodes", "Fav" & (FavouriteNodes.Count + 1)
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' addToFavouriteNodes
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
Sub addToFavouriteNodes(arg)
Dim FavouriteName
FavouriteName = InputBoxFavourite()
If FavouriteName = "" Then
Exit Sub
End If
Dim FavouriteNameArray
FavouriteNameArray = Split(FavouriteName, splitString)
Dim FavouriteNodes
Set FavouriteNodes = SDB.Objects("FavouriteNodes")
If FavouriteNodes.Exists(FavouriteNameArray(0)) Then
SDB.MessageBox "A favourite node under this name already exists." , mtError, Array(mbOk)
Exit Sub
End If
Dim PathToNode
PathToNode = GetPathToNode(SDB.MainTree.CurrentNode)
Dim NewFavouriteNodesCount
NewFavouriteNodesCount = SDB.IniFile.StringValue("FavouriteNodes", "Count")
If NewFavouriteNodesCount = "" Then
NewFavouriteNodesCount = 1
Else
NewFavouriteNodesCount = NewFavouriteNodesCount + 1
End If
SDB.IniFile.StringValue("FavouriteNodes", "Count") = NewFavouriteNodesCount
Dim ShortcutKey
If UBound(FavouriteNameArray) = 1 Then
ShortcutKey = FavouriteNameArray(1)
Else
ShortcutKey = ""
End If
SDB.IniFile.StringValue("FavouriteNodes", "Fav" & NewFavouriteNodesCount) = FavouriteNameArray(0) & splitString & PathToNode & splitString & ShortcutKey
Dim PathToNodeArray
PathToNodeArray = Split(FavouriteNameArray(0) & splitString & PathToNode & splitString & ShortcutKey, splitString)
Dim MyFavNodesTBB
Set MyFavNodesTBB = SDB.Objects("MyFavNodesTBB")
Dim MyMoreArtist
Set MyMoreArtist = SDB.UI.AddMenuItem(MyFavNodesTBB,0,0)
MyMoreArtist.Caption = FavouriteNameArray(0)
MyMoreArtist.Hint = ArrayToPathString(PathToNodeArray)
MyMoreArtist.OnClickFunc = "BrowseIt"
MyMoreArtist.UseScript = Script.ScriptPath
MyMoreArtist.ShortCut = ShortcutKey
Set SDB.Objects("FavouriteNodes_" & FavouriteNameArray(0)) = MyMoreArtist
Dim FavouriteNodesRemoveMenu
Set FavouriteNodesRemoveMenu = SDB.Objects("FavouriteNodesRemoveMenu")
Dim AMyMoreArtist
Set AMyMoreArtist = SDB.UI.AddMenuItem(FavouriteNodesRemoveMenu,0,0)
AMyMoreArtist.Caption = FavouriteNameArray(0)
AMyMoreArtist.Hint = ArrayToPathString(PathToNodeArray)
AMyMoreArtist.OnClickFunc = "deleteNodeFromFavourites"
AMyMoreArtist.UseScript = Script.ScriptPath
AMyMoreArtist.IconIndex = 8
FavouriteNodes.Add FavouriteNameArray(0), PathToNodeArray
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Some utility functions
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
Function ArrayToPathString(NodePathArray)
ArrayToPathString = NodePathArray(1)
Dim i
For i = 2 to UBound(NodePathArray) - 1
ArrayToPathString = ArrayToPathString & " > " & NodePathArray(i)
Next
End Function
Function ArrayToSplittedString(NodePathArray)
ArrayToSplittedString = NodePathArray(0)
Dim i
For i = 1 to UBound(NodePathArray)
ArrayToSplittedString = ArrayToSplittedString & splitString & NodePathArray(i)
Next
End Function
Function InputBoxFavourite()
Dim Form, Label, Edt, Label2, Edt2, btnOk, btnCancel, modalResult
' Create the window to be shown
Set Form = SDB.UI.NewForm
Form.Common.SetRect 100, 100, 360, 160
Form.BorderStyle = 2 ' Resizable
Form.FormPosition = 4 ' Screen Center
'Form.SavePositionName = "FavouriteNodes_InputBox"
Form.Caption = "Add node to favourites"
' Create a button that closes the window
Set Label = SDB.UI.NewLabel(Form)
Label.Caption = "Enter a name for the favourite node:"
Label.Common.Left = 5
Label.Common.Top = 10
Set Edt = SDB.UI.NewEdit(Form)
Edt.Common.Left = Label.Common.Left
Edt.Common.Top = Label.Common.Top + Label.Common.Height + 5
Edt.Common.Width = Form.Common.Width - 20
Edt.Common.ControlName = "Edit1"
Edt.Common.Anchors = 1+2+4 'Left+Top+Right
Edt.Text = SDB.MainTree.CurrentNode.Caption
Set Label2 = SDB.UI.NewLabel(Form)
Label2.Caption = "Enter shortcut key:"
Label2.Common.Left = Edt.Common.Left
Label2.Common.Top = Edt.Common.Top + Edt.Common.Height + 15
Set Edt2 = SDB.UI.NewEdit(Form)
Edt2.Common.Left = Label2.Common.Left + Label2.Common.Width + 5
Edt2.Common.Top = Label2.Common.Top - 3
Edt2.Common.Width = 100
Edt2.Common.ControlName = "Edit2"
Edt2.Common.Anchors = 1+2+4 'Left+Top+Right
Edt2.Text = ""
' Create a button that closes the window
Set BtnOk = SDB.UI.NewButton(Form)
BtnOk.Caption = "&OK"
BtnOk.Common.Top = Edt2.Common.Top + Edt2.Common.Height + 10
BtnOk.Common.Hint = "OK"
BtnOk.Common.Anchors = 4 ' Right
BtnOk.UseScript = Script.ScriptPath
BtnOk.Default = True
BtnOk.ModalResult = 1
Set BtnCancel = SDB.UI.NewButton(Form)
BtnCancel.Caption = "&Cancel"
BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width - 15
BtnOK.Common.Left = BtnCancel.Common.Left - BtnOK.Common.Width - 10
BtnCancel.Common.Top = BtnOK.Common.Top
BtnCancel.Common.Hint = "Cancel"
BtnCancel.Common.Anchors = 4 ' Right
BtnCancel.UseScript = Script.ScriptPath
BtnCancel.Cancel = True
BtnCancel.ModalResult = 2
modalResult = Form.showModal
InputBoxFavourite = Cond(modalResult=1, Edt.Text & splitString & Edt2.Text, "")
End Function
' Emulates (Test)?Result1:Result2 "conditional if" behaviour as in Java(Script) and other languages
Function Cond(Test, ResultTrue, ResultFalse) ' Returns ResultTrue if Test evaluates to True, ResultFalse otherwise
If test Then
Cond = ResultTrue
Else
Cond = ResultFalse
End If
End Function
' Returns the index of the specified KeyName in the specified Dictionary
' Dictionary = Dictionary object
' KeyName = Key (String) of the specified Dictionary
Function GetIndexOfDictionaryKey(Dictionary, KeyName)
getIndexOfDictionaryKey = -1
Dim DictionaryKeys
DictionaryKeys = Dictionary.Keys
Dim i
For i = 0 To UBound(DictionaryKeys)
If DictionaryKeys(i) = KeyName Then
getIndexOfDictionaryKey = i
Exit Function
End If
Next
End Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Function to get the path to the wanted node
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
Function GetPathToNode(myNode)
On Error Resume Next
Dim myNode2
Dim ParentNode
Set ParentNode = myNode
GetPathToNode = myNode.Caption
Do While True
Set myNode2 = SDB.MainTree.ParentNode(ParentNode)
If myNode2 Is ParentNode Then
Exit Do
End If
Set ParentNode = myNode2
GetPathToNode = ParentNode.Caption & splitString & GetPathToNode
Loop
End Function
In-depth information:
The script uses configuration entries in MediaMonkey's ini file.
(normally under folder My Documents\My Music\MediaMonkey)
Example:
Code: Select all
[FavouriteNodes]
Count=5
Fav1=Files to Edit§$§$§Library§$§$§Files to Edit§$§$§Ctrl+Alt+1
Fav2=Icecast directory§$§$§Net Radio§$§$§Icecast directory§$§$§Ctrl+Alt+2
Fav3=Mediumsoort§$§$§Magic Nodes§$§$§Mediumsoort§$§$§Ctrl+Alt+3
Fav4=Trance§$§$§Library§$§$§Genre§$§$§Trance§$§$§Ctrl+Alt+4
Fav5=Some Nice Songs: Lamb§$§$§Library§$§$§Artist§$§$§Lamb§$§$§Ctrl+Alt+5
For people that want to use their old favourites on the new script version, just add "§$§$§Ctrl+Alt+5" or "§$§$§" at the end of the FavX lines. (without the quotes: the first sets shortcut keys Ctrl+Alt+5, the second doesn't uses shortcut keys).
Toolbar button and submenu, added to the standard toolbar.
Submenu in the Edit menu, to remove favourites from the list.
Shortcut keys that can be used: (from the scripting reference help)
for example Ctrl+Alt+2. Any standard character can be used, additional keys include: BkSp, Tab, Esc, Enter, Space, PgUp, PgDn, End, Home, Left, Up, Right, Down, Ins, Del and F1-F12. Any key could contain Ctrl+, Alt+ or Shift+ in front of it (and any combination of them).