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

📄 kscope.cpp

📁 linux下的sourceinsight
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	// Create the new editor page	pMenu = (QPopupMenu*)factory()->container(Config().getEditorPopupName(),		this);	pPage = new EditorPage(pDoc, pMenu, m_pEditTabs);	m_pEditTabs->addEditorPage(pPage);	// Show the file's path in the main title	connect(pPage, SIGNAL(fileOpened(EditorPage*, const QString&)), this,		SLOT(slotFileOpened(EditorPage*, const QString&)));	// Show cursor position in the status bar	connect(pPage, SIGNAL(cursorPosChanged(uint, uint)), this,		SLOT(slotShowCursorPos(uint, uint)));		// Rebuild the database after a file has changed	connect(pPage, SIGNAL(fileSaved(const QString&, bool)), this,		SLOT(slotFileSaved(const QString&, bool)));		// Handle file drops	connect(pPage->getView(), SIGNAL(dropEventPass(QDropEvent*)), this,		SLOT(slotDropEvent(QDropEvent*)));	// Apply per-project configuration	pProj = m_pProjMgr->curProject();	if (pProj && pProj->getTabWidth() > 0)		pPage->setTabWidth(pProj->getTabWidth());		return pPage;}	/** * @return	true if database auto-rebuild is enabled for the current project, *			false otherwise */inline bool KScope::isAutoRebuildEnabled(){	ProjectBase* pProj;		pProj = m_pProjMgr->curProject();	return (pProj && pProj->getAutoRebuildTime() >= 0);}/** * Deletes an editor page after it has been removed. * The document object associated with the page is removed from the part  * manager, and the view object is removed from the GUI manager. * This slot is connected to the editorRemoved() signal of the EditorTabs  * object. * @param	pPage	The editor page to delete */void KScope::slotDeleteEditor(EditorPage* pPage){	guiFactory()->removeClient(pPage->getView());	m_pEditMgr->remove(pPage->getDocument());	delete pPage;}/** * Sets an editor part as active when its owner tab is chosen. * Whenever a different editor tab is chosen, its editor part should become * the active part. This means that this part's GUI is merged with the * application's, and that it responds to actions. * @param	pOldPage	The editor page that has ceased to be active * @param	pNewPage	The newly chosen editor page */void KScope::slotChangeEditor(EditorPage* pOldPage, EditorPage* pNewPage){	KXMLGUIFactory* pFactory = guiFactory();		// Remove the current GUI	if (pOldPage)		pFactory->removeClient(pOldPage->getView());	// Set the new active part and create its GUI	if (m_bUpdateGUI && pNewPage) {		m_pEditMgr->setActivePart(pNewPage->getDocument());		pFactory->addClient(pNewPage->getView());		m_sCurFilePath = pNewPage->getFilePath();		setCaption(m_pProjMgr->getProjName() + " - " + m_sCurFilePath);	}		// Enable/disable file-related actions, if necessary	if (pOldPage && !pNewPage)		m_pActions->slotEnableFileActions(false);	else if (!pOldPage && pNewPage)		m_pActions->slotEnableFileActions(true);}/** * Opens an editor for the given file and sets the cursor to the beginning of  * the requested line. * @param	sFilePath	The full path of the file to open for editing * @param	nLine		The number of the line on which to position the *						cursor, or 0 to maintain the cursor in its current *						position (which does not affect the position history) */void KScope::slotShowEditor(const QString& sFilePath, uint nLine){	EditorPage* pPage;	// Save current position in the position history	if (nLine != 0 && (pPage = m_pEditTabs->getCurrentPage())) {		m_pQueryWidget->addHistoryRecord(m_sCurFilePath, m_nCurLine,			pPage->getLineContents(m_nCurLine));	}		// Open the requested file (or select an already-open editor page)	pPage = addEditor(sFilePath);	if (pPage == NULL)		return;		// Make sure the main window is visible	raise();	setWindowState(windowState() & ~WindowMinimized | WindowActive);		if (nLine != 0) {		// Set the cursor to the requested line		pPage->slotGotoLine(nLine);			// Add the new position to the position history		m_pQueryWidget->addHistoryRecord(m_sCurFilePath, m_nCurLine,			pPage->getLineContents(m_nCurLine));	}}/** * A wrapper around slotShowEditor, that enables auto-hiding of the query * widget after a query result has been chosen. * This slot is connected to the lineRequested() signal emitted by a QueryPage * object. * @param	sFilePath	The full path of the file to open for editing * @param	nLine		The number of the line on which to position the cursor */void KScope::slotQueryShowEditor(const QString& sFilePath, uint nLine){	// Hide the query window, if it was hidden before a query was initiated	if (m_bHideQueryOnSelection)		toggleQueryWindow(false);		// Open an editor at the requested line	slotShowEditor(sFilePath, nLine);}/** * Handles the "Go->Position History" menu command. * Ensures that the query window is visible, and selects the active history * page. */void KScope::slotHistoryShow(){	toggleQueryWindow(true);	m_pQueryWidget->selectActiveHistory();}/** * Handles the "File->New" menu command. * Creates an editor page for a new unnamed file. */void KScope::slotNewFile(){	EditorPage* pPage;	// Create the new editor page	pPage = createEditorPage();		// Mark the page as containing a new file	pPage->setNewFile();}/** * Handles the "File->Open" menu command. * Prompts the user for a file name, and opens it in a new editor page. */void KScope::slotOpenFile(){	ProjectBase* pProj;	QStringList slFiles;	QStringList::Iterator itr;		// Prompt the user for the file(s) to open.	pProj = m_pProjMgr->curProject();	slFiles = KFileDialog::getOpenFileNames(pProj ? pProj->getSourceRoot() : 		QString::null);		// Open all selected files.	for (itr = slFiles.begin(); itr != slFiles.end(); ++itr) {		if (!(*itr).isEmpty())			slotShowEditor(*itr, 0);	}}/** * Handles the "File->Close" menu command. * Closes the currently active editor page. */void KScope::slotCloseEditor(){	m_pEditTabs->removeCurrentPage();}/** * Handles the "Window->Close All" menu command. * Closes all open editor pages. */void KScope::slotCloseAllWindows(){	m_bUpdateGUI = false;	m_pEditTabs->removeAllPages();	m_bUpdateGUI = true;}/** * Displays error messages from a Cscope process. * This slot is connected to the progress() signal emitted by the any * Cscope process. * @param	sMsg	The error message */void KScope::slotCscopeError(const QString& sMsg){	m_pMsgDlg->addText(sMsg);}/** * Reports progress information from the Cscope process responsible for * rebuilding the cross-reference database. * This slot is connected to the progress() signal emitted by the builder * process. * Progress information is displayed in the status bar. * @param	nFiles	The number of files scanned * @param	nTotal	The total number of files in the project */void KScope::slotBuildProgress(int nFiles, int nTotal){	QString sMsg;		// Use the progress dialogue, if it exists (first time builds)	if (m_pProgressDlg) {		m_pProgressDlg->setValue((nFiles * 100) / nTotal);		return;	}		// Show progress information	sMsg = i18n("Rebuilding the cross reference database...") + " " +		QString::number((nFiles * 100) / nTotal) + "%";	statusBar()->message(sMsg);}/** * Reports to the user that Cscope has started building the inverted index. * This slot is connected to the buildInvIndex() signal emitted by the  * builder process. */void KScope::slotBuildInvIndex(){	if (m_pProgressDlg) {		m_pProgressDlg->setLabel(i18n("Please wait while KScope builds the "			"inverted index"));		m_pProgressDlg->setIdle();		return;	}		statusBar()->message(i18n("Rebuilding inverted index..."));}/** * Informs the user the database rebuild process has finished. * This slot is connected to the finished() signal emitted by the builder * process. */void KScope::slotBuildFinished(uint){	// Delete the progress dialogue, if it exists (first time builds)	if (m_pProgressDlg) {		delete m_pProgressDlg;		m_pProgressDlg = NULL;		return;	}		// Show a message in the status bar	statusBar()->message(i18n("Rebuilding the cross reference database..."		"Done!"), 3000);}/** * Called if the build process failed to complete. * This slot is connected to the aborted() signal emitted by the builder * process. */void KScope::slotBuildAborted(){	// Delete the progress dialogue, if it exists (first time builds)	if (m_pProgressDlg) {		delete m_pProgressDlg;		m_pProgressDlg = NULL;			// Display a failure message		KMessageBox::error(0, i18n("The database could not be built.\n"			"Cross-reference information will not be available for this "			"project.\n"			"Please ensure that the Cscope parameters were correctly "			"entered in the \"Settings\" dialogue."));				return;	}		// Show a message in the status bar	statusBar()->message(i18n("Rebuilding the cross reference database..."		"Failed"), 3000);	}/** * Applies the selected user preferences once the "Apply" or "OK" buttons in * the preferences dialog is clicked. */void KScope::slotApplyPref(){	m_pQueryWidget->applyPrefs();	m_pFileList->applyPrefs();	m_pEditTabs->applyPrefs();	m_pEditMgr->applyPrefs();	// Enable/disable the external editor menu item	m_pActions->enableExtEditor(Config().useExtEditor());}/** * Displays the current cursor position, whenever it is moved by the user. * This slot is connected to the cursorPosChanged() signal emitted by an * EditorPage object. * @param	nLine	The new line number * @param	nCol	The new column number */void KScope::slotShowCursorPos(uint nLine, uint nCol){	KStatusBar* pStatus = statusBar();	QString sText;		/* Show the line and column numbers. */	QTextOStream(&sText) << " Line: " << nLine << " Col: " << nCol << " ";	pStatus->changeItem(sText, 0);		/* Store the current line. */	m_nCurLine = nLine;}/** * Stores the path of a newly opened file. * This slot is connected to the fileOpened() signal emitted by an * EditorPage object. * @param	sFilePath	The full path of the opened file */void KScope::slotFileOpened(EditorPage*, const QString& sFilePath){	m_sCurFilePath = sFilePath;	setCaption(m_pProjMgr->getProjName() + " - " + m_sCurFilePath);}/** * Sets a timer for rebuilding the database after a file has been saved. * This slot is connected to the fileSaved() signal emitted by an EditorPage * object. * The time period before rebuilding is determined on a per-project basis. * @param	sPath	The full path of the modified file that caused this event * @param	bIsNew	true if this is a new file, false otherwise */void KScope::slotFileSaved(const QString& sPath, bool bIsNew){	ProjectBase* pProj;	int nTime;		pProj = m_pProjMgr->curProject();	if (!pProj)		return;		// Prompt the user to add this file to the current project	if (bIsNew && !pProj->isTemporary()) {		if (KMessageBox::questionYesNo(0, 			i18n("Whould you like to add this file to the active project?")) == 				  KMessageBox::Yes) {						// Add the path to the 'cscope.files' file			if (!((Project*)pProj)->addFile(sPath)) {				KMessageBox::error(0, i18n("Failed to write the file list."));				return;			}						// Add the path to the file list widget			m_pFileList->addItem(sPath);						// Rebuild immediately			slotRebuildDB();			return;		}	}		// Get the project's auto-rebuild time	nTime = pProj->getAutoRebuildTime();		// Do nothing if the time is set to -1	if (nTime == -1)		return;			// Check if the file is included in the project (external files should	// not trigger the timer)	if (!m_pFileList->findFile(sPath))		return;		// Rebuild immediately for a time set to 0	if (nTime == 0) {		slotRebuildDB();		return;	}	// Reset the rebuild timer	m_timerRebuild.start(nTime * 1000, true);}/** * Handles file drops inside the editors tab widget. * Opens all files dropped over the widget. * @param	pEvent	Pointer to an object containing the list of dropped files */void KScope::slotDropEvent(QDropEvent* pEvent){	KURL::List list;	KURL::List::Iterator itr;			// Create a list of file URLs	if (!KURLDrag::decode(pEvent, list))		return;			// Open all files in the list	for (itr = list.begin(); itr != list.end(); ++itr)		addEditor((*itr).path());}#include "kscope.moc"

⌨️ 快捷键说明

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