summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/document/katedialogs.cpp54
1 files changed, 25 insertions, 29 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedialogs.cpp b/noncore/apps/tinykate/libkate/document/katedialogs.cpp
index f4edd7e..b492c26 100644
--- a/noncore/apps/tinykate/libkate/document/katedialogs.cpp
+++ b/noncore/apps/tinykate/libkate/document/katedialogs.cpp
@@ -1,588 +1,584 @@
1/*************************************************************************** 1/***************************************************************************
2 katedialogs.cpp - description 2 katedialogs.cpp - description
3 ------------------- 3 -------------------
4 copyright : (C) 2001 by The Kate Team 4 copyright : (C) 2001 by The Kate Team
5 (C) 2002 by Joseph Wenninger 5 (C) 2002 by Joseph Wenninger
6 email : kwrite-devel@kde.org 6 email : kwrite-devel@kde.org
7 jowenn@kde.org 7 jowenn@kde.org
8 8
9 ***************************************************************************/ 9 ***************************************************************************/
10 10
11/*************************************************************************** 11/***************************************************************************
12 * * 12 * *
13 * This program is free software; you can redistribute it and/or modify * 13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by * 14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or * 15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. * 16 * (at your option) any later version. *
17 * * 17 * *
18 ***************************************************************************/ 18 ***************************************************************************/
19#include "katedialogs.h" 19#include "katedialogs.h"
20#include <klocale.h> 20#include <klocale.h>
21#include <kdebug.h> 21#include <kdebug.h>
22#include <qgroupbox.h> 22#include <qgroupbox.h>
23#include <qvgroupbox.h> 23#include <qvgroupbox.h>
24#include <qhgroupbox.h> 24#include <qhgroupbox.h>
25#include <qhbox.h> 25#include <qhbox.h>
26#include <qvbox.h> 26#include <qvbox.h>
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qwidgetstack.h> 29#include <qwidgetstack.h>
30#include <qlabel.h> 30#include <qlabel.h>
31#include <qlistview.h> 31#include <qlistview.h>
32#include <qlineedit.h> 32#include <qlineedit.h>
33#include <qcombobox.h> 33#include <qcombobox.h>
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35//FIXME #include <kcharsets.h> 35//FIXME #include <kcharsets.h>
36#include <kglobal.h> 36#include <kglobal.h>
37#include <qmap.h> 37#include <qmap.h>
38#include <kmessagebox.h> 38#include <kmessagebox.h>
39#include <kstddirs.h> 39#include <kstddirs.h>
40 40
41 41
42/******************************************************************************************************************* 42/*******************************************************************************************************************
43* Context Editor * 43* Context Editor *
44*******************************************************************************************************************/ 44*******************************************************************************************************************/
45 45
46StyleChanger::StyleChanger( QWidget *parent ) 46StyleChanger::StyleChanger( QWidget *parent )
47 : QWidget(parent) 47 : QWidget(parent)
48{ 48{
49 QLabel *label; 49 QLabel *label;
50 50
51 QGridLayout *glay = new QGridLayout( this, 4, 3, 0, KDialog::spacingHint() ); 51 QGridLayout *glay = new QGridLayout( this, 2, 6, 0, KDialog::spacingHint() );
52 CHECK_PTR(glay); 52 CHECK_PTR(glay);
53 glay->addColSpacing( 1, KDialog::spacingHint() ); // Looks better 53 glay->addColSpacing( 1, KDialog::spacingHint() ); // Looks better
54 glay->setColStretch( 2, 10 ); 54 glay->addColSpacing( 3, KDialog::spacingHint() );
55 glay->addColSpacing( 5, KDialog::spacingHint() );
55 56
56 col = new KColorButton(this); 57 col = new KColorButton(this);
57 CHECK_PTR(col); 58 CHECK_PTR(col);
58 connect(col,SIGNAL(changed(const QColor&)),this,SLOT(changed())); 59 connect(col,SIGNAL(changed(const QColor&)),this,SLOT(changed()));
59 label = new QLabel(col,i18n("Normal:"),this); 60 label = new QLabel(col,i18n("Normal:"),this);
60 CHECK_PTR(label); 61 CHECK_PTR(label);
61 glay->addWidget(label,0,0); 62 glay->addWidget(label,0,0);
62 glay->addWidget(col,1,0); 63 glay->addWidget(col,1,0);
63 64
64 selCol = new KColorButton(this); 65 selCol = new KColorButton(this);
65 CHECK_PTR(selCol); 66 CHECK_PTR(selCol);
66 connect(selCol,SIGNAL(changed(const QColor&)),this,SLOT(changed())); 67 connect(selCol,SIGNAL(changed(const QColor&)),this,SLOT(changed()));
67 label = new QLabel(selCol,i18n("Selected:"),this); 68 label = new QLabel(selCol,i18n("Selected:"),this);
68 CHECK_PTR(label); 69 CHECK_PTR(label);
69 glay->addWidget(label,2,0); 70 glay->addWidget(label,0,2);
70 glay->addWidget(selCol,3,0); 71 glay->addWidget(selCol,1,2);
71 72
72 bold = new QCheckBox(i18n("Bold"),this); 73 bold = new QCheckBox(i18n("Bold"),this);
73 CHECK_PTR(bold); 74 CHECK_PTR(bold);
74 connect(bold,SIGNAL(clicked()),SLOT(changed())); 75 connect(bold,SIGNAL(clicked()),SLOT(changed()));
75 glay->addWidget(bold,1,2); 76 glay->addWidget(bold,0,4);
76 77
77 italic = new QCheckBox(i18n("Italic"),this); 78 italic = new QCheckBox(i18n("Italic"),this);
78 CHECK_PTR(italic); 79 CHECK_PTR(italic);
79 connect(italic,SIGNAL(clicked()),SLOT(changed())); 80 connect(italic,SIGNAL(clicked()),SLOT(changed()));
80 glay->addWidget(italic,2,2); 81 glay->addWidget(italic,1,4);
81} 82}
82 83
83void StyleChanger::setRef(ItemStyle *s) { 84void StyleChanger::setRef(ItemStyle *s) {
84 85
85 style = s; 86 style = s;
86 col->setColor(style->col); 87 col->setColor(style->col);
87 selCol->setColor(style->selCol); 88 selCol->setColor(style->selCol);
88 bold->setChecked(style->bold); 89 bold->setChecked(style->bold);
89 italic->setChecked(style->italic); 90 italic->setChecked(style->italic);
90 91
91} 92}
92 93
93void StyleChanger::setEnabled(bool enable) { 94void StyleChanger::setEnabled(bool enable) {
94 95
95 col->setEnabled(enable); 96 col->setEnabled(enable);
96 selCol->setEnabled(enable); 97 selCol->setEnabled(enable);
97 bold->setEnabled(enable); 98 bold->setEnabled(enable);
98 italic->setEnabled(enable); 99 italic->setEnabled(enable);
99} 100}
100 101
101void StyleChanger::changed() { 102void StyleChanger::changed() {
102 103
103 if (style) { 104 if (style) {
104 style->col = col->color(); 105 style->col = col->color();
105 style->selCol = selCol->color(); 106 style->selCol = selCol->color();
106 style->bold = bold->isChecked(); 107 style->bold = bold->isChecked();
107 style->italic = italic->isChecked(); 108 style->italic = italic->isChecked();
108 } 109 }
109} 110}
110 111
111HighlightDialog::HighlightDialog( HlManager *hlManager, ItemStyleList *styleList, 112HighlightDialog::HighlightDialog( HlManager *hlManager, ItemStyleList *styleList,
112 HlDataList *highlightDataList, 113 HlDataList *highlightDataList,
113 int hlNumber, QWidget *parent, 114 int hlNumber, QWidget *parent,
114 const char *name, bool modal ) 115 const char *name, bool modal )
115 :KDialogBase(parent,name,modal,i18n("Highlight Settings"), Ok|Cancel, Ok) 116 :KDialogBase(parent,name,modal,i18n("Highlight Settings"), Ok|Cancel, Ok)
116{ 117{
117// QVBox *page = makeVBoxMainWidget(); 118// QVBox *page = makeVBoxMainWidget();
118 QFrame *page=addPage("FIXME"); 119 QFrame *page=addPage("FIXME");
119 (new QVBoxLayout(page))->setAutoAdd(true); 120 (new QVBoxLayout(page))->setAutoAdd(true);
120 content=new HighlightDialogPage(hlManager,styleList,highlightDataList,hlNumber,page); 121 content=new HighlightDialogPage(hlManager,styleList,highlightDataList,hlNumber,page);
121} 122}
122 123
123void HighlightDialog::done(int r) 124void HighlightDialog::done(int r)
124{ 125{
125 kdDebug(13010)<<"HighlightDialod done"<<endl; 126 kdDebug(13010)<<"HighlightDialod done"<<endl;
126 content->saveData(); 127 content->saveData();
127 KDialogBase::done(r); 128 KDialogBase::done(r);
128} 129}
129 130
130HighlightDialogPage::HighlightDialogPage(HlManager *hlManager, ItemStyleList *styleList, 131HighlightDialogPage::HighlightDialogPage(HlManager *hlManager, ItemStyleList *styleList,
131 HlDataList* highlightDataList, 132 HlDataList* highlightDataList,
132 int hlNumber,QWidget *parent, const char *name) 133 int hlNumber,QWidget *parent, const char *name)
133 :QTabWidget(parent,name),defaultItemStyleList(styleList),hlData(0L) 134 :QTabWidget(parent,name),defaultItemStyleList(styleList),hlData(0L)
134 135
135{ 136{
136 137
137 // defaults ========================================================= 138 // defaults =========================================================
138 139
139 QFrame *page1 = new QFrame(this); 140 QFrame *page1 = new QFrame(this);
140 addTab(page1,i18n("&Defaults")); 141 addTab(page1,i18n("&Defaults"));
141 QGridLayout *grid = new QGridLayout(page1, 1, 1); 142 QGridLayout *grid = new QGridLayout(page1, 1, 1);
142 143
143 QVGroupBox *dvbox1 = new QVGroupBox( i18n("Default Item Styles"), page1 ); 144 QVGroupBox *dvbox1 = new QVGroupBox( i18n("Default Item Styles"), page1 );
144 /*QLabel *label = */new QLabel( i18n("Item:"), dvbox1 ); 145 /*QLabel *label = */new QLabel( i18n("Item:"), dvbox1 );
145 QComboBox *styleCombo = new QComboBox( false, dvbox1 ); 146 QComboBox *styleCombo = new QComboBox( false, dvbox1 );
146 defaultStyleChanger = new StyleChanger( dvbox1 ); 147 defaultStyleChanger = new StyleChanger( dvbox1 );
147 for( int i = 0; i < hlManager->defaultStyles(); i++ ) { 148 for( int i = 0; i < hlManager->defaultStyles(); i++ ) {
148 styleCombo->insertItem(hlManager->defaultStyleName(i)); 149 styleCombo->insertItem(hlManager->defaultStyleName(i));
149 } 150 }
150 connect(styleCombo, SIGNAL(activated(int)), this, SLOT(defaultChanged(int))); 151 connect(styleCombo, SIGNAL(activated(int)), this, SLOT(defaultChanged(int)));
151 grid->addWidget(dvbox1, 0,0); 152 grid->addWidget(dvbox1, 0,0);
152 153
153 defaultChanged(0); 154 defaultChanged(0);
154 155
155 // highlight modes ===================================================== 156 // highlight modes =====================================================
156 157
157 QFrame *page2 = new QFrame(this); 158 QFrame *page2 = new QFrame(this);
158 addTab(page2,i18n("&Highlight Modes")); 159 addTab(page2,i18n("&Highlight Modes"));
159 //grid = new QGridLayout(page2,2,2);
160 QVBoxLayout *bl=new QVBoxLayout(page2); 160 QVBoxLayout *bl=new QVBoxLayout(page2);
161 bl->setAutoAdd(true); 161 bl->setAutoAdd(true);
162 QHGroupBox *hbox1 = new QHGroupBox( i18n("Config Select"), page2 ); 162 QGroupBox *gbox1 = new QGroupBox( 2, Qt::Horizontal, i18n("Config Select"), page2 );
163 hbox1->layout()->setMargin(5); 163 gbox1->layout()->setMargin(5);
164 QVBox *vbox1=new QVBox(hbox1); 164 QGroupBox *gbox2 = new QGroupBox( 2, Qt::Horizontal, i18n("Item Style"), page2 );
165// grid->addMultiCellWidget(vbox1,0,0,0,1); 165 gbox2->layout()->setMargin(5);
166 QVGroupBox *vbox2 = new QVGroupBox( i18n("Item Style"), page2 ); 166
167// grid->addWidget(vbox2,1,0); 167 QLabel *label = new QLabel( i18n("Highlight:"), gbox1 );
168 QVGroupBox *vbox3 = new QVGroupBox( i18n("Highlight Auto Select"), hbox1 ); 168 hlCombo = new QComboBox( false, gbox1 );
169 //grid->addWidget(vbox3,1,1); 169 hlCombo->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum ) );
170
171 QLabel *label = new QLabel( i18n("Highlight:"), vbox1 );
172 hlCombo = new QComboBox( false, vbox1 );
173 QHBox *modHl = new QHBox(vbox1);
174// connect(new QPushButton(i18n("New"),modHl),SIGNAL(clicked()),this,SLOT(hlNew())); 170// connect(new QPushButton(i18n("New"),modHl),SIGNAL(clicked()),this,SLOT(hlNew()));
175// connect(new QPushButton(i18n("Edit"),modHl),SIGNAL(clicked()),this,SLOT(hlEdit())); 171// connect(new QPushButton(i18n("Edit"),modHl),SIGNAL(clicked()),this,SLOT(hlEdit()));
176 connect( hlCombo, SIGNAL(activated(int)), 172 connect( hlCombo, SIGNAL(activated(int)),
177 this, SLOT(hlChanged(int)) ); 173 this, SLOT(hlChanged(int)) );
178 for( int i = 0; i < hlManager->highlights(); i++) { 174 for( int i = 0; i < hlManager->highlights(); i++) {
179 hlCombo->insertItem(hlManager->hlName(i)); 175 hlCombo->insertItem(hlManager->hlName(i));
180 } 176 }
181 hlCombo->setCurrentItem(hlNumber); 177 hlCombo->setCurrentItem(hlNumber);
182 178
179 label = new QLabel( i18n("File Extensions:"), gbox1 );
180 wildcards = new QLineEdit( gbox1 );
181 label = new QLabel( i18n("Mime Types:"), gbox1 );
182 mimetypes = new QLineEdit( gbox1 );
183 183
184 label = new QLabel( i18n("Item:"), vbox2 ); 184 label = new QLabel( i18n("Item:"), gbox2 );
185 itemCombo = new QComboBox( false, vbox2 ); 185 itemCombo = new QComboBox( false, gbox2 );
186 connect( itemCombo, SIGNAL(activated(int)), this, SLOT(itemChanged(int)) ); 186 connect( itemCombo, SIGNAL(activated(int)), this, SLOT(itemChanged(int)) );
187 187
188 label = new QLabel( i18n("File Extensions:"), vbox3 ); 188 styleDefault = new QCheckBox(i18n("Default"), gbox2 );
189 wildcards = new QLineEdit( vbox3 );
190 label = new QLabel( i18n("Mime Types:"), vbox3 );
191 mimetypes = new QLineEdit( vbox3 );
192
193
194 styleDefault = new QCheckBox(i18n("Default"), vbox2 );
195 connect(styleDefault,SIGNAL(clicked()),SLOT(changed())); 189 connect(styleDefault,SIGNAL(clicked()),SLOT(changed()));
196 styleChanger = new StyleChanger( vbox2 ); 190 gbox2->addSpace(1);
191 gbox2->addSpace(1);
192 styleChanger = new StyleChanger( gbox2 );
197 193
198 hlDataList = highlightDataList; 194 hlDataList = highlightDataList;
199 hlChanged(hlNumber); 195 hlChanged(hlNumber);
200} 196}
201 197
202 198
203void HighlightDialogPage::defaultChanged(int z) 199void HighlightDialogPage::defaultChanged(int z)
204{ 200{
205 defaultStyleChanger->setRef(defaultItemStyleList->at(z)); 201 defaultStyleChanger->setRef(defaultItemStyleList->at(z));
206} 202}
207 203
208 204
209void HighlightDialogPage::hlChanged(int z) 205void HighlightDialogPage::hlChanged(int z)
210{ 206{
211 writeback(); 207 writeback();
212 208
213 hlData = hlDataList->at(z); 209 hlData = hlDataList->at(z);
214 210
215 wildcards->setText(hlData->wildcards); 211 wildcards->setText(hlData->wildcards);
216 mimetypes->setText(hlData->mimetypes); 212 mimetypes->setText(hlData->mimetypes);
217 213
218 itemCombo->clear(); 214 itemCombo->clear();
219 for (ItemData *itemData = hlData->itemDataList.first(); itemData != 0L; 215 for (ItemData *itemData = hlData->itemDataList.first(); itemData != 0L;
220 itemData = hlData->itemDataList.next()) { 216 itemData = hlData->itemDataList.next()) {
221 kdDebug(13010) << itemData->name << endl; 217 kdDebug(13010) << itemData->name << endl;
222 itemCombo->insertItem(i18n(itemData->name.latin1())); 218 itemCombo->insertItem(i18n(itemData->name.latin1()));
223 } 219 }
224 220
225 itemChanged(0); 221 itemChanged(0);
226} 222}
227 223
228void HighlightDialogPage::itemChanged(int z) 224void HighlightDialogPage::itemChanged(int z)
229{ 225{
230 itemData = hlData->itemDataList.at(z); 226 itemData = hlData->itemDataList.at(z);
231 227
232 styleDefault->setChecked(itemData->defStyle); 228 styleDefault->setChecked(itemData->defStyle);
233 styleChanger->setRef(itemData); 229 styleChanger->setRef(itemData);
234} 230}
235 231
236void HighlightDialogPage::changed() 232void HighlightDialogPage::changed()
237{ 233{
238 itemData->defStyle = styleDefault->isChecked(); 234 itemData->defStyle = styleDefault->isChecked();
239} 235}
240 236
241void HighlightDialogPage::writeback() { 237void HighlightDialogPage::writeback() {
242 if (hlData) { 238 if (hlData) {
243 hlData->wildcards = wildcards->text(); 239 hlData->wildcards = wildcards->text();
244 hlData->mimetypes = mimetypes->text(); 240 hlData->mimetypes = mimetypes->text();
245 } 241 }
246} 242}
247 243
248void HighlightDialogPage::saveData() { 244void HighlightDialogPage::saveData() {
249 kdDebug(13010)<<"HighlightDialogPage::saveData()"<<endl; 245 kdDebug(13010)<<"HighlightDialogPage::saveData()"<<endl;
250 writeback(); 246 writeback();
251} 247}
252 248
253 249
254void HighlightDialogPage::hlEdit() { 250void HighlightDialogPage::hlEdit() {
255 HlEditDialog diag(0,0,"hlEdit", true,hlData); 251 HlEditDialog diag(0,0,"hlEdit", true,hlData);
256 diag.show(); 252 diag.show();
257} 253}
258 254
259void HighlightDialogPage::hlNew() { 255void HighlightDialogPage::hlNew() {
260 HlEditDialog diag(0,0,"hlEdit",true,0); 256 HlEditDialog diag(0,0,"hlEdit",true,0);
261 diag.show(); 257 diag.show();
262} 258}
263 259
264 260
265HlEditDialog::HlEditDialog(HlManager *,QWidget *parent, const char *name, bool modal,HlData *data) 261HlEditDialog::HlEditDialog(HlManager *,QWidget *parent, const char *name, bool modal,HlData *data)
266 :KDialogBase(KDialogBase::Swallow, i18n("Highlight Conditions"), Ok|Cancel, Ok, parent, name, modal) 262 :KDialogBase(KDialogBase::Swallow, i18n("Highlight Conditions"), Ok|Cancel, Ok, parent, name, modal)
267{ 263{
268 currentItem=0; 264 currentItem=0;
269 transTableCnt=0; 265 transTableCnt=0;
270 QHBox *wid=new QHBox(this); 266 QHBox *wid=new QHBox(this);
271 QVBox *lbox=new QVBox(wid); 267 QVBox *lbox=new QVBox(wid);
272 contextList=new KListView(lbox); 268 contextList=new KListView(lbox);
273 contextList->setRootIsDecorated(true); 269 contextList->setRootIsDecorated(true);
274 contextList->addColumn(i18n("Syntax structure")); 270 contextList->addColumn(i18n("Syntax structure"));
275 contextList->setSorting(-1); 271 contextList->setSorting(-1);
276 QHBox *bbox=new QHBox(lbox); 272 QHBox *bbox=new QHBox(lbox);
277 QPushButton *addContext=new QPushButton(i18n("New Context"),bbox); 273 QPushButton *addContext=new QPushButton(i18n("New Context"),bbox);
278 QPushButton *addItem=new QPushButton(i18n("New Item"),bbox); 274 QPushButton *addItem=new QPushButton(i18n("New Item"),bbox);
279 QVGroupBox *opt = new QVGroupBox( i18n("Options"), wid); 275 QVGroupBox *opt = new QVGroupBox( i18n("Options"), wid);
280 stack=new QWidgetStack(opt); 276 stack=new QWidgetStack(opt);
281 initContextOptions(contextOptions=new QVBox(stack)); 277 initContextOptions(contextOptions=new QVBox(stack));
282 stack->addWidget(contextOptions,HlEContext); 278 stack->addWidget(contextOptions,HlEContext);
283 initItemOptions(itemOptions=new QVBox(stack)); 279 initItemOptions(itemOptions=new QVBox(stack));
284 stack->addWidget(itemOptions,HlEItem); 280 stack->addWidget(itemOptions,HlEItem);
285 stack->raiseWidget(HlEContext); 281 stack->raiseWidget(HlEContext);
286 setMainWidget(wid); 282 setMainWidget(wid);
287 if (data!=0) loadFromDocument(data); 283 if (data!=0) loadFromDocument(data);
288 else newDocument(); 284 else newDocument();
289 connect(contextList,SIGNAL(currentChanged(QListViewItem*)),this,SLOT(currentSelectionChanged(QListViewItem*))); 285 connect(contextList,SIGNAL(currentChanged(QListViewItem*)),this,SLOT(currentSelectionChanged(QListViewItem*)));
290 connect(addContext,SIGNAL(clicked()),this,SLOT(contextAddNew())); 286 connect(addContext,SIGNAL(clicked()),this,SLOT(contextAddNew()));
291 connect(addItem,SIGNAL(clicked()),this,SLOT(ItemAddNew())); 287 connect(addItem,SIGNAL(clicked()),this,SLOT(ItemAddNew()));
292 } 288 }
293 289
294void HlEditDialog::newDocument() 290void HlEditDialog::newDocument()
295{ 291{
296 KStandardDirs *dirs = KGlobal::dirs(); 292 KStandardDirs *dirs = KGlobal::dirs();
297 QStringList list=dirs->findAllResources("data","kate/syntax/syntax.template",false,true); 293 QStringList list=dirs->findAllResources("data","kate/syntax/syntax.template",false,true);
298 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 294 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
299 { 295 {
300 HlData data("","",*it); 296 HlData data("","",*it);
301 loadFromDocument(&data); 297 loadFromDocument(&data);
302 return; 298 return;
303 } 299 }
304 KMessageBox::error(this,i18n("Can't find template file")); 300 KMessageBox::error(this,i18n("Can't find template file"));
305} 301}
306 302
307 303
308void HlEditDialog::initContextOptions(QVBox *co) 304void HlEditDialog::initContextOptions(QVBox *co)
309{ 305{
310 if( co!=0) 306 if( co!=0)
311 { 307 {
312 QHBox *tmp = new QHBox(co); 308 QHBox *tmp = new QHBox(co);
313 (void) new QLabel(i18n("Description:"),tmp); 309 (void) new QLabel(i18n("Description:"),tmp);
314 ContextDescr=new QLineEdit(tmp); 310 ContextDescr=new QLineEdit(tmp);
315 tmp= new QHBox(co); 311 tmp= new QHBox(co);
316 (void) new QLabel(i18n("Attribute:"),tmp); 312 (void) new QLabel(i18n("Attribute:"),tmp);
317 ContextAttribute=new QComboBox(tmp); 313 ContextAttribute=new QComboBox(tmp);
318 tmp= new QHBox(co); 314 tmp= new QHBox(co);
319 (void) new QLabel(i18n("LineEnd:"),tmp); 315 (void) new QLabel(i18n("LineEnd:"),tmp);
320 ContextLineEnd = new QComboBox(tmp); 316 ContextLineEnd = new QComboBox(tmp);
321 connect(ContextDescr,SIGNAL(textChanged(const QString&)),this,SLOT(contextDescrChanged(const QString&))); 317 connect(ContextDescr,SIGNAL(textChanged(const QString&)),this,SLOT(contextDescrChanged(const QString&)));
322 connect(ContextLineEnd,SIGNAL(activated(int)),this,SLOT(contextLineEndChanged(int))); 318 connect(ContextLineEnd,SIGNAL(activated(int)),this,SLOT(contextLineEndChanged(int)));
323 connect(ContextAttribute,SIGNAL(activated(int)),this,SLOT(contextAttributeChanged(int))); 319 connect(ContextAttribute,SIGNAL(activated(int)),this,SLOT(contextAttributeChanged(int)));
324 } 320 }
325 else 321 else
326 kdDebug(13010)<<"initContextOptions: Widget is 0"<<endl; 322 kdDebug(13010)<<"initContextOptions: Widget is 0"<<endl;
327} 323}
328 324
329 325
330void HlEditDialog::insertTranslationList(QString tag, QString trans,int length) 326void HlEditDialog::insertTranslationList(QString tag, QString trans,int length)
331 { 327 {
332 ItemInfo data(trans,length); 328 ItemInfo data(trans,length);
333 id2tag.insert(transTableCnt,tag); 329 id2tag.insert(transTableCnt,tag);
334 id2info.insert(transTableCnt,data); 330 id2info.insert(transTableCnt,data);
335 tag2id.insert(tag,transTableCnt); 331 tag2id.insert(tag,transTableCnt);
336 transTableCnt++; 332 transTableCnt++;
337 } 333 }
338 334
339 335
340void HlEditDialog::initItemOptions(QVBox *co) 336void HlEditDialog::initItemOptions(QVBox *co)
341{ 337{
342 if (co!=0) 338 if (co!=0)
343 { 339 {
344 QHBox *tmp = new QHBox(co); 340 QHBox *tmp = new QHBox(co);
345 (void) new QLabel(i18n("Type:"),tmp); 341 (void) new QLabel(i18n("Type:"),tmp);
346 ItemType = new QComboBox(tmp); 342 ItemType = new QComboBox(tmp);
347 tmp= new QHBox(co); 343 tmp= new QHBox(co);
348 (void) new QLabel(i18n("Parameter:"),tmp); 344 (void) new QLabel(i18n("Parameter:"),tmp);
349 ItemParameter= new QLineEdit(tmp); 345 ItemParameter= new QLineEdit(tmp);
350 tmp= new QHBox(co); 346 tmp= new QHBox(co);
351 (void) new QLabel(i18n("Attribute:"),tmp); 347 (void) new QLabel(i18n("Attribute:"),tmp);
352 ItemAttribute= new QComboBox(tmp); 348 ItemAttribute= new QComboBox(tmp);
353 (void) new QLabel(i18n("Context switch:"),tmp); 349 (void) new QLabel(i18n("Context switch:"),tmp);
354 ItemContext = new QComboBox(tmp); 350 ItemContext = new QComboBox(tmp);
355 co->setSpacing(15); 351 co->setSpacing(15);
356 QPushButton *delItem=new QPushButton(i18n("Delete this item"),co); 352 QPushButton *delItem=new QPushButton(i18n("Delete this item"),co);
357 353
358 /* init translation lists */ 354 /* init translation lists */
359 insertTranslationList("CharDetect","CharDetect",1); 355 insertTranslationList("CharDetect","CharDetect",1);
360 insertTranslationList("2CharDetect","2CharDetect",2); 356 insertTranslationList("2CharDetect","2CharDetect",2);
361 insertTranslationList("RangeDetect","RangeDetect",2); 357 insertTranslationList("RangeDetect","RangeDetect",2);
362 insertTranslationList("StringDetect","StringDetect",-1); 358 insertTranslationList("StringDetect","StringDetect",-1);
363 insertTranslationList("AnyChar","AnyChar",-1); 359 insertTranslationList("AnyChar","AnyChar",-1);
364 insertTranslationList("RegExpr","RegExpr",-1); 360 insertTranslationList("RegExpr","RegExpr",-1);
365 insertTranslationList("Int","Int",0); 361 insertTranslationList("Int","Int",0);
366 insertTranslationList("Float","Float",0); 362 insertTranslationList("Float","Float",0);
367 insertTranslationList("keyword","keyword",0); 363 insertTranslationList("keyword","keyword",0);
368 insertTranslationList("dataType","dataType",0); 364 insertTranslationList("dataType","dataType",0);
369 ItemType->clear(); 365 ItemType->clear();
370 for (int i=0; i<transTableCnt; i++) ItemType->insertItem(id2info[i].trans_i18n); 366 for (int i=0; i<transTableCnt; i++) ItemType->insertItem(id2info[i].trans_i18n);
371 connect(ItemType,SIGNAL(activated(int)),this,SLOT(ItemTypeChanged(int))); 367 connect(ItemType,SIGNAL(activated(int)),this,SLOT(ItemTypeChanged(int)));
372 connect(ItemParameter,SIGNAL(textChanged(const QString&)),this,SLOT(ItemParameterChanged(const QString&))); 368 connect(ItemParameter,SIGNAL(textChanged(const QString&)),this,SLOT(ItemParameterChanged(const QString&)));
373 connect(ItemAttribute,SIGNAL(activated(int)),this,SLOT(ItemAttributeChanged(int))); 369 connect(ItemAttribute,SIGNAL(activated(int)),this,SLOT(ItemAttributeChanged(int)));
374 connect(ItemContext,SIGNAL(activated(int)),this,SLOT(ItemContextChanged(int))); 370 connect(ItemContext,SIGNAL(activated(int)),this,SLOT(ItemContextChanged(int)));
375 } 371 }
376 else 372 else
377 kdDebug(13010)<<"initItemOptions: Widget is 0"<<endl; 373 kdDebug(13010)<<"initItemOptions: Widget is 0"<<endl;
378} 374}
379 375
380void HlEditDialog::loadFromDocument(HlData *hl) 376void HlEditDialog::loadFromDocument(HlData *hl)
381{ 377{
382 struct syntaxContextData *data; 378 struct syntaxContextData *data;
383 QListViewItem *last=0,*lastsub=0; 379 QListViewItem *last=0,*lastsub=0;
384 380
385 HlManager::self()->syntax->setIdentifier(hl->identifier); 381 HlManager::self()->syntax->setIdentifier(hl->identifier);
386 data=HlManager::self()->syntax->getGroupInfo("highlighting","context"); 382 data=HlManager::self()->syntax->getGroupInfo("highlighting","context");
387 int i=0; 383 int i=0;
388 if (data) 384 if (data)
389 { 385 {
390 while (HlManager::self()->syntax->nextGroup(data)) //<context tags> 386 while (HlManager::self()->syntax->nextGroup(data)) //<context tags>
391 { 387 {
392 kdDebug(13010)<< "Adding context to list"<<endl; 388 kdDebug(13010)<< "Adding context to list"<<endl;
393 last= new QListViewItem(contextList,last, 389 last= new QListViewItem(contextList,last,
394 HlManager::self()->syntax->groupData(data,QString("name")), 390 HlManager::self()->syntax->groupData(data,QString("name")),
395 QString("%1").arg(i), 391 QString("%1").arg(i),
396 HlManager::self()->syntax->groupData(data,QString("attribute")), 392 HlManager::self()->syntax->groupData(data,QString("attribute")),
397 HlManager::self()->syntax->groupData(data,QString("lineEndContext"))); 393 HlManager::self()->syntax->groupData(data,QString("lineEndContext")));
398 i++; 394 i++;
399 lastsub=0; 395 lastsub=0;
400 while (HlManager::self()->syntax->nextItem(data)) 396 while (HlManager::self()->syntax->nextItem(data))
401 { 397 {
402 kdDebug(13010)<< "Adding item to list"<<endl; 398 kdDebug(13010)<< "Adding item to list"<<endl;
403 lastsub=addContextItem(last,lastsub,data); 399 lastsub=addContextItem(last,lastsub,data);
404 } 400 }
405 401
406 402
407 } 403 }
408 if (data) HlManager::self()->syntax->freeGroupInfo(data); 404 if (data) HlManager::self()->syntax->freeGroupInfo(data);
409 } 405 }
410 ContextAttribute->clear(); 406 ContextAttribute->clear();
411 ItemAttribute->clear(); 407 ItemAttribute->clear();
412 data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); 408 data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData");
413 while (HlManager::self()->syntax->nextGroup(data)) 409 while (HlManager::self()->syntax->nextGroup(data))
414 { 410 {
415 ContextAttribute->insertItem(HlManager::self()->syntax->groupData(data,QString("name"))); 411 ContextAttribute->insertItem(HlManager::self()->syntax->groupData(data,QString("name")));
416 ItemAttribute->insertItem(HlManager::self()->syntax->groupData(data,QString("name"))); 412 ItemAttribute->insertItem(HlManager::self()->syntax->groupData(data,QString("name")));
417 } 413 }
418 if (data) HlManager::self()->syntax->freeGroupInfo(data); 414 if (data) HlManager::self()->syntax->freeGroupInfo(data);
419} 415}
420 416
421QListViewItem *HlEditDialog::addContextItem(QListViewItem *_parent,QListViewItem *prev,struct syntaxContextData *data) 417QListViewItem *HlEditDialog::addContextItem(QListViewItem *_parent,QListViewItem *prev,struct syntaxContextData *data)
422 { 418 {
423 419
424 kdDebug(13010)<<HlManager::self()->syntax->groupItemData(data,QString("name")) << endl; 420 kdDebug(13010)<<HlManager::self()->syntax->groupItemData(data,QString("name")) << endl;
425 421
426 QString dataname=HlManager::self()->syntax->groupItemData(data,QString("")); 422 QString dataname=HlManager::self()->syntax->groupItemData(data,QString(""));
427 QString attr=(HlManager::self()->syntax->groupItemData(data,QString("attribute"))); 423 QString attr=(HlManager::self()->syntax->groupItemData(data,QString("attribute")));
428 QString context=(HlManager::self()->syntax->groupItemData(data,QString("context"))); 424 QString context=(HlManager::self()->syntax->groupItemData(data,QString("context")));
429 char chr; 425 char chr;
430 if (! HlManager::self()->syntax->groupItemData(data,QString("char")).isEmpty()) 426 if (! HlManager::self()->syntax->groupItemData(data,QString("char")).isEmpty())
431 chr= (HlManager::self()->syntax->groupItemData(data,QString("char")).latin1())[0]; 427 chr= (HlManager::self()->syntax->groupItemData(data,QString("char")).latin1())[0];
432 else 428 else
433 chr=0; 429 chr=0;
434 QString stringdata=HlManager::self()->syntax->groupItemData(data,QString("String")); 430 QString stringdata=HlManager::self()->syntax->groupItemData(data,QString("String"));
435 char chr1; 431 char chr1;
436 if (! HlManager::self()->syntax->groupItemData(data,QString("char1")).isEmpty()) 432 if (! HlManager::self()->syntax->groupItemData(data,QString("char1")).isEmpty())
437 chr1= (HlManager::self()->syntax->groupItemData(data,QString("char1")).latin1())[0]; 433 chr1= (HlManager::self()->syntax->groupItemData(data,QString("char1")).latin1())[0];
438 else 434 else
439 chr1=0; 435 chr1=0;
440 bool insensitive=(HlManager::self()->syntax->groupItemData(data,QString("insensitive"))==QString("TRUE")); 436 bool insensitive=(HlManager::self()->syntax->groupItemData(data,QString("insensitive"))==QString("TRUE"));
441 QString param(""); 437 QString param("");
442 if ((dataname=="keyword") || (dataname=="dataType")) param=dataname; 438 if ((dataname=="keyword") || (dataname=="dataType")) param=dataname;
443 else if (dataname=="CharDetect") param=chr; 439 else if (dataname=="CharDetect") param=chr;
444 else if ((dataname=="2CharDetect") || (dataname=="RangeDetect")) param=QString("%1%2").arg(chr).arg(chr1); 440 else if ((dataname=="2CharDetect") || (dataname=="RangeDetect")) param=QString("%1%2").arg(chr).arg(chr1);
445 else if ((dataname=="StringDetect") || (dataname=="AnyChar") || (dataname=="RegExpr")) param=stringdata; 441 else if ((dataname=="StringDetect") || (dataname=="AnyChar") || (dataname=="RegExpr")) param=stringdata;
446 else kdDebug(13010)<<"***********************************"<<endl<<"Unknown entry for Context:"<<dataname<<endl; 442 else kdDebug(13010)<<"***********************************"<<endl<<"Unknown entry for Context:"<<dataname<<endl;
447 kdDebug(13010)<<dataname << endl; 443 kdDebug(13010)<<dataname << endl;
448 return new QListViewItem(_parent,prev,i18n(dataname.latin1())+" "+param,dataname,param,attr,context); 444 return new QListViewItem(_parent,prev,i18n(dataname.latin1())+" "+param,dataname,param,attr,context);
449 } 445 }
450 446
451 447
452void HlEditDialog::currentSelectionChanged ( QListViewItem *it) 448void HlEditDialog::currentSelectionChanged ( QListViewItem *it)
453 { 449 {
454 kdDebug(13010)<<"Update data view"<<endl<<"Depth:"<<it->depth()<<endl; 450 kdDebug(13010)<<"Update data view"<<endl<<"Depth:"<<it->depth()<<endl;
455 currentItem=it; 451 currentItem=it;
456 if (it->depth()==0) showContext(); 452 if (it->depth()==0) showContext();
457 else showItem(); 453 else showItem();
458 } 454 }
459 455
460 456
461/****************************************************************************/ 457/****************************************************************************/
462/* CONTEXTS */ 458/* CONTEXTS */
463/****************************************************************************/ 459/****************************************************************************/
464 460
465 461
466void HlEditDialog::showContext() 462void HlEditDialog::showContext()
467 { 463 {
468 stack->raiseWidget(HlEContext); 464 stack->raiseWidget(HlEContext);
469 ContextDescr->setText(currentItem->text(0)); 465 ContextDescr->setText(currentItem->text(0));
470 ContextAttribute->setCurrentItem(currentItem->text(2).toInt()); 466 ContextAttribute->setCurrentItem(currentItem->text(2).toInt());
471 ContextLineEnd->clear(); 467 ContextLineEnd->clear();
472 for (QListViewItem *it=contextList->firstChild();it;it=it->nextSibling()) 468 for (QListViewItem *it=contextList->firstChild();it;it=it->nextSibling())
473 ContextLineEnd->insertItem(it->text(0)); 469 ContextLineEnd->insertItem(it->text(0));
474 ContextLineEnd->setCurrentItem(currentItem->text(3).toInt()); 470 ContextLineEnd->setCurrentItem(currentItem->text(3).toInt());
475// ContextAttribute->setText(currentItem->text(1)); 471// ContextAttribute->setText(currentItem->text(1));
476// ContextLineEnd->setText(currentItem->text(2)); 472// ContextLineEnd->setText(currentItem->text(2));
477 } 473 }
478 474
479void HlEditDialog::contextDescrChanged(const QString& name) 475void HlEditDialog::contextDescrChanged(const QString& name)
480 { 476 {
481 if (currentItem) 477 if (currentItem)
482 { 478 {
483 currentItem->setText(0,name); 479 currentItem->setText(0,name);
484 ContextLineEnd->changeItem(name,currentItem->text(3).toInt()); 480 ContextLineEnd->changeItem(name,currentItem->text(3).toInt());
485 } 481 }
486 } 482 }
487 483
488void HlEditDialog::contextAttributeChanged(int id) 484void HlEditDialog::contextAttributeChanged(int id)
489{ 485{
490 if (currentItem) 486 if (currentItem)
491 { 487 {
492 currentItem->setText(2,QString("%1").arg(id)); 488 currentItem->setText(2,QString("%1").arg(id));
493 } 489 }
494} 490}
495 491
496void HlEditDialog::contextLineEndChanged(int id) 492void HlEditDialog::contextLineEndChanged(int id)
497{ 493{
498 kdDebug(13010)<<"contextLineEndChanged"<<endl; 494 kdDebug(13010)<<"contextLineEndChanged"<<endl;
499 if (currentItem) 495 if (currentItem)
500 { 496 {
501 currentItem->setText(3,QString("%1").arg(id)); 497 currentItem->setText(3,QString("%1").arg(id));
502 } 498 }
503} 499}
504 500
505void HlEditDialog::contextAddNew() 501void HlEditDialog::contextAddNew()
506{ 502{
507 QListViewItem *it=contextList->firstChild(); 503 QListViewItem *it=contextList->firstChild();
508 for (;it->nextSibling()!=0;it=it->nextSibling()); 504 for (;it->nextSibling()!=0;it=it->nextSibling());
509 it=new QListViewItem(contextList,it,i18n("New Context"),QString("%1").arg(it->text(1).toInt()),"0","0"); 505 it=new QListViewItem(contextList,it,i18n("New Context"),QString("%1").arg(it->text(1).toInt()),"0","0");
510 contextList->setSelected(it,true); 506 contextList->setSelected(it,true);
511} 507}
512 508
513/****************************************************************************/ 509/****************************************************************************/
514/* ITEMS */ 510/* ITEMS */
515/****************************************************************************/ 511/****************************************************************************/
516 512
517void HlEditDialog::showItem() 513void HlEditDialog::showItem()
518 { 514 {
519 stack->raiseWidget(HlEItem); 515 stack->raiseWidget(HlEItem);
520 ItemContext->clear(); 516 ItemContext->clear();
521 for (QListViewItem *it=contextList->firstChild();it;it=it->nextSibling()) 517 for (QListViewItem *it=contextList->firstChild();it;it=it->nextSibling())
522 ItemContext->insertItem(it->text(0)); 518 ItemContext->insertItem(it->text(0));
523 ItemContext->setCurrentItem(currentItem->text(4).toInt()); 519 ItemContext->setCurrentItem(currentItem->text(4).toInt());
524 ItemAttribute->setCurrentItem(currentItem->text(3).toInt()); 520 ItemAttribute->setCurrentItem(currentItem->text(3).toInt());
525 QMap<QString,int>::Iterator iter=tag2id.find(currentItem->text(1)); 521 QMap<QString,int>::Iterator iter=tag2id.find(currentItem->text(1));
526 if (iter==tag2id.end()) 522 if (iter==tag2id.end())
527 kdDebug(13010)<<"Oops, unknown itemtype in showItem: "<<currentItem->text(1)<<endl; 523 kdDebug(13010)<<"Oops, unknown itemtype in showItem: "<<currentItem->text(1)<<endl;
528 else 524 else
529 { 525 {
530 ItemType->setCurrentItem(*iter); 526 ItemType->setCurrentItem(*iter);
531 if (id2info[*iter].length==0) ItemParameter->hide(); 527 if (id2info[*iter].length==0) ItemParameter->hide();
532 else 528 else
533 { 529 {
534 ItemParameter->setMaxLength(id2info[*iter].length); 530 ItemParameter->setMaxLength(id2info[*iter].length);
535 ItemParameter->show(); 531 ItemParameter->show();
536 ItemParameter->setText(currentItem->text(2)); 532 ItemParameter->setText(currentItem->text(2));
537 } 533 }
538 } 534 }
539 535
540 } 536 }
541 537
542void HlEditDialog::ItemTypeChanged(int id) 538void HlEditDialog::ItemTypeChanged(int id)
543{ 539{
544 if (currentItem) 540 if (currentItem)
545 { 541 {
546 currentItem->setText(1,id2tag[id]); 542 currentItem->setText(1,id2tag[id]);
547 ItemParameter->setMaxLength(id2info[id].length); 543 ItemParameter->setMaxLength(id2info[id].length);
548 ItemParameterChanged(ItemParameter->text()); 544 ItemParameterChanged(ItemParameter->text());
549 } 545 }
550} 546}
551 547
552void HlEditDialog::ItemParameterChanged(const QString& name) 548void HlEditDialog::ItemParameterChanged(const QString& name)
553{ 549{
554 if (currentItem) 550 if (currentItem)
555 { 551 {
556 currentItem->setText(2,name); 552 currentItem->setText(2,name);
557 currentItem->setText(0,id2info[ItemType->currentItem()].trans_i18n+" "+currentItem->text(2)); 553 currentItem->setText(0,id2info[ItemType->currentItem()].trans_i18n+" "+currentItem->text(2));
558 } 554 }
559} 555}
560 556
561void HlEditDialog::ItemAttributeChanged(int attr) 557void HlEditDialog::ItemAttributeChanged(int attr)
562{ 558{
563 if (currentItem) 559 if (currentItem)
564 { 560 {
565 currentItem->setText(3,QString("%1").arg(attr)); 561 currentItem->setText(3,QString("%1").arg(attr));
566 } 562 }
567} 563}
568 564
569void HlEditDialog::ItemContextChanged(int cont) 565void HlEditDialog::ItemContextChanged(int cont)
570{ 566{
571 if (currentItem) 567 if (currentItem)
572 { 568 {
573 currentItem->setText(4,QString("%1").arg(cont)); 569 currentItem->setText(4,QString("%1").arg(cont));
574 } 570 }
575} 571}
576 572
577void HlEditDialog::ItemAddNew() 573void HlEditDialog::ItemAddNew()
578{ 574{
579 QListViewItem *it; 575 QListViewItem *it;
580 if (currentItem) 576 if (currentItem)
581 { 577 {
582 if (currentItem->depth()==0) it=currentItem->firstChild(); 578 if (currentItem->depth()==0) it=currentItem->firstChild();
583 else 579 else
584 it=currentItem; 580 it=currentItem;
585 if (it) for (;it->nextSibling();it=it->nextSibling()); 581 if (it) for (;it->nextSibling();it=it->nextSibling());
586 (void) new QListViewItem(it ? it->parent() : currentItem,it,"StringDetect "+i18n("New Item"),"StringDetect",i18n("New Item"),0,it ? it->parent()->text(1) : currentItem->text(1)); 582 (void) new QListViewItem(it ? it->parent() : currentItem,it,"StringDetect "+i18n("New Item"),"StringDetect",i18n("New Item"),0,it ? it->parent()->text(1) : currentItem->text(1));
587 } 583 }
588} 584}