home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 December / INTERNET97.ISO / pc / software / windows / building / xmlspy / setup44.exe / Data1.cab / F1944_XMLSpyPlugIn.cls < prev    next >
Encoding:
Visual Basic class definition  |  2001-07-19  |  4.1 KB  |  117 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "CXMLSpyPlugIn"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. ' VisualBasic generates a ProgID for the component in the following manner:
  15. ' ProjectName.ClassName --> XMLSpyPlugIn.CXMLSpyPlugIn
  16.  
  17. ' Each plugin must implement this class...
  18. Implements IXMLSpyPlugIn
  19.  
  20. Public Function IXMLSpyPlugIn_OnEvent(ByVal nEventID As Long, arrayParameters() As Variant, ByVal pXMLSpy As Object) As Variant
  21.     'if you set the return value no other PlugIn and no event handler from the
  22.     'scripting environment will get this event
  23.     'IXMLSpyPlugIn_OnEvent = True
  24. End Function
  25.  
  26. Public Function IXMLSpyPlugIn_GetUIModifications() As String
  27.     ' GetUIModifications() gets the XML file with the specified modifications of
  28.     ' the UI from the config.xml file in the plug-in folder
  29.     Dim strPath As String
  30.     strPath = App.Path
  31.     
  32.     If Len(strPath) > 0 Then
  33.         Dim fso As New FileSystemObject
  34.         Dim file As file
  35.         
  36.         Set file = fso.GetFile(strPath & "\config.xml")
  37.         
  38.         If (Not (file Is Nothing)) Then
  39.             Dim stream As TextStream
  40.             Set stream = file.OpenAsTextStream(ForReading)
  41.             
  42.             ' this replaces the token "**path**" from the XML file with
  43.             ' the actual installation path of the plug-in to get the image file
  44.             Dim strMods As String
  45.             strMods = stream.ReadAll
  46.             strMods = Replace(strMods, "**path**", strPath)
  47.             
  48.             IXMLSpyPlugIn_GetUIModifications = strMods
  49.         Else
  50.             IXMLSpyPlugIn_GetUIModifications = ""
  51.         End If
  52.     End If
  53. End Function
  54.  
  55. Public Sub IXMLSpyPlugIn_OnCommand(ByVal nID As Long, ByVal pXMLSpy As Object)
  56.     If (Not (pXMLSpy Is Nothing)) Then
  57.         Dim objDlg
  58.         Dim objDoc As XMLSpyLib.Document
  59.         Dim objSpy As XMLSpyLib.Application
  60.         Set objSpy = pXMLSpy
  61.         
  62.         If nID = 3 Or nID = 5 Then
  63.             Set objDlg = CreateObject("MSComDlg.CommonDialog")
  64.             objDlg.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*||"
  65.             objDlg.FilterIndex = 1
  66.             objDlg.ShowOpen
  67.             
  68.             If Len(objDlg.FileName) > 0 Then
  69.                 Set objDoc = objSpy.Documents.OpenFile(objDlg.FileName, False)
  70.                 Set objDoc = Nothing
  71.             End If
  72.         End If
  73.         
  74.         If nID = 4 Or nID = 6 Then
  75.             Set objDlg = CreateObject("MSComDlg.CommonDialog")
  76.             objDlg.Filter = "All Files (*.*)|*.*||"
  77.             objDlg.ShowSave
  78.             
  79.             If Len(objDlg.FileName) > 0 Then
  80.                 Set objDoc = objSpy.ActiveDocument
  81.                 
  82.                 If Not (objDoc Is Nothing) Then
  83.                     objDoc.SetPathName objDlg.FileName
  84.                     objDoc.Save
  85.                     Set objDoc = Nothing
  86.                 End If
  87.             End If
  88.         End If
  89.         
  90.         Set objSpy = Nothing
  91.     End If
  92. End Sub
  93.  
  94. Public Function IXMLSpyPlugIn_OnUpdateCommand(ByVal nID As Long, ByVal pXMLSpy As Object) As SPYUpdateAction
  95.     IXMLSpyPlugIn_OnUpdateCommand = spyDisable
  96.  
  97.     If (Not (pXMLSpy Is Nothing)) Then
  98.         Dim objSpy As XMLSpyLib.Application
  99.         Set objSpy = pXMLSpy
  100.         
  101.         If nID = 3 Or nID = 5 Then
  102.             IXMLSpyPlugIn_OnUpdateCommand = spyEnable
  103.         End If
  104.         If nID = 4 Or nID = 6 Then
  105.             If objSpy.Documents.Count > 0 Then
  106.                 IXMLSpyPlugIn_OnUpdateCommand = spyEnable
  107.             Else
  108.                 IXMLSpyPlugIn_OnUpdateCommand = spyDisable
  109.             End If
  110.         End If
  111.     End If
  112. End Function
  113.  
  114. Public Function IXMLSpyPlugIn_GetDescription() As String
  115.     IXMLSpyPlugIn_GetDescription = "Sample Plug-in for XMLSpy;This Plug-in demonstrates the implementation of a simple VisualBasic DLL as a Plug-in for XMLSpy."
  116. End Function
  117.