KDevelop API Documentation

buildtools/generic/genericproject_widget.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 Roberto Raggi * 00003 * roberto@kdevelop.org * 00004 * Copyright (C) 2003 Alexander Dymo * 00005 * cloudtemple@mksat.net * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 ***************************************************************************/ 00013 00014 #include "genericproject_part.h" 00015 #include "genericproject_widget.h" 00016 #include "overviewlistview.h" 00017 #include "detailslistview.h" 00018 #include "genericlistviewitem.h" 00019 00020 #include "kdevcore.h" 00021 #include "kdevpartcontroller.h" 00022 00023 #include <kparts/part.h> 00024 #include <klibloader.h> 00025 #include <kurl.h> 00026 #include <kdebug.h> 00027 #include <kiconloader.h> 00028 #include <kaction.h> 00029 #include <kpopupmenu.h> 00030 #include <klistview.h> 00031 #include <klocale.h> 00032 #include <klineeditdlg.h> 00033 #include <kmessagebox.h> 00034 #include <kio/netaccess.h> 00035 #include <kfiledialog.h> 00036 00037 #include <qsplitter.h> 00038 #include <qtooltip.h> 00039 #include <qwhatsthis.h> 00040 #include <qtoolbutton.h> 00041 #include <qheader.h> 00042 #include <qdir.h> 00043 #include <qfile.h> 00044 00045 #include "kdevbuildsystem.h" 00046 #include "removesubprojectdialog.h" 00047 #include "kdevcreatefile.h" 00048 00049 GenericProjectWidget::GenericProjectWidget(GenericProjectPart *part) 00050 : QVBox( 0, "GenericProjectWidget" ), m_part( part ), m_activeGroup( 0 ), m_activeTarget( 0 ) 00051 { 00052 QSplitter* splitter = new QSplitter( Vertical, this ); 00053 initOverviewListView( splitter ); 00054 initDetailsListView( splitter ); 00055 00056 initActions(); 00057 00058 connect( m_part, SIGNAL(mainGroupChanged(BuildGroupItem*)), 00059 this, SLOT(slotMainGroupChanged(BuildGroupItem*)) ); 00060 } 00061 00062 GenericProjectWidget::~GenericProjectWidget() 00063 { 00064 } 00065 00066 void GenericProjectWidget::initOverviewListView( QSplitter * splitter ) 00067 { 00068 QVBox* vbox = new QVBox( splitter ); 00069 00070 QHBox* buttonBox = new QHBox( vbox ); 00071 buttonBox->setMargin( 2 ); 00072 buttonBox->setSpacing( 2 ); 00073 00074 QToolButton* btn = 0; 00075 00076 btn = new QToolButton( buttonBox ); 00077 btn->setPixmap( SmallIcon("group_new") ); 00078 QToolTip::add( btn, i18n("Add new group") ); 00079 QWhatsThis::add( btn, i18n("<b>Add new group</b><p>Adds a new group of targets and files. " 00080 "Group is usually a subdirectory in the project directory but that depends on an underlying build system.") ); 00081 connect(btn, SIGNAL(clicked()), this, SLOT(slotNewGroup())); 00082 00083 btn = new QToolButton( buttonBox ); 00084 btn->setPixmap( SmallIcon("targetnew_kdevelop") ); 00085 QToolTip::add( btn, i18n("Add new target") ); 00086 QWhatsThis::add( btn, i18n("<b>Add new target</b><p>Adds a new target. " 00087 "Target is usually an application, static or shared library but that depends on an underlying build system.") ); 00088 connect(btn, SIGNAL(clicked()), this, SLOT(slotNewTarget())); 00089 00090 btn = new QToolButton( buttonBox ); 00091 btn->setPixmap( SmallIcon("launch") ); 00092 QToolTip::add( btn, i18n("Build") ); 00093 QWhatsThis::add( btn, i18n("<b>Build</b><p>Executes all commands necessary to build the current group.") ); 00094 connect(btn, SIGNAL(clicked()), this, SLOT(slotBuildGroup())); 00095 00096 QWidget *spacer1 = new QWidget( buttonBox ); 00097 buttonBox->setStretchFactor( spacer1, 1 ); 00098 00099 btn = new QToolButton( buttonBox ); 00100 btn->setPixmap( SmallIcon("configure") ); 00101 QToolTip::add( btn, i18n("Configure group") ); 00102 QWhatsThis::add( btn, i18n("<b>Configure group</b><p>Opens a group configuration dialog supplied by a build system plugin.") ); 00103 connect(btn, SIGNAL(clicked()), this, SLOT(slotConfigureGroup())); 00104 00105 buttonBox->setMaximumHeight( btn->height() ); 00106 00107 m_overviewListView = new OverviewListView( m_part, vbox, "GroupListView" ); 00108 00109 m_overviewListView->setResizeMode( QListView::LastColumn ); 00110 m_overviewListView->setSorting( -1 ); 00111 m_overviewListView->header()->hide(); 00112 m_overviewListView->addColumn( QString::null ); 00113 00114 connect( m_overviewListView, SIGNAL(selectionChanged(QListViewItem*)), 00115 this, SLOT(slotItemSelected(QListViewItem*)) ); 00116 00117 connect( this, SIGNAL(groupSelected(BuildGroupItem*)), 00118 this, SLOT(showDetails(BuildGroupItem*)) ); 00119 00120 connect(m_overviewListView, SIGNAL(contextMenu(KListView *, QListViewItem *, const QPoint &)), 00121 this, SLOT(showGroupContextMenu(KListView *, QListViewItem *, const QPoint &))); 00122 } 00123 00124 void GenericProjectWidget::initDetailsListView( QSplitter * splitter ) 00125 { 00126 QVBox* vbox = new QVBox( splitter ); 00127 00128 QHBox* buttonBox = new QHBox( vbox ); 00129 buttonBox->setMargin( 2 ); 00130 buttonBox->setSpacing( 2 ); 00131 00132 QToolButton* btn = 0; 00133 00134 btn = new QToolButton( buttonBox ); 00135 btn->setPixmap( SmallIcon("filenew") ); 00136 QToolTip::add( btn, i18n("New file") ); 00137 QWhatsThis::add( btn, i18n("<b>New file</b><p>Creates a new file and adds it to a current target.") ); 00138 connect(btn, SIGNAL(clicked()), this, SLOT(slotNewFile())); 00139 00140 btn = new QToolButton( buttonBox ); 00141 btn->setPixmap( SmallIcon("fileimport") ); 00142 QToolTip::add( btn, i18n("Add files") ); 00143 QWhatsThis::add( btn, i18n("<b>Add files</b><p>Adds existing files to a current target.") ); 00144 connect(btn, SIGNAL(clicked()), this, SLOT(slotAddFiles())); 00145 00146 btn = new QToolButton( buttonBox ); 00147 btn->setPixmap( SmallIcon("editdelete") ); 00148 QToolTip::add( btn, i18n("Remove target or file") ); 00149 QWhatsThis::add( btn, i18n("<b>Remove target or file</b><p>Removes current target or file.") ); 00150 connect(btn, SIGNAL(clicked()), this, SLOT(slotDeleteTargetOrFile())); 00151 00152 /* btn = new QToolButton( buttonBox ); 00153 btn->setPixmap( SmallIcon("editdelete") ); 00154 QToolTip::add( btn, i18n("Remove file") ); 00155 QWhatsThis::add( btn, i18n("<b></b><p>") ); 00156 connect(btn, SIGNAL(clicked()), this, SLOT(slotDeleteFile())); 00157 */ 00158 btn = new QToolButton( buttonBox ); 00159 btn->setPixmap( SmallIcon("launch") ); 00160 QToolTip::add( btn, i18n("Build target") ); 00161 QWhatsThis::add( btn, i18n("<b>Build target</b><p>Executes all commands necessary to build the current target.") ); 00162 connect(btn, SIGNAL(clicked()), this, SLOT(slotBuildTarget())); 00163 00164 00165 QWidget *spacer1 = new QWidget( buttonBox ); 00166 buttonBox->setStretchFactor( spacer1, 1 ); 00167 00168 btn = new QToolButton( buttonBox ); 00169 btn->setPixmap( SmallIcon("configure") ); 00170 QToolTip::add( btn, i18n("Configure target or file") ); 00171 QWhatsThis::add( btn, i18n("<b>Configure target or file</b><p>Opens a target or file configuration dialog supplied by a build system plugin.") ); 00172 connect(btn, SIGNAL(clicked()), this, SLOT(slotConfigureTargetOrFile())); 00173 00174 buttonBox->setMaximumHeight( btn->height() ); 00175 00176 m_detailsListView = new DetailsListView( m_part, vbox, "DetailsListView" ); 00177 00178 m_detailsListView->setResizeMode( QListView::LastColumn ); 00179 m_detailsListView->setSorting( -1 ); 00180 m_detailsListView->header()->hide(); 00181 m_detailsListView->addColumn( QString::null ); 00182 00183 connect( m_detailsListView, SIGNAL(clicked(QListViewItem*)), 00184 this, SLOT(slotItemSelected(QListViewItem*)) ); 00185 connect( m_detailsListView, SIGNAL(executed(QListViewItem*)), 00186 this, SLOT(slotItemExecuted(QListViewItem*)) ); 00187 connect( m_detailsListView, SIGNAL(returnPressed(QListViewItem*)), 00188 this, SLOT(slotItemExecuted(QListViewItem*)) ); 00189 00190 connect( this, SIGNAL(targetSelected(BuildTargetItem*)), 00191 this, SLOT(showTargetDetails(BuildTargetItem*)) ); 00192 connect( this, SIGNAL(fileExecuted(BuildFileItem*)), 00193 this, SLOT(showFileDetails(BuildFileItem*)) ); 00194 connect(m_detailsListView, SIGNAL(contextMenu(KListView *, QListViewItem *, const QPoint &)), 00195 this, SLOT(showDetailContextMenu(KListView *, QListViewItem *, const QPoint &))); 00196 00197 } 00198 00199 void GenericProjectWidget::slotMainGroupChanged( BuildGroupItem * mainGroup ) 00200 { 00201 m_overviewListView->clear(); 00202 00203 m_groupToItem.clear(); 00204 m_targetToItem.clear(); 00205 m_fileToItem.clear(); 00206 00207 if( !mainGroup ) 00208 return; 00209 00210 GenericGroupListViewItem* mainItem = new GenericGroupListViewItem( m_overviewListView, mainGroup ); 00211 mainItem->setOpen( true ); 00212 fillGroupItem( mainGroup, mainItem ); 00213 } 00214 00215 void GenericProjectWidget::fillGroupItem( BuildGroupItem * group, GenericGroupListViewItem * item ) 00216 { 00217 m_groupToItem.insert( group, item ); 00218 00219 QValueList<BuildGroupItem*> groups = group->groups(); 00220 QValueListIterator<BuildGroupItem*> it = groups.begin(); 00221 while( it != groups.end() ){ 00222 GenericGroupListViewItem* createdItem = new GenericGroupListViewItem( item, *it ); 00223 createdItem->setOpen( (*it)->groups().size() > 0 ); 00224 fillGroupItem( *it, createdItem ); 00225 00226 ++it; 00227 } 00228 } 00229 00230 void GenericProjectWidget::slotItemSelected( QListViewItem * item ) 00231 { 00232 GenericGroupListViewItem* groupItem = dynamic_cast<GenericGroupListViewItem*>( item ); 00233 GenericTargetListViewItem* targetItem = dynamic_cast<GenericTargetListViewItem*>( item ); 00234 GenericFileListViewItem* fileItem = dynamic_cast<GenericFileListViewItem*>( item ); 00235 00236 if( groupItem && groupItem->groupItem() ) 00237 emit groupSelected( groupItem->groupItem() ); 00238 else if( targetItem && targetItem->targetItem() ){ 00239 kdDebug() << "set active target" << endl; 00240 m_activeTarget = targetItem->targetItem(); 00241 emit targetSelected( m_activeTarget ); 00242 } 00243 // else if( fileItem && m_itemToFile.contains(fileItem) ) 00244 // emit fileSelected( m_itemToFile[fileItem] ); 00245 } 00246 00247 void GenericProjectWidget::showDetails( BuildGroupItem * groupItem ) 00248 { 00249 m_activeGroup = groupItem; 00250 kdDebug() << "unset active target" << endl; 00251 m_activeTarget = 0; 00252 00253 m_detailsListView->clear(); 00254 00255 m_targetToItem.clear(); 00256 m_fileToItem.clear(); 00257 00258 if( !groupItem ) 00259 return; 00260 00261 QValueList<BuildTargetItem*> targets = groupItem->targets(); 00262 QValueListIterator<BuildTargetItem*> it = targets.begin(); 00263 while( it != targets.end() ){ 00264 GenericTargetListViewItem* createdItem = new GenericTargetListViewItem( m_detailsListView, *it ); 00265 m_targetToItem.insert( *it, createdItem ); 00266 fillTarget( *it, createdItem ); 00267 createdItem->setOpen( true ); 00268 ++it; 00269 } 00270 } 00271 00272 void GenericProjectWidget::fillTarget( BuildTargetItem * target, GenericTargetListViewItem * targetItem ) 00273 { 00274 QValueList<BuildFileItem*> files = target->files(); 00275 QValueListIterator<BuildFileItem*> it = files.begin(); 00276 while( it != files.end() ){ 00277 GenericFileListViewItem* createdItem = new GenericFileListViewItem( targetItem, *it ); 00278 m_fileToItem.insert( *it, createdItem ); 00279 ++it; 00280 } 00281 } 00282 00283 BuildGroupItem * GenericProjectWidget::activeGroup( ) 00284 { 00285 return m_activeGroup; 00286 } 00287 00288 GenericGroupListViewItem * GenericProjectWidget::addGroup( BuildGroupItem * group ) 00289 { 00290 if( !group ) 00291 return 0; 00292 00293 GenericGroupListViewItem* createdItem = 0; 00294 if( group->parentGroup() && m_groupToItem.contains(group->parentGroup()) ){ 00295 kdDebug() << "creating GenericGroupListViewItem from parent group" << endl; 00296 createdItem = new GenericGroupListViewItem( m_groupToItem[group->parentGroup()], group ); 00297 m_groupToItem.insert( group, createdItem ); 00298 } else if( group->parentGroup() ){ 00299 kdDebug() << "creating GenericGroupListViewItem from parent group (wo map)" << endl; 00300 addGroup( group->parentGroup() ); 00301 createdItem = new GenericGroupListViewItem( m_groupToItem[group->parentGroup()], group ); 00302 m_groupToItem.insert( group, createdItem ); 00303 m_groupToItem[group->parentGroup()]->setExpandable( true ); 00304 } else { 00305 kdDebug() << "creating GenericGroupListViewItem standalone" << endl; 00306 createdItem = new GenericGroupListViewItem( m_overviewListView, group ); 00307 m_groupToItem.insert( group, createdItem ); 00308 } 00309 return createdItem; 00310 } 00311 00312 void GenericProjectWidget::addTarget( BuildTargetItem * target ) 00313 { 00314 if( !target || !target->parentGroup() || activeGroup() != target->parentGroup() ) 00315 return; 00316 00317 if( m_groupToItem.contains(target->parentGroup()) ){ 00318 // GenericTargetListViewItem* createdItem = new GenericTargetListViewItem( m_groupToItem[target->parentGroup()], target ); 00319 GenericTargetListViewItem* createdItem = new GenericTargetListViewItem( m_detailsListView, target ); 00320 m_detailsListView->takeItem(createdItem); 00321 m_targetToItem.insert( target, createdItem ); 00322 00323 showDetails(target->parentGroup()); 00324 } 00325 } 00326 00327 void GenericProjectWidget::addFile( BuildFileItem * file ) 00328 { 00329 if( !file || !file->parentTarget() || file->parentTarget()->parentGroup() != activeGroup() ) 00330 return; 00331 00332 if( m_targetToItem.contains(file->parentTarget()) ){ 00333 GenericFileListViewItem* createdItem = new GenericFileListViewItem( m_targetToItem[file->parentTarget()], file ); 00334 m_fileToItem.insert( file, createdItem ); 00335 } 00336 } 00337 00338 BuildTargetItem * GenericProjectWidget::activeTarget( ) 00339 { 00340 return m_activeTarget; 00341 } 00342 00343 void GenericProjectWidget::showTargetDetails( BuildTargetItem * targetItem ) 00344 { 00345 } 00346 00347 void GenericProjectWidget::showFileDetails( BuildFileItem * fileItem ) 00348 { 00349 kdDebug() << "GenericProjectWidget::showFileDetails" << endl; 00350 m_part->partController()->editDocument(fileItem->url()); 00351 } 00352 00353 void GenericProjectWidget::initActions( ) 00354 { 00355 newGroupAction = new KAction (i18n("New Group"), "group_new", 0, 00356 this, SLOT( slotNewGroup() ), m_part->actionCollection(), "new_group" ); 00357 newGroupAction->setToolTip(i18n("New group")); 00358 newGroupAction->setWhatsThis(i18n("<b>New group</b><p>Adds a new group of targets and files. " 00359 "Group is usually a subdirectory in the project directory but that depends on an underlying build system.")); 00360 newTargetAction = new KAction (i18n("New Target"), "targetnew_kdevelop", 0, 00361 this, SLOT( slotNewTarget() ), m_part->actionCollection(), "new_target" ); 00362 newTargetAction->setToolTip(i18n("New target")); 00363 newTargetAction->setWhatsThis(i18n("<b>New target</b><p>Adds a new target. " 00364 "Target is usually an application, static or shared library but that depends on an underlying build system.")); 00365 buildGroupAction = new KAction (i18n("Build Group"), "launch", 0, 00366 this, SLOT( slotBuildGroup() ), m_part->actionCollection(), "build_group" ); 00367 buildGroupAction->setToolTip(i18n("Build group")); 00368 buildGroupAction->setWhatsThis(i18n("<b>Build group</b><p>Executes all commands necessary to build the current group.")); 00369 buildAction = new KAction (i18n("Build"), "launch", 0, 00370 this, SLOT( slotBuild() ), m_part->actionCollection(), "build" ); 00371 buildAction->setToolTip(i18n("Build project")); 00372 buildAction->setWhatsThis(i18n("<b>Build project</b><p>Executes all commands necessary to build the project.")); 00373 buildTargetAction = new KAction (i18n("Build Target"), "launch", 0, 00374 this, SLOT( slotBuildTarget() ), m_part->actionCollection(), "build_target" ); 00375 buildTargetAction->setToolTip(i18n("Build target")); 00376 buildTargetAction->setWhatsThis(i18n("<b>Build target</b><p>Executes all commands necessary to build the current target.")); 00377 buildFileAction = new KAction (i18n("Build File"), "launch", 0, 00378 this, SLOT( slotBuildFile() ), m_part->actionCollection(), "build_file" ); 00379 buildFileAction->setToolTip(i18n("Build file")); 00380 buildFileAction->setWhatsThis(i18n("<b>Build file</b><p>Executes all commands necessary to build the current file.")); 00381 installGroupAction = new KAction (i18n("Install Group"), 0, 0, 00382 this, SLOT( slotInstallGroup() ), m_part->actionCollection(), "install_group" ); 00383 installGroupAction->setToolTip(i18n("Install group")); 00384 installGroupAction->setWhatsThis(i18n("<b>Install group</b><p>Executes all commands necessary to install the current group.")); 00385 installAction = new KAction (i18n("Install"), 0, 0, 00386 this, SLOT( slotInstall() ), m_part->actionCollection(), "install" ); 00387 installAction->setToolTip(i18n("Install")); 00388 installAction->setWhatsThis(i18n("<b>Install</b><p>Executes all commands necessary to install the project.")); 00389 newFileAction = new KAction (i18n("New File"), "filenew", 0, 00390 this, SLOT( slotNewFile() ), m_part->actionCollection(), "new_file" ); 00391 newFileAction->setToolTip(i18n("New file")); 00392 newFileAction->setWhatsThis(i18n("<b>New file</b><p>Creates a new file and adds it to a current target.")); 00393 addFilesAction = new KAction (i18n("Add Files"), "fileimport", 0, 00394 this, SLOT( slotAddFiles() ), m_part->actionCollection(), "add_files" ); 00395 addFilesAction->setToolTip(i18n("Add files")); 00396 addFilesAction->setWhatsThis(i18n("<b>Add files</b><p>Adds existing files to a current target.")); 00397 deleteGroupAction = new KAction (i18n("Remove Group"), 0, 0, 00398 this, SLOT( slotDeleteGroup() ), m_part->actionCollection(), "remove_group" ); 00399 deleteGroupAction->setToolTip(i18n("Remove group")); 00400 deleteGroupAction->setWhatsThis(i18n("<b>Remove group</b><p>Removes current group.")); 00401 deleteTargetAction = new KAction (i18n("Remove Target"), 0, 0, 00402 this, SLOT( slotDeleteTarget() ), m_part->actionCollection(), "remove_target" ); 00403 deleteTargetAction->setToolTip(i18n("Remove target")); 00404 deleteTargetAction->setWhatsThis(i18n("<b>Remove target</b><p>Removes current target.")); 00405 deleteFileAction = new KAction (i18n("Remove File"), 0, 0, 00406 this, SLOT( slotDeleteFile() ), m_part->actionCollection(), "remove_file" ); 00407 deleteFileAction->setToolTip(i18n("Remove file")); 00408 deleteFileAction->setWhatsThis(i18n("<b>Remove file</b><p>Removes current file.")); 00409 configureGroupAction = new KAction (i18n("Options..."), "configure", 0, 00410 this, SLOT( slotConfigureGroup() ), m_part->actionCollection(), "configure_group" ); 00411 configureGroupAction->setToolTip(i18n("Options")); 00412 configureGroupAction->setWhatsThis(i18n("<b>Options</b><p>Opens a group configuration dialog supplied by a build system plugin.")); 00413 configureTargetAction = new KAction (i18n("Options..."), "configure", 0, 00414 this, SLOT( slotConfigureTarget() ), m_part->actionCollection(), "configure_target" ); 00415 configureTargetAction->setToolTip(i18n("Options")); 00416 configureTargetAction->setWhatsThis(i18n("<b>Options</b><p>Opens a target configuration dialog supplied by a build system plugin.")); 00417 configureFileAction = new KAction (i18n("Options..."), "configure", 0, 00418 this, SLOT( slotConfigureFile() ), m_part->actionCollection(), "configure_item" ); 00419 configureFileAction->setToolTip(i18n("Options")); 00420 configureFileAction->setWhatsThis(i18n("<b>Options</b><p>Opens a file configuration dialog supplied by a build system plugin.")); 00421 executeAction = new KAction (i18n("Execute"), "exec", 0, 00422 this, SLOT( slotExecute() ), m_part->actionCollection(), "execute" ); 00423 executeAction->setToolTip(i18n("Execute project")); 00424 executeAction->setWhatsThis(i18n("<b>Execute project</b><p>Executes the main project executable or the current application target.")); 00425 executeGroupAction = new KAction (i18n("Execute"), "exec", 0, 00426 this, SLOT( slotExecuteGroup() ), m_part->actionCollection(), "execute_group" ); 00427 executeGroupAction->setToolTip(i18n("Execute group")); 00428 executeGroupAction->setWhatsThis(i18n("<b>Execute group</b><p>Executes the current application target in a group.")); 00429 executeTargetAction = new KAction (i18n("Execute"), "exec", 0, 00430 this, SLOT( slotExecuteTarget() ), m_part->actionCollection(), "execute_target" ); 00431 executeTargetAction->setToolTip(i18n("Execute target")); 00432 executeTargetAction->setWhatsThis(i18n("<b>Execute target</b><p>Executes application target.")); 00433 cleanAction = new KAction (i18n("Clean"), 0, 0, 00434 this, SLOT( slotClean() ), m_part->actionCollection(), "clean" ); 00435 cleanAction->setToolTip(i18n("Clean project")); 00436 cleanAction->setWhatsThis(i18n("<b>Clean project</b><p>Executes all commands necessary to clean the project.")); 00437 cleanGroupAction = new KAction (i18n("Clean"), 0, 0, 00438 this, SLOT( slotCleanGroup() ), m_part->actionCollection(), "clean_group" ); 00439 cleanGroupAction->setToolTip(i18n("Clean group")); 00440 cleanGroupAction->setWhatsThis(i18n("<b>Clean group</b><p>Executes all commands necessary to clean the current group.")); 00441 cleanTargetAction = new KAction (i18n("Clean"), 0, 0, 00442 this, SLOT( slotCleanTarget() ), m_part->actionCollection(), "clean_target" ); 00443 cleanTargetAction->setToolTip(i18n("Clean target")); 00444 cleanTargetAction->setWhatsThis(i18n("<b>Clean target</b><p>Executes all commands necessary to clean the current target.")); 00445 00446 } 00447 00448 void GenericProjectWidget::showGroupContextMenu( KListView * l, QListViewItem * i, const QPoint & p ) 00449 { 00450 if (( !l ) || (!i) ) 00451 return ; 00452 00453 KPopupMenu popup( i18n( "Group: %1" ).arg( i->text( 0 ) ), this ); 00454 00455 configureGroupAction->plug(&popup); 00456 popup.insertSeparator(); 00457 newGroupAction->plug(&popup); 00458 newTargetAction->plug(&popup); 00459 popup.insertSeparator(); 00460 deleteGroupAction->plug(&popup); 00461 popup.insertSeparator(); 00462 buildGroupAction->plug(&popup); 00463 cleanGroupAction->plug(&popup); 00464 executeGroupAction->plug(&popup); 00465 00466 popup.exec(p); 00467 } 00468 00469 void GenericProjectWidget::showDetailContextMenu( KListView * l, QListViewItem * i, const QPoint & p ) 00470 { 00471 if (( !l ) || (!i) ) 00472 return ; 00473 00474 GenericTargetListViewItem *t = dynamic_cast<GenericTargetListViewItem*>(i); 00475 GenericFileListViewItem *f = dynamic_cast<GenericFileListViewItem*>(i); 00476 00477 if (t) 00478 { 00479 KPopupMenu popup( i18n( "Target: %1" ).arg( t->text( 0 ) ), this ); 00480 00481 configureTargetAction->plug(&popup); 00482 popup.insertSeparator(); 00483 newFileAction->plug(&popup); 00484 addFilesAction->plug(&popup); 00485 popup.insertSeparator(); 00486 deleteTargetAction->plug(&popup); 00487 popup.insertSeparator(); 00488 buildTargetAction->plug(&popup); 00489 cleanTargetAction->plug(&popup); 00490 executeTargetAction->plug(&popup); 00491 00492 popup.exec(p); 00493 } 00494 if (f) 00495 { 00496 KPopupMenu popup( i18n( "File: %1" ).arg( f->text( 0 ) ), this ); 00497 00498 configureFileAction->plug(&popup); 00499 popup.insertSeparator(); 00500 deleteFileAction->plug(&popup); 00501 00502 popup.exec(p); 00503 } 00504 } 00505 00506 00507 00508 //Important slot definitions: 00509 00510 void GenericProjectWidget::slotNewGroup( ) 00511 { 00512 if (!m_overviewListView->currentItem()) 00513 return; 00514 GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem()); 00515 if (!git) 00516 return; 00517 bool ok; 00518 QString groupName = KLineEditDlg::getText(i18n("Group Name"), i18n("Enter the group name:"), "", &ok, this ); 00519 if (!ok) 00520 return; 00521 QDir dir; 00522 if (!dir.mkdir( QDir::cleanDirPath(m_part->projectDirectory() + "/" + git->groupItem()->path() + "/" + groupName)) ) 00523 return; 00524 BuildGroupItem *bit = new BuildGroupItem(groupName, git->groupItem()); 00525 addGroup(bit); 00526 } 00527 00528 void GenericProjectWidget::slotNewTarget( ) 00529 { 00530 if (!m_overviewListView->currentItem()) 00531 return; 00532 GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem()); 00533 if (!git) 00534 return; 00535 bool ok; 00536 QString targetName = KLineEditDlg::getText(i18n("Target Name"), i18n("Enter the target name:"), "", &ok, this ); 00537 if (!ok) 00538 return; 00539 BuildTargetItem *tit = new BuildTargetItem(targetName, git->groupItem()); 00540 addTarget(tit); 00541 } 00542 00543 void GenericProjectWidget::slotBuild( ) 00544 { 00545 m_part->buildSystem()->build(); 00546 } 00547 00548 void GenericProjectWidget::slotBuildGroup( ) 00549 { 00550 if (!m_overviewListView->currentItem()) 00551 return; 00552 GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem()); 00553 if (!git) 00554 return; 00555 m_part->buildSystem()->build(git->groupItem()); 00556 } 00557 00558 void GenericProjectWidget::slotBuildTarget( ) 00559 { 00560 if (!m_detailsListView->currentItem()) 00561 return; 00562 GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem()); 00563 if (!tit) 00564 return; 00565 m_part->buildSystem()->build(tit->targetItem()); 00566 } 00567 00568 void GenericProjectWidget::slotBuildFile( ) 00569 { 00570 if (!m_detailsListView->currentItem()) 00571 return; 00572 GenericFileListViewItem *fit = dynamic_cast<GenericFileListViewItem *>(m_detailsListView->currentItem()); 00573 if (!fit) 00574 return; 00575 m_part->buildSystem()->build(fit->fileItem()); 00576 } 00577 00578 void GenericProjectWidget::slotInstall( ) 00579 { 00580 m_part->buildSystem()->install(); 00581 } 00582 00583 void GenericProjectWidget::slotInstallGroup( ) 00584 { 00585 if (!m_overviewListView->currentItem()) 00586 return; 00587 GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem()); 00588 if (!git) 00589 return; 00590 m_part->buildSystem()->install(git->groupItem()); 00591 } 00592 00593 void GenericProjectWidget::slotInstallTarget( ) 00594 { 00595 if (!m_detailsListView->currentItem()) 00596 return; 00597 GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem()); 00598 if (!tit) 00599 return; 00600 m_part->buildSystem()->install(tit->targetItem()); 00601 } 00602 00603 void GenericProjectWidget::slotExecute( ) 00604 { 00605 m_part->buildSystem()->execute(); 00606 } 00607 00608 void GenericProjectWidget::slotExecuteGroup( ) 00609 { 00610 if (!m_overviewListView->currentItem()) 00611 return; 00612 GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem()); 00613 if (!git) 00614 return; 00615 m_part->buildSystem()->execute(git->groupItem()); 00616 } 00617 00618 void GenericProjectWidget::slotExecuteTarget( ) 00619 { 00620 if (!m_detailsListView->currentItem()) 00621 return; 00622 GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem()); 00623 if (!tit) 00624 return; 00625 m_part->buildSystem()->execute(tit->targetItem()); 00626 } 00627 00628 void GenericProjectWidget::slotNewFile( ) 00629 { 00630 if (!m_detailsListView->currentItem()) 00631 return; 00632 GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem()); 00633 if (!tit) 00634 return; 00635 00636 KDevCreateFile * createFileSupport = m_part->createFileSupport(); 00637 if (createFileSupport) 00638 { 00639 kdDebug() << "GenericProjectWidget::slotNewFile " << tit->targetItem()->parentGroup()->name() << endl; 00640 KDevCreateFile::CreatedFile crFile = 00641 createFileSupport->createNewFile(QString::null, QDir::cleanDirPath(m_part->projectDirectory() + "/" + tit->targetItem()->parentGroup()->path())); 00642 kdDebug() << "status for " << QDir::cleanDirPath(m_part->projectDirectory() + "/" + tit->targetItem()->parentGroup()->path()) << " is " << crFile.status << endl; 00643 // KURL url; 00644 // url.setPath(QDir::cleanDirPath(crFile.dir + "/" + crFile.filename)); 00645 // BuildFileItem *fit = new BuildFileItem(url, tit->targetItem()); 00646 // addFile(fit); 00647 } 00648 } 00649 00650 void GenericProjectWidget::slotAddFiles( ) 00651 { 00652 QString startDir = m_part->projectDirectory(); 00653 if (activeTarget()) 00654 startDir += "/" + activeTarget()->path(); 00655 else if (activeGroup()) 00656 startDir += "/" + activeGroup()->path(); 00657 00658 QStringList fileList = KFileDialog::getOpenFileNames( startDir ); 00659 if( fileList.isEmpty() ) 00660 return; 00661 00662 QStringList lst; 00663 for( QStringList::Iterator it=fileList.begin(); it!=fileList.end(); ++it ) 00664 { 00665 QString absFileName = *it; 00666 if( !absFileName.startsWith(m_part->projectDirectory()) ) 00667 continue; 00668 00669 lst << absFileName.mid( m_part->projectDirectory().length() + 1 ); 00670 } 00671 00672 m_part->addFiles( lst ); 00673 } 00674 00675 void GenericProjectWidget::slotDeleteGroup( ) 00676 { 00677 if (!m_overviewListView->currentItem()) 00678 return; 00679 GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem()); 00680 if (!git) 00681 return; 00682 00683 RemoveSubprojectDialog dia(i18n("Remove Group"), i18n("Remove group?"), this); 00684 if (dia.exec() == QDialog::Accepted) 00685 { 00686 if (dia.removeFromDisk()) 00687 { 00688 QDir d; 00689 d.rmdir( QDir::cleanDirPath(m_part->projectDirectory() + "/" + git->groupItem()->path())); 00690 } 00691 takeGroup(git); 00692 } 00693 } 00694 00695 void GenericProjectWidget::slotDeleteTarget( ) 00696 { 00697 if (!m_detailsListView->currentItem()) 00698 return; 00699 GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem()); 00700 if (!tit) 00701 return; 00702 00703 if (KMessageBox::questionYesNo(this, i18n("Remove target?")) == KMessageBox::Yes) 00704 { 00705 takeTarget(tit); 00706 } 00707 } 00708 00709 void GenericProjectWidget::slotDeleteFile( ) 00710 { 00711 if (!m_detailsListView->currentItem()) 00712 return; 00713 GenericFileListViewItem *fit = dynamic_cast<GenericFileListViewItem *>(m_detailsListView->currentItem()); 00714 if (!fit) 00715 return; 00716 00717 RemoveSubprojectDialog dia(i18n("Remove File"), i18n("Remove file?"), this); 00718 if (dia.exec() == QDialog::Accepted) 00719 { 00720 if (dia.removeFromDisk()) 00721 { 00722 kdDebug() << "GenericProjectWidget::slotDeleteFile " << fit->fileItem()->url().url() << endl; 00723 KIO::NetAccess::del(fit->fileItem()->url()); 00724 } 00725 takeFile(fit); 00726 } 00727 } 00728 00729 void GenericProjectWidget::slotConfigureGroup( ) 00730 { 00731 kdDebug() << "GenericProjectWidget::slotConfigureGroup 1" << endl; 00732 if (!m_overviewListView->currentItem()) 00733 return; 00734 kdDebug() << "GenericProjectWidget::slotConfigureGroup 2" << endl; 00735 GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem()); 00736 if (!git) 00737 return; 00738 kdDebug() << "GenericProjectWidget::slotConfigureGroup 3" << endl; 00739 00740 KDialogBase *dia = new KDialogBase(KDialogBase::Tabbed, i18n("Group Options"), 00741 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, this); 00742 kdDebug() << "GenericProjectWidget::slotConfigureGroup 4" << endl; 00743 00744 m_part->buildSystem()->configureBuildItem(dia, git->buildItem()); 00745 kdDebug() << "GenericProjectWidget::slotConfigureGroup 5" << endl; 00746 } 00747 00748 void GenericProjectWidget::slotConfigureTarget( ) 00749 { 00750 if (!m_detailsListView->currentItem()) 00751 return; 00752 GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem()); 00753 if (!tit) 00754 return; 00755 00756 KDialogBase *dia = new KDialogBase(KDialogBase::Tabbed, i18n("Target Options"), 00757 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, this); 00758 00759 m_part->buildSystem()->configureBuildItem(dia, tit->buildItem()); 00760 } 00761 00762 void GenericProjectWidget::slotConfigureFile( ) 00763 { 00764 if (!m_detailsListView->currentItem()) 00765 return; 00766 GenericFileListViewItem *fit = dynamic_cast<GenericFileListViewItem *>(m_detailsListView->currentItem()); 00767 if (!fit) 00768 return; 00769 00770 KDialogBase *dia = new KDialogBase(KDialogBase::Tabbed, i18n("File Options"), 00771 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, this); 00772 00773 m_part->buildSystem()->configureBuildItem(dia, fit->buildItem()); 00774 } 00775 00776 void GenericProjectWidget::slotClean( ) 00777 { 00778 m_part->buildSystem()->clean(); 00779 } 00780 00781 void GenericProjectWidget::slotCleanGroup( ) 00782 { 00783 if (!m_overviewListView->currentItem()) 00784 return; 00785 GenericGroupListViewItem *git = dynamic_cast<GenericGroupListViewItem *>(m_overviewListView->currentItem()); 00786 if (!git) 00787 return; 00788 m_part->buildSystem()->clean(git->groupItem()); 00789 } 00790 00791 void GenericProjectWidget::slotCleanTarget( ) 00792 { 00793 if (!m_detailsListView->currentItem()) 00794 return; 00795 GenericTargetListViewItem *tit = dynamic_cast<GenericTargetListViewItem *>(m_detailsListView->currentItem()); 00796 if (!tit) 00797 return; 00798 m_part->buildSystem()->clean(tit->targetItem()); 00799 } 00800 00801 00802 void GenericProjectWidget::takeGroup( GenericGroupListViewItem * it ) 00803 { 00804 //@todo adymo: allow to remove nested subdirs 00805 BuildGroupItem *group = it->groupItem(); 00806 if (group->groups().count() == 0) 00807 { 00808 m_groupToItem.remove( group ); 00809 delete group; 00810 delete it; 00811 } 00812 } 00813 00814 void GenericProjectWidget::takeTarget( GenericTargetListViewItem * item ) 00815 { 00816 kdDebug() << "============> takeTarget" << endl; 00817 00818 BuildTargetItem *target = item->targetItem(); 00819 if( !target ){ 00820 kdDebug() << "============> no target!!!!!" << endl; 00821 return; 00822 } 00823 00824 QStringList fileList; 00825 QValueList<BuildFileItem*> files = target->files(); 00826 for( QValueList<BuildFileItem*>::Iterator it=files.begin(); it!=files.end(); ++ it ) 00827 { 00828 QString path = (*it)->url().path(); 00829 kdDebug() << "============> remove: " << path << endl; 00830 if( !path.startsWith(m_part->projectDirectory()) ) 00831 continue; 00832 00833 fileList << path.mid( m_part->projectDirectory().length() + 1 ); 00834 } 00835 00836 delete item; 00837 m_targetToItem.remove( target ); 00838 delete target; 00839 00840 kdDebug() << "===========> remove files: " << fileList.join( ", " ); 00841 } 00842 00843 void GenericProjectWidget::takeFile( GenericFileListViewItem * it ) 00844 { 00845 BuildFileItem *file = it->fileItem(); 00846 m_fileToItem.remove( file ); 00847 delete file; 00848 delete it; 00849 } 00850 00851 void GenericProjectWidget::slotItemExecuted( QListViewItem * item ) 00852 { 00853 GenericGroupListViewItem* groupItem = dynamic_cast<GenericGroupListViewItem*>( item ); 00854 GenericTargetListViewItem* targetItem = dynamic_cast<GenericTargetListViewItem*>( item ); 00855 GenericFileListViewItem* fileItem = dynamic_cast<GenericFileListViewItem*>( item ); 00856 00857 if( groupItem && groupItem->groupItem() ) 00858 emit groupExecuted( groupItem->groupItem() ); 00859 else if( targetItem && targetItem->targetItem() ){ 00860 kdDebug() << "set active target while execute" << endl; 00861 m_activeTarget = targetItem->targetItem(); 00862 emit targetExecuted( m_activeTarget ); 00863 } 00864 else if( fileItem ) 00865 { 00866 kdDebug() << "emit fileExecuted()" << endl; 00867 emit fileExecuted( fileItem->fileItem() ); 00868 } 00869 } 00870 00871 void GenericProjectWidget::slotDeleteTargetOrFile( ) 00872 { 00873 QListViewItem * item = m_detailsListView->currentItem(); 00874 if (!item) 00875 return; 00876 GenericTargetListViewItem* targetItem = dynamic_cast<GenericTargetListViewItem*>( item ); 00877 GenericFileListViewItem* fileItem = dynamic_cast<GenericFileListViewItem*>( item ); 00878 if (targetItem) 00879 slotDeleteTarget(); 00880 else if (fileItem) 00881 slotDeleteFile(); 00882 } 00883 00884 void GenericProjectWidget::slotConfigureTargetOrFile( ) 00885 { 00886 QListViewItem * item = m_detailsListView->currentItem(); 00887 if (!item) 00888 return; 00889 GenericTargetListViewItem* targetItem = dynamic_cast<GenericTargetListViewItem*>( item ); 00890 GenericFileListViewItem* fileItem = dynamic_cast<GenericFileListViewItem*>( item ); 00891 if (targetItem) 00892 slotConfigureTarget(); 00893 else if (fileItem) 00894 slotConfigureFile(); 00895 } 00896 00897 #include "genericproject_widget.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 Wed Oct 6 17:38:54 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003