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
|
/***************************************************************************
* Copyright (C) 2003 Alexander Dymo *
* cloudtemple@mksat.net *
* *
* 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 <kurlrequester.h>
#include <kservice.h>
#include <kdebug.h>
#include <tdemessagebox.h>
#include <tdelocale.h>
#include <tqlineedit.h>
#include <tqcombobox.h>
#include <tqregexp.h>
#include <tqvalidator.h>
#include "domutil.h"
#include "kdevcompileroptions.h"
#include "service.h"
#include "pascalproject_part.h"
#include "pascalprojectoptionsdlg.h"
PascalProjectOptionsDlg::PascalProjectOptionsDlg(PascalProjectPart *part, TQWidget* parent, const char* name, WFlags fl)
: PascalProjectOptionsDlgBase(parent,name, fl), m_part(part)
{
config_combo->setValidator(new TQRegExpValidator(TQRegExp("^\\D.*"), TQT_TQOBJECT(this)));
offers = TDETrader::self()->query("TDevelop/CompilerOptions", "[X-TDevelop-Language] == 'Pascal'");
ServiceComboBox::insertStringList(compiler_box, offers, &service_names, &service_execs);
if (offers.isEmpty())
options_button->setEnabled(false);
allConfigs = allBuildConfigs();
config_combo->insertStringList(allConfigs);
dirty = false;
TQDomDocument &dom = *(m_part->projectDom());
currentConfig = TQString();
configChanged(DomUtil::readEntry(dom, "/kdevpascalproject/general/useconfiguration", "default"));
}
PascalProjectOptionsDlg::~PascalProjectOptionsDlg()
{
}
TQStringList PascalProjectOptionsDlg::allBuildConfigs()
{
TQDomDocument &dom = *(m_part->projectDom());
TQStringList allConfigs;
allConfigs.append("default");
TQDomNode node = dom.documentElement().namedItem("kdevpascalproject").namedItem("configurations");
TQDomElement childEl = node.firstChild().toElement();
while (!childEl.isNull()) {
TQString config = childEl.tagName();
kdDebug() << "Found config " << config << endl;
if (config != "default")
allConfigs.append(config);
childEl = childEl.nextSibling().toElement();
}
return allConfigs;
}
void PascalProjectOptionsDlg::accept()
{
DomUtil::writeEntry(*m_part->projectDom(), "/kdevpascalproject/general/useconfiguration", currentConfig);
if (dirty)
{
saveConfig(currentConfig);
}
}
void PascalProjectOptionsDlg::compiler_box_activated( const TQString& /*s*/ )
{
TQString exec = ServiceComboBox::currentText(compiler_box, service_execs);
exec_edit->setText(exec);
}
void PascalProjectOptionsDlg::saveConfig( TQString config )
{
TQDomDocument dom = *m_part->projectDom();
TQString prefix = "/kdevpascalproject/configurations/" + config + "/";
DomUtil::writeEntry(dom, prefix + "compiler",
ServiceComboBox::currentText(compiler_box, service_names));
DomUtil::writeEntry(dom, prefix + "compileroptions", options_edit->text());
DomUtil::writeEntry(dom, prefix + "compilerexec", exec_edit->text());
DomUtil::writeEntry(dom, prefix + "mainsource", mainSourceUrl->url().replace(TQRegExp(m_part->projectDirectory() + TQString("/")),""));
}
void PascalProjectOptionsDlg::readConfig( TQString config )
{
TQDomDocument dom = *m_part->projectDom();
TQString prefix = "/kdevpascalproject/configurations/" + config + "/";
TQString compiler = DomUtil::readEntry(dom, prefix + "compiler", "");
if (compiler.isEmpty())
{
offers = TDETrader::self()->query("TDevelop/CompilerOptions", "[X-TDevelop-Language] == 'Pascal'");
TQValueList<KService::Ptr>::ConstIterator it;
for (it = offers.begin(); it != offers.end(); ++it) {
if ((*it)->property("X-TDevelop-Default").toBool()) {
compiler = (*it)->name();
kdDebug() << "compiler is " << compiler << endl;
break;
}
}
}
ServiceComboBox::setCurrentText(compiler_box, compiler, service_names);
TQString exec = DomUtil::readEntry(dom, prefix + "compilerexec", "");
if (exec.isEmpty())
exec = ServiceComboBox::currentText(compiler_box, service_execs);
exec_edit->setText(exec);
options_edit->setText(DomUtil::readEntry(dom, prefix + "compileroptions"));
mainSourceUrl->setURL(m_part->projectDirectory() + "/" + DomUtil::readEntry(dom, prefix + "mainsource"));
}
void PascalProjectOptionsDlg::configComboTextChanged(const TQString &config)
{
bool canAdd = !allConfigs.contains(config) && !config.contains("/") && !config.isEmpty();
bool canRemove = allConfigs.contains(config) && config != "default";
addconfig_button->setEnabled(canAdd);
removeconfig_button->setEnabled(canRemove);
}
void PascalProjectOptionsDlg::configChanged(const TQString &config)
{
if (config == currentConfig || !allConfigs.contains(config))
return;
if (!currentConfig.isNull() && dirty)
saveConfig(currentConfig);
currentConfig = config;
readConfig(config);
dirty = false;
config_combo->blockSignals(true);
config_combo->setEditText(config);
config_combo->blockSignals(false);
}
void PascalProjectOptionsDlg::configAdded()
{
TQString config = config_combo->currentText();
allConfigs.append(config);
config_combo->clear();
config_combo->insertStringList(allConfigs);
configChanged(config);
setDirty(); // force saving
}
void PascalProjectOptionsDlg::configRemoved()
{
TQString config = config_combo->currentText();
TQDomDocument dom = *m_part->projectDom();
TQDomNode node = dom.documentElement().namedItem("kdevpascalproject").namedItem("configurations");
node.removeChild(node.namedItem(config));
allConfigs.remove(config);
config_combo->clear();
config_combo->insertStringList(allConfigs);
currentConfig = TQString();
configChanged("default");
}
void PascalProjectOptionsDlg::optionsButtonClicked( )
{
TQString name = ServiceComboBox::currentText(compiler_box, service_names);
KDevCompilerOptions *plugin = m_part->createCompilerOptions(name);
if (plugin) {
TQString flags = plugin->exec(this, options_edit->text());
options_edit->setText(flags);
delete plugin;
}
}
void PascalProjectOptionsDlg::setDirty( )
{
dirty = true;
}
void PascalProjectOptionsDlg::setDefaultOptions( )
{
if (!compiler_box->currentText().isEmpty())
options_edit->setText(m_part->defaultOptions(compiler_box->currentText()));
}
#include "pascalprojectoptionsdlg.moc"
|