summaryrefslogtreecommitdiffstats
path: root/buildtools/autotools/autodetailsview.cpp
blob: 7002b7c803a6896d8a4d76c0618b0f1dab5964de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
/*
   KDevelop Autotools Support
   Copyright (c) 2002 by Victor Roeder <victor_roeder@gmx.de>
   Copyright (c) 2005 by Matt Rogers <mattr@kde.org>

 ***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************
*/

#include "autodetailsview.h"

/** TQt */
#include <tqregexp.h>
#include <tqlistview.h>
#include <tqwidget.h>
#include <tqheader.h>
#include <tqlayout.h>

 /** KDE Libs */
#include <kxmlguiclient.h>
#include <kaction.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <klocale.h>
#include <klistview.h>
#include <kpopupmenu.h>

/** KDevelop */
#include "kdevappfrontend.h"
#include "kdevcore.h"
#include "kdevmainwindow.h"
#include "kdevpartcontroller.h"
#include "kdevcreatefile.h"
#include "kdevlanguagesupport.h"
#include "kdevmakefrontend.h"
#include "urlutil.h"

#include "domutil.h"

#include "targetoptionsdlg.h"
#include "addfiledlg.h"
#include "addicondlg.h"
#include "addexistingfilesdlg.h"
#include "removefiledlg.h"
#include "removetargetdlg.h"

#include "autolistviewitems.h"
#include "autotoolsaction.h"
#include "autoprojectpart.h"
#include "autoprojectwidget.h"

#include "subclassesdlg.h"

AutoDetailsView::AutoDetailsView(AutoProjectWidget* widget, AutoProjectPart* part, TQWidget *tqparent, const char *name)
  : AutoProjectViewBase(tqparent, name)
{
	m_widget = widget;
	m_part = part;

	initActions();
	TQDomDocument dom = *(m_part->projectDom());
	m_subclasslist = DomUtil::readPairListEntry(dom, "/kdevautoproject/subclassing",
	                                            "subclass","sourcefile", "uifile");

	m_listView->setAllColumnsShowFocus( true );
	m_listView->setRootIsDecorated( true );
	m_listView->setResizeMode( TQListView::LastColumn );
	m_listView->addColumn( TQString() );
	m_listView->header()->hide();
	targetOptionsAction->setEnabled( false );
	addNewFileAction->setEnabled( false );
	addExistingFileAction->setEnabled( false );
	buildTargetAction->setEnabled( false );
	executeTargetAction->setEnabled( false );
	removeDetailAction->setEnabled(false);
	connect( m_listView, TQT_SIGNAL( selectionChanged( TQListViewItem* ) ),
	         this, TQT_SLOT( slotSelectionChanged( TQListViewItem* ) ) );
	connect( m_listView, TQT_SIGNAL( selectionChanged() ),
	         this, TQT_SLOT( slotSelectionChanged( ) ) );
}


AutoDetailsView::~AutoDetailsView()
{
}

/**
 * If nothing selected, disable all the icons.
 */
void AutoDetailsView::slotSelectionChanged( ){

	if ( m_listView->selectedItems().isEmpty()){
		targetOptionsAction->setEnabled( false );
		addNewFileAction->setEnabled( false );
		addExistingFileAction->setEnabled( false );
		buildTargetAction->setEnabled( false );
		executeTargetAction->setEnabled( false );
		removeDetailAction->setEnabled(false);
	}
}

/**
 * Change the enabled icons depending on what is selected.
 * This is never called if nothing is selected..
 * @param item
 */
void AutoDetailsView::slotSelectionChanged( TQListViewItem* item )
{
	bool isTarget = false;
	bool isRegularTarget = false;
	bool isFile = false;
	bool isProgram = false;

	if ( item )
	{
		// We assume here that ALL items in the detail list view
		// are ProjectItem's
		ProjectItem * pvitem = static_cast<ProjectItem*>( item );
		TargetItem* titem = 0;

		if ( pvitem->type() == ProjectItem::File )
		{
			titem = static_cast <TargetItem*> ( pvitem->tqparent() );

			TQString primary = titem->primary;
			if ( primary == "PROGRAMS" || primary == "LIBRARIES" ||
					primary == "LTLIBRARIES" || primary == "JAVA" )
			{
				isRegularTarget = true; // not a data group
				isFile = true;
			}
		}
		else
		{
			titem = static_cast <TargetItem*> ( pvitem );
			isTarget = true;
		}

		TQString primary = titem->primary;
		if ( primary == "PROGRAMS" || primary == "LIBRARIES" ||
				primary == "LTLIBRARIES" || primary == "JAVA" )
		{
			isRegularTarget = true; // not a data group
		}

		if ( primary == "PROGRAMS" )
			isProgram = true;
	}

	targetOptionsAction->setEnabled( isRegularTarget && !isFile );
	addNewFileAction->setEnabled( isTarget );
	addExistingFileAction->setEnabled( isTarget );
	removeDetailAction->setEnabled ( true );

	if ( isRegularTarget && isFile || isRegularTarget )
	{
		buildTargetAction->setEnabled ( true );
		if( isProgram )
			executeTargetAction->setEnabled ( true );
	}
	else
	{
		buildTargetAction->setEnabled ( false );
		executeTargetAction->setEnabled ( false );
	}
	emit selectionChanged( item );
}

