📄 kscope.cpp
字号:
/** * 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();}/** * 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 bPrompt){ EditorPage* pPage; QString sSuggested; QStringList slSymHistory; // 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; } // Get the list of previously requested symbols m_pProjMgr->getSymHistory(slSymHistory); // Show the symbol dialogue sSymbol = SymbolDlg::promptSymbol(this, nType, sSuggested, slSymHistory); // Cannot accept empty strings if (sSymbol.isEmpty()) return false; // Update the symbol history list from the dialog m_pProjMgr->setSymHistory(slSymHistory); 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; // If the file name is given using a relative path, we need to convert // it to an absolute one if (sFilePath[0] != '/') { sAbsFilePath = QDir::cleanDirPath(m_pProjMgr->getPath() + "/" + 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; // Load a new document part pDoc = m_pEditMgr->add(); if (pDoc == NULL) return NULL; // 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&)), this, SLOT(slotSetRebuildTimer(const QString&))); // Handle file drops connect(pPage->getView(), SIGNAL(dropEventPass(QDropEvent*)), this, SLOT(slotDropEvent(QDropEvent*))); return pPage;} /** * @return true if database auto-rebuild is enabled for the current project, * false otherwise */inline bool KScope::isAutoRebuildEnabled(){ return (m_pProjMgr->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->getName() + " - " + m_sCurFilePath); }}/** * 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; 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(){ QStringList slFiles; QStringList::Iterator itr; // Prompt the user for the file(s) to open. slFiles = KFileDialog::getOpenFileNames(); // 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("Building cross reference database...") + " " + QString::number((nFiles * 100) / nTotal) + "%"; statusBar()->message(sMsg);}/** * 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("Building cross reference database...Done!"), 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_pExtEditAction->setEnabled(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->getName() + " - " + 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 */void KScope::slotSetRebuildTimer(const QString& sPath){ int nTime; // Get the project's auto-rebuild time nTime = m_pProjMgr->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);}/** * Sets a new file tree root for the current project. * This slot is connected to the rootChanged() signal of the FileView object. * @param sRoot The full path of the directory to serve as the new root */void KScope::slotProjectRootChanged(const QString& sRoot){ m_pProjMgr->setRoot(sRoot);}/** * 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());}/** * Ensures the "Show/Hide Query Window" action is unchecked when the dock * is closed through its close button. * This slot is conncted to the headerCloseButtonClicked() signal of the * query window dock widget. */void KScope::slotQueryDockClosed(){ m_pToggleQueryWindowAction->setChecked(false);}/** * Ensures the "Show/Hide File View" action is unchecked when the dock * is closed through its close button. * This slot is conncted to the headerCloseButtonClicked() signal of the * file view dock widget. */void KScope::slotFileViewDockClosed(){ m_pToggleFileViewAction->setChecked(false);}#include "kscope.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -