• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • sources
  • kde-4.12
  • applications
  • kate
  • part
  • schema
kateschemaconfig.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2007, 2008 Matthew Woehlke <mw_triad@users.sourceforge.net>
3  Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org>
4  Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
5  Copyright (C) 2012 Dominik Haumann <dhaumann kde org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License version 2 as published by the Free Software Foundation.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 //BEGIN Includes
23 #include "kateschemaconfig.h"
24 #include "kateschemaconfig.moc"
25 
26 #include "kateschema.h"
27 #include "kateconfig.h"
28 #include "kateglobal.h"
29 #include "kateview.h"
30 #include "katerenderer.h"
31 #include "katestyletreewidget.h"
32 #include "katecolortreewidget.h"
33 
34 #include "ui_howtoimportschema.h"
35 
36 #include <kcolorscheme.h>
37 #include <kcolorutils.h>
38 #include <kinputdialog.h>
39 #include <kfontchooser.h>
40 #include <kmessagebox.h>
41 #include <khbox.h>
42 #include <ktabwidget.h>
43 
44 #include <QtGui/QPushButton>
45 #include <QtGui/QProgressDialog>
46 //END
47 
48 
49 //BEGIN KateSchemaConfigColorTab -- 'Colors' tab
50 KateSchemaConfigColorTab::KateSchemaConfigColorTab()
51 {
52  QGridLayout* l = new QGridLayout(this);
53  setLayout(l);
54 
55  ui = new KateColorTreeWidget(this);
56  QPushButton* btnUseColorScheme = new QPushButton(i18n("Use KDE Color Scheme"), this);
57 
58  l->addWidget(ui, 0, 0, 1, 2);
59  l->addWidget(btnUseColorScheme, 1, 1);
60 
61  l->setColumnStretch(0, 1);
62  l->setColumnStretch(1, 0);
63 
64  connect(btnUseColorScheme, SIGNAL(clicked()), ui, SLOT(selectDefaults()));
65  connect(ui, SIGNAL(changed()), SIGNAL(changed()));
66 }
67 
68 KateSchemaConfigColorTab::~KateSchemaConfigColorTab()
69 {
70 }
71 
72 QVector<KateColorItem> KateSchemaConfigColorTab::colorItemList() const
73 {
74  QVector<KateColorItem> items;
75 
76  KColorScheme schemeWindow = KColorScheme(QPalette::Active, KColorScheme::Window);
77  KColorScheme schemeView = KColorScheme(QPalette::Active, KColorScheme::View);
78 
79  //
80  // editor background colors
81  //
82  KateColorItem ci;
83  ci.category = i18n("Editor Background Colors");
84 
85  ci.name = i18n("Text Area");
86  ci.key = "Color Background";
87  ci.whatsThis = i18n("<p>Sets the background color of the editing area.</p>");
88  ci.defaultColor = schemeView.background().color();
89  items.append(ci);
90 
91  ci.name = i18n("Selected Text");
92  ci.key = "Color Selection";
93  ci.whatsThis = i18n("<p>Sets the background color of the selection.</p><p>To set the text color for selected text, use the &quot;<b>Configure Highlighting</b>&quot; dialog.</p>");
94  ci.defaultColor = KColorScheme(QPalette::Inactive, KColorScheme::Selection).background().color();
95  items.append(ci);
96 
97  ci.name = i18n("Current Line");
98  ci.key = "Color Highlighted Line";
99  ci.whatsThis = i18n("<p>Sets the background color of the currently active line, which means the line where your cursor is positioned.</p>");
100  ci.defaultColor = schemeView.background(KColorScheme::AlternateBackground).color();
101  items.append(ci);
102 
103  ci.name = i18n("Search Highlight");
104  ci.key = "Color Search Highlight";
105  ci.whatsThis = i18n("<p>Sets the background color of search results.</p>");
106  ci.defaultColor = Qt::yellow; // schemeView.background(KColorScheme::NeutralBackground).color();
107  items.append(ci);
108 
109  ci.name = i18n("Replace Highlight");
110  ci.key = "Color Replace Highlight";
111  ci.whatsThis = i18n("<p>Sets the background color of replaced text.</p>");
112  ci.defaultColor = Qt::green; // schemeView.background(KColorScheme::PositiveBackground).color();
113  items.append(ci);
114 
115 
116  //
117  // icon border
118  //
119  ci.category = i18n("Icon Border");
120 
121  ci.name = i18n("Background Area");
122  ci.key = "Color Icon Bar";
123  ci.whatsThis = i18n("<p>Sets the background color of the icon border.</p>");
124  ci.defaultColor = schemeWindow.background().color();
125  items.append(ci);
126 
127  ci.name = i18n("Line Numbers");
128  ci.key = "Color Line Number";
129  ci.whatsThis = i18n("<p>This color will be used to draw the line numbers (if enabled).</p>");
130  ci.defaultColor = schemeWindow.foreground().color();
131  items.append(ci);
132 
133  ci.name = i18n("Separator");
134  ci.key = "Color Separator";
135  ci.whatsThis = i18n("<p>This color will be used to draw the line between line numbers and the icon borders, if both are enabled.</p>");
136  ci.defaultColor = schemeView.foreground(KColorScheme::InactiveText).color();
137  items.append(ci);
138 
139  ci.name = i18n("Word Wrap Marker");
140  ci.key = "Color Word Wrap Marker";
141  ci.whatsThis = i18n("<p>Sets the color of Word Wrap-related markers:</p><dl><dt>Static Word Wrap</dt><dd>A vertical line which shows the column where text is going to be wrapped</dd><dt>Dynamic Word Wrap</dt><dd>An arrow shown to the left of visually-wrapped lines</dd></dl>");
142  qreal bgLuma = KColorUtils::luma(schemeView.background().color());
143  ci.defaultColor = KColorUtils::shade( schemeView.background().color(), bgLuma > 0.3 ? -0.15 : 0.03 );
144  items.append(ci);
145 
146  ci.name = i18n("Code Folding");
147  ci.key = "Color Code Folding";
148  ci.whatsThis = i18n("<p>Sets the color of the code folding bar.</p>");
149  ci.defaultColor = KColorScheme(QPalette::Inactive, KColorScheme::Selection).background().color();
150  items.append(ci);
151 
152 
153  ci.name = i18n("Modified Lines");
154  ci.key = "Color Modified Lines";
155  ci.whatsThis = i18n("<p>Sets the color of the line modification marker for modified lines.</p>");
156  ci.defaultColor = schemeView.background(KColorScheme::NegativeBackground).color();
157  items.append(ci);
158 
159  ci.name = i18n("Saved Lines");
160  ci.key = "Color Saved Lines";
161  ci.whatsThis = i18n("<p>Sets the color of the line modification marker for saved lines.</p>");
162  ci.defaultColor = schemeView.background(KColorScheme::PositiveBackground).color();
163  items.append(ci);
164 
165 
166  //
167  // text decorations
168  //
169  ci.category = i18n("Text Decorations");
170 
171  ci.name = i18n("Spelling Mistake Line");
172  ci.key = "Color Spelling Mistake Line";
173  ci.whatsThis = i18n("<p>Sets the color of the line that is used to indicate spelling mistakes.</p>");
174  ci.defaultColor = schemeView.foreground(KColorScheme::NegativeText).color();
175  items.append(ci);
176 
177  ci.name = i18n("Tab and Space Markers");
178  ci.key = "Color Tab Marker";
179  ci.whatsThis = i18n("<p>Sets the color of the tabulator marks.</p>");
180  ci.defaultColor = KColorUtils::shade(schemeView.background().color(), bgLuma > 0.7 ? -0.35 : 0.3);
181  items.append(ci);
182 
183  ci.name = i18n("Indentation Line");
184  ci.key = "Color Indentation Line";
185  ci.whatsThis = i18n("<p>Sets the color of the vertical indentation lines.</p>");
186  ci.defaultColor = KColorUtils::shade(schemeView.background().color(), bgLuma > 0.7 ? -0.35 : 0.3);
187  items.append(ci);
188 
189  ci.name = i18n("Bracket Highlight");
190  ci.key = "Color Highlighted Bracket";
191  ci.whatsThis = i18n("<p>Sets the bracket matching color. This means, if you place the cursor e.g. at a <b>(</b>, the matching <b>)</b> will be highlighted with this color.</p>");
192  ci.defaultColor = KColorUtils::tint(schemeView.background().color(),
193  schemeView.decoration(KColorScheme::HoverColor).color());
194  items.append(ci);
195 
196 
197  //
198  // marker colors
199  //
200  ci.category = i18n("Marker Colors");
201 
202  ci.name = i18n("Bookmark");
203  ci.key = "Color MarkType 1";
204  ci.whatsThis = i18n("<p>Sets the background color of mark type.</p><p><b>Note</b>: The marker color is displayed lightly because of transparency.</p>");
205  ci.defaultColor = Qt::blue; // TODO: if possible, derive from system color scheme
206  items.append(ci);
207 
208  ci.name = i18n("Active Breakpoint");
209  ci.key = "Color MarkType 2";
210  ci.defaultColor = Qt::red; // TODO: if possible, derive from system color scheme
211  items.append(ci);
212 
213  ci.name = i18n("Reached Breakpoint");
214  ci.key = "Color MarkType 3";
215  ci.defaultColor = Qt::yellow; // TODO: if possible, derive from system color scheme
216  items.append(ci);
217 
218  ci.name = i18n("Disabled Breakpoint");
219  ci.key = "Color MarkType 4";
220  ci.defaultColor = Qt::magenta; // TODO: if possible, derive from system color scheme
221  items.append(ci);
222 
223  ci.name = i18n("Execution");
224  ci.key = "Color MarkType 5";
225  ci.defaultColor = Qt::gray; // TODO: if possible, derive from system color scheme
226  items.append(ci);
227 
228  ci.name = i18n("Warning");
229  ci.key = "Color MarkType 6";
230  ci.defaultColor = Qt::green; // TODO: if possible, derive from system color scheme
231  items.append(ci);
232 
233  ci.name = i18n("Error");
234  ci.key = "Color MarkType 7";
235  ci.defaultColor = Qt::red; // TODO: if possible, derive from system color scheme
236  items.append(ci);
237 
238 
239  //
240  // text templates
241  //
242  ci.category = i18n("Text Templates & Snippets");
243 
244  ci.whatsThis = QString(); // TODO: add whatsThis for text templates
245 
246  ci.name = i18n("Background");
247  ci.key = "Color Template Background";
248  ci.defaultColor = schemeWindow.background().color();
249  items.append(ci);
250 
251  ci.name = i18n("Editable Placeholder");
252  ci.key = "Color Template Editable Placeholder";
253  ci.defaultColor = schemeView.background(KColorScheme::PositiveBackground).color();
254  items.append(ci);
255 
256  ci.name = i18n("Focused Editable Placeholder");
257  ci.key = "Color Template Focused Editable Placeholder";
258  ci.defaultColor = schemeWindow.background(KColorScheme::PositiveBackground).color();
259  items.append(ci);
260 
261  ci.name = i18n("Not Editable Placeholder");
262  ci.key = "Color Template Not Editable Placeholder";
263  ci.defaultColor = schemeView.background(KColorScheme::NegativeBackground).color();
264  items.append(ci);
265 
266 
267  //
268  // finally, add all elements
269  //
270  return items;
271 }
272 
273 void KateSchemaConfigColorTab::schemaChanged ( const QString &newSchema )
274 {
275  // save curent schema
276  if ( !m_currentSchema.isEmpty() ) {
277  if (m_schemas.contains(m_currentSchema)) {
278  m_schemas.remove(m_currentSchema); // clear this color schema
279  }
280 
281  // now add it again
282  m_schemas[m_currentSchema] = ui->colorItems();
283  }
284 
285  if ( newSchema == m_currentSchema ) return;
286 
287  // switch
288  m_currentSchema = newSchema;
289 
290  // If we havent this schema, read in from config file
291  if ( ! m_schemas.contains( newSchema ) )
292  {
293  KConfigGroup config = KateGlobal::self()->schemaManager()->schema(newSchema);
294  QVector<KateColorItem> items = readConfig(config);
295 
296  m_schemas[ newSchema ] = items;
297  }
298 
299  // first block signals otherwise setColor emits changed
300  const bool blocked = blockSignals(true);
301 
302  ui->clear();
303  ui->addColorItems(m_schemas[m_currentSchema]);
304 
305  blockSignals(blocked);
306 }
307 
308 QVector<KateColorItem> KateSchemaConfigColorTab::readConfig(KConfigGroup& config)
309 {
310  QVector<KateColorItem> items = colorItemList();
311  for (int i = 0; i < items.count(); ++i ) {
312  KateColorItem& item(items[i]);
313  item.useDefault = !config.hasKey(item.key);
314  if (item.useDefault) {
315  item.color = item.defaultColor;
316  } else {
317  item.color = config.readEntry(item.key, item.defaultColor);
318  if (!item.color.isValid()) {
319  config.deleteEntry(item.key);
320  item.useDefault = true;
321  item.color = item.defaultColor;
322  }
323  }
324  }
325  return items;
326 }
327 
328 void KateSchemaConfigColorTab::importSchema(KConfigGroup& config)
329 {
330  m_schemas[m_currentSchema] = readConfig(config);
331 
332  // first block signals otherwise setColor emits changed
333  const bool blocked = blockSignals(true);
334 
335  ui->clear();
336  ui->addColorItems(m_schemas[m_currentSchema]);
337 
338  blockSignals(blocked);
339 }
340 
341 void KateSchemaConfigColorTab::exportSchema(KConfigGroup& config)
342 {
343  QVector<KateColorItem> items = ui->colorItems();
344  foreach (const KateColorItem& item, items) {
345  QColor c = item.useDefault ? item.defaultColor : item.color;
346  config.writeEntry(item.key, c);
347  }
348 }
349 
350 void KateSchemaConfigColorTab::apply ()
351 {
352  schemaChanged( m_currentSchema );
353  QMap<QString, QVector<KateColorItem> >::Iterator it;
354  for ( it = m_schemas.begin(); it != m_schemas.end(); ++it )
355  {
356  KConfigGroup config = KateGlobal::self()->schemaManager()->schema( it.key() );
357  kDebug(13030) << "writing 'Color' tab: scheme =" << it.key()
358  << "and config group =" << config.name();
359 
360  foreach (const KateColorItem& item, m_schemas[it.key()]) {
361  if (item.useDefault) {
362  config.deleteEntry(item.key);
363  } else {
364  config.writeEntry(item.key, item.color);
365  }
366  }
367 
368  // add dummy entry to prevent the config group from being empty.
369  // As if the group is empty, KateSchemaManager will not find it anymore.
370  config.writeEntry("dummy", "prevent-empty-group");
371  }
372 
373  // all colors are written, so throw away all cached schemas
374  m_schemas.clear();
375 }
376 
377 void KateSchemaConfigColorTab::reload()
378 {
379  // drop all cached data
380  m_schemas.clear();
381 
382  // load from config
383  KConfigGroup config = KateGlobal::self()->schemaManager()->schema(m_currentSchema);
384  QVector<KateColorItem> items = readConfig(config);
385 
386  // first block signals otherwise setColor emits changed
387  const bool blocked = blockSignals(true);
388 
389  ui->clear();
390  ui->addColorItems(items);
391 
392  blockSignals(blocked);
393 }
394 
395 QColor KateSchemaConfigColorTab::backgroundColor() const
396 {
397  return ui->findColor("Color Background");
398 }
399 
400 QColor KateSchemaConfigColorTab::selectionColor() const
401 {
402  return ui->findColor("Color Selection");
403 }
404 //END KateSchemaConfigColorTab
405 
406 //BEGIN FontConfig -- 'Fonts' tab
407 KateSchemaConfigFontTab::KateSchemaConfigFontTab()
408 {
409  QGridLayout *grid = new QGridLayout( this );
410 
411  m_fontchooser = new KFontChooser ( this, KFontChooser::NoDisplayFlags );
412  grid->addWidget( m_fontchooser, 0, 0);
413 }
414 
415 KateSchemaConfigFontTab::~KateSchemaConfigFontTab()
416 {
417 }
418 
419 void KateSchemaConfigFontTab::slotFontSelected( const QFont &font )
420 {
421  if ( !m_currentSchema.isEmpty() ) {
422  m_fonts[m_currentSchema] = font;
423  emit changed();
424  }
425 }
426 
427 void KateSchemaConfigFontTab::apply()
428 {
429  QMap<QString, QFont>::Iterator it;
430  for ( it = m_fonts.begin(); it != m_fonts.end(); ++it )
431  {
432  KateGlobal::self()->schemaManager()->schema( it.key() ).writeEntry( "Font", it.value() );
433  }
434 
435  // all fonts are written, so throw away all cached schemas
436  m_fonts.clear();
437 }
438 
439 void KateSchemaConfigFontTab::reload()
440 {
441  // drop all cached data
442  m_fonts.clear();
443 
444  // now set current schema font in the font chooser
445  schemaChanged(m_currentSchema);
446 }
447 
448 void KateSchemaConfigFontTab::schemaChanged( const QString &newSchema )
449 {
450  m_currentSchema = newSchema;
451 
452  // reuse font, if cached
453  QFont newFont (KGlobalSettings::fixedFont());
454  if (m_fonts.contains(m_currentSchema)) {
455  newFont = m_fonts[m_currentSchema];
456  } else {
457  newFont = KateGlobal::self()->schemaManager()->schema(m_currentSchema).readEntry("Font", newFont);
458  }
459 
460  m_fontchooser->disconnect ( this );
461  m_fontchooser->setFont ( newFont );
462  connect (m_fontchooser, SIGNAL (fontSelected(QFont)), this, SLOT (slotFontSelected(QFont)));
463 }
464 
465 void KateSchemaConfigFontTab::importSchema(KConfigGroup& config)
466 {
467  QFont f (KGlobalSettings::fixedFont());
468  m_fontchooser->setFont(config.readEntry("Font", f));
469  m_fonts[m_currentSchema] = m_fontchooser->font();
470 }
471 
472 void KateSchemaConfigFontTab::exportSchema(KConfigGroup& config)
473 {
474  config.writeEntry("Font", m_fontchooser->font());
475 }
476 //END FontConfig
477 
478 //BEGIN FontColorConfig -- 'Normal Text Styles' tab
479 KateSchemaConfigDefaultStylesTab::KateSchemaConfigDefaultStylesTab(KateSchemaConfigColorTab* colorTab)
480 {
481  m_colorTab = colorTab;
482 
483  // size management
484  QGridLayout *grid = new QGridLayout( this );
485 
486  m_defaultStyles = new KateStyleTreeWidget( this );
487  m_defaultStyles->setRootIsDecorated(false);
488  connect(m_defaultStyles, SIGNAL(changed()), this, SIGNAL(changed()));
489  grid->addWidget( m_defaultStyles, 0, 0);
490 
491  m_defaultStyles->setWhatsThis(i18n(
492  "<p>This list displays the default styles for the current schema and "
493  "offers the means to edit them. The style name reflects the current "
494  "style settings.</p>"
495  "<p>To edit the colors, click the colored squares, or select the color "
496  "to edit from the popup menu.</p><p>You can unset the Background and Selected "
497  "Background colors from the popup menu when appropriate.</p>") );
498 }
499 
500 KateSchemaConfigDefaultStylesTab::~KateSchemaConfigDefaultStylesTab()
501 {
502  qDeleteAll(m_defaultStyleLists);
503 }
504 
505 KateAttributeList *KateSchemaConfigDefaultStylesTab::attributeList (const QString &schema)
506 {
507  if (!m_defaultStyleLists.contains(schema))
508  {
509  KateAttributeList *list = new KateAttributeList ();
510  KateHlManager::self()->getDefaults(schema, *list);
511 
512  m_defaultStyleLists.insert (schema, list);
513  }
514 
515  return m_defaultStyleLists[schema];
516 }
517 
518 void KateSchemaConfigDefaultStylesTab::schemaChanged (const QString &schema)
519 {
520  m_currentSchema = schema;
521 
522  m_defaultStyles->clear ();
523 
524  KateAttributeList *l = attributeList (schema);
525  updateColorPalette(l->at(0)->foreground().color());
526 
527  for ( uint i = 0; i < KateHlManager::self()->defaultStyles(); i++ )
528  {
529  m_defaultStyles->addItem( KateHlManager::self()->defaultStyleName(i, true), l->at( i ) );
530  }
531 }
532 
533 void KateSchemaConfigDefaultStylesTab::updateColorPalette(const QColor& textColor)
534 {
535  QPalette p ( m_defaultStyles->palette() );
536  p.setColor( QPalette::Base, m_colorTab->backgroundColor() );
537  p.setColor( QPalette::Highlight, m_colorTab->selectionColor() );
538  p.setColor( QPalette::Text, textColor );
539  m_defaultStyles->setPalette( p );
540 }
541 
542 void KateSchemaConfigDefaultStylesTab::reload ()
543 {
544  m_defaultStyles->clear ();
545  qDeleteAll(m_defaultStyleLists);
546  m_defaultStyleLists.clear ();
547 
548  schemaChanged(m_currentSchema);
549 }
550 
551 void KateSchemaConfigDefaultStylesTab::apply ()
552 {
553  QHashIterator<QString,KateAttributeList*> it = m_defaultStyleLists;
554  while (it.hasNext()) {
555  it.next();
556  KateHlManager::self()->setDefaults(it.key(), *it.value());
557  }
558 }
559 
560 void KateSchemaConfigDefaultStylesTab::exportSchema(const QString &schema, KConfig *cfg)
561 {
562  KateHlManager::self()->setDefaults(schema, *(m_defaultStyleLists[schema]),cfg);
563 }
564 
565 void KateSchemaConfigDefaultStylesTab::importSchema(const QString& schemaName, const QString &schema, KConfig *cfg)
566 {
567  KateHlManager::self()->getDefaults(schemaName, *(m_defaultStyleLists[schema]),cfg);
568 }
569 
570 void KateSchemaConfigDefaultStylesTab::showEvent(QShowEvent* event)
571 {
572  if (!event->spontaneous() && !m_currentSchema.isEmpty()) {
573  KateAttributeList *l = attributeList (m_currentSchema);
574  Q_ASSERT(l != 0);
575  updateColorPalette(l->at(0)->foreground().color());
576  }
577 
578  QWidget::showEvent(event);
579 }
580 //END FontColorConfig
581 
582 //BEGIN KateSchemaConfigHighlightTab -- 'Highlighting Text Styles' tab
583 KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab(KateSchemaConfigDefaultStylesTab *page, KateSchemaConfigColorTab* colorTab)
584 {
585  m_defaults = page;
586  m_colorTab = colorTab;
587 
588  m_hl = 0;
589 
590  QVBoxLayout *layout = new QVBoxLayout(this);
591 
592  // hl chooser
593  KHBox *hbHl = new KHBox( this );
594  layout->addWidget (hbHl);
595 
596  hbHl->setSpacing( -1 );
597  QLabel *lHl = new QLabel( i18n("H&ighlight:"), hbHl );
598  hlCombo = new KComboBox( hbHl );
599  hlCombo->setEditable( false );
600  lHl->setBuddy( hlCombo );
601  connect( hlCombo, SIGNAL(activated(int)),
602  this, SLOT(hlChanged(int)) );
603 
604  QPushButton *btnexport = new QPushButton( i18n("Export..."), hbHl );
605  QPushButton *btnimport = new QPushButton( i18n("Import..."), hbHl );
606 
607  qobject_cast<QBoxLayout*>(hbHl->layout())->addStretch();
608 
609  connect( btnexport,SIGNAL(clicked()),this,SLOT(exportHl()));
610  connect( btnimport,SIGNAL(clicked()),this,SLOT(importHl()));
611 
612  for( int i = 0; i < KateHlManager::self()->highlights(); i++) {
613  if (KateHlManager::self()->hlSection(i).length() > 0)
614  hlCombo->addItem(KateHlManager::self()->hlSection(i) + QString ("/") + KateHlManager::self()->hlNameTranslated(i));
615  else
616  hlCombo->addItem(KateHlManager::self()->hlNameTranslated(i));
617  }
618  hlCombo->setCurrentIndex(0);
619 
620  // styles listview
621  m_styles = new KateStyleTreeWidget( this, true );
622  connect(m_styles, SIGNAL(changed()), this, SIGNAL(changed()));
623  layout->addWidget (m_styles, 999);
624 
625  // get current highlighting from the host application
626  int hl = 0;
627  KTextEditor::MdiContainer *iface = qobject_cast<KTextEditor::MdiContainer*>(KateGlobal::self()->container());
628  if (iface) {
629  KateView *kv = qobject_cast<KateView*>(iface->activeView());
630  if (kv) {
631  const QString hlName = kv->doc()->highlight()->name();
632  hl = KateHlManager::self()->nameFind(hlName);
633  Q_ASSERT(hl >= 0);
634  }
635  }
636  hlCombo->setCurrentIndex ( hl );
637  hlChanged ( hl );
638 
639  m_styles->setWhatsThis(i18n(
640  "<p>This list displays the contexts of the current syntax highlight mode and "
641  "offers the means to edit them. The context name reflects the current "
642  "style settings.</p><p>To edit using the keyboard, press "
643  "<strong>&lt;SPACE&gt;</strong> and choose a property from the popup menu.</p>"
644  "<p>To edit the colors, click the colored squares, or select the color "
645  "to edit from the popup menu.</p><p>You can unset the Background and Selected "
646  "Background colors from the context menu when appropriate.</p>") );
647 }
648 
649 KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab()
650 {
651 }
652 
653 void KateSchemaConfigHighlightTab::hlChanged(int z)
654 {
655  m_hl = z;
656  schemaChanged (m_schema);
657 }
658 
659 bool KateSchemaConfigHighlightTab::loadAllHlsForSchema(const QString &schema)
660 {
661  QProgressDialog progress(i18n("Loading all highlightings for schema"), QString(), 0, KateHlManager::self()->highlights(), this);
662  progress.setWindowModality(Qt::WindowModal);
663  for (int i = 0; i < KateHlManager::self()->highlights(); ++i) {
664  if (!m_hlDict[schema].contains(i))
665  {
666  kDebug(13030) << "NEW HL, create list";
667 
668  QList<KateExtendedAttribute::Ptr> list;
669  KateHlManager::self()->getHl(i)->getKateExtendedAttributeListCopy(schema, list);
670  m_hlDict[schema].insert (i, list);
671  }
672  progress.setValue(progress.value() + 1);
673  }
674  progress.setValue(KateHlManager::self()->highlights());
675  return true;
676 }
677 
678 void KateSchemaConfigHighlightTab::schemaChanged (const QString &schema)
679 {
680  m_schema = schema;
681 
682  kDebug(13030) << "NEW SCHEMA: " << m_schema << " NEW HL: " << m_hl;
683 
684  m_styles->clear ();
685 
686  if (!m_hlDict.contains(m_schema))
687  {
688  kDebug(13030) << "NEW SCHEMA, create dict";
689 
690  m_hlDict.insert (schema, QHash<int, QList<KateExtendedAttribute::Ptr> >());
691  }
692 
693  if (!m_hlDict[m_schema].contains(m_hl))
694  {
695  kDebug(13030) << "NEW HL, create list";
696 
697  QList<KateExtendedAttribute::Ptr> list;
698  KateHlManager::self()->getHl( m_hl )->getKateExtendedAttributeListCopy(m_schema, list);
699  m_hlDict[m_schema].insert (m_hl, list);
700  }
701 
702  KateAttributeList *l = m_defaults->attributeList (schema);
703 
704  // Set listview colors
705  updateColorPalette(l->at(0)->foreground().color());
706 
707  QHash<QString, QTreeWidgetItem*> prefixes;
708  QList<KateExtendedAttribute::Ptr>::ConstIterator it = m_hlDict[m_schema][m_hl].constBegin();
709  while (it != m_hlDict[m_schema][m_hl].constEnd())
710  {
711  const KateExtendedAttribute::Ptr itemData = *it;
712  Q_ASSERT(itemData);
713 
714  kDebug(13030) << "insert items " << itemData->name();
715 
716  // All stylenames have their language mode prefixed, e.g. HTML:Comment
717  // split them and put them into nice substructures.
718  int c = itemData->name().indexOf(':');
719  if ( c > 0 ) {
720  QString prefix = itemData->name().left(c);
721  QString name = itemData->name().mid(c+1);
722 
723  QTreeWidgetItem *parent = prefixes[prefix];
724  if ( ! parent )
725  {
726  parent = new QTreeWidgetItem( m_styles, QStringList() << prefix );
727  m_styles->expandItem(parent);
728  prefixes.insert( prefix, parent );
729  }
730  m_styles->addItem( parent, name, l->at(itemData->defaultStyleIndex()), itemData );
731  } else {
732  m_styles->addItem( itemData->name(), l->at(itemData->defaultStyleIndex()), itemData );
733  }
734  ++it;
735  }
736 
737  m_styles->resizeColumns();
738 }
739 
740 void KateSchemaConfigHighlightTab::updateColorPalette(const QColor& textColor)
741 {
742  QPalette p ( m_styles->palette() );
743  p.setColor( QPalette::Base, m_colorTab->backgroundColor() );
744  p.setColor( QPalette::Highlight, m_colorTab->selectionColor() );
745  p.setColor( QPalette::Text, textColor );
746  m_styles->setPalette( p );
747 }
748 
749 void KateSchemaConfigHighlightTab::reload ()
750 {
751  m_styles->clear ();
752 
753  m_hlDict.clear ();
754 
755  hlChanged( hlCombo->currentIndex() );
756 }
757 
758 void KateSchemaConfigHighlightTab::apply ()
759 {
760  QMutableHashIterator<QString, QHash<int, QList<KateExtendedAttribute::Ptr> > > it = m_hlDict;
761  while (it.hasNext()) {
762  it.next();
763  QMutableHashIterator<int, QList<KateExtendedAttribute::Ptr> > it2 = it.value();
764  while (it2.hasNext()) {
765  it2.next();
766  KateHlManager::self()->getHl( it2.key() )->setKateExtendedAttributeList (it.key(), it2.value());
767  }
768  }
769 }
770 
771 
772 QList<int> KateSchemaConfigHighlightTab::hlsForSchema(const QString &schema) {
773  return m_hlDict[schema].keys();
774 }
775 
776 
777 void KateSchemaConfigHighlightTab::importHl(const QString& fromSchemaName, QString schema, int hl, KConfig *cfg) {
778  QString schemaNameForLoading(fromSchemaName);
779  QString hlName;
780  bool doManage=(cfg==0);
781  if (schema.isEmpty()) schema=m_schema;
782 
783  if (doManage) {
784  QString srcName=KFileDialog::getOpenFileName( QString(KateHlManager::self()->getHl(hl)->name()+QString(".katehlcolor")),
785  QString::fromLatin1("*.katehlcolor|%1").arg(i18n("Kate color schema")),
786  this,
787  i18n("Importing colors for single highlighting"));
788  kDebug(13030)<<"hl file to open "<<srcName;
789  if (srcName.isEmpty()) return;
790  cfg=new KConfig(srcName,KConfig::SimpleConfig);
791  KConfigGroup grp(cfg,"KateHLColors");
792  hlName=grp.readEntry("highlight",QString());
793  schemaNameForLoading=grp.readEntry("schema",QString());
794  if ( (grp.readEntry("full schema","true").toUpper()!="FALSE") || hlName.isEmpty() || schemaNameForLoading.isEmpty()) {
795  //ERROR - file format
796  KMessageBox::information(
797  this,
798  i18n("File is not a single highlighting color file"),
799  i18n("Fileformat error"));
800  hl=-1;
801  schemaNameForLoading=QString();
802  } else {
803  hl = KateHlManager::self()->nameFind(hlName);
804  kDebug(13030)<<hlName<<"--->"<<hl;
805  if (hl==-1) {
806  //hl not found
807  KMessageBox::information(
808  this,
809  i18n("The selected file contains colors for a non existing highlighting:%1",hlName),
810  i18n("Import failure"));
811  hl=-1;
812  schemaNameForLoading=QString();
813  }
814  }
815  }
816 
817  if ( (hl!=-1) && (!schemaNameForLoading.isEmpty())) {
818 
819  QList<KateExtendedAttribute::Ptr> list;
820  KateHlManager::self()->getHl( hl )->getKateExtendedAttributeListCopy(schemaNameForLoading, list, cfg);
821  KateHlManager::self()->getHl( hl )->setKateExtendedAttributeList(schema, list);
822  m_hlDict[schema].insert (hl, list);
823  }
824 
825  if (cfg && doManage) {
826  apply();
827  delete cfg;
828  cfg=0;
829  if ( (hl!=-1) && (!schemaNameForLoading.isEmpty())) {
830  hlChanged(m_hl);
831  KMessageBox::information(
832  this,
833  i18n("Colors have been imported for highlighting: %1",hlName),
834  i18n("Import has finished"));
835  }
836  }
837 
838 
839 }
840 
841 
842 void KateSchemaConfigHighlightTab::exportHl(QString schema, int hl, KConfig *cfg) {
843  bool doManage=(cfg==0);
844  if (schema.isEmpty()) schema=m_schema;
845  if (hl==-1) hl=m_hl;
846 
847  QList<KateExtendedAttribute::Ptr> items=m_hlDict[schema][hl];
848  if (doManage) {
849  QString destName=KFileDialog::getSaveFileName( QString(KateHlManager::self()->getHl(hl)->name()+".katehlcolor"),
850  QString::fromLatin1("*.katehlcolor|%1").arg(i18n("Kate color schema")),
851  this,
852  i18n("Exporting colors for single highlighting: %1", KateHlManager::self()->getHl(hl)->name()),
853  KFileDialog::ConfirmOverwrite );
854 
855  if (destName.isEmpty()) return;
856 
857  cfg=new KConfig(destName,KConfig::SimpleConfig);
858  KConfigGroup grp(cfg,"KateHLColors");
859  grp.writeEntry("highlight",KateHlManager::self()->getHl(hl)->name());
860  grp.writeEntry("schema",schema);
861  grp.writeEntry("full schema","false");
862  }
863  KateHlManager::self()->getHl(hl)->setKateExtendedAttributeList(schema,items,cfg,doManage);
864 
865  if (doManage) {
866  cfg->sync();
867  delete cfg;
868  }
869 
870 }
871 
872 void KateSchemaConfigHighlightTab::showEvent(QShowEvent* event)
873 {
874  if (!event->spontaneous()) {
875  KateAttributeList *l = m_defaults->attributeList (m_schema);
876  Q_ASSERT(l != 0);
877  updateColorPalette(l->at(0)->foreground().color());
878  }
879 
880  QWidget::showEvent(event);
881 }
882 //END KateSchemaConfigHighlightTab
883 
884 //BEGIN KateSchemaConfigPage -- Main dialog page
885 KateSchemaConfigPage::KateSchemaConfigPage( QWidget *parent)
886  : KateConfigPage( parent ),
887  m_currentSchema (-1)
888 {
889  QVBoxLayout *layout = new QVBoxLayout(this);
890  layout->setMargin(0);
891 
892  KHBox *hbHl = new KHBox( this );
893  layout->addWidget(hbHl);
894  hbHl->setSpacing( -1 );
895  QLabel *lHl = new QLabel( i18n("&Schema:"), hbHl );
896  schemaCombo = new KComboBox( hbHl );
897  schemaCombo->setEditable( false );
898  lHl->setBuddy( schemaCombo );
899  connect( schemaCombo, SIGNAL(currentIndexChanged(int)),
900  this, SLOT(comboBoxIndexChanged(int)) );
901 
902  QPushButton *btnnew = new QPushButton( i18n("&New..."), hbHl );
903  connect( btnnew, SIGNAL(clicked()), this, SLOT(newSchema()) );
904 
905  btndel = new QPushButton( i18n("&Delete"), hbHl );
906  connect( btndel, SIGNAL(clicked()), this, SLOT(deleteSchema()) );
907 
908  QPushButton *btnexport = new QPushButton( i18n("Export..."), hbHl );
909  connect(btnexport,SIGNAL(clicked()),this,SLOT(exportFullSchema()));
910  QPushButton *btnimport = new QPushButton( i18n("Import..."), hbHl );
911  connect(btnimport,SIGNAL(clicked()),this,SLOT(importFullSchema()));
912 
913  qobject_cast<QBoxLayout *>(hbHl->layout())->addStretch();
914 
915  m_tabWidget = new KTabWidget ( this );
916  layout->addWidget (m_tabWidget);
917 
918  m_colorTab = new KateSchemaConfigColorTab();
919  m_tabWidget->addTab (m_colorTab, i18n("Colors"));
920  connect(m_colorTab, SIGNAL(changed()), SLOT(slotChanged()));
921 
922  m_fontTab = new KateSchemaConfigFontTab();
923  m_tabWidget->addTab (m_fontTab, i18n("Font"));
924  connect(m_fontTab, SIGNAL(changed()), SLOT(slotChanged()));
925 
926  m_defaultStylesTab = new KateSchemaConfigDefaultStylesTab(m_colorTab);
927  m_tabWidget->addTab (m_defaultStylesTab, i18n("Default Text Styles"));
928  connect(m_defaultStylesTab, SIGNAL(changed()), SLOT(slotChanged()));
929 
930  m_highlightTab = new KateSchemaConfigHighlightTab(m_defaultStylesTab, m_colorTab);
931  m_tabWidget->addTab(m_highlightTab, i18n("Highlighting Text Styles"));
932  connect(m_highlightTab, SIGNAL(changed()), SLOT(slotChanged()));
933 
934  hbHl = new KHBox( this );
935  layout->addWidget (hbHl);
936  hbHl->setSpacing( -1 );
937  lHl = new QLabel( i18n("&Default schema for %1:", KGlobal::mainComponent().aboutData()->programName ()), hbHl );
938  defaultSchemaCombo = new KComboBox( hbHl );
939  defaultSchemaCombo->setEditable( false );
940  lHl->setBuddy( defaultSchemaCombo );
941 
942  reload();
943 
944  connect( defaultSchemaCombo, SIGNAL(currentIndexChanged(int)),
945  this, SLOT(slotChanged()) );
946 }
947 
948 KateSchemaConfigPage::~KateSchemaConfigPage ()
949 {
950 }
951 
952 void KateSchemaConfigPage::exportFullSchema()
953 {
954  // get save destination
955  const QString currentSchemaName = m_currentSchema;
956  QString destName = KFileDialog::getSaveFileName(
957  QString(currentSchemaName + ".kateschema"),
958  QString::fromLatin1("*.kateschema|%1").arg(i18n("Kate color schema")),
959  this,
960  i18n("Exporting color schema: %1", currentSchemaName),
961  KFileDialog::ConfirmOverwrite );
962 
963  if (destName.isEmpty()) return;
964 
965  // open config file
966  KConfig cfg(destName, KConfig::SimpleConfig);
967 
968  //
969  // export editor Colors (background, ...)
970  //
971  KConfigGroup colorConfigGroup(&cfg, "Editor Colors");
972  m_colorTab->exportSchema(colorConfigGroup);
973 
974  //
975  // export Default Styles
976  //
977  m_defaultStylesTab->exportSchema(m_currentSchema, &cfg);
978 
979  //
980  // export Highlighting Text Styles
981  //
982  // force a load of all Highlighting Text Styles
983  QStringList hlList;
984  m_highlightTab->loadAllHlsForSchema(m_currentSchema);
985 
986  QList<int> hls = m_highlightTab->hlsForSchema(m_currentSchema);
987 
988  int cnt = 0;
989  QProgressDialog progress(i18n("Exporting schema"), QString(), 0, hls.count(), this);
990  progress.setWindowModality(Qt::WindowModal);
991  foreach (int hl, hls) {
992  hlList << KateHlManager::self()->getHl (hl)->name();
993  m_highlightTab->exportHl(m_currentSchema, hl, &cfg);
994  progress.setValue(++cnt);
995  if (progress.wasCanceled()) break;
996  }
997  progress.setValue(hls.count());
998 
999  KConfigGroup grp(&cfg, "KateSchema");
1000  grp.writeEntry("full schema", "true");
1001  grp.writeEntry("highlightings", hlList);
1002  grp.writeEntry("schema", currentSchemaName);
1003  m_fontTab->exportSchema(grp);
1004  cfg.sync();
1005 }
1006 
1007 QString KateSchemaConfigPage::requestSchemaName(const QString& suggestedName)
1008 {
1009  QString schemaName = suggestedName;
1010 
1011  bool reask = true;
1012  do {
1013  KDialog howToImportDialog(this);
1014  Ui_KateHowToImportSchema howToImport;
1015  howToImport.setupUi(howToImportDialog.mainWidget());
1016 
1017  // if schema exists, prepare option to replace
1018  if (KateGlobal::self()->schemaManager()->schema(schemaName).exists()) {
1019  howToImport.radioReplaceExisting->show();
1020  howToImport.radioReplaceExisting->setText(i18n("Replace existing schema %1", schemaName));
1021  howToImport.radioReplaceExisting->setChecked(true);
1022  } else {
1023  howToImport.radioReplaceExisting->hide();
1024  howToImport.newName->setText(schemaName);
1025  }
1026 
1027  // cancel pressed?
1028  if (howToImportDialog.exec() == KDialog::Cancel) {
1029  schemaName.clear();
1030  reask = false;
1031  }
1032  // check what the user wants
1033  else {
1034  // replace existing
1035  if (howToImport.radioReplaceExisting->isChecked()) {
1036  reask = false;
1037  }
1038  // replace current
1039  else if (howToImport.radioReplaceCurrent->isChecked()) {
1040  schemaName = m_currentSchema;
1041  reask = false;
1042  }
1043  // new one, check again, whether the schema already exists
1044  else if (howToImport.radioAsNew->isChecked()) {
1045  schemaName = howToImport.newName->text();
1046  if (KateGlobal::self()->schemaManager()->schema(schemaName).exists()) {
1047  reask = true;
1048  } else reask = false;
1049  }
1050  // should never happen
1051  else reask = true;
1052  }
1053  } while (reask);
1054 
1055  return schemaName;
1056 }
1057 
1058 void KateSchemaConfigPage::importFullSchema()
1059 {
1060  const QString srcName = KFileDialog::getOpenFileName(KUrl(),
1061  QString::fromLatin1("*.kateschema|%1").arg(i18n("Kate color schema")),
1062  this, i18n("Importing Color Schema"));
1063 
1064  if (srcName.isEmpty()) return;
1065 
1066  // carete config + sanity check for full color schema
1067  KConfig cfg(srcName, KConfig::SimpleConfig);
1068  KConfigGroup schemaGroup(&cfg, "KateSchema");
1069  if (schemaGroup.readEntry("full schema", "false").toUpper() != "TRUE") {
1070  KMessageBox::sorry(this, i18n("The file does not contain a full color schema."),
1071  i18n("Fileformat error"));
1072  return;
1073  }
1074 
1075  // read color schema name
1076  const QStringList highlightings = schemaGroup.readEntry("highlightings",QStringList());
1077  const QString fromSchemaName = schemaGroup.readEntry("schema", i18n("Name unspecified"));
1078 
1079  // request valid schema name
1080  const QString schemaName = requestSchemaName(fromSchemaName);
1081  if (schemaName.isEmpty()) {
1082  return;
1083  }
1084 
1085  // if the schema already exists, select it in the combo box
1086  if (schemaCombo->findData(schemaName) != -1) {
1087  schemaCombo->setCurrentIndex(schemaCombo->findData(schemaName));
1088  }
1089  else { // it is really a new schema, easy meat :-)
1090  newSchema(schemaName);
1091  }
1092 
1093  // make sure the correct schema is activated
1094  schemaChanged(schemaName);
1095 
1096 
1097  // Finally, the correct schema is activated.
1098  // Next, start importing.
1099  kDebug(13030) << "Importing schema: " << schemaName;
1100 
1101  //
1102  // import editor Colors (background, ...)
1103  //
1104  KConfigGroup colorConfigGroup(&cfg, "Editor Colors");
1105  m_colorTab->importSchema(colorConfigGroup);
1106 
1107  //
1108  // import font
1109  //
1110  m_fontTab->importSchema(schemaGroup);
1111 
1112  //
1113  // import Default Styles
1114  //
1115  m_defaultStylesTab->importSchema(fromSchemaName, schemaName, &cfg);
1116 
1117  //
1118  // import all Highlighting Text Styles
1119  //
1120  // create mapping from highlighting name to internal id
1121  const int hlCount = KateHlManager::self()->highlights();
1122  QHash<QString, int> nameToId;
1123  for(int i = 0; i < hlCount; ++i) {
1124  nameToId.insert(KateHlManager::self()->hlName(i),i);
1125  }
1126 
1127  // may take some time, as we have > 200 highlightings
1128  int cnt = 0;
1129  QProgressDialog progress(i18n("Importing schema"), QString(), 0, highlightings.count(), this);
1130  progress.setWindowModality(Qt::WindowModal);
1131  foreach(const QString& hl,highlightings) {
1132  if (nameToId.contains(hl)) {
1133  const int i = nameToId[hl];
1134  m_highlightTab->importHl(fromSchemaName, schemaName, i, &cfg);
1135  kDebug(13030) << "hl imported:" << hl;
1136  } else {
1137  kDebug(13030) << "could not import hl, hl unknown:" << hl;
1138  }
1139  progress.setValue(++cnt);
1140  }
1141  progress.setValue(highlightings.count());
1142 }
1143 
1144 void KateSchemaConfigPage::apply()
1145 {
1146  // remember name + index
1147  const QString schemaName = schemaCombo->itemData (schemaCombo->currentIndex()).toString();
1148 
1149  // first apply all tabs
1150  m_colorTab->apply();
1151  m_fontTab->apply();
1152  m_defaultStylesTab->apply ();
1153  m_highlightTab->apply ();
1154 
1155  // just sync the config and reload
1156  KateGlobal::self()->schemaManager()->config ().sync();
1157  KateGlobal::self()->schemaManager()->config ().reparseConfiguration();
1158 
1159  // clear all attributes
1160  for (int i = 0; i < KateHlManager::self()->highlights(); ++i)
1161  KateHlManager::self()->getHl (i)->clearAttributeArrays();
1162 
1163  // than reload the whole stuff
1164  KateRendererConfig::global()->setSchema (defaultSchemaCombo->itemData (defaultSchemaCombo->currentIndex()).toString());
1165  KateRendererConfig::global()->reloadSchema();
1166 
1167  // sync the hl config for real
1168  KateHlManager::self()->getKConfig()->sync ();
1169 
1170  // KateSchemaManager::update() sorts the schema alphabetically, hence the
1171  // schema indexes change. Thus, repopulate the schema list...
1172  refillCombos(schemaCombo->itemData (schemaCombo->currentIndex()).toString(), defaultSchemaCombo->itemData (defaultSchemaCombo->currentIndex()).toString());
1173  schemaChanged(schemaName);
1174 }
1175 
1176 void KateSchemaConfigPage::reload()
1177 {
1178  // now reload the config from disc
1179  KateGlobal::self()->schemaManager()->config ().reparseConfiguration();
1180 
1181  // reinitialize combo boxes
1182  refillCombos(KateRendererConfig::global()->schema(), KateRendererConfig::global()->schema());
1183 
1184  // finally, activate the current schema again
1185  schemaChanged(schemaCombo->itemData(schemaCombo->currentIndex()).toString());
1186 
1187  // all tabs need to reload to discard all the cached data, as the index
1188  // mapping may have changed
1189  m_colorTab->reload ();
1190  m_fontTab->reload ();
1191  m_defaultStylesTab->reload ();
1192  m_highlightTab->reload ();
1193 }
1194 
1195 void KateSchemaConfigPage::refillCombos(const QString& schemaName, const QString& defaultSchemaName)
1196 {
1197  schemaCombo->blockSignals(true);
1198  defaultSchemaCombo->blockSignals(true);
1199 
1200  // reinitialize combo boxes
1201  schemaCombo->clear();
1202  defaultSchemaCombo->clear();
1203  QList<KateSchema> schemaList = KateGlobal::self()->schemaManager()->list();
1204  foreach (const KateSchema& s, schemaList) {
1205  schemaCombo->addItem(s.translatedName(), s.rawName);
1206  defaultSchemaCombo->addItem(s.translatedName(), s.rawName);
1207  }
1208 
1209  // set the correct indexes again, fallback to always existing "Normal"
1210  int schemaIndex = schemaCombo->findData (schemaName);
1211  if (schemaIndex == -1)
1212  schemaIndex = schemaCombo->findData ("Normal");
1213 
1214  int defaultSchemaIndex = defaultSchemaCombo->findData (defaultSchemaName);
1215  if (defaultSchemaIndex == -1)
1216  defaultSchemaIndex = defaultSchemaCombo->findData ("Normal");
1217 
1218  Q_ASSERT(schemaIndex != -1);
1219  Q_ASSERT(defaultSchemaIndex != -1);
1220 
1221  defaultSchemaCombo->setCurrentIndex (defaultSchemaIndex);
1222  schemaCombo->setCurrentIndex (schemaIndex);
1223 
1224  schemaCombo->blockSignals(false);
1225  defaultSchemaCombo->blockSignals(false);
1226 }
1227 
1228 void KateSchemaConfigPage::reset()
1229 {
1230  reload ();
1231 }
1232 
1233 void KateSchemaConfigPage::defaults()
1234 {
1235  reload ();
1236 }
1237 
1238 void KateSchemaConfigPage::deleteSchema ()
1239 {
1240  const int comboIndex = schemaCombo->currentIndex ();
1241  const QString schemaNameToDelete = schemaCombo->itemData (comboIndex).toString();
1242 
1243  if (KateGlobal::self()->schemaManager()->schemaData(schemaNameToDelete).shippedDefaultSchema) {
1244  // Default and Printing schema cannot be deleted.
1245  kDebug(13030) << "default and printing schema cannot be deleted";
1246  return;
1247  }
1248 
1249  // kill group
1250  KateGlobal::self()->schemaManager()->config().deleteGroup (schemaNameToDelete);
1251 
1252  // fallback to Default schema
1253  schemaCombo->setCurrentIndex(schemaCombo->findData (QVariant ("Normal")));
1254  if (defaultSchemaCombo->currentIndex() == defaultSchemaCombo->findData (schemaNameToDelete))
1255  defaultSchemaCombo->setCurrentIndex(defaultSchemaCombo->findData (QVariant ("Normal")));
1256 
1257  // remove schema from combo box
1258  schemaCombo->removeItem(comboIndex);
1259  defaultSchemaCombo->removeItem(comboIndex);
1260 }
1261 
1262 bool KateSchemaConfigPage::newSchema (const QString& newName)
1263 {
1264  // get sane name
1265  QString schemaName(newName);
1266  if (newName.isEmpty()) {
1267  bool ok = false;
1268  schemaName = KInputDialog::getText (i18n("Name for New Schema"), i18n ("Name:"), i18n("New Schema"), &ok, this);
1269  if (!ok) return false;
1270  }
1271 
1272  // try if schema already around
1273  if (KateGlobal::self()->schemaManager()->schema (schemaName).exists()) {
1274  KMessageBox::information(this, i18n("<p>The schema %1 already exists.</p><p>Please choose a different schema name.</p>", schemaName), i18n("New Schema"));
1275  return false;
1276  }
1277 
1278  // append items to combo boxes
1279  schemaCombo->addItem(schemaName, QVariant (schemaName));
1280  defaultSchemaCombo->addItem(schemaName, QVariant (schemaName));
1281 
1282  // finally, activate new schema (last item in the list)
1283  schemaCombo->setCurrentIndex(schemaCombo->count() - 1);
1284 
1285  return true;
1286 }
1287 
1288 void KateSchemaConfigPage::schemaChanged (const QString &schema)
1289 {
1290  btndel->setEnabled( !KateGlobal::self()->schemaManager()->schemaData(schema).shippedDefaultSchema );
1291 
1292  // propagate changed schema to all tabs
1293  m_colorTab->schemaChanged(schema);
1294  m_fontTab->schemaChanged(schema);
1295  m_defaultStylesTab->schemaChanged(schema);
1296  m_highlightTab->schemaChanged(schema);
1297 
1298  // save current schema index
1299  m_currentSchema = schema;
1300 }
1301 
1302 void KateSchemaConfigPage::comboBoxIndexChanged (int currentIndex)
1303 {
1304  schemaChanged (schemaCombo->itemData (currentIndex).toString());
1305 }
1306 //END KateSchemaConfigPage
1307 
1308 // kate: space-indent on; indent-width 2; replace-tabs on;
KateSchemaConfigFontTab::changed
void changed()
QVariant
QColor
KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab
KateSchemaConfigHighlightTab(KateSchemaConfigDefaultStylesTab *page, KateSchemaConfigColorTab *colorTab)
Definition: kateschemaconfig.cpp:583
KateColorItem::key
QString key
Definition: katecolortreewidget.h:38
KateSchemaConfigDefaultStylesTab::reload
void reload()
Definition: kateschemaconfig.cpp:542
KateColorItem::useDefault
bool useDefault
Definition: katecolortreewidget.h:41
KSharedPtr< KateExtendedAttribute >
KConfig::sync
void sync()
KTextEditor::ConfigPage::changed
void changed()
KateRendererConfig::setSchema
void setSchema(const QString &schema)
Definition: kateconfig.cpp:2002
KateSchemaConfigColorTab
Definition: kateschemaconfig.h:39
kateview.h
KateSchemaConfigPage::reset
void reset()
Definition: kateschemaconfig.cpp:1228
Kate::Script::i18n
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
Definition: katescripthelpers.cpp:186
ktabwidget.h
KateSchemaConfigColorTab::selectionColor
QColor selectionColor() const
Definition: kateschemaconfig.cpp:400
KateSchemaConfigDefaultStylesTab::changed
void changed()
KColorScheme::HoverColor
KateSchemaConfigColorTab::schemaChanged
void schemaChanged(const QString &newSchema)
Definition: kateschemaconfig.cpp:273
KComboBox::setEditable
void setEditable(bool editable)
KateColorItem::defaultColor
QColor defaultColor
Definition: katecolortreewidget.h:40
KColorScheme::background
QBrush background(BackgroundRole=NormalBackground) const
KColorScheme::NegativeText
KateSchemaConfigHighlightTab::hlsForSchema
QList< int > hlsForSchema(const QString &schema)
Definition: kateschemaconfig.cpp:772
KateColorItem
Definition: katecolortreewidget.h:27
KateSchema
Definition: kateschema.h:33
katerenderer.h
KateGlobal::container
QObject * container()
Get the currently associated Container object.
Definition: kateglobal.cpp:516
KateColorTreeWidget::colorItems
QVector< KateColorItem > colorItems() const
Definition: katecolortreewidget.cpp:345
KateDocument::highlight
KateHighlighting * highlight() const
Definition: katedocument.cpp:4702
KateSchemaConfigDefaultStylesTab::schemaChanged
void schemaChanged(const QString &schema)
Definition: kateschemaconfig.cpp:518
KateExtendedAttribute::defaultStyleIndex
int defaultStyleIndex() const
Definition: kateextendedattribute.cpp:69
KateSchemaConfigHighlightTab::showEvent
virtual void showEvent(QShowEvent *event)
Definition: kateschemaconfig.cpp:872
KateHighlighting::clearAttributeArrays
void clearAttributeArrays()
Definition: katehighlight.cpp:2102
KateSchemaConfigHighlightTab::importHl
void importHl(const QString &fromSchemaName=QString(), QString schema=QString(), int hl=-1, KConfig *cfg=0)
Definition: kateschemaconfig.cpp:777
KMessageBox::information
static void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
KateSchemaConfigColorTab::exportSchema
void exportSchema(KConfigGroup &config)
Definition: kateschemaconfig.cpp:341
KateColorItem::color
QColor color
Definition: katecolortreewidget.h:39
kcolorutils.h
KColorUtils::tint
QColor tint(const QColor &base, const QColor &color, qreal amount=0.3)
KColorScheme::Selection
QWidget
KateSchemaConfigDefaultStylesTab::apply
void apply()
Definition: kateschemaconfig.cpp:551
KateSchemaConfigColorTab::apply
void apply()
Definition: kateschemaconfig.cpp:350
name
const char * name(StandardAction id)
QPushButton
KateSchemaConfigPage::reload
void reload()
Definition: kateschemaconfig.cpp:1176
KConfig::deleteGroup
void deleteGroup(const QByteArray &group, WriteConfigFlags flags=Normal)
KConfig::SimpleConfig
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
KateSchemaConfigHighlightTab::updateColorPalette
void updateColorPalette(const QColor &textColor)
Definition: kateschemaconfig.cpp:740
KColorScheme::InactiveText
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:462
KDialog
KateSchemaConfigPage::exportFullSchema
void exportFullSchema()
Definition: kateschemaconfig.cpp:952
QString
QHash
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KateStyleTreeWidget
QTreeWidget that automatically adds columns for KateStyleListItems and provides a popup menu and a sl...
Definition: katestyletreewidget.h:36
KColorScheme::Window
KateSchema::translatedName
QString translatedName() const
construct translated name for shipped schemas
Definition: kateschema.h:42
KateSchemaConfigHighlightTab::reload
void reload()
Definition: kateschemaconfig.cpp:749
KateConfigPage::slotChanged
void slotChanged()
Definition: katedialogs.cpp:135
KUrl
KateHlManager::hlNameTranslated
QString hlNameTranslated(int n)
Definition: katesyntaxmanager.cpp:365
prefix
QString prefix()
KFontChooser::font
QFont font
KateSchemaConfigFontTab::exportSchema
void exportSchema(KConfigGroup &config)
Definition: kateschemaconfig.cpp:472
config
KSharedConfigPtr config()
KateSchemaConfigFontTab::reload
void reload()
Definition: kateschemaconfig.cpp:439
KateSchemaManager::config
KConfig & config()
Config.
Definition: kateschema.h:55
KateSchemaConfigColorTab::changed
void changed()
KConfigGroup::deleteEntry
void deleteEntry(const QString &pKey, WriteConfigFlags pFlags=Normal)
KateSchema::rawName
QString rawName
Definition: kateschema.h:36
KColorUtils::luma
qreal luma(const QColor &)
KateSchemaConfigDefaultStylesTab::~KateSchemaConfigDefaultStylesTab
~KateSchemaConfigDefaultStylesTab()
Definition: kateschemaconfig.cpp:500
KateSchemaConfigHighlightTab::schemaChanged
void schemaChanged(const QString &schema)
Definition: kateschemaconfig.cpp:678
KateSchemaConfigHighlightTab::exportHl
void exportHl(QString schema=QString(), int hl=-1, KConfig *cfg=0)
Definition: kateschemaconfig.cpp:842
KateSchemaConfigDefaultStylesTab::attributeList
KateAttributeList * attributeList(const QString &schema)
Definition: kateschemaconfig.cpp:505
KateSchemaConfigDefaultStylesTab::updateColorPalette
void updateColorPalette(const QColor &textColor)
Definition: kateschemaconfig.cpp:533
KateSchemaConfigColorTab::~KateSchemaConfigColorTab
~KateSchemaConfigColorTab()
Definition: kateschemaconfig.cpp:68
KateSchemaConfigPage::~KateSchemaConfigPage
virtual ~KateSchemaConfigPage()
Definition: kateschemaconfig.cpp:948
KateSchemaConfigPage::defaults
void defaults()
Definition: kateschemaconfig.cpp:1233
KColorScheme::foreground
QBrush foreground(ForegroundRole=NormalText) const
KateExtendedAttribute::name
QString name() const
Definition: kateextendedattribute.cpp:54
KFontChooser::setFont
void setFont(const QFont &font, bool onlyFixed=false)
KateColorTreeWidget::addColorItems
void addColorItems(const QVector< KateColorItem > &colorItems)
Definition: katecolortreewidget.cpp:339
kateschema.h
KConfigGroup::exists
bool exists() const
KColorScheme::PositiveBackground
kateglobal.h
KateHlManager::defaultStyles
static uint defaultStyles()
Definition: katesyntaxmanager.cpp:127
QStringList
KMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KateHlManager::setDefaults
void setDefaults(const QString &schema, KateAttributeList &, KConfig *cfg=0)
Definition: katesyntaxmanager.cpp:327
kateschemaconfig.h
KTextEditor::MdiContainer
KColorScheme::AlternateBackground
KateHlManager::getKConfig
KConfig * getKConfig()
Definition: katesyntaxmanager.h:60
KateSchemaConfigDefaultStylesTab::showEvent
virtual void showEvent(QShowEvent *event)
Definition: kateschemaconfig.cpp:570
KateSchemaConfigFontTab::KateSchemaConfigFontTab
KateSchemaConfigFontTab()
Definition: kateschemaconfig.cpp:407
KateRendererConfig::global
static KateRendererConfig * global()
Definition: kateconfig.h:613
KateStyleTreeWidget::addItem
void addItem(QTreeWidgetItem *parent, const QString &styleName, KTextEditor::Attribute::Ptr defaultstyle, KateExtendedAttribute::Ptr data=KateExtendedAttribute::Ptr())
Definition: katestyletreewidget.cpp:325
kfontchooser.h
KColorScheme::View
KColorUtils::shade
QColor shade(const QColor &, qreal lumaAmount, qreal chromaAmount=0.0)
KateRendererConfig::reloadSchema
void reloadSchema()
Reload the schema from the schema manager.
Definition: kateconfig.cpp:2014
KateSchemaConfigHighlightTab::changed
void changed()
KateView
Definition: kateview.h:78
KInputDialog::getText
QString getText(const QString &caption, const QString &label, const QString &value=QString(), bool *ok=0, QWidget *parent=0, QValidator *validator=0, const QString &mask=QString(), const QString &whatsThis=QString(), const QStringList &completionList=QStringList())
katecolortreewidget.h
writeEntry
void writeEntry(KConfigGroup &group, const char *key, const KGlobalSettings::Completion &aValue, KConfigBase::WriteConfigFlags flags=KConfigBase::Normal)
KateSchemaConfigHighlightTab::apply
void apply()
Definition: kateschemaconfig.cpp:758
KFontChooser::NoDisplayFlags
KateSchemaConfigHighlightTab::hlChanged
void hlChanged(int z)
Definition: kateschemaconfig.cpp:653
KateGlobal::schemaManager
KateSchemaManager * schemaManager()
manager for the katepart schemas
Definition: kateglobal.h:297
KConfigGroup::name
QString name() const
KateSchemaManager::list
QList< KateSchema > list()
Constructs list of schemas atm known in config object.
Definition: kateschema.cpp:65
KateSchemaManager::schema
KConfigGroup schema(const QString &name)
return kconfiggroup for the given schema
Definition: kateschema.cpp:43
ok
KGuiItem ok()
KConfigGroup::hasKey
bool hasKey(const QString &key) const
KateColorTreeWidget
Definition: katecolortreewidget.h:44
KColorScheme::NegativeBackground
KateSchemaConfigPage::KateSchemaConfigPage
KateSchemaConfigPage(QWidget *parent)
Definition: kateschemaconfig.cpp:885
kinputdialog.h
KConfigGroup
KateSchemaConfigDefaultStylesTab
Definition: kateschemaconfig.h:104
QFont
KConfig
KateSchemaConfigPage::importFullSchema
void importFullSchema()
Definition: kateschemaconfig.cpp:1058
KateSchemaConfigDefaultStylesTab::KateSchemaConfigDefaultStylesTab
KateSchemaConfigDefaultStylesTab(KateSchemaConfigColorTab *colorTab)
Definition: kateschemaconfig.cpp:479
KateSchemaConfigDefaultStylesTab::importSchema
void importSchema(const QString &schemaName, const QString &schema, KConfig *cfg)
Definition: kateschemaconfig.cpp:565
KFontChooser
KateSchemaConfigFontTab::~KateSchemaConfigFontTab
~KateSchemaConfigFontTab()
Definition: kateschemaconfig.cpp:415
KateStyleTreeWidget::resizeColumns
void resizeColumns()
Definition: katestyletreewidget.cpp:191
KateColorItem::category
QString category
Definition: katecolortreewidget.h:36
QProgressDialog
KateHlManager::hlSection
QString hlSection(int n)
Definition: katesyntaxmanager.cpp:370
KateHlManager::getHl
KateHighlighting * getHl(int n)
Definition: katesyntaxmanager.cpp:108
KColorScheme
KateSchemaConfigHighlightTab::loadAllHlsForSchema
bool loadAllHlsForSchema(const QString &schema)
Definition: kateschemaconfig.cpp:659
KateConfigPage
Definition: katedialogs.h:92
KConfig::reparseConfiguration
void reparseConfiguration()
KateHlManager::nameFind
int nameFind(const QString &name)
Definition: katesyntaxmanager.cpp:116
KateColorItem::whatsThis
QString whatsThis
Definition: katecolortreewidget.h:37
khbox.h
QLabel
KHBox::setSpacing
void setSpacing(int space)
KateSchemaConfigFontTab::schemaChanged
void schemaChanged(const QString &newSchema)
Definition: kateschemaconfig.cpp:448
KComboBox
KGlobal::mainComponent
const KComponentData & mainComponent()
KColorScheme::decoration
QBrush decoration(DecorationRole) const
KateSchemaConfigHighlightTab
Definition: kateschemaconfig.h:135
KateHlManager::getDefaults
void getDefaults(const QString &schema, KateAttributeList &, KConfig *cfg=0)
Definition: katesyntaxmanager.cpp:177
katestyletreewidget.h
KateSchemaConfigFontTab
Definition: kateschemaconfig.h:73
KateHighlighting::setKateExtendedAttributeList
void setKateExtendedAttributeList(const QString &schema, QList< KateExtendedAttribute::Ptr > &, KConfig *cfg=0, bool writeDefaultsToo=false)
Saves the attribute definitions to the config file.
Definition: katehighlight.cpp:657
KateHighlighting::getKateExtendedAttributeListCopy
void getKateExtendedAttributeListCopy(const QString &schema, QList< KateExtendedAttribute::Ptr > &, KConfig *cfg=0)
Definition: katehighlight.cpp:639
KateView::doc
KateDocument * doc()
accessor to katedocument pointer
Definition: kateview.h:552
KateColorItem::name
QString name
Definition: katecolortreewidget.h:35
KHBox
KateSchemaConfigColorTab::KateSchemaConfigColorTab
KateSchemaConfigColorTab()
Definition: kateschemaconfig.cpp:50
KateSchemaConfigDefaultStylesTab::exportSchema
void exportSchema(const QString &schema, KConfig *cfg)
Definition: kateschemaconfig.cpp:560
KateHighlighting::name
const QString & name() const
Definition: katehighlight.h:153
KTextEditor::MdiContainer::activeView
virtual View * activeView()=0
KateSchemaConfigColorTab::backgroundColor
QColor backgroundColor() const
Definition: kateschemaconfig.cpp:395
kmessagebox.h
KateColorTreeWidget::findColor
QColor findColor(const QString &key) const
Definition: katecolortreewidget.cpp:359
KateSchemaConfigFontTab::importSchema
void importSchema(KConfigGroup &config)
Definition: kateschemaconfig.cpp:465
kateconfig.h
KateSchemaConfigColorTab::importSchema
void importSchema(KConfigGroup &config)
Definition: kateschemaconfig.cpp:328
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
kcolorscheme.h
KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab
~KateSchemaConfigHighlightTab()
Definition: kateschemaconfig.cpp:649
KateHlManager::self
static KateHlManager * self()
Definition: katesyntaxmanager.cpp:103
KateSchemaConfigPage::apply
void apply()
Definition: kateschemaconfig.cpp:1144
QMap
KGlobalSettings::fixedFont
static QFont fixedFont()
KateSchemaConfigFontTab::apply
void apply()
Definition: kateschemaconfig.cpp:427
QList
list
QStringList list(const QString &fileClass)
KateHlManager::highlights
int highlights()
Definition: katesyntaxmanager.cpp:355
KateSchemaConfigColorTab::reload
void reload()
Definition: kateschemaconfig.cpp:377
KateAttributeList
QList< KTextEditor::Attribute::Ptr > KateAttributeList
Definition: kateextendedattribute.h:26
KTabWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:52 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Applications
  •   Libraries
  •     libkonq
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal