commands.cpp

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

CPP
1,435
字号
	    readme.Replace( "$QMSDEVQTFILELIST", classheader+"base.h\n"+classheader+"base.cpp\nmoc_"+						 classheader+"base.cpp\nmoc_"+classheader+".cpp\n" );	}	infoFile.WriteString( replaceTemplateStrings(readme, classheader, 						     classname, instancename, instancecall, projectName) );	infoFile.Close();	if ( dialog.m_dialog ) {	    CString uiFileName(dialog.m_name+"dialogbase.ui");	    m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating basic dialog UI...") );	    	    CStdioFile uiFile( baseDir + uiFileName, CFile::modeCreate | CFile::modeWrite );	    uiFile.WriteString( replaceTemplateStrings(dialogbase_ui, classheader, 						       classname, instancename, instancecall, projectName) );	    uiFile.Close();	    CString hFileName(classheader+".h");	    CString iFileName(classheader+".cpp");	    m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating basic dialog implementation...") );	    CStdioFile hFile( baseDir + hFileName, CFile::modeCreate | CFile::modeWrite );	    hFile.WriteString( replaceTemplateStrings(dialog_h, classheader, 						      classname, instancename, instancecall, projectName) );	    hFile.Close();	    CStdioFile iFile( baseDir + iFileName, CFile::modeCreate | CFile::modeWrite );	    iFile.WriteString( replaceTemplateStrings(dialog_cpp, classheader, 						      classname, instancename, instancecall, projectName) );	    iFile.Close();	    m_pApplication->PrintToOutputWindow( CComBSTR("\tadding files...") );	    pProject->AddFile( CComBSTR(uiFileName), CComVariant(VARIANT_TRUE) );	    pProject->AddFile( CComBSTR(hFileName), CComVariant(VARIANT_TRUE) );	    pProject->AddFile( CComBSTR(iFileName), CComVariant(VARIANT_TRUE) );	    m_pApplication->PrintToOutputWindow( CComBSTR("\tadding build steps...") );	    addUIC( pProject, uiFileName );	    addMOC( pProject, hFileName );	    runDesigner( baseDir + uiFileName );	} else if ( dialog.m_mdi ) {	    CString hFileName;	    CString iFileName;	    hFileName = classheader+".h";	    iFileName = classheader+".cpp";	    	    CStdioFile hFile( baseDir + hFileName, CFile::modeCreate | CFile::modeWrite );	    CStdioFile iFile( baseDir + iFileName, CFile::modeCreate | CFile::modeWrite );	    m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating MDI interface...") );	    hFile.WriteString( replaceTemplateStrings(mdi_h, classheader, 		classname, instancename, instancecall, projectName) );	    iFile.WriteString( replaceTemplateStrings(mdi_cpp, classheader, 		classname, instancename, instancecall, projectName) );	    hFile.Close();	    iFile.Close();	    m_pApplication->PrintToOutputWindow( CComBSTR("\tadding files...") );	    pProject->AddFile( CComBSTR(hFileName), CComVariant(VARIANT_TRUE) );	    pProject->AddFile( CComBSTR(iFileName), CComVariant(VARIANT_TRUE) );	    m_pApplication->PrintToOutputWindow( CComBSTR("\tadding build steps...") );	    addMOC( pProject, hFileName);	} else {	    CString uiFileName(dialog.m_name+"mainwindowbase.ui");	    m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating basic main window UI...") );	    	    CStdioFile uiFile( baseDir + uiFileName, CFile::modeCreate | CFile::modeWrite );	    uiFile.WriteString( replaceTemplateStrings(mainwinbase_ui, classheader, 		classname, instancename, instancecall, projectName) );	    uiFile.Close();	    	    CString hFileName(classheader+".h");	    CString iFileName(classheader+".cpp");	    m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating basic main window implementation...") );	    CStdioFile hFile( baseDir + hFileName, CFile::modeCreate | CFile::modeWrite );	    hFile.WriteString( replaceTemplateStrings(window_h, classheader, 		classname, instancename, instancecall, projectName) );	    hFile.Close();	    	    CStdioFile iFile( baseDir + iFileName, CFile::modeCreate | CFile::modeWrite );	    iFile.WriteString( replaceTemplateStrings(window_cpp, classheader, 		classname, instancename, instancecall, projectName) );	    iFile.Close();	    	    m_pApplication->PrintToOutputWindow( CComBSTR("\tadding files...") );	    pProject->AddFile( CComBSTR(uiFileName), CComVariant(VARIANT_TRUE) );	    pProject->AddFile( CComBSTR(hFileName), CComVariant(VARIANT_TRUE) );	    pProject->AddFile( CComBSTR(iFileName), CComVariant(VARIANT_TRUE) );	    m_pApplication->PrintToOutputWindow( CComBSTR("\tadding build steps...") );	    addUIC( pProject, uiFileName );	    addMOC( pProject, hFileName );	    runDesigner( baseDir + uiFileName );	}    }    catch ( CFileException* e )    {	char err[256];	e->GetErrorMessage( (char*)&err, 255, NULL );	::MessageBox( NULL, err, "Error", MB_OK );	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	return S_FALSE;    }        pProject->AddFile( CComBSTR("main.cpp"), CComVariant(VARIANT_TRUE) );    pProject->AddFile( CComBSTR("readme.txt"), CComVariant(VARIANT_TRUE) );        m_pApplication->PrintToOutputWindow( CComBSTR(dialog.m_name+" finished!\n") );    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));    return S_OK;}STDMETHODIMP CCommands::QMsDevNewQtDialog(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());        CComQIPtr<IBuildProject, &IID_IBuildProject> pProject;    if ( getActiveProject( pProject ) != S_OK ) {	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));	if ( ::MessageBox( NULL, "There is no active project.\nDo you want to create a new Qt Project?", 	    "New Dialog", MB_YESNOCANCEL | MB_ICONQUESTION ) == IDYES )	    QMsDevNewQtProject();	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	return S_FALSE;    }    CComBSTR fp;    pProject->get_FullName( &fp );    CString file(fp);    CString filepath;    CString filename;    CString fileext;    CString classname;        splitFileName( file, filepath, filename, fileext );    // TODO: ask for classname    CFileDialog fd( TRUE, "ui", "NewDialog.ui", OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, 	"User Interface File (*.ui)|*.ui|"	"All Files (*.*)|*.*||", NULL);    fd.m_ofn.lpstrInitialDir = filepath;    int result = fd.DoModal();    if ( result == IDCANCEL ) {	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	return S_OK;    }    file = fd.GetPathName();    splitFileName( file, filepath, filename, fileext );    if ( CFileFind().FindFile( file ) ) {	m_pApplication->PrintToOutputWindow( CComBSTR("Add UIC buildstep for "+file+"...") );	m_pApplication->PrintToOutputWindow( CComBSTR("Add buildstep for "+file+"...") );	addUIC( pProject, filepath + file );	m_pApplication->PrintToOutputWindow( CComBSTR("Finished!\n") );    	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	return S_OK;    }    classname = filename;    filename.MakeLower();    m_pApplication->PrintToOutputWindow( CComBSTR("Adding new dialog \"" + classname + "\"...") );    m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating dialog...") );    file = filename+".ui";    file.MakeLower();    CStdioFile uiFile( filepath + file , CFile::modeCreate | CFile::modeWrite );    uiFile.WriteString( replaceTemplateStrings(dialogbase_ui, "", 					       classname, "", "", classname) );    uiFile.Close();    m_pApplication->PrintToOutputWindow( CComBSTR("\tadding files...") );    addUIC( pProject, filepath+file );    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));    if ( ::MessageBox( NULL, "Do you want me to add a basic implementation for your dialog?", 	"Question", MB_YESNOCANCEL | MB_ICONQUESTION ) == IDYES ) {	m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating implementation...") );	int error = system( "uic -subdecl "+classname+" "+filename+".h "+filepath+filename+".ui -o "+filepath+filename+"impl.h" );	error +=    system( "uic -subimpl "+classname+" "+filename+"impl.h "+filepath+filename+".ui -o "+filepath+filename+"impl.cpp" );	if ( error ) {	    ::MessageBox( NULL, "Failed to create subclass implementation!", "Error", MB_OK );	    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	    return S_FALSE;	}	m_pApplication->PrintToOutputWindow( CComBSTR("\tadding implementation files...") );	pProject->AddFile( CComBSTR(filepath+filename+"impl.h"), CComVariant(VARIANT_TRUE));	addMOC( pProject, filepath+filename+"impl.h" );	pProject->AddFile( CComBSTR(filepath+filename+"impl.cpp"), CComVariant(VARIANT_TRUE));    }    m_pApplication->PrintToOutputWindow( CComBSTR("New Dialog \"" + classname + "\" finished!") );    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));    return S_OK;}bool projectIsLibrary( CString projectPath ){    AFX_MANAGE_STATE( AfxGetStaticModuleState() );    CFile inFile;    CString buffer;    char c;    if( inFile.Open( projectPath, CFile::modeRead ) ) {	while( inFile.Read( &c, sizeof( c ) ) ) {	    if( c != '\n' )		buffer += c;	    else {		// A complete line has been read.		if( buffer.Left( 8 ) == "TEMPLATE" ) {		    // This is the template line		    if( buffer.Find( "lib" ) != -1 )			return true;		    break;		}		buffer.Empty();	    }	}    }    return false;}STDMETHODIMP CCommands::QMsDevCreateDSP(){    AFX_MANAGE_STATE(AfxGetStaticModuleState());    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));    CString file;    CString filepath;    CString filename;    CString fileext;    CFileDialog fd( TRUE, NULL, NULL, OFN_HIDEREADONLY, 	"Qt Project (*.pro)|*.pro|"	"All Files (*.*)|*.*||", NULL);    int result = fd.DoModal();    if ( result == IDCANCEL ) {	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	return S_OK;    }    file = fd.GetPathName();    splitFileName( file, filepath, filename, fileext );    chdir( filepath );    CString tFile = "vcapp.t";    try {	CStdioFile file( filepath + file, CFile::modeRead );	CString line;	BOOL eof;	do {	    eof = !file.ReadString( line );	    if ( eof )		break;	    if ( line.Find( "TEMPLATE" ) != -1 ) {		if ( ( line.Find( "lib" ) != -1 ) || 		    ( line.Find( "vclib" ) != -1 ) )		    tFile = "vclib.t";		break;	    }	} while ( !eof );    }    catch ( CFileException* e ) {	char err[256];	e->GetErrorMessage( (char*)&err, 255, NULL );	::MessageBox( NULL, err, "Error", MB_OK );	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));	return S_FALSE;    }    m_pApplication->PrintToOutputWindow( CComBSTR("Running qmake...") );    if ( system( "qmake "+file+" -t "+tFile ) )	m_pApplication->PrintToOutputWindow( CComBSTR("FAILED TO RUN QMAKE!") );    else	::MessageBox(NULL, "Created Developer Studio Project for Qt Project "+file+"\n"			   "Add the new project file to your current workspace,\n"			   "or open it in an empty workspace.", 			   "Open Qt Project", MB_OK | MB_ICONINFORMATION );    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));    return S_OK;}STDMETHODIMP CCommands::QMsDevAddUICStep(){    return S_OK;}STDMETHODIMP CCommands::QMsDevStartLinguist(){    AFX_MANAGE_STATE(AfxGetStaticModuleState())	    CString file;    CString filepath;    CString filename;    CString fileext;        // Get the active file    file = getActiveFileName();    splitFileName( file, filepath, filename, fileext );        // Check if we can use the file    if ( file.IsEmpty() || fileext != "ts" )	return S_FALSE;        runDesigner( filepath + file );        return S_OK;}STDMETHODIMP CCommands::QMsDevStartAssistant(){    AFX_MANAGE_STATE(AfxGetStaticModuleState())    CString path;    CString command;    path = getenv("QTDIR");    if ( path.IsEmpty() ) {	// Get the location from the registry	CRegKey key;	char* value = new char[256];	unsigned long length;	if (key.Open(HKEY_CURRENT_USER, "Software\\Trolltech\\Qt Assistant") == ERROR_SUCCESS) {	    length = 255;	    key.QueryValue( value, "PathToExe", &length );	    path = value;	    length = 255;	    key.QueryValue( value, "NameOfExe", &length );	    command = value;	    key.Close();	} else {	    ::MessageBox(NULL, "Can't locate Qt Assistant", 			       "Error", MB_OK | MB_ICONINFORMATION);	    return S_FALSE;	}	delete[] value;    } else {	command = "assistant.exe";	path+="\\bin";    }    // Run the assistant    if ( spawnl(_P_NOWAIT, path+"\\"+command, command, 0 ) == -1 ) {	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));	::MessageBox(NULL, "Failed to run Qt Assistant: "+command, 			   "Start Designer", MB_OK | MB_ICONINFORMATION);	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));    }    return S_OK;}

⌨️ 快捷键说明

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