00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "classbrowser_widget.h"
00013 #include "classbrowser_part.h"
00014 #include "catalog.h"
00015
00016 #include <qwhatsthis.h>
00017
00018 #include <kiconloader.h>
00019 #include <klocale.h>
00020 #include <kgenericfactory.h>
00021 #include <kaction.h>
00022 #include <kdebug.h>
00023
00024 #include <kdevcore.h>
00025 #include <kdevpartcontroller.h>
00026 #include <kdevmainwindow.h>
00027 #include <kdevcoderepository.h>
00028 #include <kdevlanguagesupport.h>
00029
00030 #include <kcomboview.h>
00031 #include <klistviewaction.h>
00032
00033
00034 class TagListViewItem: public QListViewItem{
00035 public:
00036 TagListViewItem(QListView *parent, Tag tag, QString name):
00037 QListViewItem(parent, name), m_tag(tag)
00038 {
00039 }
00040 Tag tag() const { return m_tag; }
00041 private:
00042 Tag m_tag;
00043 };
00044
00045
00046 typedef KGenericFactory<ClassBrowserPart> ClassBrowserFactory;
00047 K_EXPORT_COMPONENT_FACTORY( libkdevclassbrowser, ClassBrowserFactory( "kdevclassbrowser" ) );
00048
00049 ClassBrowserPart::ClassBrowserPart( QObject* parent, const char* name, const QStringList& )
00050 : KDevPlugin("ClassBrowser", "classbrowser", parent, name ? name : "ClassBrowserPart" )
00051 {
00052 setInstance( ClassBrowserFactory::instance() );
00053 setXMLFile( "kdevpart_classbrowser.rc" );
00054
00055 m_widget = new ClassBrowserWidget( this );
00056 QWhatsThis::add( m_widget, i18n("Class browser") );
00057
00058 setupActions();
00059
00060 mainWindow()->embedSelectView( m_widget, i18n("Class Browser"), i18n("Class Browser") );
00061
00062 connect( codeRepository(), SIGNAL(catalogRegistered(Catalog*)),
00063 this, SLOT(slotCatalogAdded(Catalog*)) );
00064 connect( codeRepository(), SIGNAL(catalogUnregistered(Catalog*)),
00065 this, SLOT(slotCatalogRemoved(Catalog*)) );
00066 connect( codeRepository(), SIGNAL(catalogChanged(Catalog*)),
00067 this, SLOT(slotCatalogChanged(Catalog*)) );
00068
00069 connect( core(), SIGNAL(projectOpened()), this, SLOT(slotProjectOpened()) );
00070 connect( core(), SIGNAL(projectClosed()), this, SLOT(slotProjectClosed()) );
00071 connect( core(), SIGNAL(languageChanged()), this, SLOT(slotProjectOpened()) );
00072 }
00073
00074 ClassBrowserPart::~ClassBrowserPart()
00075 {
00076 delete (ClassBrowserWidget*) m_widget;
00077 }
00078
00079 void ClassBrowserPart::slotProjectOpened()
00080 {
00081 QValueList<Catalog*> l = codeRepository()->registeredCatalogs();
00082 QValueList<Catalog*>::Iterator it = l.begin();
00083 while( it != l.end() ){
00084 Catalog* catalog = *it;
00085 ++it;
00086
00087 m_widget->addCatalog( catalog );
00088 }
00089
00090 connect( languageSupport(), SIGNAL(updatedSourceInfo()), this, SLOT(refresh()) );
00091 }
00092
00093 void ClassBrowserPart::slotProjectClosed()
00094 {
00095
00096 }
00097
00098 void ClassBrowserPart::setupActions( )
00099 {
00100 m_actionNamespaces = new KListViewAction( new KComboView(true), i18n("Namespaces"), 0, 0, 0, actionCollection(), "namespaces_combo" );
00101 connect( m_actionNamespaces->view(), SIGNAL(activated(QListViewItem*)), this, SLOT(selectNamespace(const QListViewItem*)) );
00102
00103 m_actionClasses = new KListViewAction( new KComboView(true), i18n("Classes"), 0, 0, 0, actionCollection(), "classes_combo" );
00104 connect( m_actionClasses->view(), SIGNAL(activated(QListViewItem*)), this, SLOT(selectClass(const QListViewItem*)) );
00105
00106 m_actionMethods = new KListViewAction( new KComboView(true), i18n("Methods"), 0, 0, 0, actionCollection(), "methods_combo" );
00107 connect( m_actionMethods->view(), SIGNAL(activated(QListViewItem*)), this, SLOT(selectMethod(QListViewItem*)) );
00108 }
00109
00110 void ClassBrowserPart::slotCatalogAdded( Catalog * catalog )
00111 {
00112 Q_UNUSED( catalog );
00113 refresh();
00114 }
00115
00116 void ClassBrowserPart::slotCatalogRemoved( Catalog * catalog )
00117 {
00118 Q_UNUSED( catalog );
00119 refresh();
00120 }
00121
00122 void ClassBrowserPart::slotCatalogChanged( Catalog * catalog )
00123 {
00124 Q_UNUSED( catalog );
00125
00126
00127
00128
00129
00130 refresh();
00131
00132
00133
00134
00135
00136 }
00137
00138 void ClassBrowserPart::refresh( )
00139 {
00140 kdDebug() << "---------------------------------- REFRESH!!!!!!!!" << endl;
00141 QValueList<Tag> namespaceList;
00142
00143 QValueList<Catalog::QueryArgument> args;
00144 args << Catalog::QueryArgument( "kind", Tag::Kind_Namespace );
00145
00146 m_actionNamespaces->view()->clear();
00147 QValueList<Catalog*> l = codeRepository()->registeredCatalogs();
00148 QValueList<Catalog*>::Iterator it = l.begin();
00149 while( it != l.end() ){
00150 Catalog* catalog = *it;
00151 ++it;
00152
00153 namespaceList += catalog->query( args );
00154 }
00155
00156 namespaceList = ClassBrowserUtils::simplifyNamespaces( namespaceList );
00157
00158 new QListViewItem(m_actionNamespaces->view()->listView(), i18n("(Global Scope)"));
00159 QValueList<Tag>::Iterator dit = namespaceList.begin();
00160 while( dit != namespaceList.end() ){
00161 new TagListViewItem(m_actionNamespaces->view()->listView(), *dit, (*dit).path());
00162 ++dit;
00163 }
00164
00165 refreshClasses();
00166 refreshMethods();
00167 adjust();
00168 }
00169
00170 void ClassBrowserPart::selectNamespace( const QListViewItem * it )
00171 {
00172 Q_UNUSED( it );
00173
00174 refreshClasses();
00175 refreshMethods();
00176 adjust();
00177 }
00178
00179 void ClassBrowserPart::selectClass( const QListViewItem * it )
00180 {
00181 Q_UNUSED( it );
00182
00183 refreshMethods();
00184 adjust();
00185 }
00186
00187 void ClassBrowserPart::selectMethod( QListViewItem * it )
00188 {
00189 TagListViewItem * tagItem = dynamic_cast<TagListViewItem*>(it);
00190 if (!tagItem)
00191 return;
00192
00193 int line, col;
00194 tagItem->tag().getStartPosition( &line, &col );
00195 kdDebug() << "found tag at " << tagItem->tag().fileName() << " " << line << ", " << col << endl;
00196 partController()->editDocument( KURL(tagItem->tag().fileName()), line );
00197 adjust();
00198 }
00199
00200 void ClassBrowserPart::refreshClasses( )
00201 {
00202 QValueList<Tag> classList;
00203
00204 QStringList scope;
00205 if (m_actionNamespaces->view()->currentItem())
00206 {
00207 TagListViewItem *tagItem = dynamic_cast<TagListViewItem*>(m_actionNamespaces->view()->currentItem());
00208 if (tagItem)
00209 scope = tagItem->tag().scope();
00210 }
00211
00212 QValueList<Catalog::QueryArgument> args;
00213 args << Catalog::QueryArgument( "kind", Tag::Kind_Class )
00214 << Catalog::QueryArgument( "scope", scope );
00215
00216 m_actionClasses->view()->clear();
00217 QValueList<Catalog*> l = codeRepository()->registeredCatalogs();
00218 QValueList<Catalog*>::Iterator it = l.begin();
00219 while( it != l.end() ){
00220 Catalog* catalog = *it;
00221 ++it;
00222
00223 classList += catalog->query( args );
00224 }
00225
00226 new QListViewItem(m_actionClasses->view()->listView(), i18n("(Globals)"));
00227 QValueList<Tag>::Iterator dit = classList.begin();
00228 while( dit != classList.end() ){
00229 new TagListViewItem(m_actionClasses->view()->listView(), *dit, (*dit).name());
00230 ++dit;
00231 }
00232
00233 adjust();
00234 }
00235
00236 void ClassBrowserPart::refreshMethods( )
00237 {
00238 QValueList<Tag> methodList;
00239
00240 QStringList scope;
00241 if (m_actionNamespaces->view()->currentItem())
00242 {
00243 TagListViewItem *tagItem = dynamic_cast<TagListViewItem*>(m_actionNamespaces->view()->currentItem());
00244 if (tagItem)
00245 scope = tagItem->tag().scope();
00246 }
00247
00248 if (m_actionClasses->view()->currentItem())
00249 {
00250 TagListViewItem *tagItem = dynamic_cast<TagListViewItem*>(m_actionClasses->view()->currentItem());
00251 if (tagItem)
00252 scope << tagItem->tag().name();
00253 }
00254
00255 QValueList<Catalog::QueryArgument> args;
00256 args << Catalog::QueryArgument( "kind", Tag::Kind_FunctionDeclaration )
00257 << Catalog::QueryArgument( "scope", scope );
00258
00259 if( !m_selectedFileName.isEmpty() )
00260 args << Catalog::QueryArgument( "fileName", m_selectedFileName );
00261
00262 kdDebug() << "inside refreshMethods" << endl;
00263 m_actionMethods->view()->clear();
00264 QValueList<Catalog*> l = codeRepository()->registeredCatalogs();
00265 QValueList<Catalog*>::Iterator it = l.begin();
00266 while( it != l.end() ){
00267 Catalog* catalog = *it;
00268 ++it;
00269
00270 methodList += catalog->query( args );
00271 }
00272
00273 new QListViewItem(m_actionMethods->view()->listView(), "");
00274 QValueList<Tag>::Iterator dit = methodList.begin();
00275 while( dit != methodList.end() ){
00276 new TagListViewItem(m_actionMethods->view()->listView(), *dit, languageSupport()->formatTag(*dit));
00277 ++dit;
00278 }
00279
00280 adjust();
00281 }
00282
00283 void ClassBrowserPart::adjust( )
00284 {
00285
00286
00287
00288 m_actionNamespaces->view()->setMinimumWidth(200);
00289 m_actionClasses->view()->setMinimumWidth(150);
00290 m_actionMethods->view()->setMinimumWidth(150);
00291 }
00292
00293 #include "classbrowser_part.moc"