diff --git a/plugins/classbrowser/CMakeLists.txt b/plugins/classbrowser/CMakeLists.txt index 0cecc121f8..951fa13fbc 100644 --- a/plugins/classbrowser/CMakeLists.txt +++ b/plugins/classbrowser/CMakeLists.txt @@ -1,38 +1,39 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ) # workaround a boost bug in 1.37 and 1.38 that causes link failure when exceptions are disabled # see https://svn.boost.org/trac/boost/ticket/2947 for details if( ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_PATCH_VERSION} VERSION_GREATER 1.36.1 ) add_definitions( ${KDE4_ENABLE_EXCEPTIONS} ) endif( ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_PATCH_VERSION} VERSION_GREATER 1.36.1 ) add_definitions( -DKDE_DEFAULT_DEBUG_AREA=9512 ) ########### next target ############### set(kdevclassbrowser_PART_SRCS classbrowserplugin.cpp classmodel.cpp classmodelnode.cpp classmodelnodescontroller.cpp + classwidget.cpp classtree.cpp documentclassesfolder.cpp projectfolder.cpp allclassesfolder.cpp ) kde4_add_plugin(kdevclassbrowser ${kdevclassbrowser_PART_SRCS}) target_link_libraries(kdevclassbrowser ${KDE4_KDEUI_LIBS} ${KDE4_KTEXTEDITOR_LIBS} kdevplatformlanguage kdevplatforminterfaces kdevplatformproject) install(TARGETS kdevclassbrowser DESTINATION ${PLUGIN_INSTALL_DIR}) ########### install files ############### install(FILES kdevclassbrowser.desktop DESTINATION ${SERVICES_INSTALL_DIR}) install(FILES kdevclassbrowser.rc DESTINATION ${DATA_INSTALL_DIR}/kdevclassbrowser) diff --git a/plugins/classbrowser/classbrowserplugin.cpp b/plugins/classbrowser/classbrowserplugin.cpp index 9bf1ca627f..84900baf83 100644 --- a/plugins/classbrowser/classbrowserplugin.cpp +++ b/plugins/classbrowser/classbrowserplugin.cpp @@ -1,264 +1,265 @@ /* * This file is part of KDevelop * * Copyright 2006 Adam Treat * Copyright 2006-2008 Hamish Rodda * Copyright 2009 Lior Mualem * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "classbrowserplugin.h" #include #include #include #include #include #include "interfaces/icore.h" #include "interfaces/iuicontroller.h" #include "interfaces/idocumentcontroller.h" #include "interfaces/contextmenuextension.h" #include "language/interfaces/codecontext.h" #include "language/duchain/duchainbase.h" #include "language/duchain/duchain.h" #include "language/duchain/duchainlock.h" #include "language/duchain/declaration.h" #include "language/duchain/indexedstring.h" #include "classmodel.h" #include "classtree.h" +#include "classwidget.h" #include #include #include #include #include #include K_PLUGIN_FACTORY(KDevClassBrowserFactory, registerPlugin(); ) K_EXPORT_PLUGIN(KDevClassBrowserFactory(KAboutData("kdevclassbrowser","kdevclassbrowser",ki18n("Class Browser"), "0.1", ki18n("Browser for all known classes"), KAboutData::License_GPL))) using namespace KDevelop; class ClassBrowserFactory: public KDevelop::IToolViewFactory { public: ClassBrowserFactory(ClassBrowserPlugin *plugin): m_plugin(plugin) {} virtual QWidget* create(QWidget *parent = 0) { return new ClassWidget(parent, m_plugin); } virtual Qt::DockWidgetArea defaultPosition() { return Qt::LeftDockWidgetArea; } virtual QString id() const { return "org.kdevelop.ClassBrowserView"; } private: ClassBrowserPlugin *m_plugin; }; ClassBrowserPlugin::ClassBrowserPlugin(QObject *parent, const QVariantList&) : KDevelop::IPlugin(KDevClassBrowserFactory::componentData(), parent) , m_factory(new ClassBrowserFactory(this)) , m_activeClassTree(0) { core()->uiController()->addToolView(i18n("Classes"), m_factory); setXMLFile( "kdevclassbrowser.rc" ); m_findInBrowser = new QAction(i18n("Find in &Class Browser"), this); connect(m_findInBrowser, SIGNAL(triggered(bool)), this, SLOT(findInClassBrowser())); m_openDec = new QAction(i18n("Show &Declaration"), this); connect(m_openDec, SIGNAL(triggered(bool)), this, SLOT(openDeclaration())); m_openDef = new QAction(i18n("Show De&finition"), this); connect(m_openDef, SIGNAL(triggered(bool)), this, SLOT(openDefinition())); } ClassBrowserPlugin::~ClassBrowserPlugin() { } void ClassBrowserPlugin::unload() { core()->uiController()->removeToolView(m_factory); } KDevelop::ContextMenuExtension ClassBrowserPlugin::contextMenuExtension( KDevelop::Context* context) { KDevelop::ContextMenuExtension menuExt = KDevelop::IPlugin::contextMenuExtension( context ); // No context menu if we don't have a class browser at hand. if ( m_activeClassTree == 0 ) return menuExt; KDevelop::DeclarationContext *codeContext = dynamic_cast(context); if (!codeContext) return menuExt; DUChainReadLocker readLock(DUChain::lock()); Declaration* decl(codeContext->declaration().data()); if (decl) { if(decl->inSymbolTable()) { if(!ClassTree::populatingClassBrowserContextMenu() && ICore::self()->projectController()->findProjectForUrl(decl->url().toUrl()) && decl->kind() == Declaration::Type && decl->internalContext() && decl->internalContext()->type() == DUContext::Class) { //Currently "Find in Class Browser" seems to only work for classes, so only show it in that case m_findInBrowser->setData(QVariant::fromValue(DUChainBasePointer(decl))); menuExt.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, m_findInBrowser); } m_openDec->setData(QVariant::fromValue(DUChainBasePointer(decl))); menuExt.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, m_openDec); if(FunctionDefinition::definition(decl)) { m_openDef->setData(QVariant::fromValue(DUChainBasePointer(decl))); menuExt.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, m_openDef); } } } return menuExt; } void ClassBrowserPlugin::findInClassBrowser() { ICore::self()->uiController()->findToolView(i18n("Classes"), m_factory, KDevelop::IUiController::CreateAndRaise); Q_ASSERT(qobject_cast(sender())); if ( m_activeClassTree == 0 ) return; DUChainReadLocker readLock(DUChain::lock()); QAction* a = static_cast(sender()); Q_ASSERT(a->data().canConvert()); DeclarationPointer decl = qvariant_cast(a->data()).dynamicCast(); if (decl) m_activeClassTree->highlightIdentifier(decl->qualifiedIdentifier()); } template static DestClass* getBestDeclaration(Declaration* a_decl) { if ( a_decl == 0 ) return 0; uint declarationCount = 0; const IndexedDeclaration* declarations = 0; PersistentSymbolTable::self().declarations( a_decl->qualifiedIdentifier(), declarationCount, declarations ); for ( uint i = 0; i < declarationCount; ++i ) { // See if this declaration matches and return it. DestClass* decl = dynamic_cast(declarations[i].declaration()); if ( decl && !decl->isForwardDeclaration() ) { return decl; } } return 0; } void ClassBrowserPlugin::openDeclaration() { Q_ASSERT(qobject_cast(sender())); DUChainReadLocker readLock(DUChain::lock()); QAction* a = static_cast(sender()); Q_ASSERT(a->data().canConvert()); DeclarationPointer declPtr = qvariant_cast(a->data()).dynamicCast(); Declaration* bestDeclaration = getBestDeclaration(declPtr.data()); // If it's a function, find the function definition to go to the actual declaration. if ( bestDeclaration && bestDeclaration->isFunctionDeclaration() ) { FunctionDefinition* funcDefinition = dynamic_cast(bestDeclaration); if ( funcDefinition == 0 ) funcDefinition = FunctionDefinition::definition(bestDeclaration); if ( funcDefinition && funcDefinition->declaration() ) bestDeclaration = funcDefinition->declaration(); } if (bestDeclaration) { KUrl url(bestDeclaration->url().str()); KTextEditor::Range range = bestDeclaration->range().textRange(); readLock.unlock(); ICore::self()->documentController()->openDocument(url, range.start()); } } void ClassBrowserPlugin::openDefinition() { Q_ASSERT(qobject_cast(sender())); DUChainReadLocker readLock(DUChain::lock()); QAction* a = static_cast(sender()); Q_ASSERT(a->data().canConvert()); DeclarationPointer declPtr = qvariant_cast(a->data()).dynamicCast(); Declaration* bestDeclaration = getBestDeclaration(declPtr.data()); // If it's a function, find the function definition to go to the actual declaration. if ( bestDeclaration && bestDeclaration->isFunctionDeclaration() ) { FunctionDefinition* funcDefinition = dynamic_cast(bestDeclaration); if ( funcDefinition == 0 ) funcDefinition = FunctionDefinition::definition(bestDeclaration); if ( funcDefinition ) bestDeclaration = funcDefinition; } if (bestDeclaration) { KUrl url(bestDeclaration->url().str()); KTextEditor::Range range = bestDeclaration->range().textRange(); readLock.unlock(); ICore::self()->documentController()->openDocument(url, range.start()); } } #include "classbrowserplugin.moc" // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on diff --git a/plugins/classbrowser/classtree.cpp b/plugins/classbrowser/classtree.cpp index 7e344093fb..edaf7dbadf 100644 --- a/plugins/classbrowser/classtree.cpp +++ b/plugins/classbrowser/classtree.cpp @@ -1,210 +1,140 @@ /* * KDevelop Class viewer * * Copyright 2006 Adam Treat * Copyright (c) 2006-2007 Hamish Rodda * Copyright 2009 Lior Mualem * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "classtree.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include +#include +#include +#include #include "interfaces/contextmenuextension.h" #include "interfaces/icore.h" #include "interfaces/idocumentcontroller.h" #include "interfaces/idocument.h" #include "interfaces/iplugincontroller.h" #include "language/interfaces/codecontext.h" #include "language/duchain/duchainbase.h" #include "language/duchain/duchain.h" #include "language/duchain/duchainlock.h" #include "language/duchain/declaration.h" #include "language/duchain/indexedstring.h" #include "classmodel.h" #include "classbrowserplugin.h" using namespace KDevelop; - -ClassWidget::ClassWidget(QWidget* parent, ClassBrowserPlugin* plugin) - : QWidget(parent) - , m_plugin(plugin) - , m_model(new ClassModel()) - , m_tree(new ClassTree(this, plugin)) - , m_searchLine(new KLineEdit(this)) -{ - setObjectName("Class Browser Tree"); - setWindowTitle(i18n("Classes")); - setWindowIcon(SmallIcon("code-class")); - - // Set tree in the plugin - m_plugin->setActiveClassTree(m_tree); - - // Set model in the tree view - m_tree->setModel(m_model); - - // We need notification in the model for the collapse/expansion of nodes. - connect(m_tree, SIGNAL(collapsed(const QModelIndex&)), - m_model, SLOT(collapsed(const QModelIndex&))); - connect(m_tree, SIGNAL(expanded(const QModelIndex&)), - m_model, SLOT(expanded(const QModelIndex&))); - - // Init search box - m_searchLine->setClearButtonShown( true ); - connect(m_searchLine, SIGNAL(textChanged(QString)), m_model, SLOT(updateFilterString(QString))); - QLabel *searchLabel = new QLabel( i18n("S&earch:"), this ); - searchLabel->setBuddy( m_searchLine ); - - QHBoxLayout* layout = new QHBoxLayout(); - layout->setSpacing( 5 ); - layout->setMargin( 0 ); - layout->addWidget(searchLabel); - layout->addWidget(m_searchLine); - - setFocusProxy( m_searchLine ); - - QVBoxLayout* vbox = new QVBoxLayout(this); - vbox->setMargin(0); - vbox->addLayout(layout); - vbox->addWidget(m_tree); - setLayout( vbox ); - - setWhatsThis( i18n( "Class Browser" ) ); -} - -ClassWidget::~ClassWidget() -{ - delete m_model; -} - - - ClassTree::ClassTree(QWidget* parent, ClassBrowserPlugin* plugin) : QTreeView(parent) , m_plugin(plugin) { header()->hide(); setIndentation(10); connect(this, SIGNAL(activated(const QModelIndex&)), SLOT(itemActivated(const QModelIndex&))); } ClassTree::~ClassTree() { } static bool _populatingClassBrowserContextMenu = false; bool ClassTree::populatingClassBrowserContextMenu() { return _populatingClassBrowserContextMenu; } void ClassTree::contextMenuEvent(QContextMenuEvent* e) { QMenu *menu = new QMenu(this); QModelIndex index = indexAt(e->pos()); if (index.isValid()) { Context* c; { DUChainReadLocker readLock(DUChain::lock()); if(Declaration* decl = dynamic_cast(model()->duObjectForIndex(index))) c = new DeclarationContext( decl ); else { delete menu; return; } } _populatingClassBrowserContextMenu = true; QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( c ); ContextMenuExtension::populateMenu(menu, extensions); _populatingClassBrowserContextMenu = false; } if (!menu->actions().isEmpty()) menu->exec(QCursor::pos()); } ClassModel* ClassTree::model() { return static_cast(QTreeView::model()); } void ClassTree::itemActivated(const QModelIndex& index) { DUChainReadLocker readLock(DUChain::lock()); DUChainBase* base = model()->duObjectForIndex(index); if (base) { KUrl url = KUrl(base->url().str()); KTextEditor::Range range = base->range().textRange(); readLock.unlock(); m_plugin->core()->documentController()->openDocument(url, range.start()); } if(isExpanded(index)) collapse(index); else expand(index); } void ClassTree::highlightIdentifier(KDevelop::IndexedQualifiedIdentifier a_id) { QModelIndex index = model()->getIndexForIdentifier(a_id); if ( !index.isValid() ) return; // expand and select the item. selectionModel()->select(index, QItemSelectionModel::ClearAndSelect); scrollTo(index, PositionAtCenter); expand(index); } // kate: space-indent on; indent-width 2; tab-width: 4; replace-tabs on; auto-insert-doxygen on #include "classtree.moc" diff --git a/plugins/classbrowser/classtree.h b/plugins/classbrowser/classtree.h index b0a0d88d43..af7cb35407 100644 --- a/plugins/classbrowser/classtree.h +++ b/plugins/classbrowser/classtree.h @@ -1,86 +1,60 @@ /* * KDevelop Class viewer * * Copyright (c) 2007 Hamish Rodda * Copyright 2009 Lior Mualem * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CLASSTREE_H #define CLASSTREE_H #include -#include "language/duchain/duchainbase.h" -#include "language/duchain/duchainobserver.h" #include class ClassBrowserPlugin; -class KLineEdit; class ClassModel; -class ClassTree; - -namespace KDevelop -{ - class TopDUContext; - class IDocument; -} - -/// The class browser widget -class ClassWidget : public QWidget -{ - Q_OBJECT - -public: - ClassWidget(QWidget* parent, ClassBrowserPlugin* plugin); - virtual ~ClassWidget(); - -private: - ClassBrowserPlugin* m_plugin; - ClassModel* m_model; - ClassTree* m_tree; - KLineEdit* m_searchLine; -}; class ClassTree : public QTreeView { Q_OBJECT public: ClassTree(QWidget* parent, ClassBrowserPlugin* plugin); virtual ~ClassTree(); public: /// Find the given a_id in the tree and highlight it. void highlightIdentifier(KDevelop::IndexedQualifiedIdentifier a_id); static bool populatingClassBrowserContextMenu(); protected: virtual void contextMenuEvent(QContextMenuEvent* e); ClassModel* model(); private Q_SLOTS: void itemActivated(const QModelIndex& index); private: ClassBrowserPlugin* m_plugin; }; #endif // kate: space-indent on; indent-width 2; tab-width: 4; replace-tabs on; auto-insert-doxygen on diff --git a/plugins/classbrowser/classwidget.cpp b/plugins/classbrowser/classwidget.cpp new file mode 100644 index 0000000000..3f8d97e0d0 --- /dev/null +++ b/plugins/classbrowser/classwidget.cpp @@ -0,0 +1,93 @@ +/* + * KDevelop Class viewer + * + * Copyright 2006 Adam Treat + * Copyright (c) 2006-2007 Hamish Rodda + * Copyright 2009 Lior Mualem + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "classwidget.h" + +#include +#include +#include + +#include +#include +#include + +#include "classmodel.h" +#include "classtree.h" +#include "classbrowserplugin.h" + +using namespace KDevelop; + +ClassWidget::ClassWidget(QWidget* parent, ClassBrowserPlugin* plugin) + : QWidget(parent) + , m_plugin(plugin) + , m_model(new ClassModel()) + , m_tree(new ClassTree(this, plugin)) + , m_searchLine(new KLineEdit(this)) +{ + setObjectName("Class Browser Tree"); + setWindowTitle(i18n("Classes")); + setWindowIcon(SmallIcon("code-class")); + + // Set tree in the plugin + m_plugin->setActiveClassTree(m_tree); + + // Set model in the tree view + m_tree->setModel(m_model); + + // We need notification in the model for the collapse/expansion of nodes. + connect(m_tree, SIGNAL(collapsed(const QModelIndex&)), + m_model, SLOT(collapsed(const QModelIndex&))); + connect(m_tree, SIGNAL(expanded(const QModelIndex&)), + m_model, SLOT(expanded(const QModelIndex&))); + + // Init search box + m_searchLine->setClearButtonShown( true ); + connect(m_searchLine, SIGNAL(textChanged(QString)), m_model, SLOT(updateFilterString(QString))); + QLabel *searchLabel = new QLabel( i18n("S&earch:"), this ); + searchLabel->setBuddy( m_searchLine ); + + QHBoxLayout* layout = new QHBoxLayout(); + layout->setSpacing( 5 ); + layout->setMargin( 0 ); + layout->addWidget(searchLabel); + layout->addWidget(m_searchLine); + + setFocusProxy( m_searchLine ); + + QVBoxLayout* vbox = new QVBoxLayout(this); + vbox->setMargin(0); + vbox->addLayout(layout); + vbox->addWidget(m_tree); + setLayout( vbox ); + + setWhatsThis( i18n( "Class Browser" ) ); +} + +ClassWidget::~ClassWidget() +{ + delete m_model; +} + +// kate: space-indent on; indent-width 2; tab-width: 4; replace-tabs on; auto-insert-doxygen on + +#include "classwidget.moc" diff --git a/plugins/classbrowser/classtree.h b/plugins/classbrowser/classwidget.h similarity index 62% copy from plugins/classbrowser/classtree.h copy to plugins/classbrowser/classwidget.h index b0a0d88d43..1e1ed58e01 100644 --- a/plugins/classbrowser/classtree.h +++ b/plugins/classbrowser/classwidget.h @@ -1,86 +1,52 @@ /* * KDevelop Class viewer * * Copyright (c) 2007 Hamish Rodda * Copyright 2009 Lior Mualem * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef CLASSTREE_H -#define CLASSTREE_H -#include +#ifndef CLASSWIDGET_H +#define CLASSWIDGET_H -#include "language/duchain/duchainbase.h" -#include "language/duchain/duchainobserver.h" -#include +#include class ClassBrowserPlugin; -class KLineEdit; -class ClassModel; class ClassTree; - -namespace KDevelop -{ - class TopDUContext; - class IDocument; -} +class ClassModel; +class KLineEdit; /// The class browser widget class ClassWidget : public QWidget { Q_OBJECT public: ClassWidget(QWidget* parent, ClassBrowserPlugin* plugin); virtual ~ClassWidget(); private: ClassBrowserPlugin* m_plugin; ClassModel* m_model; ClassTree* m_tree; KLineEdit* m_searchLine; }; -class ClassTree : public QTreeView -{ - Q_OBJECT - -public: - ClassTree(QWidget* parent, ClassBrowserPlugin* plugin); - virtual ~ClassTree(); - -public: - /// Find the given a_id in the tree and highlight it. - void highlightIdentifier(KDevelop::IndexedQualifiedIdentifier a_id); - - static bool populatingClassBrowserContextMenu(); - -protected: - virtual void contextMenuEvent(QContextMenuEvent* e); - ClassModel* model(); - -private Q_SLOTS: - void itemActivated(const QModelIndex& index); - -private: - ClassBrowserPlugin* m_plugin; -}; - -#endif +#endif // CLASSWIDGET_H // kate: space-indent on; indent-width 2; tab-width: 4; replace-tabs on; auto-insert-doxygen on