|
#include "stdafx.h"
#include "resource.h"
#include "IESBDSAddin.h"
#include "EventHandler.h"
#include "DSAddin.h"
#include <string>
using namespace std;
HRESULT ApplicationEventHandler::BeforeBuildStart()
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT ApplicationEventHandler::BuildFinish(long nNumErrors, long nNumWarnings)
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT ApplicationEventHandler::BeforeApplicationShutDown()
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT ApplicationEventHandler::DocumentOpen(IDispatch* theDocument)
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT ApplicationEventHandler::BeforeDocumentClose(IDispatch* theDocument)
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT ApplicationEventHandler::DocumentSave(IDispatch* theDocument)
{
static const string function = "ApplicationEventHandler::DocumentSave";
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
// if(!getAddIn()->isEnabled() || !theDocument) {
// return S_OK;
// }
try {
CComQIPtr<ITextDocument> active(theDocument);
BSTR name;
cex_ = active->get_FullName(&name);
getAddIn()->documentChanged(string(bstr_t(name)));
return S_OK;
} catch(exception &e) {
DebugBox(function + e.what());
} catch(_com_error &e) {
DebugBox(function + asString(e));
} catch(...) {
DebugBox(function + " unknown error");
}
return E_FAIL;
}
HRESULT ApplicationEventHandler::NewDocument(IDispatch* theDocument)
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT ApplicationEventHandler::WindowActivate(IDispatch* theWindow)
{
static const string function = "ApplicationEventHandler::WindowActivate";
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
// if(!getAddIn()->isEnabled()) {
// return S_OK;
// }
try {
CComPtr<IDispatch> tmp;
CComQIPtr<ITextWindow> pWindow(theWindow);
cex_ = pWindow->get_Application(&tmp);
CComQIPtr<IApplication> pApplication(tmp);
tmp = 0;
cex_ = pApplication->get_ActiveDocument(&tmp);
CComQIPtr<ITextDocument> active(tmp);
BSTR name;
cex_ = active->get_FullName(&name);
getAddIn()->documentActivated(string(bstr_t(name)));
return S_OK;
} catch(exception &e) {
DebugBox(function + e.what());
} catch(_com_error &e) {
DebugBox(function + asString(e));
} catch(...) {
DebugBox(function + " unknown error");
}
return E_FAIL;
}
HRESULT ApplicationEventHandler::WindowDeactivate(IDispatch* theWindow)
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT ApplicationEventHandler::WorkspaceOpen()
{
static const string function = "ApplicationEventHandler::WorkspaceOpen";
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
// if(!getAddIn()->isEnabled()) {
// return S_OK;
// }
try {
CComPtr<IDispatch> tmp;
cex_ = getAddIn()->getApplication()->get_Projects(&tmp.p);
CComQIPtr<IProjects> projects(tmp);
long cnt;
cex_ = projects->get_Count(&cnt);
BSTR workspace;
getAddIn()->getApplication()->get_CurrentDirectory(&workspace);
string projectNames;
for(int i = 1; i <= cnt; i++) {
CComPtr<IGenericProject> project;
cex_ = projects->Item(CComVariant(i), &project.p);
CComBSTR name;
project->get_FullName(&name);
projectNames += bstr_t(name) + (i == cnt ? "" : ";");
}
//DebugBox(workspace + projects);
getAddIn()->workspaceLoaded(string(bstr_t(workspace)), projectNames);
return S_OK;
} catch(exception &e) {
DebugBox(function + e.what());
} catch(_com_error &e) {
DebugBox(function + asString(e));
} catch(...) {
DebugBox(function + " unknown error");
}
return E_FAIL;
}
HRESULT ApplicationEventHandler::WorkspaceClose()
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
HRESULT ApplicationEventHandler::NewWorkspace()
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
return S_OK;
}
// Debugger event
//HRESULT CCommands::XDebuggerEvents::BreakpointHit(IDispatch* pBreakpoint)
//{
// //AFX_MANAGE_STATE(AfxGetStaticModuleState());
// return S_OK;
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.