📄 kscope.cpp
字号:
else m_bHideQueryOnSelection = false; // Change the visibility state of the widget, if required if (m_pQueryDock->isShown() != bShow) m_pQueryDock->changeHideShowState(); // Synchronise with the menu command's state m_pActions->slotQueryDockToggled(bShow);}/** * Parses the command line, after it was stripped of its KDE options. * The command line may contain one of the following options: * 1. A project file (named cscope.proj) * 2. A Cscope cross-reference database * 3. A list of source files * @param pArgs Command line arguments */void KScope::parseCmdLine(KCmdLineArgs* pArgs){ QString sArg; QFileInfo fi; int i; // Loop over all arguments for (i = 0; i < pArgs->count(); i++) { // Verify the argument is a file or directory name sArg = pArgs->arg(i); fi.setFile(sArg); if (!fi.exists()) continue; // Handle the current argument if (fi.isFile()) { if (fi.fileName() == "cscope.proj") { // Open a project file openProject(fi.dirPath(true)); return; } else if (openCscopeOut(sArg)) { // Opened the file as a cross-reference database return; } else { // Assume this is a source file slotShowEditor(sArg, 0); } } else if (fi.isDir()) { // Treat the given path as a project directory openProject(fi.absFilePath()); return; } }}/** * Starts a shell script to ensure that Cscope is properly installed and to * extract the supported command-line arguments. */void KScope::verifyCscope(){ CscopeVerifier* pVer; statusBar()->message(i18n("Verifying Cscope installation...")); pVer = new CscopeVerifier(); connect(pVer, SIGNAL(done(bool, uint)), this, SLOT(slotCscopeVerified(bool, uint))); pVer->verify();}/** * Initialises the CscopeFrontend class with the current project arguments, * and creates an object used for rebuilding the symbol database. */void KScope::initCscope(){ ProjectBase* pProj; // Delete the current object, if one exists if (m_pCscopeBuild) delete m_pCscopeBuild; // Initialise CscopeFrontend pProj = m_pProjMgr->curProject(); CscopeFrontend::init(pProj->getPath(), pProj->getArgs()); // Create a persistent Cscope process m_pCscopeBuild = new CscopeFrontend(); // Show build progress information in the main status bar connect(m_pCscopeBuild, SIGNAL(progress(int, int)), this, SLOT(slotBuildProgress(int, int))); connect(m_pCscopeBuild, SIGNAL(buildInvIndex()), this, SLOT(slotBuildInvIndex())); connect(m_pCscopeBuild, SIGNAL(finished(uint)), this, SLOT(slotBuildFinished(uint))); connect(m_pCscopeBuild, SIGNAL(aborted()), this, SLOT(slotBuildAborted())); // Show errors in a modeless dialogue connect(m_pCscopeBuild, SIGNAL(error(const QString&)), this, SLOT(slotCscopeError(const QString&)));}/** * Closes the active project. * Closing a project involves closing all of the editor windows (prompting * the user for unsaved changes); terminating the Cscope process; and further * clean-up of the project's data. */bool KScope::slotCloseProject(){ ProjectBase* pProj; Project::Session sess; // Do nothing if no project is open pProj = m_pProjMgr->curProject(); if (!pProj) return true; // Make sure all FileLocation objects are deleted sess.fllOpenFiles.setAutoDelete(true); sess.fllBookmarks.setAutoDelete(true); // Close all open editor pages if (m_pEditTabs->count() > 0) { // Save session information for persistent projects if (!pProj->isTemporary()) { sess.sLastFile = m_pEditTabs->getCurrentPage()->getFilePath(); m_pEditTabs->getOpenFiles(sess.fllOpenFiles); m_pEditTabs->getBookmarks(sess.fllBookmarks); } if (!m_pEditTabs->removeAllPages()) return false; } // Disable project-related actions m_pActions->slotEnableProjectActions(false); // Destroy the make dialogue if (m_pMakeDlg != NULL) { // Save session information for persistent projects if (!pProj->isTemporary()) { sess.sMakeCmd = m_pMakeDlg->getCommand(); sess.sMakeRoot = m_pMakeDlg->getDir(); } delete m_pMakeDlg; m_pMakeDlg = NULL; } // Save session information for persistent projects if (!pProj->isTemporary()) { m_pQueryWidget->savePages(pProj->getPath(), sess.slQueryFiles); m_pCallTreeMgr->saveOpenDialogs(pProj->getPath(), sess.slCallTreeFiles); } // Close all query pages and call trees m_pQueryWidget->slotCloseAll(); m_pCallTreeMgr->closeAll(); // Store session information for persistent projects if (!pProj->isTemporary()) ((Project*)pProj)->storeSession(sess); // Close the project in the project manager, and terminate the Cscope // process m_pProjMgr->close(); delete m_pCscopeBuild; m_pCscopeBuild = NULL; setCaption(QString::null); // Clear the contents of the file list m_pFileView->clear(); // Reset queried symbols history SymbolDlg::resetHistory(); // Remove any remaining status bar messages statusBar()->message(""); return true;}/** * Handles the "Edit->Edit in External Editor" menu command. * Invokes an external editor for the current file and line number. */void KScope::slotExtEdit(){ QString sCmdLine; KProcess proc; // Create the command line for the external editor sCmdLine = Config().getExtEditor(); sCmdLine.replace("%F", m_sCurFilePath); sCmdLine.replace("%L", QString::number(m_nCurLine)); // Run the external editor proc.setUseShell(true); proc << sCmdLine; proc.start(KProcess::DontCare);}/** * Handles the "Edit->Complete Symbol" menu command. * Creates a list of possible completions for the symbol currently under the * cursor. */void KScope::slotCompleteSymbol(){ EditorPage* pPage; pPage = m_pEditTabs->getCurrentPage(); if (pPage != NULL) pPage->slotCompleteSymbol();}/** * Handles the "Help->Show Welcome Message..." menu command. * Displays the "Welcome" dialogue. */void KScope::slotShowWelcome(){ WelcomeDlg dlg; dlg.exec();}/** * Handles the "Edit->Go To Tag" menu command. * Sets the cursor to the edit box of the current tag list. */void KScope::slotGotoTag(){ EditorPage* pPage; pPage = m_pEditTabs->getCurrentPage(); if (pPage) pPage->setTagListFocus();}/** * Reports the results of the Cscope verification script. * This slot is connected to the done() signal emitted by the CscopeVerifier * object constructed in verifyCscope(). */void KScope::slotCscopeVerified(bool bResult, uint nArgs){ statusBar()->message(i18n("Verifying Cscope installation...Done"), 3000); // Mark the flag even if Cscope was not found, to avoid nagging the user // (who may wish to use KScope even with Cscope disabled) m_bCscopeVerified = true; // Prompt the user in case Cscope is not properly installed if (!bResult) { KMessageBox::error(0, i18n("Cscope may not be properly installed on " "this system.\nPlease check the Cscope path specified in KScope's " "configuration dialogue.")); slotConfigure(); return; } // Set the discoverred supported command-line arguments CscopeFrontend::setSupArgs(nArgs); // Build the database, if required if (m_bRebuildDB) { m_bRebuildDB = false; slotRebuildDB(); }}/** * Handles the "Project->Make..." menu command. * Displays the make dialogue. */void KScope::slotProjectMake(){ QString sCmd, sDir; // Create the make dialogue, if it does not exist if (m_pMakeDlg == NULL) { // Create the dialogue m_pMakeDlg = new MakeDlg(); // Set make parameters for this project m_pProjMgr->curProject()->getMakeParams(sCmd, sDir); m_pMakeDlg->setCommand(sCmd); m_pMakeDlg->setDir(sDir); // Show the relevant source location when an error link is clicked connect(m_pMakeDlg, SIGNAL(fileRequested(const QString&, uint)), this, SLOT(slotShowEditor(const QString&, uint))); // Show the dialogue m_pMakeDlg->show(); } else if (m_pMakeDlg->isShown()) { // The dialogue exists, and is visible, just raise it m_pMakeDlg->raise(); m_pMakeDlg->setActiveWindow(); } else { // The dialogue exists but is closed, show it m_pMakeDlg->show(); }}/** * Handles the "Project->Remake..." menu command. * Displays the make dialogue and runs the make command. */void KScope::slotProjectRemake(){ // Make sure the make dialogue exists and is displayed slotProjectMake(); // Run the make command m_pMakeDlg->slotMake();}/** * Handles the "Go->Global Bookmarks" menu command. * Displays a dialogue with the set of all bookmarks currently set in this * project. */void KScope::slotShowBookmarks(){ BookmarksDlg dlg; QString sPath; uint nLine; // Load the bookmark list m_pEditTabs->showBookmarks(dlg.getView()); // Show the dialogue if (dlg.exec() != QDialog::Accepted) return; // Go to the selected bookmark dlg.getBookmark(sPath, nLine); slotShowEditor(sPath, nLine);}/** * Prompts the user for a symbol to query. * Shows a dialog with a line edit widget, where the user can enter a symbol * on which to query Cscope. The meaning of the symbol depends on the type of * query. * @param nType The requested type of query (may be changed in the * dialogue) * @param sSymbol Holds the requested symbol, upon successful return * @param bPrompt If false, the user is prompted only if a symbol cannot be * determined automatically * @return true if the user hs enetered a symbol, false otherwise */bool KScope::getSymbol(uint& nType, QString& sSymbol, bool& bCase, bool bPrompt){ EditorPage* pPage; QString sSuggested; // Set the currently selected text, if any if ((pPage = m_pEditTabs->getCurrentPage()) != NULL) sSuggested = pPage->getSuggestedText(); // Return if a symbol was found, and prompting is turned off if (!sSuggested.isEmpty() && !bPrompt) { sSymbol = sSuggested; return true; } // Show the symbol dialogue sSymbol = SymbolDlg::promptSymbol(this, nType, sSuggested, bCase); // Cannot accept empty strings if (sSymbol.isEmpty()) return false; return true;}/** * Opens a file in a new editor tab. * If an editor page already exists for the requested file, it is selected. * Otherwise, a new page is created, and the requested file is loaded. * @param sFilePath The path of the file to open * @return A pointer to the found or newly created editor page */EditorPage* KScope::addEditor(const QString& sFilePath){ EditorPage* pPage; QString sAbsFilePath; ProjectBase* pProj; // If the file name is given using a relative path, we need to convert // it to an absolute one // TODO: Project needs a translatePath() method pProj = m_pProjMgr->curProject(); if (sFilePath[0] != '/' && pProj) { sAbsFilePath = QDir::cleanDirPath(pProj->getSourceRoot() + "/" + sFilePath); } else { sAbsFilePath = QDir::cleanDirPath(sFilePath); } // Do not open a new editor if one exists for this file pPage = m_pEditTabs->findEditorPage(sAbsFilePath); if (pPage != NULL) return pPage; // Create a new page pPage = createEditorPage(); // Open the requested file pPage->open(sAbsFilePath); return pPage;}/** * Creates a new editor page, and adds it to the editors tab widget. * @return A pointer to the new page */EditorPage* KScope::createEditorPage(){ KTextEditor::Document* pDoc; EditorPage* pPage; QPopupMenu* pMenu; ProjectBase* pProj; // Load a new document part pDoc = m_pEditMgr->add(); if (pDoc == NULL) return NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -