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

Kate

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