home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / Code_Libra1935849272005.psc / CL.Dsr < prev    next >
Text File  |  2005-09-27  |  9KB  |  276 lines

  1. VERSION 5.00
  2. Begin {AC0714F6-3D04-11D1-AE7D-00A0C90F26F4} Connect 
  3.    ClientHeight    =   9948
  4.    ClientLeft      =   1740
  5.    ClientTop       =   1548
  6.    ClientWidth     =   6588
  7.    _ExtentX        =   11621
  8.    _ExtentY        =   17547
  9.    _Version        =   393216
  10.    Description     =   "Code library access for cut and paste"
  11.    DisplayName     =   "Code Library"
  12.    AppName         =   "Visual Basic"
  13.    AppVer          =   "Visual Basic 98 (ver 6.0)"
  14.    LoadName        =   "Command Line / Startup"
  15.    LoadBehavior    =   5
  16.    RegLocation     =   "HKEY_CURRENT_USER\Software\Microsoft\Visual Basic\6.0"
  17.    CmdLineSafe     =   -1  'True
  18.    CmdLineSupport  =   -1  'True
  19. End
  20. Attribute VB_Name = "Connect"
  21. Attribute VB_GlobalNameSpace = False
  22. Attribute VB_Creatable = True
  23. Attribute VB_PredeclaredId = False
  24. Attribute VB_Exposed = True
  25. Option Explicit
  26. Public VBI As VBIDE.VBE
  27. Public db As DAO.Database
  28. Public rst As DAO.Recordset
  29. Dim mcbComboCtrl As Office.CommandBarControl
  30. Dim mcbPasteToImmCtrl As Office.CommandBarControl
  31. Dim mcbAddNewCtrl As Office.CommandBarControl
  32. Dim mcbDeleteCodeCtrl As Office.CommandBarControl
  33. Public WithEvents PasteImmMenuHandler As CommandBarEvents    'Command Bar Event Handler
  34. Attribute PasteImmMenuHandler.VB_VarHelpID = -1
  35. Public WithEvents AddNewMenuHandler As CommandBarEvents      'Command Bar Event Handler
  36. Attribute AddNewMenuHandler.VB_VarHelpID = -1
  37. Public WithEvents DeleteCodeMenuHandler As CommandBarEvents
  38. Attribute DeleteCodeMenuHandler.VB_VarHelpID = -1
  39.  
  40. 'Change this to suit your needs
  41. Const TOOLBOX As String = "C:\Program Files\Microsoft Visual Studio\Common\Tools\CodeLibrary\CodeSamples.mdb" 'Location Of Your Code Library Database
  42.  
  43. 'Use of Windows native Message box circumvents the VB MsgBox 1024 character limit for long code snippets
  44. Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
  45.  
  46. Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
  47.  
  48. On Error GoTo Err_Handler
  49. Set db = DAO.OpenDatabase(TOOLBOX)
  50. Set VBI = Application
  51.  
  52. 'If you want to add a separate toolbar instead of adding controls to the standard toolbar
  53. 'replace the code between the '** lines with the lines commented out below
  54.  
  55. 'Dim cbMenu As CommandBar
  56. 'Set cbMenu = VBI.CommandBars.Add("CodeLibrary")
  57. 'Set mcbComboCtrl = cbMenu.Controls.Add(msoControlDropdown)
  58. 'mcbComboCtrl.Tag = "CS"
  59. 'RefreshData
  60. ''Customize The Tooltip Captions Below If You Want
  61. 'Set mcbPasteToImmCtrl = AddToAddInCommandBar("CodeLibrary", "View/Paste code from database", 488, "IMM")
  62. 'Set mcbAddNewCtrl = AddToAddInCommandBar("CodeLibrary", "Add Current Procedure to Database", 643, "NEW")
  63. 'Set mcbDeleteCodeCtrl = AddToAddInCommandBar("CodeLibrary", "Delete item from database", 644, "DEL")
  64.  
  65. '**
  66. Set mcbComboCtrl = VBI.CommandBars("Standard").Controls.Add(msoControlDropdown)
  67. mcbComboCtrl.Tag = "CS"
  68. mcbComboCtrl.BeginGroup = True
  69. RefreshData
  70. 'Customize The Tooltip Captions Below If You Want
  71. Set mcbPasteToImmCtrl = AddToAddInCommandBar("Standard", "View/Paste code from database", 488, "IMM")
  72. Set mcbAddNewCtrl = AddToAddInCommandBar("Standard", "Add Current Procedure to Database", 643, "NEW")
  73. Set mcbDeleteCodeCtrl = AddToAddInCommandBar("Standard", "Delete item from database", 644, "DEL")
  74. '**
  75.  
  76. Set Me.PasteImmMenuHandler = VBI.Events.CommandBarEvents(mcbPasteToImmCtrl)
  77. Set Me.AddNewMenuHandler = VBI.Events.CommandBarEvents(mcbAddNewCtrl)
  78. Set Me.DeleteCodeMenuHandler = VBI.Events.CommandBarEvents(mcbDeleteCodeCtrl)
  79.  
  80. Exit Sub
  81. Err_Handler:
  82. SendError Err.Description, "AddinInstance_OnConnection"
  83.  
  84. End Sub
  85.  
  86. Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
  87. Dim cmbrItem As CommandBarControl
  88.  
  89. On Error GoTo Err_Handler
  90.  
  91. 'If you have added a separate toolbar instead of adding the controls to the standard toolbar
  92. 'replace the code between the '** lines with the lines commented out below
  93.  
  94. 'VBI.CommandBars("CodeLibrary").Delete
  95.  
  96. '**
  97. For Each cmbrItem In VBI.CommandBars("Standard").Controls
  98.   If LenB(cmbrItem.Tag) > 0 Then
  99.     If InStr(1, "*CS*IMM*NEW*DEL*", cmbrItem.Tag) Then
  100.       cmbrItem.Delete
  101.     End If
  102.   End If
  103. Next
  104. '**
  105.  
  106. Set db = Nothing
  107.  
  108. Exit Sub
  109. Err_Handler:
  110. SendError Err.Description, "AddinInstance_OnDisconnection"
  111.  
  112. End Sub
  113.  
  114. Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
  115.  
  116. On Error GoTo Err_Handler
  117.  
  118. Exit Sub
  119. Err_Handler:
  120. SendError Err.Description, "IDTExtensibility_OnStartupComplete"
  121.  
  122. End Sub
  123.  
  124. Function AddToAddInCommandBar(strBar As String, sCaption As String, lngID As Long, strTag As String) As Office.CommandBarControl
  125. Dim cbMenuCommandBar As Office.CommandBarControl  'Command Bar Object
  126. Dim cbMenu As Object
  127.  
  128. On Error GoTo Err_Handler
  129. Set cbMenu = VBI.CommandBars(strBar)
  130. Set cbMenuCommandBar = cbMenu.Controls.Add(1)
  131. cbMenuCommandBar.Caption = sCaption
  132. cbMenuCommandBar.FaceId = lngID
  133. cbMenuCommandBar.Tag = strTag
  134. Set AddToAddInCommandBar = cbMenuCommandBar
  135.  
  136. Exit Function
  137. Err_Handler:
  138. SendError Err.Description, "AddToAddInCommandBar"
  139.  
  140. End Function
  141.  
  142. Private Sub AddNewMenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  143. Dim oCodePane As CodePane
  144. Dim oCodeMod As CodeModule
  145. Dim iCurrentLine As Long, b As Long, c As Long, d As Long, StartLine As Long
  146. Dim sProcName As String
  147. Dim eProcKind As vbext_ProcKind
  148. Dim strQuestion As String
  149. Dim strCopy As String
  150. Dim strTagName As String
  151.  
  152. On Error GoTo Err_Handler
  153. Set oCodePane = VBI.ActiveCodePane
  154. If oCodePane Is Nothing Then
  155.   MsgBox "Error - no active code pane!", "Error!"
  156.   Exit Sub
  157. End If
  158. Set oCodeMod = oCodePane.CodeModule
  159. 'Returns The Current Line That Cursor Is On
  160. oCodePane.GetSelection iCurrentLine, b, c, d
  161. 'Returns The Procedure Name And The Prockind (procedure, Property Get, Etc)
  162. sProcName = oCodeMod.ProcOfLine(iCurrentLine, eProcKind)
  163. If LenB(sProcName) = 0 Then
  164.   MsgBox "Error - no active procedure!", "Error!"
  165. Else
  166.   strQuestion = "Enter search tag for procedure " & sProcName
  167.   StartLine = oCodeMod.ProcStartLine(sProcName, eProcKind)
  168.   strCopy = oCodeMod.Lines(StartLine, oCodeMod.ProcCountLines(sProcName, eProcKind))
  169.   strTagName = InputBox(strQuestion, "Tag Name", sProcName)
  170.   If Len(strTagName) Then
  171.     Set rst = db.OpenRecordset("tblCode", dbOpenDynaset)
  172.     With rst
  173.       .AddNew
  174.       'Tag Name Is The Text That Will Appear In The Combo Box Dropdown On The Toolbar
  175.       'procedure name is offered as a default tag name
  176.       ![ProcName] = strTagName
  177.       ![Code] = strCopy
  178.       .Update
  179.       .Close
  180.     End With
  181.     RefreshData
  182.     Set rst = Nothing
  183.   End If
  184. End If
  185.  
  186. Exit Sub
  187. Err_Handler:
  188. SendError Err.Description, "AddNewMenuHandler_Click"
  189.  
  190. End Sub
  191.  
  192. Private Sub PasteImmMenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  193. Dim strSearch As String
  194. Dim wdwActive As Window
  195. Dim oCodePane As CodePane
  196. Dim oCodeMod As CodeModule
  197. Dim strGetCode As String
  198.  
  199. On Error GoTo Err_Handler
  200. Set oCodePane = VBI.ActiveCodePane
  201. If oCodePane Is Nothing Then
  202.   MsgBox "Error - no active code pane!", "Error!"
  203.   Exit Sub
  204. End If
  205. Set oCodeMod = oCodePane.CodeModule
  206. strSearch = mcbComboCtrl.Text
  207. Set rst = db.OpenRecordset("tblCode", dbOpenDynaset)
  208. With rst
  209.   .FindFirst "[ProcName]='" & strSearch & "'"
  210.   If Not .NoMatch Then
  211.     strGetCode = ![Code]
  212.   Else
  213.     MsgBox "Error - procedure not found!", "Error!"
  214.     Exit Sub
  215.   End If
  216. End With
  217. Set rst = Nothing
  218. If vbYes = MessageBox(0, strGetCode, strSearch & "  " & "[Yes]Paste [No]Close", vbYesNo) Then
  219.   Set wdwActive = VBI.ActiveWindow
  220.   'Paste Code At Bottom Of Current Code Window
  221.   oCodeMod.InsertLines oCodeMod.CountOfLines + 1, strGetCode
  222.   wdwActive.SetFocus
  223.   'Put Cursor Below Newly Pasted Code
  224.   SendKeys "^({End})", True
  225. End If
  226. Exit Sub
  227. Err_Handler:
  228. SendError Err.Description, "PasteImmMenuHandler_Click"
  229.  
  230. End Sub
  231.  
  232. Private Sub DeleteCodeMenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  233. Dim strSearch As String
  234. Dim varRet As Variant
  235.  
  236. On Error GoTo Err_Handler
  237. strSearch = mcbComboCtrl.Text
  238. Set rst = db.OpenRecordset("tblCode", dbOpenDynaset)
  239. With rst
  240.   .FindFirst "[ProcName]='" & strSearch & "'"
  241.   .Delete
  242.   .Close
  243. End With
  244. Set rst = Nothing
  245. RefreshData
  246. Exit Sub
  247. Err_Handler:
  248. SendError Err.Description, "DeleteCodeMenuHandler_Click"
  249. End Sub
  250. Private Sub RefreshData()
  251. Dim lngLength As Long
  252.  
  253. On Error GoTo Err_Handler
  254. 'If You Change The Code Database Structure, Change The Sql Text And Field References Below
  255. mcbComboCtrl.Clear
  256. Set rst = db.OpenRecordset("SELECT tblCode.* FROM tblCode ORDER BY tblCode.ProcName", dbOpenDynaset)
  257. With rst
  258.   Do While Not .EOF
  259.     mcbComboCtrl.AddItem ![ProcName]
  260.     'Ensures width of combo box is long enough to accomodate longest tag name
  261.     If Len(![ProcName]) > lngLength Then
  262.       lngLength = Len(![ProcName])
  263.     End If
  264.     .MoveNext
  265.   Loop
  266.   mcbComboCtrl.ListIndex = 1
  267.   mcbComboCtrl.Width = 8 * lngLength
  268. End With
  269. rst.Close
  270. Set rst = Nothing
  271. Exit Sub
  272. Err_Handler:
  273. SendError Err.Description, "RefreshData"
  274.  
  275. End Sub
  276.