📄 commands.cpp
字号:
if ( result == IDCANCEL ) { VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); return S_OK; } file = fd.GetPathName(); splitFileName( file, filepath, filename, fileext ); chdir( filepath ); CString contents; 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 tmake...") ); if ( system( "tmake "+file+" -o "+filename+".dsp"+" -t "+tFile ) ) m_pApplication->PrintToOutputWindow( CComBSTR("FAILED TO RUN TMAKE!") ); 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::QMsDevNewQtProject(){ AFX_MANAGE_STATE(AfxGetStaticModuleState()); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); NewQtProjectDialog dialog; if ( dialog.DoModal() == IDCANCEL ) { VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); return S_FALSE; } if ( mkdir( dialog.m_location ) < 0 ) { ::MessageBox(NULL, "Couldn't create Directory\n"+dialog.m_location, "New Qt Project", MB_OK | MB_ICONINFORMATION ); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); return S_FALSE; } m_pApplication->PrintToOutputWindow( CComBSTR("Creating Qt Project \"" + dialog.m_name + "\"...") ); CString filename = dialog.m_location; if ( filename[ filename.GetLength() -1 ] != '\\' ) filename+="\\"; filename += dialog.m_name + ".dsp"; if ( m_pApplication->AddProject( CComBSTR(filename), CComBSTR(dialog.m_location), CComBSTR("Application"), VARIANT_TRUE ) != S_OK ) { CComBSTR err; GetLastErrorDescription( err ); ::MessageBox(NULL, (LPCTSTR)err.m_str, "New Qt Project", MB_OK | MB_ICONINFORMATION ); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); return S_FALSE; } // Get project object we just created CComQIPtr<IBuildProject, &IID_IBuildProject> pProject; if ( getActiveProject( pProject ) != S_OK ) { VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE)); ::MessageBox(NULL, "Project creation failed!", "QMsDev", MB_OK | MB_ICONINFORMATION ); VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); return S_FALSE; } // Get the list of configurations CComQIPtr<IConfigurations, &IID_IConfigurations> pConfigs; if ( getConfigurations( pProject, pConfigs ) != S_OK ) { VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE)); return S_FALSE; } long cCount; VERIFY_OK( pConfigs->get_Count(&cCount)); for (long c = 0; c < cCount; c++ ) { CComVariant Varc = c+1; CComPtr<IConfiguration> pConfig; VERIFY_OK(pConfigs->Item(Varc, &pConfig)); BSTR bstr; pConfig->get_Name(&bstr); if ( dialog.m_shared ) { m_pApplication->PrintToOutputWindow( CComBSTR("\tadding Qt shared library to "+ CString(bstr) + "...") ); addSharedSettings( pConfig ); } else { m_pApplication->PrintToOutputWindow( CComBSTR("\tadding Qt static library to "+ CString(bstr) + "...") ); addStaticSettings( pConfig ); } } CString projectName = dialog.m_name; dialog.m_name.MakeLower(); CString classheader; CString classname; CString instancename; CString instancecall; CString runapp; if ( dialog.m_dialog ) { classheader = dialog.m_name + "dialog"; classname = projectName + "Dialog"; instancename = "dialog"; instancecall = "( 0, 0, TRUE )"; runapp = "dialog.exec();\n\n\treturn 0;"; } else { classheader = dialog.m_name + "window"; classname = projectName + "Window"; instancename = "window"; instancecall = ""; runapp = "window.show();\n\n\treturn app.exec();"; } CString baseDir = dialog.m_location + "\\"; m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating basic files...") ); // Write files and replace $MSDEV... strings with project-specific stuff try { CStdioFile mainFile( baseDir + "main.cpp", CFile::modeCreate | CFile::modeWrite ); mainFile.WriteString( replaceTemplateStrings(main_cpp, classheader, classname, instancename, instancecall, projectName, runapp) ); mainFile.Close(); CStdioFile infoFile( baseDir + "readme.txt", CFile::modeCreate | CFile::modeWrite ); CString readme( readme_txt ); if ( dialog.m_dialog ) { readme.Replace( "$QMSDEVUITYPE", "Dialog interface" ); readme.Replace( "$QMSDEVFILELIST", classheader+"base.ui\n\tA dialog with basic buttons.\n" "\tUse the Qt GUI Designer change the layout.\n" ); readme.Replace( "$QMSDEVQTFILELIST", classheader+"base.h\n"+classheader+"base.cpp\nmoc_"+ classheader+"base.cpp\nmoc_"+classheader+".cpp\n" ); } else if ( dialog.m_mdi ) { readme.Replace( "$QMSDEVUITYPE", "Multi Document interface (MDI)" ); readme.Replace( "$QMSDEVFILELIST", "" ); readme.Replace( "$QMSDEVQTFILELIST", "moc_"+classheader+".cpp\n" ); } else { readme.Replace( "$QMSDEVUITYPE", "Basic interface" ); readme.Replace( "$QMSDEVFILELIST", "" ); readme.Replace( "$QMSDEVQTFILELIST", "moc_"+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 { 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 ); if ( dialog.m_mdi ) { 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) ); } else { m_pApplication->PrintToOutputWindow( CComBSTR("\tcreating basic main window...") ); hFile.WriteString( replaceTemplateStrings(window_h, classheader, classname, instancename, instancecall, projectName) ); iFile.WriteString( replaceTemplateStrings(window_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); } } 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( FALSE, "ui", "NewDialog.ui", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST, "User Interface File (*.ui)|*.ui|" "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 ); 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -