BUG
Using: MJViewItemAutomation to navigate the MC tree seems to produce unusual effects.
Sometimes the view schemes are populated with the values as if the view scheme was set to populate the tree - other times it doesn't populate.
This is using the standard tree/playlist settings from MC with the following code:
' our global MJ automation object (used to get other objects)
' this will get set when Media Jukebox/Center calls "Init" in the plugin
Public g_MC As MediaJukebox.MJAutomation
Public Function Init(ByVal MediaJukebox As Object)
' set the global Media Jukebox object on init
' (Media Jukebox will call this function when the plugin starts)
Set g_MC = MediaJukebox
End Function
' Gets the ID for the next node name
Public Function getNewNodeID(fullPath As String) As String
Static nodeID As Integer
' If beginning value not set then set it
If nodeID <= 0 Then nodeID = 0
' Increment the count
nodeID = nodeID + 1
getNewNodeID = "node" & nodeID
End Function
Private Sub Command1_Click()
On Error GoTo anError
TV.ImageList = imgListTV
' Declare the variables
Dim res1 As Boolean, res2 As Boolean
Dim nodX As Node, plNodeName As String, mlNodeName As String
Dim MCView As MediaJukebox.MJViewItemAutomation
' Get the node names for the root items
plNodeName = getNewNodeID("Media Library")
mlNodeName = getNewNodeID("Playlists")
' Add the root nodes
Set nodX = TV.Nodes.Add(, , mlNodeName, "Media Library")
Set nodX = TV.Nodes.Add(, , plNodeName, "Playlists")
' Add the child nodes for the Playlists
Set MCView = g_MC.GetViewItem("Playlists")
res1 = addChildNodes(MCView, plNodeName)
' Add the child nodes for the Media Library
Set MCView = g_MC.GetViewItem("Media Library")
res2 = addChildNodes(MCView, mlNodeName)
' Make sure all the nodes are visible
nodX.EnsureVisible
Exit Sub
anError:
MsgBox "ERROR: " & Err.Number & " : " & Err.Description
End Sub
' Adds all the child nodes
Public Function addChildNodes(MCView As MediaJukebox.MJViewItemAutomation, parentName As String) As Boolean
On Error GoTo addChildNodesError
' If no children to add then exit the function
If MCView.GetNumberChildren = 0 Then Exit Function
' Otherwise add all the children
For x = 0 To MCView.GetNumberChildren - 1
' Get the child item
Dim aChild As MediaJukebox.MJViewItemAutomation
Set aChild = MCView.GetChild(x)
' Get the new node name
Dim newNodeName As String
newNodeName = getNewNodeID(aChild.GetFullName)
' Add the child node
' Set nodX = TV.Nodes.Add(parentName, tvwChild, newNodeName, aChild.GetName)
' If the child has it's own children then add them
If aChild.GetNumberChildren > 0 Then
' Set the icon
Set nodX = TV.Nodes.Add(parentName, tvwChild, newNodeName, aChild.GetName, "folderOpen")
' Add the children
Dim reschild As Boolean
reschild = addChildNodes(aChild, newNodeName)
Else
' Set the icon
Set nodX = TV.Nodes.Add(parentName, tvwChild, newNodeName, aChild.GetName, "files")
End If
Next x
' Return true if it completes successfully
addChildNodes = True
Exit Function
' Deal with errors
addChildNodesError:
MsgBox "ERROR: " & Err.Number & " : " & Err.Description
addChildNodes = False
End Function
(Form contains one button and one treeview (called TV) and one imagelist called: imgListTV)
The resulting info in the TreeView follows no pattern and seems to be very random.