KDevelop API Documentation

buildtools/autotools/autodetailsview.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 ------------------- 00003 begin : 19.01.2003 00004 copyright : (C) 2002 by Victor Rder 00005 email : victor_roeder@gmx.de 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00018 #include <qregexp.h> 00019 00021 #include <kaction.h> 00022 #include <kdebug.h> 00023 #include <kiconloader.h> 00024 #include <klocale.h> 00025 #include <kpopupmenu.h> 00026 00028 #include "autodetailsview.h" 00029 00030 #include "kdevcore.h" 00031 #include "kdevmainwindow.h" 00032 #include "kdevpartcontroller.h" 00033 #include "kdevcreatefile.h" 00034 #include "kdevlanguagesupport.h" 00035 00036 #include "domutil.h" 00037 00038 #include "targetoptionsdlg.h" 00039 #include "addfiledlg.h" 00040 #include "addicondlg.h" 00041 #include "addexistingfilesdlg.h" 00042 #include "removefiledlg.h" 00043 #include "removetargetdlg.h" 00044 00045 #include "autolistviewitems.h" 00046 00047 #include "autoprojectpart.h" 00048 #include "autoprojectwidget.h" 00049 00050 #include "subclassesdlg.h" 00051 00052 AutoDetailsView::AutoDetailsView(AutoProjectWidget* widget, AutoProjectPart* part, QWidget *parent, const char *name) 00053 : KListView(parent, name) 00054 { 00055 m_widget = widget; 00056 m_part = part; 00057 00058 initActions(); 00059 QDomDocument &dom = *(m_part->projectDom()); 00060 m_subclasslist = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing" , 00061 "subclass","sourcefile", "uifile"); 00062 } 00063 00064 00065 AutoDetailsView::~AutoDetailsView() 00066 { 00067 } 00068 00069 void AutoDetailsView::initActions() 00070 { 00071 KActionCollection * actions = new KActionCollection( this ); 00072 00073 targetOptionsAction = new KAction( i18n( "Options..." ), "configure", 0, 00074 this, SLOT( slotTargetOptions() ), actions, "target options" ); 00075 targetOptionsAction->setWhatsThis(i18n("<b>Options</b><p>Target options dialog that provides settings for linker flags and lists of dependencies and external libraries.")); 00076 addNewFileAction = new KAction( i18n( "Create New File..." ), "filenew", 0, 00077 this, SLOT( slotAddNewFile() ), actions, "add new file" ); 00078 addNewFileAction->setWhatsThis(i18n("<b>Create new file</b><p>Creates a new file and adds it to a currently selected target.")); 00079 addExistingFileAction = new KAction( i18n( "Add Existing Files..." ), "fileimport", 0, 00080 this, SLOT( slotAddExistingFile() ), actions, "add existing file" ); 00081 addExistingFileAction->setWhatsThis(i18n("<b>Add existing files</b><p>Adds existing file to a currently selected target. Header files will not be included in SOURCES list of a target. " 00082 "They will be added to noinst_HEADERS instead.")); 00083 addIconAction = new KAction( i18n( "Add Icon..." ), "iconadd_kdevelop", 0, 00084 this, SLOT( slotAddIcon() ), actions, "add icon" ); 00085 addIconAction->setWhatsThis(i18n("<b>Add icon</b><p>Adds an icon to a KDEICON target.")); 00086 buildTargetAction = new KAction( i18n( "Build Target..." ), "launch", 0, 00087 this, SLOT( slotBuildTarget() ), actions, "build target" ); 00088 buildTargetAction->setWhatsThis(i18n("<b>Build target</b><p>Constructs a series of make commands to build the selected target. " 00089 "Also builds dependent targets.")); 00090 setActiveTargetAction = new KAction( i18n( "Make Target Active" ), "", 0, 00091 this, SLOT( slotSetActiveTarget() ), actions, "set active target" ); 00092 setActiveTargetAction->setWhatsThis(i18n("<b>Make target active</b><p>Marks the currently selected target as 'active'. New files and classes by default go to an active target. " 00093 "<b>Build Active Target</b> menu command builds it.")); 00094 removeDetailAction = new KAction( i18n( "Remove" ), "editdelete", 0, 00095 this, SLOT( slotRemoveDetail() ), actions, "remove detail" ); 00096 removeDetailAction->setWhatsThis(i18n("<b>Remove</b><p>Shows a list of targets dependent on the selected target or file and asks for removal. Also asks if the target or file should be removed from disk.")); 00097 00098 connect( this, SIGNAL( executed( QListViewItem* ) ), 00099 this, SLOT( slotDetailsExecuted( QListViewItem* ) ) ); 00100 connect ( this, SIGNAL ( returnPressed ( QListViewItem* ) ), 00101 this, SLOT ( slotDetailsExecuted ( QListViewItem* ) ) ); 00102 connect( this, SIGNAL( contextMenu( KListView*, QListViewItem*, const QPoint& ) ), 00103 this, SLOT( slotDetailsContextMenu( KListView*, QListViewItem*, const QPoint& ) ) ); 00104 } 00105 00106 QString AutoDetailsView::getUiFileLink(const QString &relpath, const QString& filename) 00107 { 00108 DomUtil::PairList::iterator it; 00109 00110 for (it=m_subclasslist.begin();it != m_subclasslist.end(); ++it) 00111 { 00112 if ((*it).first==QString("/")+relpath+filename) 00113 return (*it).second; 00114 } 00115 00116 return QString (""); 00117 } 00118 00119 void AutoDetailsView::slotTargetOptions() 00120 { 00121 kdDebug( 9020 ) << "AutoDetailsView::slotTargetOptions()" << endl; 00122 TargetItem *titem = static_cast <TargetItem*> ( selectedItem() ); 00123 if ( !titem ) return ; 00124 00125 TargetOptionsDialog dlg( m_widget, titem, this, "target options dialog" ); 00126 00127 dlg.setCaption ( i18n ( "Target Options for '%1'" ).arg ( titem->name ) ); 00128 00129 dlg.exec(); 00130 } 00131 00132 00133 void AutoDetailsView::slotAddNewFile() 00134 { 00135 TargetItem * titem = static_cast <TargetItem*> ( selectedItem() ); 00136 if ( !titem ) 00137 return ; 00138 00139 KDevCreateFile * createFileSupport = m_part->createFileSupport(); 00140 if (createFileSupport) 00141 { 00142 KDevCreateFile::CreatedFile crFile = 00143 createFileSupport->createNewFile(QString::null, m_widget->selectedSubproject()->path); 00144 /* if (crFile.status == KDevCreateFile::CreatedFile::STATUS_OK) 00145 { 00146 FileItem *fitem = m_widget->createFileItem(crFile.filename, m_widget->selectedSubproject()); 00147 titem->sources.append(fitem); 00148 titem->insertItem(fitem); 00149 emit selectionChanged( titem ); // update list view 00150 }*/ 00151 } else { 00152 AddFileDialog dlg( m_part, m_widget, m_widget->selectedSubproject(), titem, 00153 this, "add file dialog" ); 00154 QString caption; 00155 if ( titem->name.isEmpty() ) 00156 caption = i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix ); 00157 else 00158 caption = titem->name; 00159 00160 dlg.setCaption ( i18n ( "Add New File to '%1'" ).arg ( caption ) ); 00161 00162 if ( dlg.exec() ) 00163 emit selectionChanged( titem ); // update list view 00164 } 00165 } 00166 00167 00168 void AutoDetailsView::slotAddExistingFile() 00169 { 00170 TargetItem * titem = static_cast <TargetItem*> ( selectedItem() ); 00171 if ( !titem ) return; 00172 00173 AddExistingFilesDialog dlg( m_part, m_widget, m_widget->selectedSubproject(), titem, 00174 this, "add existing files" ); 00175 QString caption; 00176 if ( titem->name.isEmpty() ) 00177 caption = i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix ); 00178 else 00179 caption = titem->name; 00180 00181 dlg.setCaption( i18n( "Add Existing Files to '%1'" ).arg ( caption ) ); 00182 00183 dlg.exec(); 00184 } 00185 00186 00187 void AutoDetailsView::slotAddIcon() 00188 { 00189 TargetItem * titem = static_cast <TargetItem*> ( selectedItem() ); 00190 if ( !titem ) return ; 00191 00192 AddIconDialog dlg( m_part, m_widget, m_widget->selectedSubproject(), titem, 00193 this, "add icon" ); 00194 dlg.exec(); 00195 } 00196 00197 00198 void AutoDetailsView::slotBuildTarget() 00199 { 00200 ProjectItem * pvitem = static_cast<ProjectItem*>( selectedItem() ); 00201 00202 if ( !pvitem ) 00203 return; 00204 00205 TargetItem* titem = 0; 00206 00207 if ( pvitem->type() == ProjectItem::File ) 00208 titem = static_cast <TargetItem*> ( pvitem->parent() ); 00209 else 00210 titem = static_cast <TargetItem*> ( selectedItem() ); 00211 00212 QString relpath = m_widget->selectedSubproject()->path.mid( m_part->projectDirectory().length() ); 00213 m_part->buildTarget(relpath, titem); 00214 00215 m_part->mainWindow()->lowerView( m_widget ); 00216 } 00217 00218 00219 void AutoDetailsView::slotRemoveDetail() 00220 { 00221 ProjectItem * pvitem = static_cast<ProjectItem*>( selectedItem() ); 00222 00223 if ( pvitem && ( pvitem->type() == ProjectItem::File ) ) 00224 { 00225 FileItem * fitem = static_cast <FileItem*> ( selectedItem() ); 00226 QListViewItem* sibling = fitem->nextSibling(); 00227 00228 if ( !fitem ) 00229 return; 00230 00231 TargetItem *titem = static_cast<TargetItem*>( fitem->parent() ); 00232 00233 RemoveFileDialog dlg( m_widget, m_part, m_widget->selectedSubproject(), titem, fitem->text( 0 ), 00234 this, "remove file dialog" ); 00235 00236 QString caption; 00237 if ( titem->name.isEmpty() ) 00238 caption = i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix ); 00239 else 00240 caption = titem->name; 00241 00242 dlg.setCaption ( i18n ( "Remove File From '%1'" ).arg ( caption ) ); 00243 00244 if ( dlg.exec() ) 00245 { 00246 emit selectionChanged( titem ); 00247 00248 if ( sibling) 00249 { 00250 setSelected ( sibling, true ); 00251 ensureItemVisible ( sibling ); 00252 } 00253 } 00254 00255 return; 00256 } 00257 00258 if ( pvitem && ( pvitem->type() == ProjectItem::Target ) ) 00259 { 00260 TargetItem* titem = static_cast <TargetItem*> ( selectedItem() ); 00261 QListViewItem* sibling = titem->nextSibling(); 00262 00263 if ( !titem ) return; 00264 00265 RemoveTargetDialog dlg ( m_widget, m_part, m_widget->selectedSubproject(), titem, this, "remove target dialog" ); 00266 00267 dlg.setCaption ( i18n ( "Remove Target From '%1'" ).arg ( m_widget->selectedSubproject()->subdir ) ); 00268 00269 if ( dlg.exec() ) 00270 { 00271 //details->takeItem ( titem ); 00272 00273 m_widget->slotOverviewSelectionChanged ( m_widget->selectedSubproject() ); 00274 00275 if ( sibling) 00276 { 00277 setSelected ( sibling, true ); 00278 ensureItemVisible ( sibling ); 00279 } 00280 } 00281 00282 return; 00283 } 00284 } 00285 00286 00287 void AutoDetailsView::slotDetailsContextMenu( KListView *, QListViewItem *item, const QPoint &p ) 00288 { 00289 if ( !item ) 00290 return ; 00291 00292 ProjectItem *pvitem = static_cast<ProjectItem*>( item ); 00293 00294 if ( pvitem->type() == ProjectItem::Target ) 00295 { 00296 00297 TargetItem * titem = static_cast<TargetItem*>( pvitem ); 00298 00299 KPopupMenu popup( i18n( "Target: %1" ).arg( titem->name ), this ); 00300 00301 if ( titem->primary == "PROGRAMS" || titem->primary == "LIBRARIES" 00302 || titem->primary == "LTLIBRARIES" || titem->primary == "JAVA" ) 00303 { 00304 targetOptionsAction->plug( &popup ); 00305 popup.insertSeparator(); 00306 addNewFileAction->plug( &popup ); 00307 addExistingFileAction->plug( &popup ); 00308 popup.insertSeparator(); 00309 removeDetailAction->plug( &popup ); 00310 popup.insertSeparator(); 00311 setActiveTargetAction->plug( &popup ); 00312 popup.insertSeparator(); 00313 buildTargetAction->plug( &popup ); 00314 } 00315 else if ( titem->primary == "KDEDOCS" ) 00316 { 00317 addNewFileAction->plug( &popup ); 00318 addExistingFileAction->plug( &popup ); 00319 popup.insertSeparator(); 00320 removeDetailAction->plug( &popup ); 00321 popup.insertSeparator(); 00322 buildTargetAction->plug( &popup ); 00323 } 00324 else if ( titem->primary == "KDEICON" ) 00325 { 00326 addIconAction->plug( &popup ); 00327 popup.insertSeparator(); 00328 removeDetailAction->plug( &popup ); 00329 } 00330 else 00331 { 00332 addNewFileAction->plug( &popup ); 00333 addExistingFileAction->plug( &popup ); 00334 popup.insertSeparator(); 00335 removeDetailAction->plug( &popup ); 00336 } 00337 00338 popup.exec( p ); 00339 00340 } 00341 else if ( pvitem->type() == ProjectItem::File ) 00342 { 00343 00344 FileItem * fitem = static_cast<FileItem*>( pvitem ); 00345 00346 KPopupMenu popup( i18n( "File: %1" ).arg( fitem->name ), this ); 00347 00348 removeDetailAction->plug( &popup ); 00349 FileContext context( m_widget->selectedSubproject()->path + "/" + fitem->name, false ); 00350 00351 int idSubclassWidget = popup.insertItem(SmallIconSet("qmake_subclass.png"),i18n("Subclass Widget...") ); 00352 popup.setWhatsThis(idSubclassWidget, i18n("<b>Subclass widget</b><p>Launches <b>Subclassing</b> wizard. " 00353 "It allows to create a subclass from the class defined in .ui file. " 00354 "There is also possibility to implement slots and functions defined in the base class.")); 00355 int idUISubclasses = popup.insertItem(SmallIconSet("qmake_subclass.png"),i18n("List of Subclasses...")); 00356 popup.setWhatsThis(idUISubclasses, i18n("<b>List of subclasses</b><p>Shows subclasses list editor. " 00357 "There is possibility to add or remove subclasses from the list.")); 00358 int idUpdateWidgetclass = popup.insertItem(SmallIconSet("qmake_subclass.png"),i18n("Edit ui-Subclass...")); 00359 popup.setWhatsThis(idUpdateWidgetclass, i18n("<b>Edit ui-subclass</b><p>Launches <b>Subclassing</b> wizard " 00360 "and prompts to implement missing in childclass slots and functions.")); 00361 int idViewUIH = popup.insertItem(SmallIconSet("qmake_ui_h.png"),i18n("Open ui.h File")); 00362 popup.setWhatsThis(idViewUIH, i18n("<b>Open ui.h file</b><p>Opens .ui.h file assotiated with the selected .ui.")); 00363 00364 if (!fitem->name.contains(QRegExp("ui$"))) 00365 { 00366 popup.removeItem(idUISubclasses); 00367 popup.removeItem(idViewUIH); 00368 popup.removeItem(idSubclassWidget); 00369 } 00370 if (fitem->uiFileLink.isEmpty()) 00371 { 00372 popup.removeItem(idUpdateWidgetclass); 00373 } 00374 00375 m_part->core()->fillContextMenu( &popup, &context ); 00376 00377 int r = popup.exec( p ); 00378 00379 if(r == idViewUIH) 00380 { 00381 m_part->partController()->editDocument(KURL(m_widget->selectedSubproject()->path + "/" + 00382 QString(fitem->name + ".h"))); 00383 } 00384 else if (r == idSubclassWidget) 00385 { 00386 QStringList newFileNames; 00387 newFileNames = m_part->languageSupport()->subclassWidget(m_widget->selectedSubproject()->path + "/" + fitem->name); 00388 if (!newFileNames.empty()) 00389 { 00390 QDomDocument &dom = *(m_part->projectDom()); 00391 for (uint i=0; i<newFileNames.count(); i++) 00392 { 00393 QString srcfile_relpath = newFileNames[i]; 00394 srcfile_relpath.remove(0,m_part->projectDirectory().length()); 00395 QString uifile_relpath = QString(m_widget->selectedSubproject()->path + "/" + fitem->name).remove(0,m_part->projectDirectory().length()); 00396 DomUtil::PairList list = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing" , 00397 "subclass","sourcefile", "uifile"); 00398 00399 list << DomUtil::Pair(srcfile_relpath,uifile_relpath); 00400 DomUtil::writePairListEntry(dom, "/kdevautoproject/subclassing", "subclass", "sourcefile", "uifile", list); 00401 newFileNames[i] = newFileNames[i].replace(QRegExp(m_part->projectDirectory()+"/"),""); 00402 } 00403 m_subclasslist = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing" , 00404 "subclass","sourcefile", "uifile"); 00405 m_part->addFiles(newFileNames); 00406 } 00407 } 00408 else if (r == idUpdateWidgetclass) 00409 { 00410 QString noext = m_widget->selectedSubproject()->path + "/" + fitem->name; 00411 00412 if (noext.findRev('.')>-1) 00413 noext = noext.left(noext.findRev('.')); 00414 00415 QStringList dummy; 00416 QString uifile = fitem->uiFileLink; 00417 00418 if (uifile.findRev('/')>-1) 00419 { 00420 QStringList uisplit = QStringList::split('/',uifile); 00421 uifile=uisplit[uisplit.count()-1]; 00422 } 00423 00424 m_part->languageSupport()->updateWidget(m_widget->selectedSubproject()->path + "/" + uifile, noext); 00425 } 00426 else if (r == idUISubclasses) 00427 { 00428 QDomDocument &dom = *(m_part->projectDom()); 00429 DomUtil::PairList list = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing" , 00430 "subclass","sourcefile", "uifile"); 00431 SubclassesDlg *sbdlg = new SubclassesDlg( QString(m_widget->selectedSubproject()->path + "/" + fitem->name).remove(0,m_part->projectDirectory().length()), 00432 list, m_part->projectDirectory()); 00433 00434 if (sbdlg->exec()) 00435 { 00436 QDomElement el = DomUtil::elementByPath( dom, "/kdevautoproject"); 00437 QDomElement el2 = DomUtil::elementByPath( dom, "/kdevautoproject/subclassing"); 00438 if ( (!el.isNull()) && (!el2.isNull()) ) 00439 { 00440 el.removeChild(el2); 00441 } 00442 00443 DomUtil::writePairListEntry(dom, "/kdevautoproject/subclassing", "subclass", "sourcefile", "uifile", list); 00444 00445 m_subclasslist = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing" , 00446 "subclass","sourcefile", "uifile"); 00447 } 00448 } 00449 } 00450 } 00451 00452 00453 void AutoDetailsView::slotDetailsExecuted( QListViewItem *item ) 00454 { 00455 if ( !item ) 00456 return ; 00457 00458 ProjectItem *pvitem = static_cast<ProjectItem*>( item ); 00459 if ( pvitem->type() != ProjectItem::File ) 00460 return ; 00461 00462 if ( !m_widget->selectedSubproject() ) 00463 return; 00464 00465 QString dirName = m_widget->selectedSubproject()->path; 00466 FileItem *fitem = static_cast<FileItem*>( item ); 00467 00468 m_part->partController() ->editDocument( KURL( dirName + "/" + fitem->name ) ); 00469 m_part->mainWindow()->lowerView( m_widget ); 00470 } 00471 00472 void AutoDetailsView::slotSetActiveTarget() 00473 { 00474 TargetItem * titem = static_cast<TargetItem*>( selectedItem() ); 00475 if ( !titem ) return ; 00476 00477 QString targetPath = m_widget->selectedSubproject()->path + "/" + titem->name; 00478 targetPath = targetPath.mid( m_part->projectDirectory().length() + 1 ); 00479 kdDebug( 9020 ) << "Setting active " << targetPath << endl; 00480 m_widget->setActiveTarget( targetPath ); 00481 QDomDocument &dom = *m_part->projectDom(); 00482 DomUtil::writeEntry( dom, "/kdevautoproject/general/activetarget", targetPath ); 00483 } 00484 00485 #include "autodetailsview.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:36 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003