00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00099 connect( languageSupport(), SIGNAL(addedSourceInfo(const QString& )), navigator, SLOT(addFile(const QString& )));
00100 navigator->refresh();
00101 }
00102
00103 void ClassViewPart::slotProjectClosed( )
00104 {
00105
00106
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
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
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
00169
00170
00171 }
00172 if( m_activeViewCursor )
00173 {
00174 connect(m_activeView, SIGNAL(cursorPositionChanged()),
00175 navigator, SLOT(slotCursorPositionChanged()) );
00176 }
00177 }
00178
00179 #include "classviewpart.moc"