VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "connect"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' Copyright (C) 2008-2012 Jan Vorel
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.

' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.

' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

' If you have any questions, suggestions or bug reports about this product,
' contact me: info@ctuser.net; Do not contact me about general B.A.S.I.C.
' language or A.P.I. issues

Option Explicit
Option Base 0

Implements IDTExtensibility

'Public FormDisplayed As Boolean
'Public VBInstance As VBIDE.VBE
Public mcbMenuCommandBar As Office.CommandBarControl
Public WithEvents MenuHandler As CommandBarEvents
Attribute MenuHandler.VB_VarHelpID = -1
Private mWin As Window
Private mobjDoc As axdUserDoc
Const guidMyTool$ = "(4244B234-E45F-12dg-8O3f-23484)"

Public WithEvents PrjEvents As VBProjectsEvents
Attribute PrjEvents.VB_VarHelpID = -1
Public WithEvents FilEvents As FileControlEvents
Attribute FilEvents.VB_VarHelpID = -1
'Public WithEvents RefEvents As ReferencesEvents
Public WithEvents CmpEvents As VBComponentsEvents
Attribute CmpEvents.VB_VarHelpID = -1

Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
  Dim cbMenuCommandBar As Office.CommandBarControl
  Dim cbMenu As Object
  
  On Error GoTo AddToAddInCommandBarErr
  Set cbMenu = VBInstance.CommandBars("Add-Ins")
  If cbMenu Is Nothing Then
    Exit Function
    End If
  
  Set cbMenuCommandBar = cbMenu.Controls.Add(1)
  cbMenuCommandBar.Caption = sCaption
  Set AddToAddInCommandBar = cbMenuCommandBar
  Exit Function
  
AddToAddInCommandBarErr:
  End Function

Private Sub CmpEvents_ItemActivated(ByVal VBComponent As VBIDE.VBComponent)
  mobjDoc.AddLogChg "CmpEvents_ItemActivated"
  End Sub

Private Sub CmpEvents_ItemAdded(ByVal VBComponent As VBIDE.VBComponent)
  mobjDoc.AddLogChg "CmpEvents_ItemAdded"
  End Sub

Private Sub CmpEvents_ItemReloaded(ByVal VBComponent As VBIDE.VBComponent)
  mobjDoc.AddLogChg "CmpEvents_ItemReloaded"
  End Sub

Private Sub CmpEvents_ItemRemoved(ByVal VBComponent As VBIDE.VBComponent)
  mobjDoc.AddLogChg "CmpEvents_ItemRemoved"
  End Sub

Private Sub CmpEvents_ItemRenamed(ByVal VBComponent As VBIDE.VBComponent, ByVal OldName As String)
  mobjDoc.AddLogChg "CmpEvents_ItemRenamed"
  End Sub

Private Sub CmpEvents_ItemSelected(ByVal VBComponent As VBIDE.VBComponent)
  mobjDoc.AddLogChg "CmpEvents_ItemSelected"
  End Sub

Private Sub FilEvents_AfterAddFile(ByVal VBProject As VBIDE.VBProject, ByVal FileType As VBIDE.vbext_FileType, ByVal FileName As String)
  mobjDoc.AddLogChg "FilEvents_AfterAddFile"
  End Sub

Private Sub FilEvents_AfterChangeFileName(ByVal VBProject As VBIDE.VBProject, ByVal FileType As VBIDE.vbext_FileType, ByVal NewName As String, ByVal OldName As String)
  mobjDoc.AddLogChg "FilEvents_AfterChangeFileName"
  End Sub

Private Sub FilEvents_AfterRemoveFile(ByVal VBProject As VBIDE.VBProject, ByVal FileType As VBIDE.vbext_FileType, ByVal FileName As String)
  mobjDoc.AddLogChg "FilEvents_AfterRemoveFile"
  End Sub

Private Sub IDTExtensibility_OnAddInsUpdate(custom() As Variant)
  mobjDoc.AddLogChg "IDTExtensibility_OnAddInsUpdate"
  End Sub

Private Sub IDTExtensibility_OnConnection(ByVal VBInst As Object, ByVal ConnectMode As VBIDE.vbext_ConnectMode, ByVal AddInInst As VBIDE.AddIn, custom() As Variant)
  Set VBInstance = VBInst
  Set mWin = AddInInst.VBE.Windows.CreateToolWindow(AddInInst, "LibBuild.axdUserDoc", "LibBuild", guidMyTool, mobjDoc)
  'set mWin.LinkedWindows.Item(1).VBE
  'mobjDoc.
  'mWin.Visible = True
  Set mcbMenuCommandBar = AddToAddInCommandBar("LibBuild")
  Set Me.MenuHandler = VBInst.Events.CommandBarEvents(mcbMenuCommandBar)
  
  On Error Resume Next
  Set Me.PrjEvents = VBInst.Events.VBProjectsEvents
  Set Me.CmpEvents = VBInst.Events.VBComponentsEvents(Nothing)
  'Set Me.RefEvents = VBInst.Events.ReferencesEvents(Nothing)
  'Set Me.FilEvents = VBInst.Events.FileControlEvents(Nothing)
  'VBControlsEvents(Nothing, Nothing)
  End Sub

Private Sub IDTExtensibility_OnDisconnection(ByVal RemoveMode As VBIDE.vbext_DisconnectMode, custom() As Variant)
  Set Me.PrjEvents = Nothing
  Set Me.CmpEvents = Nothing
  mcbMenuCommandBar.Delete
  Set mcbMenuCommandBar = Nothing
  mWin.Close
  Set mWin = Nothing
  Set VBInstance = Nothing
  End Sub

Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
  '
  End Sub

Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  mWin.Visible = True
  End Sub

Private Sub PrjEvents_ItemActivated(ByVal VBProject As VBIDE.VBProject)
  mobjDoc.AddLogChg "PrjEvents_ItemActivated"
  End Sub

Private Sub PrjEvents_ItemAdded(ByVal VBProject As VBIDE.VBProject)
  mobjDoc.AddLogChg "PrjEvents_ItemAdded"
  End Sub

Private Sub PrjEvents_ItemRemoved(ByVal VBProject As VBIDE.VBProject)
  mobjDoc.AddLogChg "PrjEvents_ItemRemoved"
  End Sub

Private Sub PrjEvents_ItemRenamed(ByVal VBProject As VBIDE.VBProject, ByVal OldName As String)
  mobjDoc.AddLogChg "PrjEvents_ItemRenamed"
  End Sub

'Private Sub RefEvents_ItemAdded(ByVal Reference As VBIDE.Reference)
'  mobjDoc.AddLogChg "RefEvents_ItemAdded"
'  End Sub

'Private Sub RefEvents_ItemRemoved(ByVal Reference As VBIDE.Reference)
'  mobjDoc.AddLogChg "RefEvents_ItemRemoved"
'  End Sub

