Figure 3 Exec Procedure
Public Sub Exec(ByVal cmdName As String, _
ByVal executeOption As vsCommandExecOption, _
ByRef varIn As Object, ByRef varOut As Object, _
ByRef handled As Boolean) Implements IDTCommandTarget.Exec
handled = False
If (executeOption = _
vsCommandExecOption.vsCommandExecOptionDoDefault) _
Then
If cmdName = "ToolBoxLoader.Connect.ToolBoxLoader" Then
handled = True
Exit Sub
End If
End If
End Sub
Figure 6 GetFiles
If sName <> "" Then
Dim oCheckBox As New System.Windows.Forms.CheckBox()
If iFileNumber = 15 Or iFileNumber = 30 Or iFileNumber = 45 Then
x += 170
y = 120
End If
i = sName.IndexOf(".xml")
If i > 0 Then
sTabItemName = sName.Substring(0, i)
iFileNumber += 1
oCheckBox.Name = "CodeSnippet" & iFileNumber
oCheckBox.Text = sTabItemName
oCheckBox.Tag = sName
oCheckBox.Size = New Size(150, 24)
oCheckBox.ForeColor = Color.Red
iGeneralFlag = InStr(sName, "GeneralSeminar")
iDataFlag = InStr(sName, "DataCode")
If iGeneralFlag <> 0 Or iDataFlag <> 0 Then
oCheckBox.Checked = True
oCheckBox.Enabled = False
Else
oCheckBox.Checked = False
End If
oCheckBox.Location = New Point(x, y)
y += yIncrement
Controls.Add(oCheckBox)
End If
End If
Figure 7 LoadSnippetsForSelectedTabs
Sub LoadSnippetsForSelectedTabs()
Dim oControl As System.Windows.Forms.Control
Dim oCheckBox As System.Windows.Forms.CheckBox
Dim i As Integer
'Load new items
For Each oControl In Me.Controls
i = oControl.Name.IndexOf("CodeSnippet")
If i = 0 Then
oCheckBox = CType(oControl, System.Windows.Forms.CheckBox)
DeleteTab(CStr(oCheckBox.Text))
If oCheckBox.Checked Then
SetupSnippets(CStr(oCheckBox.Tag), CStr(oCheckBox.Tag))
End If
End If
Next
End Sub
Figure 8 SetupSnippets
Sub SetupSnippets(ByVal sFileName As String, _
ByVal sTabName As String)
Dim doc As New System.Xml.XmlDocument()
Dim node As System.Xml.XmlNode
Dim nodes As System.Xml.XmlNodeList
Dim tbox As ToolBox
Dim sTab As String
Dim tab As ToolBoxTab
Dim i, nochars As Short
Cursor.Current = Cursors.WaitCursor
Try
sFileName = sPath & "\" & sFileName
doc.Load(sFileName)
i = InStr(sTabName, ".xml")
If i > 0 Then
nochars = i - 1
sTabName = sTabName.Substring(0, nochars)
End If
nodes = doc.SelectNodes("//ToolBoxItem")
tbox = applicationObject.Windows.Item("ToolBox").Object
tab = tbox.ToolBoxTabs.Add(sTabName)
For Each node In nodes
tab.ToolBoxItems.Add(node.Attributes(0).Value, _
node.InnerText, _
vsToolBoxItemFormat.vsToolBoxItemFormatText)
Next
tab.Activate()
Catch
lblStatus.Text = "An error occurred in loading toolbox " _
& Err.Description
End Try
Cursor.Current = Cursors.Arrow
End Sub
Figure 9 DeleteTab
Sub DeleteTab(ByVal sTabName As String)
Dim tbox As ToolBox
Dim sTab As String
Dim i As Integer
tbox = applicationObject.Windows.Item("ToolBox").Object
For i = 1 To tbox.ToolBoxTabs.Count
Try
sTab = tbox.ToolBoxTabs.Item(i).Name
If sTab = sTabName Then
tbox.ToolBoxTabs.Item(i).Delete()
Exit For
End If
Catch
lblErrors.Text &= " ; " & sTabName & " - " _
& Err.Description
End Try
Next
End Sub
|