summaryrefslogtreecommitdiffstats
path: root/parts/ctags2/ctags2_settingswidget.cpp
blob: 4bcdb122bae9b046416a8656323e27b08724bf80 (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
/***************************************************************************
 *   Copyright (C) 2005 by Jens Dagerbo                                    *
 *   jens.dagerbo@swipnet.se                                               *
 *                                                                         *
 *   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 <qcheckbox.h>
#include <qradiobutton.h>
#include <qheader.h>

#include <klineedit.h>
#include <klistview.h>
#include <kdevproject.h>
#include <kapplication.h>
#include <kurlcompletion.h>
#include <kurlrequester.h>
#include <kconfig.h>
#include <kurl.h>
#include <kdevplugin.h>
#include <domutil.h>

#include "ctags2_settingswidget.h"
#include "ctags2_part.h"
#include "ctags2_selecttagfile.h"
#include "ctags2_createtagfile.h"


CTags2SettingsWidget::CTags2SettingsWidget( CTags2Part * part, QWidget* parent, const char* name, WFlags fl )
	: CTags2SettingsWidgetBase( parent, name, fl ), m_part( part )
{
	binaryPath->completionObject()->setMode( KURLCompletion::FileCompletion );
	binaryPath->setMode( KFile::File | KFile::LocalOnly );
	binaryPath->setShowLocalProtocol( false );

	tagfilePath->completionObject()->setMode( KURLCompletion::FileCompletion );
	tagfilePath->setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly );
	tagfilePath->setShowLocalProtocol( false );

	otherTagFiles->setSorting( -1 );
// 	otherTagFiles->addColumn( "" );
// 	otherTagFiles->header()->hide();
   otherTagFiles->setFullWidth( true );

	loadSettings();
}

CTags2SettingsWidget::~CTags2SettingsWidget()
{
}

void CTags2SettingsWidget::loadSettings()
{
	QDomDocument & dom = *m_part->projectDom();

	QString customArgs = DomUtil::readEntry( dom, "/ctagspart/customArguments" );
	if ( !customArgs.isEmpty() )
	{
		tagfileCustomBox->setChecked( true );
		tagfileCustomEdit->setText( customArgs );
	}

	QString customTagfile = DomUtil::readEntry( dom, "/ctagspart/customTagfilePath" );
	if (customTagfile.isEmpty())
	{
		customTagfile =  m_part->project()->projectDirectory() + "/tags";
	}
	tagfilePath->setURL(customTagfile);

	QStringList activeTagsFiles = DomUtil::readListEntry(dom, "/ctagspart/activeTagsFiles", "file");

	KConfig * config = kapp->config();
	config->setGroup( "CTAGS" );
	showDeclarationBox->setChecked( config->readBoolEntry( "ShowDeclaration", true ) );
	showDefinitionBox->setChecked( config->readBoolEntry( "ShowDefinition", true ) );
	showLookupBox->setChecked( config->readBoolEntry( "ShowLookup", true ) );
	jumpToFirstBox->setChecked( config->readBoolEntry( "JumpToFirst", false ) );
	QString ctagsBinary = config->readEntry( "ctags binary" ).stripWhiteSpace();
	if ( !ctagsBinary.isEmpty() )
	{
		binaryPath->setURL( ctagsBinary );
	}

	config->setGroup( "CTAGS-tagsfiles" );
	QMap<QString,QString> entryMap = config->entryMap( "CTAGS-tagsfiles" );
	QMap<QString,QString>::const_iterator it = entryMap.begin();
    while ( it != entryMap.end() )
	{
		QString file = config->readPathEntry( it.key() );
		new TagsItem( otherTagFiles, it.key(), file, activeTagsFiles.contains( file ) );
		++it;
	}
}

void CTags2SettingsWidget::storeSettings()
{
	QDomDocument & dom = *m_part->projectDom();
	DomUtil::writeEntry( dom, "/ctagspart/customArguments", tagfileCustomEdit->text() );
	DomUtil::writeEntry( dom, "/ctagspart/customTagfilePath", tagfilePath->url() );

	KConfig * config = kapp->config();
	config->setGroup( "CTAGS" );
	config->writeEntry( "ShowDeclaration", showDeclarationBox->isChecked() );
	config->writeEntry( "ShowDefinition", showDefinitionBox->isChecked() );
	config->writeEntry( "ShowLookup", showLookupBox->isChecked() );
	config->writeEntry( "JumpToFirst", jumpToFirstBox->isChecked() );
	config->writeEntry( "ctags binary", binaryPath->url() );

	config->deleteGroup( "CTAGS-tagsfiles" );
	config->setGroup( "CTAGS-tagsfiles" );

	QStringList activeTagsFiles;
	TagsItem * item = static_cast<TagsItem*>( otherTagFiles->firstChild() );
	while ( item )
	{
		config->writePathEntry( item->name(), item->tagsfilePath() );
		if ( item->isOn() )
		{
			activeTagsFiles.append( item->tagsfilePath() );
		}
		item = static_cast<TagsItem*>( item->nextSibling() );
	}
	DomUtil::writeListEntry( dom, "/ctagspart/activeTagsFiles", "file", activeTagsFiles );

	activeTagsFiles.push_front( tagfilePath->url() );
	Tags::setTagFiles( activeTagsFiles );

	config->sync();

	emit newTagsfileName( tagfilePath->url() );
}

void CTags2SettingsWidget::slotAccept( )
{
	storeSettings();
}

void CTags2SettingsWidget::createNewTagSlot()
{
	CreateTagFile* dlg = new CreateTagFile;
	if ( dlg->exec() == QDialog::Accepted )
	{
		m_part->createTagsFile( dlg->tagsfilePath(), dlg->directory() );
		new TagsItem( otherTagFiles, dlg->name(), dlg->tagsfilePath(), true );
	}
}

void CTags2SettingsWidget::addNewTagFile()
{
	SelectTagFile* dlg = new SelectTagFile;

	if ( dlg->exec() == QDialog::Accepted )
	{
		new TagsItem( otherTagFiles, dlg->name(), dlg->tagsfilePath(), true );
	}
}

void CTags2SettingsWidget::removeTagFile()
{
	if (!otherTagFiles->selectedItem())
		return;

	delete otherTagFiles->selectedItem();
}


#include "ctags2_settingswidget.moc"

// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;