Altova XMLSpy 2024 Professional Edition

Im Code unten sehen Sie eine einfache Implementierung eines XMLSpy IDE Plug-In. Damit wird ein Menübefehl und eine Trennlinie (verfügbar in XMLSpy) zum Menü "Extras" hinzugefügt. Der neue Befehl innerhalb der OnUpdateCommand() Methode ist nur aktiv, wenn das aktive Dokument über die Grid-Ansicht angezeigt wird. Der Befehl sucht nach dem XML-Element, das sich gerade im Fokus befindet, und öffnet jede URL, die mit "http://" beginnt am Textwert des Elements.

 

/////////////////////////////////////////////////////////////////////////////

// CXMLSpyIDEPlugIn

 

#import "XMLSpy.tlb"

using namespace XMLSpyLib;

 

HRESULT CXMLSpyIDEPlugIn::OnCommand(long nID, IDispatch* pXMLSpy)

{

  USES_CONVERSION;

 

  if(nID == 1)        {

     IApplicationPtr        ipSpyApp;

 

     if(pXMLSpy)        {

        if(SUCCEEDED(pXMLSpy->QueryInterface(__uuidof(IApplication),(void **)&ipSpyApp))) {

           IDocumentPtr  ipDocPtr = ipSpyApp->ActiveDocument;

 

          // we assume that grid view is active

           if(ipDocPtr) {

              IGridViewPtr          ipGridPtr = ipDocPtr->GridView;

 

              if(ipGridPtr)        {

                 IXMLDataPtr        ipXMLData = ipGridPtr->CurrentFocus;

 

                 CString        strValue = W2T(ipXMLData->TextValue);

 

                 if(!strValue.IsEmpty() && (strValue.Left(7) == _T("http://")))

                    ::ShellExecute(NULL,_T("open"),W2T(ipXMLData->TextValue),NULL,NULL,SW_SHOWNORMAL);

              }

           }

        }

     }

  }

 

  return S_OK;

}

 

 

HRESULT CXMLSpyIDEPlugIn::OnUpdateCommand(long nID, IDispatch* pXMLSpy, SPYUpdateAction* pAction)

{

  *pAction = spyDisable;

 

  if(nID == 1)        {

     IApplicationPtr        ipSpyApp;

 

     if(pXMLSpy)        {

        if(SUCCEEDED(pXMLSpy->QueryInterface(__uuidof(IApplication),(void **)&ipSpyApp)))        {

           IDocumentPtr        ipDocPtr = ipSpyApp->ActiveDocument;

 

          // only enable if grid view is active

           if((ipDocPtr != NULL) && (ipDocPtr->CurrentViewMode == spyViewGrid))

              *pAction = spyEnable;

        }

     }

  }

 

  return S_OK;

}

 

 

HRESULT CXMLSpyIDEPlugIn::OnEvent(long nEventID, SAFEARRAY **arrayParameters, IDispatch* pXMLSpy, VARIANT* pReturnValue)

{

  return S_OK;

}

 

HRESULT CXMLSpyIDEPlugIn::GetUIModifications(BSTR* pModificationsXML)

{

  CComBSTR        bstrMods = _T(" \

           <ConfigurationData>        \

              <Modifications>        ");

  // add "Open URL..." to Tools menu

  bstrMods.Append (_T(" \

                 <Modification> \

                    <Action>Add</Action> \

                    <UIElement type=\"MenuItem\"> \

                       <ID>1</ID> \

                       <Name>Open URL...</Name> \

                       <Place>0</Place> \

                       <MenuID>129</MenuID> \

                       <Parent>:Tools</Parent> \

                    </UIElement> \

                 </Modification>        "));

  // add Seperator to Tools menu

  bstrMods.Append (_T(" \

                 <Modification> \

                    <Action>Add</Action> \

                    <UIElement type=\"MenuItem\"> \

                       <ID>0</ID> \

                       <Place>1</Place> \

                       <MenuID>129</MenuID> \

                       <Parent>:Tools</Parent> \

                    </UIElement> \

                 </Modification>        "));

  // finish modification description

  bstrMods.Append (_T(" \

              </Modifications> \

           </ConfigurationData>"));

 

  return bstrMods.CopyTo(pModificationsXML);

}

 

 

HRESULT CXMLSpyIDEPlugIn::GetDescription(BSTR* pDescription)

{

  CComBSTR        bstrDescr = _T("ATL C++ XMLSpy IDE PlugIn;This PlugIn demonstrates the implementation of a simple ATL DLL as a IDE PlugIn for XMLSpy.");

  return bstrDescr.CopyTo(pDescription);

}

© 2017-2023 Altova GmbH