void AutoDetailsView::initActions()
{
	KActionCollection * actions = new KActionCollection( this );

	targetOptionsAction = new AutoToolsAction( i18n( "Options..." ), "configure", 0,
	                                           TQT_TQOBJECT(this), TQT_SLOT( slotTargetOptions() ), actions,
	                                   "target options" );
	targetOptionsAction->setWhatsThis(i18n("<b>Options</b><p>Target options dialog that "
	                                       "provides settings for linker flags and lists "
	                                       "of dependencies and external libraries that "
	                                       "are used when compiling the target."));
	targetOptionsAction->plug( m_optionsButton );
	targetOptionsAction->setEnabled( false );

	TQToolTip::add( m_button1, tr2i18n( "Create New File..." ) );
	addNewFileAction = new AutoToolsAction( i18n( "Create New File..." ), "filenew", 0,
	                                        TQT_TQOBJECT(this), TQT_SLOT( slotAddNewFile() ), actions,
	                                "add new file" );
	addNewFileAction->setWhatsThis(i18n("<b>Create new file</b><p>Creates a new file and "
	                                    "adds it to a currently selected target."));
	addNewFileAction->plug( m_button1 );
	addNewFileAction->setEnabled( false );

	TQToolTip::add( m_button2, tr2i18n( "Add Existing Files..." ) );
	addExistingFileAction = new AutoToolsAction( i18n( "Add Existing Files..." ), "fileimport", 0,
	                                             TQT_TQOBJECT(this), TQT_SLOT( slotAddExistingFile() ), actions,
	                                     "add existing file" );
	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. They will be added to "
	                                         "noinst_HEADERS instead."));
	addExistingFileAction->plug( m_button2 );
	addExistingFileAction->setEnabled( false );

	addIconAction = new KAction( i18n( "Add Icon..." ), "iconadd_kdevelop", 0,
	                             TQT_TQOBJECT(this), TQT_SLOT( slotAddIcon() ), actions, "add icon" );
	addIconAction->setWhatsThis(i18n("<b>Add icon</b><p>Adds an icon to a KDEICON target."));

	TQToolTip::add( m_button4, tr2i18n( "Build Target"));
	buildTargetAction = new AutoToolsAction( i18n( "Build Target..." ), "launch", 0,
	                                         TQT_TQOBJECT(this), TQT_SLOT( slotBuildTarget() ), actions,
	                                 "build target" );
	buildTargetAction->setWhatsThis(i18n("<b>Build target</b><p>Constructs a series of "
	                                     "make commands to build the selected target. "
	                                     "Also builds dependent targets."));
	buildTargetAction->plug( m_button4 );
	buildTargetAction->setEnabled( false );

	TQToolTip::add( m_button5, tr2i18n( "Execute Target..."));
	executeTargetAction = new AutoToolsAction( i18n( "Execute Target..." ), "exec", 0,
	                                           TQT_TQOBJECT(this), TQT_SLOT( slotExecuteTarget() ), actions,
	                                   "execute target" );
	executeTargetAction->setWhatsThis(i18n("<b>Execute target</b><p>Executes the target "
	                                       "and tries to build in case it is not built."));
	executeTargetAction->plug( m_button5 );
	executeTargetAction->setEnabled( false );

	setActiveTargetAction = new KAction( i18n( "Make Target Active" ), "", 0,
	                                     TQT_TQOBJECT(this), TQT_SLOT( slotSetActiveTarget() ), actions,
	                                     "set active target" );
	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. "
	                                         "Using the <b>Build Active Target</b> menu "
	                                         "command builds it."));

	TQToolTip::add( m_button3, tr2i18n( "Remove"));
	removeDetailAction = new AutoToolsAction( i18n( "Remove" ), "editdelete", 0, TQT_TQOBJECT(this),
	                                  TQT_SLOT( slotRemoveDetail() ), actions,
	                                  "remove detail" );
	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."));
	removeDetailAction->plug( m_button3 );
	removeDetailAction->setEnabled( false );

	connect( m_listView, TQT_SIGNAL( executed( TQListViewItem* ) ),
	         this, TQT_SLOT( slotDetailsExecuted( TQListViewItem* ) ) );
	connect( m_listView, TQT_SIGNAL( returnPressed( TQListViewItem* ) ),
	         this, TQT_SLOT( slotDetailsExecuted( TQListViewItem* ) ) );
	connect( m_listView, TQT_SIGNAL( contextMenu( KListView*, TQListViewItem*, const TQPoint& ) ),
	         this, TQT_SLOT( slotDetailsContextMenu( KListView*, TQListViewItem*, const TQPoint& ) ) );
}

