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

📄 kscope.cpp

📁 This a source insight software in Linux. It s is similar to the source insight software for windows.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*************************************************************************** * * 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 <kaction.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 "welcomedlg.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){	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	initActions();		// 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()));		// Refresh the file list if files were added to or removed from a project	connect(m_pProjMgr, SIGNAL(fileListChanged()), this,		SLOT(slotProjectFilesChanged()));	// Add files to the file list when they are added to the project	connect(m_pProjMgr, SIGNAL(filesAdded(const QStringList&)), this,		SLOT(slotFilesAdded(const QStringList&)));	// Store the new file tree root of a project	connect(m_pFileView, SIGNAL(rootChanged(const QString&)), this,		SLOT(slotProjectRootChanged(const QString&)));		// Launch a "Find File" query when the "Find File..." button of the	// file tree is clicked	connect(m_pFileView, SIGNAL(findFile()), this, 		SLOT(slotQueryFile()));	// 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;}/** * Connects menu bar and toolbar commands with class members. These members * handle the actions associated with each command. */void KScope::initActions(){	KToggleAction* pLockAction;		// File menu	KStdAction::openNew(this, SLOT(slotNewFile()), actionCollection());	KStdAction::open(this, SLOT(slotOpenFile()), actionCollection());	KStdAction::close(this, SLOT(slotCloseEditor()), actionCollection());	KStdAction::quit(this, SLOT(slotClose()), actionCollection());	(void)new KAction(i18n("Go to File List"), KShortcut("Ctrl+Shift+O"),		m_pFileList, SLOT(slotSetFocus()), actionCollection(),		"file_open_file_from_list");	(void)new KAction(i18n("Save Al&l"), 		"save_all",	KShortcut("Ctrl+L"), m_pEditTabs, SLOT(slotSaveAll()),		actionCollection(), "file_save_all");		// Edit menu	m_pExtEditAction = new KAction(i18n("Edit in E&xternal Editor"),		KShortcut("Ctrl+E"), this,		SLOT(slotExtEdit()), actionCollection(), "edit_external_editor");	(void)new KAction(i18n("Complete Symbol"), KShortcut("Ctrl+Space"), this,		SLOT(slotCompleteSymbol()), actionCollection(), "edit_comp_symbol");			// Project menu	(void)new KAction(i18n("&New Project..."), 0, this, 		SLOT(slotCreateProject()), actionCollection(), "project_new");	(void)new KAction(i18n("&Open Project..."), "project_open", 0, this,		SLOT(slotOpenProject()), actionCollection(), "project_open");	(void)new KAction(i18n("Add/Remove &Files..."), 0, this,		SLOT(slotProjectFiles()), actionCollection(),		"project_add_rem_files");	(void)new KAction(i18n("&Properties..."), 0, this,		SLOT(slotProjectProps()), actionCollection(),		"project_properties");	(void)new KAction(i18n("Open &Cscope.out..."), 0, this,		SLOT(slotProjectCscopeOut()), actionCollection(),		"project_cscope_out");	(void)new KAction(i18n("&Close Project"), 0, this,		SLOT(slotCloseProject()), actionCollection(), "project_close");	// Cscope menu	(void)new KAction(i18n("&References..."), KShortcut("Ctrl+0"), this,		SLOT(slotQueryReference()), actionCollection(), "cscope_references");	(void)new KAction(i18n("&Definition..."), 0, KShortcut("Ctrl+1"), this,		SLOT(slotQueryDefinition()), actionCollection(), "cscope_definition");	(void)new KAction(i18n("&Called Functions..."), 0, KShortcut("Ctrl+2"),		this, SLOT(slotQueryCalled()), actionCollection(), "cscope_called");	(void)new KAction(i18n("C&alling Functions..."), 0, KShortcut("Ctrl+3"),		this, SLOT(slotQueryCalling()),	actionCollection(), "cscope_calling");	(void)new KAction(i18n("Find &Text..."), 0, KShortcut("Ctrl+4"), this,		SLOT(slotQueryText()), actionCollection(), "cscope_text");	(void)new KAction(i18n("Find &EGrep Pattern..."), 0, KShortcut("Ctrl+5"),		this, SLOT(slotQueryPattern()), actionCollection(), "cscope_pattern");	(void)new KAction(i18n("Find &File..."), 0, KShortcut("Ctrl+7"), this,		SLOT(slotQueryFile()), actionCollection(), "cscope_file");	(void)new KAction(i18n("&Including Files..."), 0, KShortcut("Ctrl+8"),		this, SLOT(slotQueryIncluding()), actionCollection(),		"cscope_including");	(void)new KAction(i18n("&Quick Definition"), 0, KShortcut("Ctrl+]"), this,		SLOT(slotQueryQuickDef()), actionCollection(), "cscope_quick_def");	(void)new KAction(i18n("Call &Graph..."), 0, KShortcut("Ctrl+\\"), this,		SLOT(slotCallTree()), actionCollection(), "cscope_call_tree");	(void)new KAction(i18n("Re&build database"), "reload", 0, this,		SLOT(slotRebuildDB()), actionCollection(),		"cscope_rebuild");	// Go menu	(void)new KAction(i18n("P&revious Result"), "up", 		KShortcut(QKeySequence(ALT + Key_Up)), m_pQueryWidget,		SLOT(slotPrevResult()), actionCollection(), "go_prev_result");	(void)new KAction(i18n("N&ext Result"), "down", 		KShortcut(QKeySequence(ALT + Key_Down)), m_pQueryWidget,		SLOT(slotNextResult()), actionCollection(),		"go_next_result");	(void)new KAction(i18n("&Previous Position"), "previous", 		KShortcut(QKeySequence(ALT + Key_Left)), m_pQueryWidget,		SLOT(slotHistoryPrev()), actionCollection(), "go_prev_pos");	(void)new KAction(i18n("&Next Position"), "next", 		KShortcut(QKeySequence(ALT + Key_Right)), m_pQueryWidget,		SLOT(slotHistoryNext()), actionCollection(),		"go_next_pos");	(void)new KAction(i18n("Position &History"), 0, KShortcut("Ctrl+h"),		this, SLOT(slotHistoryShow()), actionCollection(),		"go_history");	// View menu	m_pToggleFileViewAction = new KToggleAction(i18n("Show/Hide File List"),		"view_sidetree", KShortcut("Ctrl+/"), m_pFileViewDock,		SLOT(changeHideShowState()), actionCollection(),		"view_toggle_filelist_dock");	m_pToggleQueryWindowAction = new KToggleAction(		i18n("Show/Hide Query Window"), "view_top_bottom",		KShortcut("Ctrl+."), m_pQueryDock, SLOT(changeHideShowState()),		actionCollection(), "view_toggle_query_dock");	m_pToggleTagListAction = new KToggleAction(i18n("Show/Hide Tag List"),		"view_detailed", KShortcut("Ctrl+'"), m_pEditTabs,		SLOT(slotToggleTagList()), actionCollection(),		"view_toggle_tag_list");		// Window menu	(void)new KAction(i18n("Close &All Windows..."), 0, 0, this,		SLOT(slotCloseAllWindows()), actionCollection(), "window_close_all");			// Settings menu	KStdAction::preferences(this, SLOT(slotConfigure()), actionCollection());	KStdAction::keyBindings(this, SLOT(slotShortcuts()), actionCollection());		// Help menu	(void)new KAction(i18n("Show &Welcome Message..."), 0, 0, this,		SLOT(slotShowWelcome()), actionCollection(), "help_welcome");		// Query widget popup menu	(void)new KAction(i18n("&New"), "filenew", 0, m_pQueryWidget,		SLOT(slotNewQueryPage()), actionCollection(), "query_new");	(void)new KAction(i18n("&Refresh"), "reload", 0, m_pQueryWidget,		SLOT(slotRefreshCurrent()), actionCollection(), "query_refresh");	pLockAction = new KToggleAction(i18n("&Lock/Unlock"), "encrypted", 0,		m_pQueryWidget, SLOT(slotLockCurrent()), actionCollection(),		"query_toggle_locked");	(void)new KAction(i18n("&Close"), "fileclose", 0, m_pQueryWidget,		SLOT(slotCloseCurrent()), actionCollection(), "query_close");		m_pExtEditAction->setEnabled(Config().useExtEditor());		// Show a toolbar show/hide menu	setStandardToolBarMenuEnabled(true);		// Create the initial GUI (no active part)	setXMLFile("kscopeui.rc");	createShellGUI();	// Associate the "Window" menu with the editor tabs widdget	m_pEditTabs->setWindowMenu((QPopupMenu*)factory()->container("window",		this));	// Associate the "Query" popup menu with the query widget	m_pQueryWidget->setPageMenu((QPopupMenu*)factory()->container(		"query_popup", this), pLockAction);}/** * Positions child widgets into their docking stations, and performs some * other main window initialisation. */void KScope::initMainWindow(){	KStatusBar* pStatus;	KDockWidget* pMainDock;	// 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()), this,		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()), this,		SLOT(slotFileViewDockClosed()));		// Restore dock configuration	Config().loadWorkspace(this);	m_bHideQueryOnSelection = m_pQueryDock->isHidden();	m_pToggleFileViewAction->setChecked(m_pFileViewDock->isShown());	m_pToggleQueryWindowAction->setChecked(m_pQueryDock->isShown());	m_pToggleTagListAction->setChecked(Config().getShowTagList());}/** * 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 true;}/** * 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);	ProjectManager::Options opt;	// Prompt the user to close any active projects	if (m_pProjMgr->isOpen()) {		KMessageBox::error(0, i18n("Please close the active project before"			" creating a new one"));		return;	}		// Display the "New Project" dialog	if (dlg.exec() != QDialog::Accepted)		return;	// Create the new project	dlg.getOptions(opt);	m_pProjMgr->create(dlg.getName(), dlg.getPath(), opt);	// Open the project	openProject(dlg.getPath() + "/" + dlg.getName());}/** * Handles the "Project->Open..." command. * Prompts the user for a project file ("cscope.proj"), and opens the * selected project. */void KScope::slotOpenProject(){	OpenProjectDlg dlg;	if (dlg.exec() == QDialog::Rejected)		return;	openProject(dlg.m_pPathEdit->text());}/** * 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(){	// A project must be open	if (!m_pProjMgr->isOpen())		return;	// Display the files dialog	ProjectFilesDlg dlg(m_pProjMgr, this);	if (dlg.exec() == QDialog::Accepted)		m_pProjMgr->writeList(&dlg);}/** * 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(){	ProjectManager::Options opt;		// A project must be open	if (!m_pProjMgr->isOpen())		return;	// No properties for a temporary project	if (m_pProjMgr->isTemporary()) {		KMessageBox::error(0, i18n("The Project Properties dialogue is not "			"available for temporary projects."));		return;	}		// Create the properties dialog	NewProjectDlg dlg(false, this);	m_pProjMgr->getOptions(opt);	dlg.setProperties(m_pProjMgr->getName(), m_pProjMgr->getPath(), opt);		// Display the properties dialog	if (dlg.exec() != QDialog::Accepted)		return;	// Set new properties	dlg.getOptions(opt);	m_pProjMgr->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);}/** * 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.

⌨️ 快捷键说明

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