⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwidget.cpp

📁 Linux下的C、C++ IDE
💻 CPP
📖 第 1 页 / 共 3 页
字号:
void MainWidget::projSave(){		m_HideProj.save();	m_status->message((QString) m_HideProj.getName() + " saved", 5000);}void MainWidget::projClose(){		m_HideProj.save();	m_HideProj.clear();	fileCloseAll();		enableProjectTools(false);		m_bOpenProj = false;		m_ProjName->clear();		m_hidemain->setBuildOutput("");}void MainWidget::projAddFile(){	// Display an "Open" file dialog for the user to select a file.	QString fn(QFileDialog::getOpenFileName(QString::null,						"All Files (*)",						this,						"add file",						"Add File"));	// If "Cancel" was clicked return...	if (fn.isEmpty())		return;			m_HideProj.addFile(fn);	m_HideProj.save();	fileOpen(fn);}void MainWidget::projAddNewFile(){	if (!fileNew())		return;	m_HideProj.addFile(m_CurDoc.getPath());	m_HideProj.save();}void MainWidget::projRemFile(){	RemoveFileDlg dlg(this, &m_HideProj);	dlg.exec();}void MainWidget::projBuild(){	if (m_bOpenFile)		fileSaveAll();	if ((m_HideProj.getLang() == LANG_C) ||	    (m_HideProj.getLang() == LANG_CPP))		cppMake();	else	if (m_HideProj.getLang() == LANG_JAVA)	{		JMakeMgr jmake;		jmake.create(&m_HideProj);		m_CurCmd = "javac";		showBuildWnd(true);		m_hidemain->setBuildOutput((QString) "Building " +		m_HideProj.getName() + "..."); 		 		if (!m_BuildMgr->make(m_HideProj.getRoot(), 				      m_HideProj.getCompileOpt(),				      BM_JAVA))		{			QMessageBox::warning(this, "hIDE",				"Unable to create build thread.");			return;		}		enableBuildTools(false);		enableCustTools(false);	}}void MainWidget::projConfig(){	ProjConfDlg dlg(this, &m_HideProj);	bool bCBased = 		((m_HideProj.getLang() == LANG_C) || 		 (m_HideProj.getLang() == LANG_CPP));	dlg.editCOpt->setText(m_HideProj.getCompileOpt());	if (bCBased)	{		dlg.editBOpt->setText(m_HideProj.getBuildOpt());		dlg.checkAuto->setChecked(m_HideProj.isAutoMake());	}	if (dlg.exec() == QDialog::Accepted)	{		m_HideProj.setCompileOpt(dlg.editCOpt->text());		if (bCBased)		{			m_HideProj.setBuildOpt(dlg.editBOpt->text());			m_HideProj.setAutoMake(dlg.checkAuto->isChecked());		}		m_HideProj.save();	}}// A selection was made in the open files list box, display that file.void MainWidget::srcSelChanged(QListBoxItem *item){	if (item == 0)		return;	//	if (item->text() == m_CurDoc.getName())//		return;	// Update the current document with the the contents of the editor.			m_CurDoc.setData(m_hidemain->getContent());		// Update the document in the list.	m_DocList->update(m_CurDoc);		// Set the selected document as the current one.	m_CurDoc = m_DocList->getByName(item->text());	showDoc();	if (!m_CurDoc.isModified())			setTitle(m_CurDoc.getName());	else		setTitle((QString) m_CurDoc.getName() + DOC_MOD_FLAG);}void MainWidget::docModified(){	if (m_bOpenFile)	{		m_CurDoc.setModified(1);		m_CurDoc.setData(m_hidemain->getContent());		m_DocList->update(m_CurDoc);		setTitle((QString) m_CurDoc.getName() + DOC_MOD_FLAG);		}}void MainWidget::onEnter(){/*  	int line=0, pos=0;  	  	//if (m_bColorize) ...  	m_hidemain->getEdit()->getCursorPosition(&line, &pos);  	m_hidemain->getEdit()->colorize(line-1);  	m_hidemain->getEdit()->setCursorPosition(line, pos);*/}void MainWidget::updateLine(int para, int pos){	QString line = "", col = "";		line.setNum(para+1);	col.setNum(pos+1);	line = (QString) STATUS_LINE + line;	col = (QString) STATUS_COL + col;	m_LineNum->setText(line);	m_ColNum->setText(col);}void MainWidget::cppCompile(){	QFileInfo fi;	QString ext = "";	unsigned lang = 0;	bool ok = false; 	if (!m_bOpenFile) 		return;	QString opt = QInputDialog::getText("Compiler Options",					    QString::null,					    QLineEdit::Normal,					    "",					    &ok,					    this);	if (!ok)		return; 	 	fi.setFile(m_CurDoc.getPath()); 	ext = fi.extension(0); 	 	if (IS_COMPILABLE_CPP(ext)) 		lang = BM_CPP; 	else 	if (IS_COMPILABLE_C(ext)) 		lang = BM_C; 	else 	{ 	 	QMessageBox::warning(this, 	 			     "hIDE", 	 			     (QString) m_CurDoc.getName() + 	 			     " is not compilable C or C++."); 	 			 	 	return; 	}	m_CurCmd = "gcc";	showBuildWnd(true);	m_hidemain->setBuildOutput((QString) "Compiling " +				m_CurDoc.getName() + "..."); 		 	if (!m_BuildMgr->compile(m_CurDoc.getPath(), "", opt, lang))	{		QMessageBox::warning(this, "hIDE",			"Unable to create compilation thread.");		return;	}	enableBuildTools(false);	enableCustTools(false);}void MainWidget::cppMake(){	QFileInfo fi;	QString path = "";       	MakeMgr mk;       		if (!m_bOpenFile && !m_bOpenProj)		return;			if (m_bOpenProj)	{		if (m_HideProj.isAutoMake())		{			if (!mk.create(&m_HideProj))			{				QMessageBox::warning(this,					"hIDE",					"Unable to generate makefile.");				return;			}		}				fi.setFile(m_HideProj.getRoot());		path = fi.absFilePath();	}	else	{			fi.setFile(m_CurDoc.getPath());		path = fi.dirPath(1);        }	if (!m_BuildMgr->hasMakefile(path))	{		m_hidemain->setBuildOutput("Unable to locate a makefile.");				return;	}		m_CurCmd = "make";	showBuildWnd(true);					m_hidemain->setBuildOutput((QString) "Building " + m_ProjName->text() + "...");		if (!m_BuildMgr->make(path, "", 0))	{		QMessageBox::warning(this, "hIDE",			"Unable to create make thread.");		return;	}	enableBuildTools(false);	enableCustTools(false);	if (m_bOpenProj)		m_menu->setItemEnabled(MENU_PROJ_BUILD, false);}void MainWidget::cppClean(){	QFileInfo fi;	QString cmd = "", path = "";			if (!m_bOpenFile && !m_bOpenProj)		return;		if (m_bOpenProj)	{		fi.setFile(m_HideProj.getRoot());		path = fi.absFilePath();	}	else	{			fi.setFile(m_CurDoc.getPath());		path = fi.dirPath(1);	}		if (!m_BuildMgr->hasMakefile(path))	{		m_hidemain->setBuildOutput("Unable to locate a makefile.");				return;	}	m_CurCmd = "make clean";	cmd = (QString) "cd " + path + "; " + m_CurCmd;	showBuildWnd(true);	m_hidemain->setBuildOutput("Cleaning...");	if (!m_BuildMgr->cmd(cmd))	{		QMessageBox::warning(this, "hIDE",			"Unable to create command thread.");		return;	}	enableBuildTools(false);	enableCustTools(false);	}void MainWidget::javaCompile(){  	QFileInfo fi;  	  	if (!m_bOpenFile)  		return;  		  	fi.setFile(m_CurDoc.getPath());  	  	if (!IS_COMPILABLE_JAVA(fi.extension(0)))  	{ 	 	QMessageBox::warning(this, 	 			     "hIDE", 	 			     (QString) m_CurDoc.getName() + 	 			     " is not compilable Java."); 	 			 	 	return;  	  	}  		m_CurCmd = "javac";	showBuildWnd(true);	m_hidemain->setBuildOutput((QString) "Compiling " +					m_CurDoc.getName() + "...");					  	if (!m_BuildMgr->compile(m_CurDoc.getPath(),  		     "",  		     (QString) "-classpath " + "\"" + fi.dirPath(1) + "\"",  		     BM_JAVA))	{		QMessageBox::warning(this, "hIDE",			"Unable to create compilation thread.");		return;	}	enableBuildTools(false);	enableCustTools(false);}// *nix way, this method will differ under win32.void MainWidget::javaExecute(){	QString cmd = "", x = "";	QFileInfo fi;	cmd = "xterm -hold -e java -classpath ";	m_CurCmd = "java";	if (m_bOpenProj)	{		cmd += (QString)			m_HideProj.getRoot() + " " + 			m_HideProj.getName();		x = m_HideProj.getName();	}	else	{		fi.setFile(m_CurDoc.getPath());		cmd += (QString)			fi.dirPath(1) + " " + fi.baseName();		fi.baseName();	}	if (!m_BuildMgr->cmd(cmd))	{		QMessageBox::warning(this,					   "hIDE",					   "Unable to spawn Java execution thread.");		return;	}	showBuildWnd(true);	m_hidemain->setBuildOutput((QString) "Executing " + x + "...");	enableBuildTools(false);	enableCustTools(false);}void MainWidget::javaExecuteApplet(){	QString cmd = "", html = "", htpath = "", name = "";	QFileInfo fi;	SrcGen h;	cmd = "cd ";	if (m_bOpenProj)	{		htpath = m_HideProj.getRoot();		cmd += htpath;		name = m_HideProj.getName(); 	}	else	{		fi.setFile(m_CurDoc.getPath());		htpath = fi.dirPath(1);		cmd += htpath;		name = fi.baseName();	}	m_CurCmd = "appletviewer";	cmd += (QString) "; xterm -e appletviewer " + name + ".html";	html = (QString)		"<html>\n" +		"<body>\n" +		"<applet code=\"" + name + ".class\" width=\"500\" height=\"500\"></applet>\n" +		"</body>\n" +		"</html>\n";	h.create((QString) htpath + FILE_SEP + name + ".html", html);	if (!m_BuildMgr->cmd(cmd))	{		QMessageBox::warning(this,					   "hIDE",					   "Unable to spawn Java applet execution thread.");		return;	}	showBuildWnd(true);	m_hidemain->setBuildOutput((QString) "Executing " + name + "...");	enableBuildTools(false);	enableCustTools(false);}void MainWidget::javaDebug(){	QString cmd = "", x = "";	QFileInfo fi;	cmd = "xterm -hold -e jdb -classpath ";	m_CurCmd = "jdb";	if (m_bOpenProj)	{		cmd += (QString)			m_HideProj.getRoot() + " " + 			m_HideProj.getName();		x = m_HideProj.getName();	}	else	{		fi.setFile(m_CurDoc.getPath());		cmd += (QString)			fi.dirPath(1) + " " + fi.baseName();		fi.baseName();	}	if (!m_BuildMgr->cmd(cmd))	{		QMessageBox::warning(this,					   "hIDE",					   "Unable to spawn Java debugging thread.");		return;	}	showBuildWnd(true);	m_hidemain->setBuildOutput((QString) "Debugging " + x + "...");	enableBuildTools(false);	enableCustTools(false);}void MainWidget::javaJNI(){	QString cmd = "";	QFileInfo fi;	fi.setFile(m_CurDoc.getPath());	cmd = (QString) "cd " + fi.dirPath(1) + "; javah -jni " + fi.baseName(); 	m_CurCmd = "javah";	if (!m_BuildMgr->cmd(cmd))	{		QMessageBox::warning(this,					   "hIDE",					   "Unable to spawn Java JNI header thread.");		return;	}	showBuildWnd(true);	m_hidemain->setBuildOutput((QString) "Creating JNI C Header from " + 							m_CurDoc.getName() + "...");	enableBuildTools(false);	enableCustTools(false);}void MainWidget::settingEditor(){	EditorSettingsDlg dlg;	if (dlg.exec() == QDialog::Accepted)	{		EditorConfMgr ecm;		ecm.load();		m_hidemain->getEdit()->setFontSize(ecm.getFontSize());	}}void MainWidget::settingCustTools(){	CustToolDlg dlg(this, &m_CustToolMgr);	dlg.exec();	initCustTools();}void MainWidget::settingGlobal(){	GlobalSettingsDlg dlg(this);	dlg.exec();}void MainWidget::helpAbout(){	AboutDlg dlg(this);	dlg.exec();}////////////////////////////////////////////////////////////////////////////// BuildMgr Notificationsvoid MainWidget::compileDone(){	QFileInfo fi;	QString ext = "";	m_hidemain->setBuildOutput((QString) getHPLinkData() + "Compilation done.");			// Make sure there's still a file open...	if (m_bOpenFile)	{		fi.setFile(m_CurDoc.getPath());		ext = fi.extension(0);		if (m_CurCmd == "gcc" || m_CurCmd == "g++")		{			if (IS_C(ext) || IS_CPP(ext))				enableCppTools(true);		}		else		if (m_CurCmd == "javac")		{			if (IS_JAVA(ext))				enableJavaTools(true);		}		enableCustTools(true);	}	m_CurCmd = "";}void MainWidget::makeDone(){	QFileInfo fi;	QString ext = "";	m_hidemain->setBuildOutput((QString) getHPLinkData() + "Build done.");		m_CurCmd = "";	if (m_bOpenFile)	{		fi.setFile(m_CurDoc.getPath());		ext = fi.extension(0);		if (IS_C(ext) || IS_CPP(ext))			enableCppTools(true);		else		if (IS_JAVA(ext))			enableJavaTools(true);		enableCustTools(true);	}		if (m_bOpenProj)		m_menu->setItemEnabled(MENU_PROJ_BUILD, true);}void MainWidget::cmdDone(){	QFileInfo fi;	QString ext = "";	m_hidemain->setBuildOutput((QString) getHPLinkData() + "\'" + m_CurCmd + "\' done.");	if (m_bOpenFile)	{		fi.setFile(m_CurDoc.getPath());		ext = fi.extension(0);		if (IS_C(ext) || IS_CPP(ext))			enableCppTools(true);		else		if (IS_JAVA(ext))			enableJavaTools(true);		enableCustTools(true);	}	m_CurCmd = ""; }

⌨️ 快捷键说明

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