TQString AutoDetailsView::getUiFileLink(const TQString& relpath, const TQString& filename)
{
	DomUtil::PairList::iterator it;

	for (it=m_subclasslist.begin(); it != m_subclasslist.end(); ++it)
	{
		if ((*it).first == TQString("/")+relpath+filename)
			return (*it).second;
	}

	return TQString();
}

void AutoDetailsView::slotTargetOptions()
{
	kdDebug( 9020 ) << "AutoDetailsView::slotTargetOptions()" << endl;
	TargetItem *titem = dynamic_cast <TargetItem*> ( m_listView->selectedItem() );

	if ( !titem )
		return;

	TargetOptionsDialog dlg( m_widget, titem, this, "target options dialog" );

	dlg.setCaption ( i18n ( "Target Options for '%1'" ).arg ( titem->name ) );

	dlg.exec();
}


void AutoDetailsView::slotAddNewFile()
{
	TargetItem * titem = dynamic_cast <TargetItem*> ( m_listView->selectedItem() );
	if ( !titem )
		return;

	KDevCreateFile * createFileSupport = m_part->extension<KDevCreateFile>("KDevelop/CreateFile");
	if (createFileSupport)
	{
		KDevCreateFile::CreatedFile crFile =
			createFileSupport->createNewFile(TQString(),
			                                 m_widget->selectedSubproject()->path);
/*		if (crFile.status == KDevCreateFile::CreatedFile::STATUS_OK)
        {
			FileItem *fitem = m_widget->createFileItem(crFile.filename, m_widget->selectedSubproject());
			titem->sources.append(fitem);
			titem->insertItem(fitem);
			emit selectionChanged( titem ); // update list view
		}*/
    } else {
		AddFileDialog dlg( m_part, m_widget, m_widget->selectedSubproject(), titem,
		                   this, "add file dialog" );
		TQString caption;
		if ( titem->name.isEmpty() )
			caption = i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix );
		else
			caption = titem->name;

		dlg.setCaption ( i18n ( "Add New File to '%1'" ).arg ( caption ) );

		if ( dlg.exec() )
			emit selectionChanged( titem ); // update list view
	}
}


void AutoDetailsView::slotAddExistingFile()
{
	TargetItem * titem = dynamic_cast <TargetItem*> ( m_listView->selectedItem() );
	if ( !titem )
		return;

	AddExistingFilesDialog dlg( m_part, m_widget, m_widget->selectedSubproject(), titem,
	                            this, "add existing files" );
	TQString caption;
	if ( titem->name.isEmpty() )
		caption = i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix );
	else
		caption = titem->name;

	dlg.setCaption( i18n( "Add Existing Files to '%1'" ).arg ( caption ) );

	dlg.exec();
}


void AutoDetailsView::slotAddIcon()
{
	TargetItem * titem = dynamic_cast <TargetItem*> ( m_listView->selectedItem() );
	if ( !titem )
		return ;

	AddIconDialog dlg( m_part, m_widget, m_widget->selectedSubproject(), titem,
	                   this, "add icon" );
	dlg.exec();
}


