📄 kscope.cpp
字号:
/*************************************************************************** * * Copyright (C) 2005 Elad Lahav (elad_lahav@users.sourceforge.net) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ***************************************************************************/#include <qfile.h>#include <kfiledialog.h>#include <kmenubar.h>#include <klocale.h>#include <kmessagebox.h>#include <klineedit.h>#include <kinputdialog.h>#include <kxmlguifactory.h>#include <kstatusbar.h>#include <kurldrag.h>#include <kkeydialog.h>#include "kscope.h"#include "kscopeconfig.h"#include "projectmanager.h"#include "editortabs.h"#include "fileview.h"#include "filelist.h"#include "querywidget.h"#include "editormanager.h"#include "cscopefrontend.h"#include "ctagslist.h"#include "newprojectdlg.h"#include "openprojectdlg.h"#include "preferencesdlg.h"#include "dirscanner.h"#include "querypage.h"#include "calltreedlg.h"#include "calltreemanager.h"#include "kscopepixmaps.h"#include "progressdlg.h"#include "projectfilesdlg.h"#include "cscopemsgdlg.h"#include "symboldlg.h"#include "symbolcompletion.h"#include "queryviewdlg.h"#include "graphwidget.h"#include "makedlg.h"#include "welcomedlg.h"#include "bookmarksdlg.h"#include "kscopeactions.h"/** * Class constructor. * @param pParent The parent widget * @param szName The widget's name */KScope::KScope(QWidget* pParent, const char* szName) : KParts::DockMainWindow(pParent, szName), m_pCscopeBuild(NULL), m_sCurFilePath(""), m_nCurLine(0), m_pProgressDlg(NULL), m_bUpdateGUI(true), m_bCscopeVerified(false), m_bRebuildDB(false), m_pMakeDlg(NULL){ QString sPath; // Load configuration Config().load(); // Create the main child widgets m_pEditTabs = new EditorTabs(this, NULL); m_pQueryWidget = new QueryWidget(this); m_pFileView = new FileView(this); m_pFileList = m_pFileView->getFileList(); m_pMsgDlg = new CscopeMsgDlg(this); m_pQueryDock = createDockWidget("Query Window", QPixmap()); m_pFileViewDock = createDockWidget("File List Window", QPixmap()); // Connect menu and toolbar items with the object's slots m_pActions = new KScopeActions(this); m_pActions->init(); m_pActions->slotEnableProjectActions(false); // Show a toolbar show/hide menu setStandardToolBarMenuEnabled(true); // Create the initial GUI (no active part) setXMLFile("kscopeui.rc"); createShellGUI(); // Create all child widgets initMainWindow(); // Create control objects m_pProjMgr = new ProjectManager(); m_pEditMgr = new EditorManager(this); m_pCallTreeMgr = new CallTreeManager(this); // Initialise the icon manager Pixmaps().init(); // Open a file for editing when selected in the project's file list or the // file tree connect(m_pFileView, SIGNAL(fileRequested(const QString&, uint)), this, SLOT(slotShowEditor(const QString&, uint))); // Delete an editor page object after it is removed connect(m_pEditTabs, SIGNAL(editorRemoved(EditorPage*)), this, SLOT(slotDeleteEditor(EditorPage*))); connect(m_pEditTabs, SIGNAL(filesDropped(QDropEvent*)), this, SLOT(slotDropEvent(QDropEvent*))); // Set an editor as the active part whenever its owner tab is selected connect(m_pEditTabs, SIGNAL(editorChanged(EditorPage*, EditorPage*)), this, SLOT(slotChangeEditor(EditorPage*, EditorPage*))); // Display a file at a specific line when selected in a query list connect(m_pQueryWidget, SIGNAL(lineRequested(const QString&, uint)), this, SLOT(slotQueryShowEditor(const QString&, uint))); // Display the symbol dialogue when the user opens a new query page connect(m_pQueryWidget, SIGNAL(newQuery()), this, SLOT(slotQueryReference())); // Rebuild the project database after a certain time period has elapsed // since the last save connect(&m_timerRebuild, SIGNAL(timeout()), this, SLOT(slotRebuildDB())); // Display a file at a specific line when selected in a call tree dialogue connect(m_pCallTreeMgr, SIGNAL(lineRequested(const QString&, uint)), this, SLOT(slotQueryShowEditor(const QString&, uint))); // Store main window settings when closed setAutoSaveSettings(); // Initialise arrow head drawing GraphWidget::setArrowInfo(20, 15); // Use a maximised window the first time if (Config().isFirstTime()) showMaximized(); // Show the Welcome message if (Config().showWelcomeDlg()) { show(); slotShowWelcome(); } // If this is the first time the user has launched KScope, prompt him/her // to configure the global parameters if (Config().isFirstTime()) slotConfigure(); }/** * Class destructor. */KScope::~KScope(){ // Save configuration Config().store(); Config().storeWorkspace(this); delete m_pCallTreeMgr; delete m_pEditMgr; delete m_pCscopeBuild; delete m_pProjMgr; if (m_pMakeDlg != NULL) delete m_pMakeDlg;}/** * Positions child widgets into their docking stations, and performs some * other main window initialisation. */void KScope::initMainWindow(){ KStatusBar* pStatus; KDockWidget* pMainDock; QPopupMenu* pPopup; // Create the status bar pStatus = statusBar(); pStatus->insertItem(i18n(" Line: N/A Col: N/A "), 0, 0, true); // Create the main dock for the editor tabs widget pMainDock = createDockWidget("Editors Window", QPixmap()); pMainDock->setWidget(m_pEditTabs); pMainDock->setDockSite(KDockWidget::DockCorner); setMainDockWidget(pMainDock); setView(pMainDock); pMainDock->setEnableDocking(KDockWidget::DockNone); // Create the query window dock m_pQueryDock->setWidget(m_pQueryWidget); m_pQueryDock->manualDock(pMainDock, KDockWidget::DockBottom, 65); // Update the relevant shell action when the dock is hidden through its // close button connect(m_pQueryDock, SIGNAL(headerCloseButtonClicked()), m_pActions, SLOT(slotQueryDockClosed())); // Create the file view dock m_pFileViewDock->setWidget(m_pFileView); m_pFileViewDock->manualDock(pMainDock, KDockWidget::DockRight, 80); // Update the relevant shell action when the dock is hidden through its // close button connect(m_pFileViewDock, SIGNAL(headerCloseButtonClicked()), m_pActions, SLOT(slotFileViewDockClosed())); // Associate the "Window" menu with the editor tabs widdget pPopup = (QPopupMenu*)factory()->container("window", this); m_pEditTabs->setWindowMenu(pPopup); // Associate the "Query" popup menu with the query widget pPopup = (QPopupMenu*)factory()->container("query_popup", this); m_pQueryWidget->setPageMenu(pPopup, m_pActions->getLockAction()); // Restore dock configuration Config().loadWorkspace(this); m_bHideQueryOnSelection = m_pQueryDock->isHidden(); m_pActions->initLayoutActions();}/** * Handles the "File->Quit" command. Closes the main window, which terminates * the application. */void KScope::slotClose(){ // Destroy the main window KParts::DockMainWindow::close();}/** * Called when a request has been issued to close the main window. * Tries to close the active project. * @return true if the main window can be closed, false otherwise */bool KScope::queryClose(){ bool bResult; m_bUpdateGUI = false; bResult = slotCloseProject(); m_bUpdateGUI = true; return bResult;}/** * Handles the "Project->New..." command. * Prompts the user for the name and folder for the project, and then creates * the project. */void KScope::slotCreateProject(){ NewProjectDlg dlg(true, this); ProjectBase::Options opt; QString sProjPath; // Prompt the user to close any active projects if (m_pProjMgr->curProject()) { if (KMessageBox::questionYesNo(0, i18n("The current project needs to be closed before a new one is" " created.\nWould you like to close it now?")) != KMessageBox::Yes) { return; } // Try to close the project. if (!slotCloseProject()) return; } // Display the "New Project" dialog if (dlg.exec() != QDialog::Accepted) return; // Create and open the new project dlg.getOptions(opt); if (m_pProjMgr->create(dlg.getName(), dlg.getPath(), opt, sProjPath)) openProject(sProjPath);}/** * Handles the "Project->Open..." command. * Prompts the user for a project file ("cscope.proj"), and opens the * selected project. */void KScope::slotOpenProject(){ OpenProjectDlg dlg; QString sPath; if (dlg.exec() == QDialog::Rejected) return; sPath = dlg.getPath(); // Check if the path refers to a permanent or temporary project if (QFileInfo(sPath).isDir()) openProject(sPath); else openCscopeOut(sPath);}/** * Handles the "Project->Add/Remove Files..." command. * Opens the project's files dialog, which allows the user to add and remove * source files. */void KScope::slotProjectFiles(){ ProjectBase* pProj; // A project must be open pProj = m_pProjMgr->curProject(); if (!pProj) return; // Cannot update the file list of a temporary project if (pProj->isTemporary()) { KMessageBox::error(0, i18n("The Add/Remove Files dialogue is not " "available for temporary projects.")); return; } // Display the files dialog ProjectFilesDlg dlg((Project*)pProj, this); if (dlg.exec() != QDialog::Accepted) return; // Update the project's file list if (pProj->storeFileList(&dlg)) slotProjectFilesChanged();}/** * Handles the "Project->Properties..." command. * Opens the project's properties dialog, which allows the user to change * some attributes of the current project. * source files. */void KScope::slotProjectProps(){ ProjectBase* pProj; ProjectBase::Options opt; // A project must be open pProj = m_pProjMgr->curProject(); if (!pProj) return; // No properties for a temporary project if (pProj->isTemporary()) { KMessageBox::error(0, i18n("The Project Properties dialogue is not " "available for temporary projects.")); return; } // Create the properties dialog NewProjectDlg dlg(false, this); pProj->getOptions(opt); dlg.setProperties(pProj->getName(), pProj->getPath(), opt); // Display the properties dialog if (dlg.exec() != QDialog::Accepted) return; // Set new properties dlg.getOptions(opt); pProj->setOptions(opt); // Reset the CscopeFrontend class and the builder object initCscope(); // Set auto-completion parameters SymbolCompletion::initAutoCompletion(opt.bACEnabled, opt.nACMinChars, opt.nACDelay, opt.nACMaxEntries); // Set per-project command-line arguments for Ctags CtagsFrontend::setExtraArgs(opt.sCtagsCmd); // Set the source root m_pFileView->setRoot(pProj->getSourceRoot());}/** * Handles the "Cscope->Open Cscope.out..." menu command. * Prompts the user for a Cscope.out file, and, if successful, opens a new * session for working with this file. */void KScope::slotProjectCscopeOut(){ QString sFilePath; // Prompt for a Cscope.out file sFilePath = KFileDialog::getOpenFileName(); if (sFilePath.isEmpty()) return; // Open a temporary project openCscopeOut(sFilePath); }/** * Handles the "Cscope->References..." menu command. * Prompts the user for a symbol name, and initiates a query to find all * references to that symbol. */void KScope::slotQueryReference(){ slotQuery(SymbolDlg::Reference, true);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -