KDevelop API Documentation

classviewpart.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2003 Roberto Raggi (roberto@kdevelop.org)
00003  *  Copyright (C) 2003 Alexander Dymo (cloudtemple@mksat.net)
00004  *
00005  *  This program is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; see the file COPYING.LIB.  If not, write to
00017  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  *  Boston, MA 02111-1307, USA.
00019  *
00020  */
00021 
00022 #include <qwhatsthis.h>
00023 #include <qlistview.h>
00024 #include <qfileinfo.h>
00025 #include <qlineedit.h>
00026 
00027 #include <kiconloader.h>
00028 #include <klocale.h>
00029 #include <kdevgenericfactory.h>
00030 #include <kpopupmenu.h>
00031 #include <kdebug.h>
00032 #include <kmimetype.h>
00033 
00034 #include <kdevcore.h>
00035 #include <kdevmainwindow.h>
00036 #include <kdevlanguagesupport.h>
00037 #include <kcomboview.h>
00038 #include <kdevpartcontroller.h>
00039 #include <kdevproject.h>
00040 #include <urlutil.h>
00041 
00042 #include <codemodel.h>
00043 #include <codemodel_utils.h>
00044 
00045 #include "classviewwidget.h"
00046 #include "classviewpart.h"
00047 #include "hierarchydlg.h"
00048 #include "navigator.h"
00049 
00050 #include "klistviewaction.h"
00051 
00052 #include <ktexteditor/document.h>
00053 #include <ktexteditor/editinterface.h>
00054 #include <ktexteditor/view.h>
00055 #include <ktexteditor/selectioninterface.h>
00056 #include <ktexteditor/viewcursorinterface.h>
00057 #include <ktexteditor/clipboardinterface.h>
00058 
00059 typedef KDevGenericFactory<ClassViewPart> ClassViewFactory;
00060 static const KAboutData data("kdevclassview", I18N_NOOP("Class browser"), "1.0");
00061 K_EXPORT_COMPONENT_FACTORY( libkdevclassview, ClassViewFactory( &data ) )
00062 
00063 ClassViewPart::ClassViewPart(QObject *parent, const char *name, const QStringList& )
00064     : KDevPlugin("ClassView", "classview", parent, name ? name : "ClassViewPart" ),
00065     m_activeDocument(0), m_activeView(0), m_activeSelection(0), m_activeEditor(0), m_activeViewCursor(0)
00066 {
00067     setInstance(ClassViewFactory::instance());
00068     setXMLFile("kdevclassview.rc");
00069     
00070     navigator = new Navigator(this);
00071 
00072     setupActions();
00073 
00074     m_widget = new ClassViewWidget(this);
00075     m_widget->setIcon( SmallIcon("view_tree") );
00076     m_widget->setCaption(i18n("Class Browser"));
00077     mainWindow()->embedSelectView( m_widget, i18n("Classes"), i18n("Class browser") );
00078     QWhatsThis::add(m_widget, i18n("<b>Class browser</b><p>"
00079             "The class browser shows all namespaces, classes and namespace and class members in a project."));
00080 
00081     connect( core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) );
00082     connect( core(), SIGNAL(projectClosed()), this, SLOT(slotProjectClosed()) );
00083     connect( core(), SIGNAL(languageChanged()), this, SLOT(slotProjectOpened()) );
00084     connect( partController(), SIGNAL(activePartChanged(KParts::Part*)),
00085         this, SLOT(activePartChanged(KParts::Part*)));
00086     connect( m_widget, SIGNAL(removedNamespace(const QString&)), this, SLOT(removeNamespace(const QString& )));
00087 }
00088 
00089 
00090 ClassViewPart::~ClassViewPart()
00091 {
00092     mainWindow()->removeView( m_widget );
00093     delete (ClassViewWidget*) m_widget;
00094 }
00095 
00096 void ClassViewPart::slotProjectOpened( )
00097 {
00098 //    connect( languageSupport(), SIGNAL(updatedSourceInfo()), navigator, SLOT(refresh()) );
00099     connect( languageSupport(), SIGNAL(addedSourceInfo(const QString& )), navigator, SLOT(addFile(const QString& )));
00100     navigator->refresh();
00101 }
00102 
00103 void ClassViewPart::slotProjectClosed( )
00104 {
00105 //    navigator->refresh();
00106 //    disconnect( languageSupport(), SIGNAL(updatedSourceInfo()), navigator, SLOT(refresh()) );
00107 }
00108 
00109 void ClassViewPart::setupActions( )
00110 {
00111     m_functionsnav = new KListViewAction( new KComboView(true, 150, 0, "m_functionsnav_combo"), i18n("Functions Navigation"), 0, 0, 0, actionCollection(), "functionsnav_combo", true );
00112     connect(m_functionsnav->view(), SIGNAL(activated(QListViewItem*)), navigator, SLOT(selectFunctionNav(QListViewItem*)));
00113 //    m_functionsnav->view()->setEditable(false);
00114     connect(m_functionsnav->view(), SIGNAL(focusGranted()), navigator, SLOT(functionNavFocused()));
00115     connect(m_functionsnav->view(), SIGNAL(focusLost()), navigator, SLOT(functionNavUnFocused()));
00116     m_functionsnav->setToolTip(i18n("Functions in file"));
00117     m_functionsnav->setWhatsThis(i18n("<b>Function navigator</b><p>Navigates over functions contained in the file."));
00118 //    m_functionsnav->view()->setCurrentText(NAV_NODEFINITION);
00119     m_functionsnav->view()->setDefaultText(NAV_NODEFINITION);
00120     
00121     if (langHasFeature(KDevLanguageSupport::Classes))
00122     {
00123         KAction *ac = new KAction(i18n("Class Inheritance Diagram"), "view_tree", 0, this, SLOT(graphicalClassView()), actionCollection(), "inheritance_dia");
00124         ac->setToolTip(i18n("Class inheritance diagram"));
00125         ac->setWhatsThis(i18n("<b>Class inheritance diagram</b><p>Displays inheritance relationship between classes in project. "
00126                                  "Note, it does not display classes outside inheritance hierarchy."));    
00127     }
00128 }
00129 
00130 bool ClassViewPart::langHasFeature(KDevLanguageSupport::Features feature)
00131 {
00132     bool result = false;
00133     if (languageSupport())
00134         result = (feature & languageSupport()->features());
00135     return result;
00136 }
00137 
00138 void ClassViewPart::graphicalClassView( )
00139 {
00140     HierarchyDialog dia(this);
00141     dia.exec();
00142 }
00143 
00144 void ClassViewPart::activePartChanged( KParts::Part * part)
00145 {
00146     navigator->stopTimer();
00147     if (m_activeView)
00148     {
00149         disconnect(m_activeView, SIGNAL(cursorPositionChanged()), 
00150             navigator, SLOT(slotCursorPositionChanged()));
00151     }
00152     
00153     kdDebug() << "ClassViewPart::activePartChanged()" << endl;
00154 
00155     m_activeDocument = dynamic_cast<KTextEditor::Document*>( part );
00156     m_activeView = part ? dynamic_cast<KTextEditor::View*>( part->widget() ) : 0;
00157     m_activeEditor = dynamic_cast<KTextEditor::EditInterface*>( part );
00158     m_activeSelection = dynamic_cast<KTextEditor::SelectionInterface*>( part );
00159     m_activeViewCursor = part ? dynamic_cast<KTextEditor::ViewCursorInterface*>( m_activeView ) : 0;
00160 
00161     m_activeFileName = QString::null;
00162 
00163     if (m_activeDocument)
00164     {
00165         m_activeFileName = URLUtil::canonicalPath( m_activeDocument->url().path() );
00166         navigator->refreshNavBars(m_activeFileName);
00167         navigator->syncFunctionNavDelayed(200);
00168 /*        if ( languageSupport()->mimeTypes().find(
00169             KMimeType::findByPath(m_activeFileName)) != languageSupport()->mimeTypes().end() )
00170             m_activeFileName = QString::null;*/
00171     }
00172     if( m_activeViewCursor )
00173     {
00174         connect(m_activeView, SIGNAL(cursorPositionChanged()),
00175             navigator, SLOT(slotCursorPositionChanged()) );
00176     }
00177 }
00178 
00179 #include "classviewpart.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:54 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003