void AutoDetailsView::slotBuildTarget()
{
	ProjectItem * pvitem = dynamic_cast<ProjectItem*>( m_listView->selectedItem() );
	if ( !pvitem )
		return;

	TargetItem* titem = 0;

	if ( pvitem->type() == ProjectItem::File )
		titem = static_cast <TargetItem*> ( pvitem->tqparent() );
	else
		titem = static_cast <TargetItem*> ( m_listView->selectedItem() );

	TQString relpath = URLUtil::getRelativePath( m_part->topsourceDirectory(), m_part->projectDirectory() ) + "/" + m_widget->selectedSubproject()->relativePath();

	m_part->buildTarget(relpath, titem);
}

void AutoDetailsView::slotExecuteTarget()
{
	ProjectItem * pvitem = dynamic_cast<ProjectItem*>( m_listView->selectedItem() );
	if ( !pvitem )
		return;

	TargetItem* titem = 0;

	if ( pvitem->type() == ProjectItem::File )
		titem = static_cast <TargetItem*> ( pvitem->tqparent() );
	else
		titem = static_cast <TargetItem*> ( m_listView->selectedItem() );

	TQString relpath = URLUtil::getRelativePath( m_part->topsourceDirectory(), m_part->projectDirectory() ) + "/" + m_part->activeDirectory();
	m_part->executeTarget(TQDir( DomUtil::readEntry( *m_part->projectDom(), "/kdevautoproject/run/cwd/"+titem->name )), titem);
}

void AutoDetailsView::slotRemoveDetail()
{
	ProjectItem * pvitem = dynamic_cast<ProjectItem*>( m_listView->selectedItem() );

	if ( pvitem && ( pvitem->type() == ProjectItem::File ) )
	{
		FileItem * fitem = static_cast <FileItem*> ( m_listView->selectedItem() );
		if(fitem && fitem->is_subst)
		{
			fitem->changeMakefileEntry("");
			return;
		}

		TQListViewItem* sibling = fitem->nextSibling();

		if ( !fitem )
			return;

		TargetItem *titem = static_cast<TargetItem*>( fitem->tqparent() );

		RemoveFileDialog dlg( m_widget, m_part, m_widget->selectedSubproject(),
		                      titem, fitem->text( 0 ), this, "remove file dialog" );

		TQString caption;
		if ( titem->name.isEmpty() )
			caption = i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix );
		else
			caption = titem->name;

		dlg.setCaption ( i18n ( "Remove File From '%1'" ).arg ( caption ) );

		if ( dlg.exec() )
		{
			emit selectionChanged( titem );

			if ( sibling)
			{
				m_listView->setSelected ( sibling, true );
				m_listView->ensureItemVisible ( sibling );
			}
		}

		return;
	}

	if ( pvitem && ( pvitem->type() == ProjectItem::Target ) )
	{
		TargetItem* titem = static_cast <TargetItem*> ( m_listView->selectedItem() );
		TQListViewItem* sibling = titem->nextSibling();

		if ( !titem )	return;

		bool isactive = ( titem == m_widget->activeTarget() );
		RemoveTargetDialog dlg ( m_widget, m_part, m_widget->selectedSubproject(),
		                         titem, this, "remove target dialog" );

		dlg.setCaption ( i18n ( "Remove Target From '%1'" ).arg ( m_widget->selectedSubproject()->subdir ) );

		if ( dlg.exec() )
		{
			//details->takeItem ( titem );

			m_widget->slotOverviewSelectionChanged ( m_widget->selectedSubproject() );

			if( isactive )
				m_widget->setActiveTarget("");
			if ( sibling)
			{
				m_listView->setSelected ( sibling, true );
				m_listView->ensureItemVisible ( sibling );
			}
		}

		return;
	}
}


