📄 kscope.cpp
字号:
/** * Handles the "Cscope->Definition..." menu command. * Prompts the user for a symbol name, and initiates a query to find the * global definition of that symbol. */void KScope::slotQueryDefinition(){ slotQuery(SymbolDlg::Definition, true);}/** * Handles the "Cscope->Called Functions..." menu command. * Prompts the user for a function name, and initiates a query to find all * function calls from that function. */void KScope::slotQueryCalled(){ slotQuery(SymbolDlg::Called, true);}/** * Handles the "Cscope->Calling Functions..." menu command. * Prompts the user for a function name, and initiates a query to find all * functions calling that function. */void KScope::slotQueryCalling(){ slotQuery(SymbolDlg::Calling, true);}/** * Handles the "Cscope->Find Text..." menu command. * Prompts the user for a string, and initiates a query to find alloccurances * of that string. */void KScope::slotQueryText(){ slotQuery(SymbolDlg::Text, true);}/** * Handles the "Cscope->Find EGrep Pattern..." menu command. * Prompts the user for a regular expression, and initiates a query to find * all strings matching that pattern. */void KScope::slotQueryPattern(){ slotQuery(SymbolDlg::Pattern, true);}/** * Handles the "Cscope->Find File..." menu command. * Prompts the user for a file name, and initiates a query to find all files * having that name. */void KScope::slotQueryFile(){ slotQuery(SymbolDlg::FileName, true);}/** * Handles the "Cscope->Find Including Files..." menu command. * Prompts the user for a file name, and initiates a query to find all files * having an '#include' directive to that file. */void KScope::slotQueryIncluding(){ slotQuery(SymbolDlg::Including, true);}/** * Handles the "Cscope->Quick Definition" menu command. * Initiates a query to find the global definition of the symbol currently * selected or under the cursor. The user is prompted only if no symbol can * be found. */void KScope::slotQueryQuickDef(){ QString sSymbol; QueryViewDlg* pDlg; uint nType; bool bCase; // Get the requested symbol and query type nType = SymbolDlg::Definition; if (!getSymbol(nType, sSymbol, bCase, false)) return; // Create a modeless query view dialogue pDlg = new QueryViewDlg(QueryViewDlg::DestroyOnSelect, this); // Display a line when it is selected in the dialogue connect(pDlg, SIGNAL(lineRequested(const QString&, uint)), this, SLOT(slotShowEditor(const QString&, uint))); // Start the query pDlg->query(nType, sSymbol);}/** * Handles the "Cscope->Call Tree..." menu command. * Displays a tree of functions calling the requested function. */void KScope::slotCallTree(){ slotQuery(SymbolDlg::CallTree, true);}/** * Handles the "Cscope->Rebuild Database..." command. * Rebuilds Cscope's database for the current project. */void KScope::slotRebuildDB(){ ProjectBase* pProj; pProj = m_pProjMgr->curProject(); if (!pProj) return; if (!pProj->dbExists()) { m_pProgressDlg = new ProgressDlg(i18n("KScope"), i18n("Please wait " "while KScope builds the database"), this); m_pProgressDlg->setAllowCancel(false); m_pProgressDlg->setValue(0); } m_pCscopeBuild->rebuild();}/** * Handles the "Settings->Configure Shortcuts..." command. * Displays the prferences dialog, which allows the user * to change the shortcuts for KScope. */void KScope::slotShortcuts(){ KKeyDialog::configure(actionCollection(), this);}/** * Handles the "Settings->Configure KScope..." command. * Displays the prferences dialog, which allows the user to set different * configuration parameters for KScope. */void KScope::slotConfigure(){ PreferencesDlg dlg; // Apply the preferences if either the "Apply" or the "OK" buttons are // clicked connect(&dlg, SIGNAL(applyPref()), this, SLOT(slotApplyPref())); // Show the dialog if (dlg.exec() == QDialog::Accepted) { // Verify Cscope's installation verifyCscope(); }}/** * Refreshes the file list when files are added to or removed from a project, * and rebuilds the Cscope database. * This slot is attached to the fileListChanged() signal emitted by * the ProjectManager object. */void KScope::slotProjectFilesChanged(){ QStringList slArgs; // Refresh the file list m_pFileList->setUpdatesEnabled(false); m_pFileList->clear(); m_pProjMgr->curProject()->loadFileList(m_pFileList); m_pFileList->setUpdatesEnabled(true); // Rebuild the symbol database if (isAutoRebuildEnabled()) slotRebuildDB();}/** * Adds a list of files to the current project. * This slot is connected to the filesAdded() signal of the ProjectManager * object. Once files are added to the project, they are also added to the * file list, and the project's database is rebuilt. * @param slFiles The list of file paths added to the project */void KScope::slotFilesAdded(const QStringList& slFiles){ QStringList::const_iterator itr; // Add the file paths to the project's file list for (itr = slFiles.begin(); itr != slFiles.end(); ++itr) m_pFileList->addItem(*itr); // Rebuild the database if (isAutoRebuildEnabled()) slotRebuildDB();}/** * Promts the user for a symbol, an starts a new Cscope query. * @param nType The numeric query type code * @param bPrompt true to always prompt for a symbol, false to try to * obtain the symbol automatically */void KScope::slotQuery(uint nType, bool bPrompt){ QString sSymbol; CallTreeDlg* pCallTreeDlg; bool bCase; // Get the requested symbol and query type if (!getSymbol(nType, sSymbol, bCase, bPrompt)) return; if (nType == SymbolDlg::CallTree) { // Create and display a call tree dialogue pCallTreeDlg = m_pCallTreeMgr->addDialog(); pCallTreeDlg->setRoot(sSymbol); pCallTreeDlg->show(); } else { // Run the requested query nType = SymbolDlg::getQueryType(nType); m_pQueryWidget->initQuery(nType, sSymbol, bCase); // Ensure Query Window is visible toggleQueryWindow(true); }}/** * Opens a project. * If another project is currently active, it is closed first. * @param sDir The directory of the project to open. */void KScope::openProject(const QString& sDir){ QString sProjDir; ProjectBase* pProj; QStringList slQueryFiles; QStringList slCallTreeFiles; QStringList slArgs; ProjectBase::Options opt; // Close the current project (may return false if the user clicks on the // "Cancel" button while prompted to save a file) if (!slotCloseProject()) return; // Open the project in the project manager sProjDir = QDir::cleanDirPath(sDir); if (!m_pProjMgr->open(sProjDir)) return; // Change main window title pProj = m_pProjMgr->curProject(); setCaption(pProj->getName()); // Set the root of the file tree m_pFileView->setRoot(pProj->getSourceRoot()); // Initialise Cscope and create a builder object initCscope(); // Set auto-completion parameters pProj->getOptions(opt); SymbolCompletion::initAutoCompletion(opt.bACEnabled, opt.nACMinChars, opt.nACDelay, opt.nACMaxEntries); // Set per-project command-line arguments for Ctags CtagsFrontend::setExtraArgs(opt.sCtagsCmd); // Create an initial query page m_pQueryWidget->addQueryPage(); // Enable project-related actions m_pActions->slotEnableProjectActions(true); // If this is a new project (i.e., no source files are yet included), // display the project files dialogue if (pProj->isEmpty()) { slotProjectFiles(); return; } // Fill the file list with all files in the project. m_pFileList->setUpdatesEnabled(false); pProj->loadFileList(m_pFileList); m_pFileList->setUpdatesEnabled(true); // Restore the last session restoreSession(); // Rebuild the cross-reference database if (isAutoRebuildEnabled()) { // If Cscope installation was not yet verified, postpone the build // process if (m_bCscopeVerified) slotRebuildDB(); else m_bRebuildDB = true; }}/** * Opens a temporary project for a Cscope.out file. * @param sFilePath The full path of the Cscope.out file * @return true if successful, false otherwise */bool KScope::openCscopeOut(const QString& sFilePath){ ProjectBase* pProj; // Close the current project (may return false if the user clicks on the // "Cancel" button while prompted to save a file) if (!slotCloseProject()) return false; // Open a temporary project for this cscope.out file if (!m_pProjMgr->openCscopeOut(sFilePath)) return false; // Change main window title pProj = m_pProjMgr->curProject(); setCaption(pProj->getName()); // Set the root folder in the file tree m_pFileView->setRoot(pProj->getSourceRoot()); // Initialise Cscope and create a builder object initCscope(); // Create an initial query page m_pQueryWidget->addQueryPage(); // Enable project-related actions m_pActions->slotEnableProjectActions(true); // Fill the file list with all files in the project. m_pFileList->setUpdatesEnabled(false); pProj->loadFileList(m_pFileList); m_pFileList->setUpdatesEnabled(true); return true;}/** * Opens the most recently used project. * This method is called when KScope starts, but only if the relevant * configuration flag (Reload Last Project) is set. */void KScope::openLastProject(){ const QStringList slProjects = Config().getRecentProjects(); QString sPath; if (slProjects.empty()) return; // Get the project's path sPath = *slProjects.begin(); // Check if the path refers to a temporary project if (!QFileInfo(sPath).isDir()) { openCscopeOut(sPath); return; } openProject(sPath);}/** * Reopens all files which were open when the project was last closed. * In order to reduce the time required by this operation, the GUI of all * but the last editor part is not merged with that of the main window. */void KScope::restoreSession(){ ProjectBase* pProj; Project::Session sess; FileLocation* pLoc; EditorPage* pPage; // A session is available for persistent projects only pProj = m_pProjMgr->curProject(); if (!pProj || pProj->isTemporary()) return; // Make sure all FileLocation objects are deleted sess.fllOpenFiles.setAutoDelete(true); sess.fllBookmarks.setAutoDelete(true); // Load the session ((Project*)pProj)->loadSession(sess); // Do not update the GUI when loading the editor parts of the initially // hidden windows m_bUpdateGUI = false; for (pLoc = sess.fllOpenFiles.first(); pLoc != NULL; pLoc = sess.fllOpenFiles.next()) { if (QFile::exists(pLoc->m_sPath)) { pPage = addEditor(pLoc->m_sPath); pPage->setCursorPos(pLoc->m_nLine, pLoc->m_nCol); } } // Merge the GUI of the visible editor part m_bUpdateGUI = true; // Set the active editor (or choose a default one) if (m_pEditTabs->findEditorPage(sess.sLastFile, true) == NULL) m_pEditTabs->findEditorPage(sess.fllOpenFiles.last()->m_sPath, true); // Reload bookmarks m_pEditTabs->setBookmarks(sess.fllBookmarks); // Load previously stored queries and call trees m_pQueryWidget->loadPages(pProj->getPath(), sess.slQueryFiles); m_pCallTreeMgr->loadOpenDialogs(pProj->getPath(), sess.slCallTreeFiles);}/** * Shows or hides the query dock window. * This function is only called internally, not as a result of a user's * workspace action (e.g., clicking the "Show/Hide Query Window" toolbar * button). Therefore it does not reflect the user's preference, which is * kept through the m_bHideQueryOnSelection variable. * @param bShow true to show the window, false to hide it */void KScope::toggleQueryWindow(bool bShow){ // Remember the user's preferences if (bShow) m_bHideQueryOnSelection = m_pQueryDock->isHidden();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -