commands.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 1,435 行 · 第 1/4 页

CPP
1,435
字号
// Commands.cpp : Implementierungsdatei//#include "stdafx.h"#include <afxdlgs.h>#include <afxtempl.h>#include "QMsDev.h"#include "Commands.h"#include "newqtprojectdialog.h"#include "qmsdevtemplates.h"#include <direct.h>#include <process.h>#include <windows.h>#include <oleauto.h>#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifstatic bool dontOpen = FALSE;/////////////////////////////////////////////////////////////////////////////// CCommandsCCommands::CCommands(){    m_pApplication = NULL;    m_pApplicationEventsObj = NULL;    m_pDebuggerEventsObj = NULL;}CCommands::~CCommands(){    ASSERT (m_pApplication != NULL);    m_pApplication->Release();}void CCommands::SetApplicationObject(IApplication* pApplication){    // Diese Funktion geht davon aus, dass AddRef bereits auf pApplication angewendet wurde,    //  was CDSAddIn durch den Aufruf von QueryInterface direkt vor dem Aufruf dieser    //  Funktion bereits erledigt hat.    m_pApplication = pApplication;    // Ereignis-Handler f黵 Anwendung erzeugen    XApplicationEventsObj::CreateInstance(&m_pApplicationEventsObj);    m_pApplicationEventsObj->AddRef();    m_pApplicationEventsObj->Connect(m_pApplication);    m_pApplicationEventsObj->m_pCommands = this;    // Ereignis-Handler f黵 Debugger erzeugen    CComPtr<IDispatch> pDebugger;    if (SUCCEEDED(m_pApplication->get_Debugger(&pDebugger)) 	    && pDebugger != NULL)    {	XDebuggerEventsObj::CreateInstance(&m_pDebuggerEventsObj);	m_pDebuggerEventsObj->AddRef();	m_pDebuggerEventsObj->Connect(pDebugger);	m_pDebuggerEventsObj->m_pCommands = this;    }}void CCommands::UnadviseFromEvents(){    ASSERT (m_pApplicationEventsObj != NULL);    m_pApplicationEventsObj->Disconnect(m_pApplication);    m_pApplicationEventsObj->Release();    m_pApplicationEventsObj = NULL;    if (m_pDebuggerEventsObj != NULL)    {	// Da wir die Verbindung zu den Debugger-Ereignissen herstellen konnten, 	//  sollte es auch m鰃lich sein, erneut auf das Debugger-Objekt zuzugreifen, 	//  um die Verbindung zu seinen Ereignissen zu trennen (daher das VERIFY_OK weiter unten -- siehe stdafx.h).	CComPtr<IDispatch> pDebugger;	VERIFY_OK(m_pApplication->get_Debugger(&pDebugger));	ASSERT (pDebugger != NULL);	m_pDebuggerEventsObj->Disconnect(pDebugger);	m_pDebuggerEventsObj->Release();	m_pDebuggerEventsObj = NULL;    }}/////////////////////////////////////////////////////////////////////////////// Ereignis-Handler// ZU ERLEDIGEN: F黮len Sie die Implementierung f黵 die Ereignisse aus, die Sie behandeln wollen//  Verwenden Sie m_pCommands->GetApplicationObject(), um auf das Objekt//  "Developer Studio Application" zuzugreifen//Application-EreignisseHRESULT CCommands::XApplicationEvents::BeforeBuildStart(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::BuildFinish(long nNumErrors, long nNumWarnings){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::BeforeApplicationShutDown(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::DocumentOpen(IDispatch* theDocument){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    dontOpen = TRUE;    if ( !theDocument )	return S_OK;    CComQIPtr<ITextDocument, &IID_ITextDocument> pText(theDocument);    if ( pText ) {	CString file;	CString filepath;	CString filename;	CString fileext;	CComBSTR bszStr;	pText->get_FullName(&bszStr);	file = bszStr;    	m_pCommands->splitFileName( file, filepath, filename, fileext );	if ( fileext == "ui" ) {	    DsSaveStatus saved;	    pText->Close( CComVariant(dsSaveChangesNo), &saved );	    m_pCommands->runDesigner( filepath + file );	} else if ( fileext == "ts" ) {	    DsSaveStatus saved;	    pText->Close( CComVariant(dsSaveChangesNo), &saved );	    m_pCommands->runLinguist( filepath + file );	}    }    return S_OK;}HRESULT CCommands::XApplicationEvents::BeforeDocumentClose(IDispatch* theDocument){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    dontOpen = TRUE;    return S_OK;}HRESULT CCommands::XApplicationEvents::DocumentSave(IDispatch* theDocument){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::NewDocument(IDispatch* theDocument){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::WindowActivate(IDispatch* theWindow){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    // only run if it was intended    if ( dontOpen ) {	dontOpen = FALSE;	return S_OK;    }        CComQIPtr<IGenericWindow, &IID_IGenericWindow> pGenericWindow(theWindow);    if ( !pGenericWindow )	return S_OK;    BSTR type;    pGenericWindow->get_Type( &type );    if ( CString(type) != "Text" )	return S_OK;    CComPtr<IDispatch> pDocument;    pGenericWindow->get_Parent(&pDocument);    CComQIPtr<ITextDocument, &IID_ITextDocument> pTextDocument(pDocument);    if ( pTextDocument ) {	CString file;	CString filepath;	CString filename;	CString fileext;	CComBSTR bszStr;	pTextDocument->get_FullName(&bszStr);	file = bszStr;	m_pCommands->splitFileName( file, filepath, filename, fileext );	if ( fileext == "ui" )	    m_pCommands->runDesigner( filepath + file );	else if ( fileext == "ts" )	    m_pCommands->runLinguist( filepath + file );    }    return S_OK;}HRESULT CCommands::XApplicationEvents::WindowDeactivate(IDispatch* theWindow){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::WorkspaceOpen(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::WorkspaceClose(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}HRESULT CCommands::XApplicationEvents::NewWorkspace(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}// Debugger-EreignisHRESULT CCommands::XDebuggerEvents::BreakpointHit(IDispatch* pBreakpoint){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    return S_OK;}/////////////////////////////////////////////////////////////////////////////// Little helpersCString CCommands::getActiveFileName(){    CString file;    CComPtr<IDispatch> pActiveDocument;    m_pApplication->get_ActiveDocument(&pActiveDocument);    if (pActiveDocument) {	CComQIPtr<ITextDocument, &IID_ITextDocument> pText(pActiveDocument);	if ( pText ) {	    CComBSTR bszStr;	    pText->get_FullName(&bszStr);	    file = bszStr;	}    }    return file;}void CCommands::splitFileName( CString &file, CString &filepath, CString &filetitle, CString &fileext ){    // cut file into filepath and file    int pathpos = file.ReverseFind( '\\' );    if ( pathpos != -1 ) {	filepath = file.Left( pathpos +1 );	file = file.Mid(pathpos + 1);    }    // cut file into filetitle and fileext (without dot)    int extpos = file.ReverseFind( '.' );    if ( extpos != -1 ) {	filetitle = file.Left( extpos );	fileext = file.Mid( extpos + 1 );	    }}int CCommands::getActiveProject(CComQIPtr<IBuildProject, &IID_IBuildProject>& project ){    CComPtr<IDispatch> pDispProject;    m_pApplication->get_ActiveProject(&pDispProject);    project = CComQIPtr<IBuildProject, &IID_IBuildProject>(pDispProject);    if ( !project )	return S_FALSE;    return S_OK;}int CCommands::getConfigurations(CComQIPtr<IBuildProject, &IID_IBuildProject> project, CComQIPtr<IConfigurations, &IID_IConfigurations>& configs ){    project->get_Configurations( &configs );    if ( !configs ) {	m_pApplication->PrintToOutputWindow( CComBSTR("NO CONFIGURATIONS IN THIS PROJECT") );	return S_FALSE;    }    return S_OK;}bool getGlobalQtSettings( bool &shared ){    shared = FALSE;     bool thread = FALSE;    try {	CStdioFile file( CString(_T(getenv("QTDIR")) + CString("\\.qtwinconfig")), CFile::modeRead );	CString line;	BOOL eof;	do {	    eof = !file.ReadString( line );	    if ( eof )		break;	    if ( line.Find( "shared" ) != -1 ) {		shared = TRUE;	    }	    if ( line.Find( "thread" ) != -1 ) {		thread = TRUE;	    }	} while ( !eof );    }    catch ( CFileException* e ) {	char err[256];	e->GetErrorMessage( (char*)&err, 255, NULL );	::MessageBox( NULL, err, "Error", MB_OK );    }    return thread;}void CCommands::addSharedSettings( CComPtr<IConfiguration> pConfig, bool useThreads ){    const CComBSTR compiler("cl.exe");    const CComBSTR linker("link.exe");    LPCTSTR dllDefs;    dllDefs = "/D QT_DLL";    const CComBSTR dllDefine( dllDefs );    const CComBSTR incPath(" /I$(QTDIR)\\include");    CString version;    try {	CStdioFile file( CString(_T(getenv("QTDIR")) + CString("\\.qmake.cache")), CFile::modeRead );	CString line;	BOOL eof;	do {	    eof = !file.ReadString( line );	    if ( eof )		break;	    if ( line.Find( "QMAKE_QT_VERSION_OVERRIDE=" ) != -1 ) {		version = line.Right(3);		break;	    }	} while ( !eof );    }    catch ( CFileException* e ) {	char err[256];	e->GetErrorMessage( (char*)&err, 255, NULL );	::MessageBox( NULL, err, "Error", MB_OK );    }    CString sharedLibText;#if defined(QT_TRIAL)    if ( useThreads )	sharedLibText = CString("$(QTDIR)\\lib\\qt-mteval") + version + CString(".lib");    else	sharedLibText = CString("$(QTDIR)\\lib\\qteval") + version + CString(".lib");#else    if ( useThreads )	sharedLibText = CString("$(QTDIR)\\lib\\qt-mt") + version + CString(".lib");    else	sharedLibText = CString("$(QTDIR)\\lib\\qt") + version + CString(".lib");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?