void AutoDetailsView::slotDetailsContextMenu( KListView *, TQListViewItem *item, const TQPoint &p )
{
	if ( !item )
		return;

	ProjectItem *pvitem = dynamic_cast<ProjectItem*>( item );
	if ( !pvitem )
	{
		kdDebug(9020) << k_funcinfo << "Cast to type of ProjectItem* failed."
			<< "Details context menu will be empty!";
		return;
	}

	if ( pvitem->type() == ProjectItem::Target )
	{

		TargetItem * titem = dynamic_cast<TargetItem*>( pvitem );
		if ( !titem )
		{
			kdDebug(9020) << k_funcinfo << "Unable to populate target item menu"
				<< " due to failed cast. " << endl;
			return;
		}

		TQString caption;
		if ( titem->name.isEmpty() )
			caption = i18n ( "%1 in %2" ).arg ( titem->primary ).arg ( titem->prefix );
		else
			caption = titem->name;

		KPopupMenu popup( i18n( "Target: %1" ).tqarg( caption ), this );

		if ( titem->primary == "PROGRAMS" || titem->primary == "LIBRARIES"
		        || titem->primary == "LTLIBRARIES" || titem->primary == "JAVA" )
		{
			targetOptionsAction->plug( &popup );
			popup.insertSeparator();
			addNewFileAction->plug( &popup );
			addExistingFileAction->plug( &popup );
			popup.insertSeparator();
			removeDetailAction->plug( &popup );
			popup.insertSeparator();
			setActiveTargetAction->plug( &popup );
			popup.insertSeparator();
			buildTargetAction->plug( &popup );
			if( titem->primary == "PROGRAMS")
				executeTargetAction->plug( &popup );
		}
		else if ( titem->primary == "KDEDOCS" )
		{
			addNewFileAction->plug( &popup );
			addExistingFileAction->plug( &popup );
			popup.insertSeparator();
			removeDetailAction->plug( &popup );
			popup.insertSeparator();
			buildTargetAction->plug( &popup );
		}
		else if ( titem->primary == "KDEICON" )
		{
			addIconAction->plug( &popup );
			popup.insertSeparator();
			removeDetailAction->plug( &popup );
		}
		else
		{
			addNewFileAction->plug( &popup );
			addExistingFileAction->plug( &popup );
			popup.insertSeparator();
			removeDetailAction->plug( &popup );
		}

		popup.exec( p );

	}
	else if ( pvitem->type() == ProjectItem::File )
	{

		FileItem * fitem = dynamic_cast<FileItem*>( pvitem );
		if ( !fitem )
		{
			kdDebug(9020) << k_funcinfo << "Unable to populate file item menu"
				<< " due to failed cast. " << endl;
			return;
		}

		KPopupMenu popup( i18n( "File: %1" ).tqarg( fitem->name ), this );

		removeDetailAction->plug( &popup );
		KURL::List urls;
		urls.append(m_widget->selectedSubproject()->path + "/" + fitem->name);
		FileContext context(urls);

		int idSubclassWidget = popup.insertItem(SmallIconSet("qmake_subclass"),
		                                        i18n("Subclassing Wizard...") );
		popup.tqsetWhatsThis(idSubclassWidget, i18n("<b>Subclass widget</b><p>Launches "
		                                          "<b>Subclassing</b> wizard. "
		                                          "It allows to create a subclass from the "
		                                          "class defined in .ui file. "
		                                          "There is also possibility to implement "
		                                          "slots and functions defined in the base "
		                                          "class."));
		int idUISubclasses = popup.insertItem(SmallIconSet("qmake_subclass"),
		                                      i18n("List of Subclasses..."));
		popup.tqsetWhatsThis(idUISubclasses, i18n("<b>List of subclasses</b><p>Shows "
		                                        "subclasses list editor. "
		                                        "There is possibility to add or remove "
		                                        "subclasses from the list."));
		int idUpdateWidgetclass = popup.insertItem(SmallIconSet("qmake_subclass"),
		                                           i18n("Edit ui-Subclass..."));
		popup.tqsetWhatsThis(idUpdateWidgetclass, i18n("<b>Edit ui-subclass</b><p>Launches "
		                                             "<b>Subclassing</b> wizard and prompts "
		                                             "to implement missing in childclass "
		                                             "slots and functions."));
		int idViewUIH = popup.insertItem(SmallIconSet("qmake_ui_h"),
		                                 i18n("Open ui.h File"));
		popup.tqsetWhatsThis(idViewUIH, i18n("<b>Open ui.h file</b><p>Opens .ui.h file "
		                                   "associated with the selected .ui."));

		if (!fitem->name.tqcontains(TQRegExp("ui$")) || fitem->is_subst == true)
		{
            popup.removeItem(idUISubclasses);
			popup.removeItem(idViewUIH);
			popup.removeItem(idSubclassWidget);
		}

		if (fitem->uiFileLink.isEmpty())
			popup.removeItem(idUpdateWidgetclass);

		if(fitem->is_subst == false)
			m_part->core()->fillContextMenu( &popup, &context );

		int r = popup.exec( p );

		if(r == idViewUIH)
		{
			m_part->partController()->editDocument(KURL(m_widget->selectedSubproject()->path
			                                            + "/" + TQString(fitem->name + ".h")));
		}
		else if (r == idSubclassWidget)
		{
			TQStringList newFileNames;
			newFileNames = m_part->languageSupport()->subclassWidget(m_widget->selectedSubproject()->path + "/" + fitem->name);
			if (!newFileNames.empty())
			{
				TQDomDocument &dom = *(m_part->projectDom());
				for (uint i=0; i<newFileNames.count(); i++)
				{
					TQString srcfile_relpath = newFileNames[i];
					srcfile_relpath.remove(0,m_part->projectDirectory().length());
					TQString uifile_relpath = TQString(m_widget->selectedSubproject()->path + "/" + fitem->name).remove(0,m_part->projectDirectory().length());
					DomUtil::PairList list = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing",
					                                                    "subclass","sourcefile", "uifile");

					list << DomUtil::Pair(srcfile_relpath,uifile_relpath);
					DomUtil::writePairListEntry(dom, "/kdevautoproject/subclassing",
					                            "subclass", "sourcefile", "uifile", list);
					newFileNames[i] = newFileNames[i].tqreplace(TQRegExp(m_part->projectDirectory()+"/"),"");
				}
				m_subclasslist = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing",
				                                            "subclass","sourcefile", "uifile");
				m_part->addFiles(newFileNames);
			}
		}
		else if (r == idUpdateWidgetclass)
		{
			TQString noext = m_widget->selectedSubproject()->path + "/" + fitem->name;

			if (noext.tqfindRev('.')>-1)
				noext = noext.left(noext.tqfindRev('.'));

			TQStringList dummy;
			TQString uifile = fitem->uiFileLink;

			if (uifile.tqfindRev('/')>-1)
			{
				TQStringList uisplit = TQStringList::split('/',uifile);
				uifile=uisplit[uisplit.count()-1];
			}

			m_part->languageSupport()->updateWidget(m_widget->selectedSubproject()->path
			                                        + "/" + uifile, noext);
		}
		else if (r == idUISubclasses)
		{
			TQDomDocument &dom = *(m_part->projectDom());
			DomUtil::PairList list = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing",
			                                                    "subclass","sourcefile", "uifile");
			SubclassesDlg *sbdlg = new SubclassesDlg( TQString(m_widget->selectedSubproject()->path + "/" +fitem->name).remove(0,m_part->projectDirectory().length()),
			                                          list, m_part->projectDirectory());

			if (sbdlg->exec())
			{
				TQDomElement el = DomUtil::elementByPath( dom,  "/kdevautoproject");
				TQDomElement el2 = DomUtil::elementByPath( dom,  "/kdevautoproject/subclassing");
				if ( (!el.isNull()) && (!el2.isNull()) )
				{
					el.removeChild(el2);
				}

				DomUtil::writePairListEntry(dom, "/kdevautoproject/subclassing", "subclass",
				                            "sourcefile", "uifile", list);

				m_subclasslist = DomUtil::readPairListEntry(dom,"/kdevautoproject/subclassing",
				                                            "subclass","sourcefile", "uifile");
			}
		}
	}
}


void AutoDetailsView::slotDetailsExecuted( TQListViewItem *item )
{
	if ( !item )
		return ;

	ProjectItem *pvitem = static_cast<ProjectItem*>( item );
	if ( pvitem->type() != ProjectItem::File )
		return ;

	if ( !m_widget->selectedSubproject() )
		return;

	TQString dirName = m_widget->selectedSubproject()->path;
	FileItem *fitem = static_cast<FileItem*>( item );
	if(fitem->is_subst)
	{
		fitem->changeSubstitution();
		return;
	}

	m_part->partController()->editDocument( KURL( dirName + "/" + fitem->name ) );
}

void AutoDetailsView::slotSetActiveTarget()
{
	TargetItem * titem = static_cast<TargetItem*>( m_listView->selectedItem() );
	if ( !titem ) return ;

       SubprojectItem * subpitem = m_widget->selectedSubproject();
       if ( !subpitem ) return;

	TQString targetPath = subpitem->path + "/" + titem->name;
	targetPath = targetPath.mid( m_part->projectDirectory().length() + 1 );
	kdDebug( 9020 ) << "Setting active " << targetPath << endl;
	m_widget->setActiveTarget( targetPath );
	TQDomDocument &dom = *m_part->projectDom();
	DomUtil::writeEntry( dom, "/kdevautoproject/general/activetarget", targetPath );
}

void AutoDetailsView::focusOutEvent(TQFocusEvent */*e*/)
{
    m_widget->setLastFocusedView(AutoProjectWidget::DetailsView);
}

#include "autodetailsview.moc"

//kate: indent-mode csands; tab-width 4; space-indent off;