From kde-commits Wed Feb 29 23:04:18 2012 From: Dominik Haumann Date: Wed, 29 Feb 2012 23:04:18 +0000 To: kde-commits Subject: [kate] part: refactor: split KateSchemaAction and KateSchemaManager from config classes Message-Id: <20120229230418.2B205A60A9 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=133055671508792 Git commit 73698e4afc5221a13bf7d291ea2d17da107a9ee4 by Dominik Haumann. Committed on 01/03/2012 at 00:03. Pushed by dhaumann into branch 'master'. refactor: split KateSchemaAction and KateSchemaManager from config classes M +1 -0 part/CMakeLists.txt M +0 -1084 part/schema/kateschema.cpp M +0 -157 part/schema/kateschema.h C +6 -224 part/schema/kateschemaconfig.cpp [from: part/schema/katesche= ma.cpp - 088% similarity] C +3 -82 part/schema/kateschemaconfig.h [from: part/schema/kateschema= .h - 074% similarity] M +1 -0 part/utils/kateglobal.cpp http://commits.kde.org/kate/73698e4afc5221a13bf7d291ea2d17da107a9ee4 diff --git a/part/CMakeLists.txt b/part/CMakeLists.txt index ff0c41f..fbe156f 100644 --- a/part/CMakeLists.txt +++ b/part/CMakeLists.txt @@ -172,6 +172,7 @@ utils/katepartpluginmanager.cpp = # schema schema/kateschema.cpp +schema/kateschemaconfig.cpp schema/katestyletreewidget.cpp schema/katecolortreewidget.cpp = diff --git a/part/schema/kateschema.cpp b/part/schema/kateschema.cpp index 53c28e0..24d344e 100644 --- a/part/schema/kateschema.cpp +++ b/part/schema/kateschema.cpp @@ -23,52 +23,14 @@ #include "kateschema.moc" = #include "kateconfig.h" -#include "katedocument.h" #include "kateglobal.h" #include "kateview.h" #include "katerenderer.h" -#include "kateextendedattribute.h" -#include "katestyletreewidget.h" -#include "katecolortreewidget.h" - -#include "ui_howtoimportschema.h" = #include -#include #include -#include -#include -#include -#include -#include #include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include //END = = @@ -190,1052 +152,6 @@ QString KateSchemaManager::name (uint number) } //END = -// -// DIALOGS !!! -// - -//BEGIN KateSchemaConfigColorTab -- 'Colors' tab -KateSchemaConfigColorTab::KateSchemaConfigColorTab() -{ - m_currentSchema =3D -1; - - QGridLayout* l =3D new QGridLayout(this); - setLayout(l); - - ui =3D new KateColorTreeWidget(this); - QPushButton* btnUseColorScheme =3D new QPushButton("Use KDE Color Scheme= ", this); - - l->addWidget(ui, 0, 0, 1, 2); - l->addWidget(btnUseColorScheme, 1, 1); - - l->setColumnStretch(0, 1); - l->setColumnStretch(1, 0); - - connect(btnUseColorScheme, SIGNAL(clicked()), ui, SLOT(selectDefaults())= ); - connect(ui, SIGNAL(changed()), SIGNAL(changed())); -} - -KateSchemaConfigColorTab::~KateSchemaConfigColorTab() -{ -} - -QVector KateSchemaConfigColorTab::colorItemList() const -{ - QVector items; - - KColorScheme schemeWindow =3D KColorScheme(QPalette::Active, KColorSchem= e::Window); - KColorScheme schemeView =3D KColorScheme(QPalette::Active, KColorScheme:= :View); - - // - // editor background colors - // - KateColorItem ci; - ci.category =3D "Editor Background Colors"; - - ci.name =3D i18n("Text Area"); - ci.key =3D "Color Background"; - ci.whatsThis =3D i18n("

Sets the background color of the editing area.=

"); - ci.defaultColor =3D schemeView.background().color(); - items.append(ci); - - ci.name =3D i18n("Selected Text"); - ci.key =3D "Color Selection"; - ci.whatsThis =3D i18n("

Sets the background color of the selection.

To set the text color for selected text, use the "Configure Hig= hlighting" dialog.

"); - ci.defaultColor =3D KColorScheme(QPalette::Inactive, KColorScheme::Selec= tion).background().color(); - items.append(ci); - - ci.name =3D i18n("Current Line"); - ci.key =3D "Color Highlighted Line"; - ci.whatsThis =3D i18n("

Sets the background color of the currently act= ive line, which means the line where your cursor is positioned.

"); - ci.defaultColor =3D schemeView.background(KColorScheme::AlternateBackgro= und).color(); - items.append(ci); - - ci.name =3D i18n("Search Highlight"); - ci.key =3D "Color Search Highlight"; - ci.whatsThis =3D i18n("

Sets the background color of search results."); - ci.defaultColor =3D schemeView.background(KColorScheme::NeutralBackgroun= d).color(); - items.append(ci); - - ci.name =3D i18n("Replace Highlight"); - ci.key =3D "Color Replace Highlight"; - ci.whatsThis =3D i18n("

Sets the background color of replaced text."); - ci.defaultColor =3D schemeView.background(KColorScheme::PositiveBackgrou= nd).color(); - items.append(ci); - - - // - // icon border - // - ci.category =3D i18n("Icon Border"); - - ci.name =3D i18n("Background Area"); - ci.key =3D "Color Icon Bar"; - ci.whatsThis =3D i18n("

Sets the background color of the icon border.<= /p>"); - ci.defaultColor =3D schemeWindow.background().color(); - items.append(ci); - - ci.name =3D i18n("Line Numbers"); - ci.key =3D "Color Line Number"; - ci.whatsThis =3D i18n("

This color will be used to draw the line numbe= rs (if enabled) and the lines in the code-folding pane.

"); - ci.defaultColor =3D schemeWindow.foreground().color(); - items.append(ci); - - ci.name =3D i18n("Word Wrap Marker"); - ci.key =3D "Color Word Wrap Marker"; - ci.whatsThis =3D i18n("

Sets the color of Word Wrap-related markers:

Static Word Wrap
A vertical line which shows the column w= here text is going to be wrapped
Dynamic Word Wrap
An arrow= shown to the left of visually-wrapped lines
"); - qreal bgLuma =3D KColorUtils::luma(schemeView.background().color()); - ci.defaultColor =3D KColorUtils::shade( schemeView.background().color(),= bgLuma > 0.3 ? -0.15 : 0.03 ); - items.append(ci); - - ci.name =3D i18n("Modified Lines"); - ci.key =3D "Color Modified Lines"; - ci.whatsThis =3D i18n("

Sets the color of the line modification marker= for modified lines.

"); - ci.defaultColor =3D schemeView.background(KColorScheme::NegativeBackgrou= nd).color(); - items.append(ci); - - ci.name =3D i18n("Saved Lines"); - ci.key =3D "Color Saved Lines"; - ci.whatsThis =3D i18n("

Sets the color of the line modification marker= for saved lines.

"); - ci.defaultColor =3D schemeView.background(KColorScheme::PositiveBackgrou= nd).color(); - items.append(ci); - - - // - // text decorations - // - ci.category =3D i18n("Text Decorations"); - - ci.name =3D i18n("Spelling Mistake Line"); - ci.key =3D "Color Spelling Mistake Line"; - ci.whatsThis =3D i18n("

Sets the color of the line that is used to ind= icate spelling mistakes.

"); - ci.defaultColor =3D schemeView.foreground(KColorScheme::NegativeText).co= lor(); - items.append(ci); - - ci.name =3D i18n("Tab and Space Markers"); - ci.key =3D "Color Tab Marker"; - ci.whatsThis =3D i18n("

Sets the color of the tabulator marks.

"); - ci.defaultColor =3D KColorUtils::shade(schemeView.background().color(), = bgLuma > 0.7 ? -0.35 : 0.3); - items.append(ci); - - ci.name =3D i18n("Bracket Highlight"); - ci.key =3D "Color Highlighted Bracket"; - ci.whatsThis =3D i18n("

Sets the bracket matching color. This means, i= f you place the cursor e.g. at a (, the matching ) will be hi= ghlighted with this color.

"); - ci.defaultColor =3D KColorUtils::tint(schemeView.background().color(), - schemeView.decoration(KColorScheme::= HoverColor).color()); - items.append(ci); - - - // - // marker colors - // - ci.category =3D i18n("Marker Colors"); - - ci.name =3D i18n("Bookmark"); - ci.key =3D "Color MarkType 1"; - ci.whatsThis =3D i18n("

Sets the background color of mark type.

= Note: The marker color is displayed lightly because of transparency.=

"); - ci.defaultColor =3D Qt::blue; // TODO: if possible, derive from system c= olor scheme - items.append(ci); - - ci.name =3D i18n("Active Breakpoint"); - ci.key =3D "Color MarkType 2"; - ci.defaultColor =3D Qt::red; // TODO: if possible, derive from system co= lor scheme - items.append(ci); - - ci.name =3D i18n("Reached Breakpoint"); - ci.key =3D "Color MarkType 3"; - ci.defaultColor =3D Qt::yellow; // TODO: if possible, derive from system= color scheme - items.append(ci); - - ci.name =3D i18n("Disabled Breakpoint"); - ci.key =3D "Color MarkType 4"; - ci.defaultColor =3D Qt::magenta; // TODO: if possible, derive from syste= m color scheme - items.append(ci); - - ci.name =3D i18n("Execution"); - ci.key =3D "Color MarkType 5"; - ci.defaultColor =3D Qt::gray; // TODO: if possible, derive from system c= olor scheme - items.append(ci); - - ci.name =3D i18n("Warning"); - ci.key =3D "Color MarkType 6"; - ci.defaultColor =3D Qt::green; // TODO: if possible, derive from system = color scheme - items.append(ci); - - ci.name =3D i18n("Error"); - ci.key =3D "Color MarkType 7"; - ci.defaultColor =3D Qt::red; // TODO: if possible, derive from system co= lor scheme - items.append(ci); - - - // - // text templates - // - ci.category =3D i18n("Text Templates & Snippets"); - - ci.whatsThis =3D QString(); // TODO: add whatsThis for text templates - - ci.name =3D i18n("Background"); - ci.key =3D "Color Template Background"; - ci.defaultColor =3D schemeWindow.background().color(); - items.append(ci); - - ci.name =3D i18n("Editable Placeholder"); - ci.key =3D "Color Template Editable Placeholder"; - ci.defaultColor =3D schemeView.background(KColorScheme::PositiveBackgrou= nd).color(); - items.append(ci); - - ci.name =3D i18n("Focused Editable Placeholder"); - ci.key =3D "Color Template Focused Editable Placeholder"; - ci.defaultColor =3D schemeWindow.background(KColorScheme::PositiveBackgr= ound).color(); - items.append(ci); - - ci.name =3D i18n("Not Editable Placeholder"); - ci.key =3D "Color Template Not Editable Placeholder"; - ci.defaultColor =3D schemeView.background(KColorScheme::NegativeBackgrou= nd).color(); - items.append(ci); - - - // - // finally, add all elements - // - return items; -} - -void KateSchemaConfigColorTab::schemaChanged ( int newSchema ) -{ - // save curent schema - if ( m_currentSchema > -1 ) { - if (m_schemas.contains(m_currentSchema)) { - m_schemas.remove(m_currentSchema); // clear this color schema - } - - // now add it again - m_schemas[m_currentSchema] =3D ui->colorItems(); - } - - if ( newSchema =3D=3D m_currentSchema ) return; - - // switch - m_currentSchema =3D newSchema; - - // first block signals otherwise setColor emits changed - bool blocked =3D blockSignals(true); - - // If we havent this schema, read in from config file - if ( ! m_schemas.contains( newSchema ) ) - { - KConfigGroup config =3D KateGlobal::self()->schemaManager()->schema(ne= wSchema); - - // read from config - QVector items =3D colorItemList(); - for (int i =3D 0; i < items.count(); ++i ) { - KateColorItem& item(items[i]); - item.useDefault =3D !config.hasKey(item.key); - if (item.useDefault) { - item.color =3D item.defaultColor; - } else { - item.color =3D config.readEntry(item.key, item.defaultColor); - if (!item.color.isValid()) { - config.deleteEntry(item.key); - item.useDefault =3D true; - item.color =3D item.defaultColor; - } - } - } - - m_schemas[ newSchema ] =3D items; - } - - QVector items; - ui->clear(); - ui->addColorItems(m_schemas[m_currentSchema]); - - blockSignals(blocked); -} - -void KateSchemaConfigColorTab::apply () -{ - schemaChanged( m_currentSchema ); - QMap >::Iterator it; - for ( it =3D m_schemas.begin(); it !=3D m_schemas.end(); ++it ) - { - // TODO: if a schema was deleted (Delete button), this code writes to = the - // config anyway. This might be a bug. - - KConfigGroup config =3D KateGlobal::self()->schemaManager()->schema( i= t.key() ); - kDebug(13030) << "writing 'Color' tab: scheme =3D" << it.key() - << "and config group =3D" << config.name(); - - foreach (const KateColorItem& item, m_schemas[it.key()]) { - if (item.useDefault) { - config.deleteEntry(item.key); - } else { - config.writeEntry(item.key, item.color); - } - } - } -} -//END KateSchemaConfigColorTab - -//BEGIN FontConfig -- 'Fonts' tab -KateSchemaConfigFontTab::KateSchemaConfigFontTab() -{ - // sizemanagment - QGridLayout *grid =3D new QGridLayout( this ); - - m_fontchooser =3D new KFontChooser ( this, KFontChooser::NoDisplayFlags = ); - grid->addWidget( m_fontchooser, 0, 0); - - m_schema =3D -1; -} - -KateSchemaConfigFontTab::~KateSchemaConfigFontTab() -{ -} - -void KateSchemaConfigFontTab::slotFontSelected( const QFont &font ) -{ - if ( m_schema > -1 ) - { - m_fonts[m_schema] =3D font; - emit changed(); - } -} - -void KateSchemaConfigFontTab::apply() -{ - FontMap::Iterator it; - for ( it =3D m_fonts.begin(); it !=3D m_fonts.end(); ++it ) - { - KateGlobal::self()->schemaManager()->schema( it.key() ).writeEntry( "F= ont", it.value() ); - } -} - -void KateSchemaConfigFontTab::schemaChanged( int newSchema ) -{ - if ( m_schema > -1 ) - m_fonts[ m_schema ] =3D m_fontchooser->font(); - - m_schema =3D newSchema; - - QFont f (KGlobalSettings::fixedFont()); - - m_fontchooser->disconnect ( this ); - m_fontchooser->setFont ( KateGlobal::self()->schemaManager()->schema( ne= wSchema ).readEntry("Font", f) ); - m_fonts[ newSchema ] =3D m_fontchooser->font(); - connect (m_fontchooser, SIGNAL (fontSelected(QFont)), this, SLOT (slotFo= ntSelected(QFont))); -} -//END FontConfig - -//BEGIN FontColorConfig -- 'Normal Text Styles' tab -KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab() -{ - // sizemanagment - QGridLayout *grid =3D new QGridLayout( this ); - - m_defaultStyles =3D new KateStyleTreeWidget( this ); - m_defaultStyles->setRootIsDecorated(false); - connect(m_defaultStyles, SIGNAL(changed()), this, SIGNAL(changed())); - grid->addWidget( m_defaultStyles, 0, 0); - - m_defaultStyles->setWhatsThis(i18n( - "

This list displays the default styles for the current schema and= " - "offers the means to edit them. The style name reflects the current " - "style settings.

" - "

To edit the colors, click the colored squares, or select the col= or " - "to edit from the popup menu.

You can unset the Background and= Selected " - "Background colors from the popup menu when appropriate.

") ); -} - -KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab() -{ - qDeleteAll(m_defaultStyleLists); -} - -KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schem= a) -{ - if (!m_defaultStyleLists.contains(schema)) - { - KateAttributeList *list =3D new KateAttributeList (); - KateHlManager::self()->getDefaults(KateGlobal::self()->schemaManager()= ->name (schema), *list); - - m_defaultStyleLists.insert (schema, list); - } - - return m_defaultStyleLists[schema]; -} - -void KateSchemaConfigFontColorTab::schemaChanged (uint schema) -{ - m_defaultStyles->clear (); - - KateAttributeList *l =3D attributeList (schema); - - // set colors - QPalette p ( m_defaultStyles->palette() ); - KColorScheme s ( QPalette::Active, KColorScheme::View ); - QColor _c ( s.background().color() ); - p.setColor( QPalette::Base, - KateGlobal::self()->schemaManager()->schema(schema). - readEntry( "Color Background", _c ) ); - _c =3D KColorScheme(QPalette::Active, KColorScheme::Selection).backgroun= d().color(); - p.setColor( QPalette::Highlight, - KateGlobal::self()->schemaManager()->schema(schema). - readEntry( "Color Selection", _c ) ); - _c =3D l->at(0)->foreground().color(); // not quite as much of an assump= tion ;) - p.setColor( QPalette::Text, _c ); - m_defaultStyles->viewport()->setPalette( p ); - - for ( uint i =3D 0; i < KateHlManager::self()->defaultStyles(); i++ ) - { - m_defaultStyles->addItem( KateHlManager::self()->defaultStyleName(i, t= rue), l->at( i ) ); - } -} - -void KateSchemaConfigFontColorTab::reload () -{ - m_defaultStyles->clear (); - qDeleteAll(m_defaultStyleLists); - m_defaultStyleLists.clear (); -} - -void KateSchemaConfigFontColorTab::apply () -{ - QHashIterator it =3D m_defaultStyleLists; - while (it.hasNext()) { - it.next(); - KateHlManager::self()->setDefaults(KateGlobal::self()->schemaManager()= ->name (it.key()), *it.value()); - } -} - -void KateSchemaConfigFontColorTab::exportDefaults(int schema, KConfig *cfg= ) { - KateHlManager::self()->setDefaults(KateGlobal::self()->schemaManager()->= name (schema), *(m_defaultStyleLists[schema]),cfg); -} - -void KateSchemaConfigFontColorTab::importDefaults(const QString& schemaNam= e, int schema, KConfig *cfg) { - KateHlManager::self()->getDefaults(schemaName, *(m_defaultStyleLists[sch= ema]),cfg); -} - -//END FontColorConfig - -//BEGIN KateSchemaConfigHighlightTab -- 'Highlighting Text Styles' tab -KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab(KateSchemaConfi= gFontColorTab *page) -{ - m_defaults =3D page; - - m_schema =3D 0; - m_hl =3D 0; - - QVBoxLayout *layout =3D new QVBoxLayout(this); - - // hl chooser - KHBox *hbHl =3D new KHBox( this ); - layout->addWidget (hbHl); - - hbHl->setSpacing( -1 ); - QLabel *lHl =3D new QLabel( i18n("H&ighlight:"), hbHl ); - hlCombo =3D new KComboBox( hbHl ); - hlCombo->setEditable( false ); - lHl->setBuddy( hlCombo ); - connect( hlCombo, SIGNAL(activated(int)), - this, SLOT(hlChanged(int)) ); - - QPushButton *btnexport =3D new QPushButton( i18n("Export HlColors..."), = hbHl ); - connect( btnexport,SIGNAL(clicked()),this,SLOT(exportHl())); - - QPushButton *btnimport =3D new QPushButton( i18n("Import HlColors..."), = hbHl ); - connect( btnimport,SIGNAL(clicked()),this,SLOT(importHl())); - - for( int i =3D 0; i < KateHlManager::self()->highlights(); i++) { - if (KateHlManager::self()->hlSection(i).length() > 0) - hlCombo->addItem(KateHlManager::self()->hlSection(i) + QString ("/")= + KateHlManager::self()->hlNameTranslated(i)); - else - hlCombo->addItem(KateHlManager::self()->hlNameTranslated(i)); - } - hlCombo->setCurrentIndex(0); - - // styles listview - m_styles =3D new KateStyleTreeWidget( this, true ); - connect(m_styles, SIGNAL(changed()), this, SIGNAL(changed())); - layout->addWidget (m_styles, 999); - - // get current highlighting from the host application - int hl =3D 0; - KTextEditor::MdiContainer *iface =3D qobject_cast(KateGlobal::self()->container()); - if (iface) { - KateView *kv =3D qobject_cast(iface->activeView()); - if (kv) { - const QString hlName =3D kv->doc()->highlight()->name(); - hl =3D KateHlManager::self()->nameFind(hlName); - } - } - hlCombo->setCurrentIndex ( hl ); - hlChanged ( hl ); - - m_styles->setWhatsThis(i18n( - "

This list displays the contexts of the current syntax highlight mo= de and " - "offers the means to edit them. The context name reflects the current " - "style settings.

To edit using the keyboard, press " - "<SPACE> and choose a property from the popup m= enu.

" - "

To edit the colors, click the colored squares, or select the color= " - "to edit from the popup menu.

You can unset the Background and S= elected " - "Background colors from the context menu when appropriate.

") ); -} - -KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab() -{ -} - -void KateSchemaConfigHighlightTab::hlChanged(int z) -{ - m_hl =3D z; - - schemaChanged (m_schema); -} - -bool KateSchemaConfigHighlightTab::loadAllHlsForSchema(int schema) { - QProgressDialog progress(i18n("Loading all highlightings for schema"),i1= 8n("Cancel"),0,KateHlManager::self()->highlights(),this); - progress.setWindowModality(Qt::WindowModal); - for( int i =3D 0; i < KateHlManager::self()->highlights(); i++) { - if (!m_hlDict[schema].contains(i)) - { - kDebug(13030) << "NEW HL, create list"; - - QList list; - KateHlManager::self()->getHl( i )->getKateExtendedAttributeListCopy(= KateGlobal::self()->schemaManager()->name (schema), list); - m_hlDict[schema].insert (i, list); - } - progress.setValue(progress.value()+1); - if (progress.wasCanceled()) { - progress.setValue(KateHlManager::self()->highlights()); - return false; - } - } - progress.setValue(KateHlManager::self()->highlights()); - return true; -} - -void KateSchemaConfigHighlightTab::schemaChanged (int schema) -{ - m_schema =3D schema; - - kDebug(13030) << "NEW SCHEMA: " << m_schema << " NEW HL: " << m_hl; - - m_styles->clear (); - - if (!m_hlDict.contains(m_schema)) - { - kDebug(13030) << "NEW SCHEMA, create dict"; - - m_hlDict.insert (schema, QHash = >()); - } - - if (!m_hlDict[m_schema].contains(m_hl)) - { - kDebug(13030) << "NEW HL, create list"; - - QList list; - KateHlManager::self()->getHl( m_hl )->getKateExtendedAttributeListCopy= (KateGlobal::self()->schemaManager()->name (m_schema), list); - m_hlDict[m_schema].insert (m_hl, list); - } - - KateAttributeList *l =3D m_defaults->attributeList (schema); - - // Set listview colors - // We do that now, because we can now get the "normal text" color. - // TODO this reads of the KConfig object, which should be changed when - // the color tab is fixed. - QPalette p ( m_styles->palette() ); - KColorScheme s ( QPalette::Active, KColorScheme::View ); - QColor _c ( s.background().color() ); - p.setColor( QPalette::Base, - KateGlobal::self()->schemaManager()->schema(m_schema). - readEntry( "Color Background", _c ) ); - _c =3D KColorScheme(QPalette::Active, KColorScheme::Selection).backgroun= d().color(); - p.setColor( QPalette::Highlight, - KateGlobal::self()->schemaManager()->schema(m_schema). - readEntry( "Color Selection", _c ) ); - _c =3D l->at(0)->foreground().color(); // not quite as much of an assump= tion ;) - p.setColor( QPalette::Text, _c ); - m_styles->viewport()->setPalette( p ); - - QHash prefixes; - QList::ConstIterator it =3D m_hlDict[m_schem= a][m_hl].constBegin(); - while (it !=3D m_hlDict[m_schema][m_hl].constEnd()) - { - const KateExtendedAttribute::Ptr itemData =3D *it; - Q_ASSERT(itemData); - - kDebug(13030) << "insert items " << itemData->name(); - - // All stylenames have their language mode prefixed, e.g. HTML:Comment - // split them and put them into nice substructures. - int c =3D itemData->name().indexOf(':'); - if ( c > 0 ) { - QString prefix =3D itemData->name().left(c); - QString name =3D itemData->name().mid(c+1); - - QTreeWidgetItem *parent =3D prefixes[prefix]; - if ( ! parent ) - { - parent =3D new QTreeWidgetItem( m_styles, QStringList() << prefix = ); - m_styles->expandItem(parent); - prefixes.insert( prefix, parent ); - } - m_styles->addItem( parent, name, l->at(itemData->defaultStyleIndex()= ), itemData ); - } else { - m_styles->addItem( itemData->name(), l->at(itemData->defaultStyleInd= ex()), itemData ); - } - ++it; - } - - m_styles->resizeColumns(); -} - -void KateSchemaConfigHighlightTab::reload () -{ - m_styles->clear (); - - m_hlDict.clear (); - - hlChanged (0); -} - -void KateSchemaConfigHighlightTab::apply () -{ - QMutableHashIterator >= > it =3D m_hlDict; - while (it.hasNext()) { - it.next(); - QMutableHashIterator > it2 =3D = it.value(); - while (it2.hasNext()) { - it2.next(); - KateHlManager::self()->getHl( it2.key() )->setKateExtendedAttributeL= ist (it.key(), it2.value()); - } - } -} - - -QList KateSchemaConfigHighlightTab::hlsForSchema(int schema) { - return m_hlDict[schema].keys(); -} - - -void KateSchemaConfigHighlightTab::importHl(const QString& fromSchemaName,= int schema, int hl, KConfig *cfg) { - QString schemaNameForLoading(fromSchemaName); - QString hlName; - bool doManage=3D(cfg=3D=3D0); - if (schema=3D=3D-1) schema=3Dm_schema; - - if (doManage) { - QString srcName=3DKFileDialog::getOpenFileName( QString(KateHlMa= nager::self()->getHl(hl)->name()+QString(".katehlcolor")), - QString::fromLatin1("*.katehlcolor|%1").= arg(i18n("Kate color schema")), - this, - i18n("Importing colors for single highli= ghting")); - kDebug(13030)<<"hl file to open "<nameFind(hlName); - if ( (hl=3D=3D0) && (KateHlManager::self()->getHl(0)->name().t= oLower()!=3DhlName.toLower())) - hl=3D-1; - kDebug(13030)<"< list; - KateHlManager::self()->getHl( hl )->getKateExtendedAttributeList= Copy(schemaNameForLoading, list, cfg); - KateHlManager::self()->getHl( hl )->setKateExtendedAttributeList= (schema, list); - m_hlDict[schema].insert (hl, list); - } - - if (cfg && doManage) { - apply(); - delete cfg; - cfg=3D0; - if ( (hl!=3D-1) && (!schemaNameForLoading.isEmpty())) { - hlChanged(m_hl); - KMessageBox::information( - this, - i18n("Colors have been imported for highlighting: %1= ",hlName), - i18n("Import has finished")); - } - } - - -} - - -void KateSchemaConfigHighlightTab::exportHl(int schema, int hl, KConfig *c= fg) { - bool doManage=3D(cfg=3D=3D0); - if (schema=3D=3D-1) schema=3Dm_schema; - if (hl=3D=3D-1) hl=3Dm_hl; - - QList items=3Dm_hlDict[schema][hl]; - if (doManage) { - QString destName=3DKFileDialog::getSaveFileName( QString(KateHlManager= ::self()->getHl(hl)->name()+".katehlcolor"), - QString::fromLatin1("*.katehlcolor|%1"= ).arg(i18n("Kate color schema")), - this, - i18n("Exporting colors for single high= lighting: %1", KateHlManager::self()->getHl(hl)->name()), - KFileDialog::ConfirmOverwrite ); - - if (destName.isEmpty()) return; - - cfg=3Dnew KConfig(destName,KConfig::SimpleConfig); - KConfigGroup grp(cfg,"KateHLColors"); - grp.writeEntry("highlight",KateHlManager::self()->getHl(hl)->name()); - grp.writeEntry("schema",KateGlobal::self()->schemaManager()->name(sche= ma)); - grp.writeEntry("full schema","false"); - } - KateHlManager::self()->getHl(hl)->setKateExtendedAttributeList(schema,it= ems,cfg,doManage); - - if (doManage) { - cfg->sync(); - delete cfg; - } - -} - -//END KateSchemaConfigHighlightTab - -//BEGIN KateSchemaConfigPage -- Main dialog page -KateSchemaConfigPage::KateSchemaConfigPage( QWidget *parent) - : KateConfigPage( parent ), - m_lastSchema (-1) -{ - QVBoxLayout *layout =3D new QVBoxLayout(this); - layout->setMargin(0); - - KHBox *hbHl =3D new KHBox( this ); - layout->addWidget(hbHl); - hbHl->setSpacing( -1 ); - QLabel *lHl =3D new QLabel( i18n("&Schema:"), hbHl ); - schemaCombo =3D new KComboBox( hbHl ); - schemaCombo->setEditable( false ); - lHl->setBuddy( schemaCombo ); - connect( schemaCombo, SIGNAL(activated(int)), - this, SLOT(schemaChanged(int)) ); - - QPushButton *btnnew =3D new QPushButton( i18n("&New..."), hbHl ); - connect( btnnew, SIGNAL(clicked()), this, SLOT(newSchema()) ); - - btndel =3D new QPushButton( i18n("&Delete"), hbHl ); - connect( btndel, SIGNAL(clicked()), this, SLOT(deleteSchema()) ); - - QPushButton *btnexport =3D new QPushButton( i18n("Export..."), hbHl ); - connect(btnexport,SIGNAL(clicked()),this,SLOT(exportFullSchema())); - QPushButton *btnimport =3D new QPushButton( i18n("Import..."), hbHl ); - connect(btnimport,SIGNAL(clicked()),this,SLOT(importFullSchema())); - - qobject_cast(hbHl->layout())->addStretch(); - - m_tabWidget =3D new KTabWidget ( this ); - layout->addWidget (m_tabWidget); - - m_colorTab =3D new KateSchemaConfigColorTab(); - m_tabWidget->addTab (m_colorTab, i18n("Colors")); - connect(m_colorTab, SIGNAL(changed()), SLOT(slotChanged())); - - m_fontTab =3D new KateSchemaConfigFontTab(); - m_tabWidget->addTab (m_fontTab, i18n("Font")); - connect(m_fontTab, SIGNAL(changed()), SLOT(slotChanged())); - - m_fontColorTab =3D new KateSchemaConfigFontColorTab(); - m_tabWidget->addTab (m_fontColorTab, i18n("Default Text Styles")); - connect(m_fontColorTab, SIGNAL(changed()), SLOT(slotChanged())); - - m_highlightTab =3D new KateSchemaConfigHighlightTab(m_fontColorTab); - m_tabWidget->addTab(m_highlightTab, i18n("Highlighting Text Styles")); - connect(m_highlightTab, SIGNAL(changed()), SLOT(slotChanged())); - - connect (m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT (newCurren= tPage(int))); - - hbHl =3D new KHBox( this ); - layout->addWidget (hbHl); - hbHl->setSpacing( -1 ); - lHl =3D new QLabel( i18n("&Default schema for %1:", KGlobal::mainCompone= nt().aboutData()->programName ()), hbHl ); - defaultSchemaCombo =3D new KComboBox( hbHl ); - defaultSchemaCombo->setEditable( false ); - lHl->setBuddy( defaultSchemaCombo ); - - m_defaultSchema =3D KateGlobal::self()->schemaManager()->number (KateRen= dererConfig::global()->schema()); - - reload(); - - connect( defaultSchemaCombo, SIGNAL(activated(int)), - this, SLOT(slotChanged()) ); -} - -void KateSchemaConfigPage::exportFullSchema() { - QString destName=3DKFileDialog::getSaveFileName( QString(KateGlobal::sel= f()->schemaManager()->name(m_lastSchema)+".kateschema"), - QString::fromLatin1("*.kateschema|%1")= .arg(i18n("Kate color schema")), - this, - i18n("Exporting color schema:%1", Kate= Global::self()->schemaManager()->name(m_lastSchema)), - KFileDialog::ConfirmOverwrite ); - - if (destName.isEmpty()) return; - if (!m_highlightTab->loadAllHlsForSchema(m_lastSchema)) { - //ABORT - MESSAGE - return; - } - QStringList hlList; - QList hls=3Dm_highlightTab->hlsForSchema(m_lastSchema); - KConfig cfg(destName,KConfig::SimpleConfig); - m_fontColorTab->exportDefaults(m_lastSchema,&cfg); - int cnt=3D0; - QProgressDialog progress(i18n("Exporting schema"),i18n("Stop"),0,hls.cou= nt(),this); - progress.setWindowModality(Qt::WindowModal); - foreach(int hl,hls) { - hlList<getHl (hl)->name(); - m_highlightTab->exportHl(m_lastSchema,hl,&cfg); - cnt++; - progress.setValue(cnt); - if (progress.wasCanceled()) break; - } - progress.setValue(hls.count()); - KConfigGroup grp(&cfg,"KateSchema"); - grp.writeEntry("full schema","true"); - grp.writeEntry("highlightings",hlList); - grp.writeEntry("schema",KateGlobal::self()->schemaManager()->name(m_last= Schema)); - cfg.sync(); - -} - -void KateSchemaConfigPage::importFullSchema() { - QString srcName=3DKFileDialog::getOpenFileName( KUrl(), - "*.kateschema|Kate color schema", - this, - i18n("Importing color schema") - ); - - if (srcName.isEmpty()) return; - KConfig cfg(srcName,KConfig::SimpleConfig); - KConfigGroup grp(&cfg,"KateSchema"); - if (grp.readEntry("full schema","false").toUpper()!=3D"TRUE") { - KMessageBox::information( - this, - i18n("File is not a full schema file"), - i18n("Fileformat error")); - return; - } - QStringList highlightings=3Dgrp.readEntry("highlightings",QStringList()); - QString schemaName=3Dgrp.readEntry("schema",i18n("Name unspecified")); - QString fromSchemaName=3DschemaName; - bool reask=3Dtrue; - do { - KDialog howToImportDialog(this); - Ui_KateHowToImportSchema howToImport; - howToImport.setupUi(howToImportDialog.mainWidget()); - if (KateGlobal::self()->schemaManager()->list().contains(schemaName)) { - howToImport.radioReplaceExisting->show(); - howToImport.radioReplaceExisting->setText(i18n("Replace existing sch= ema %1",schemaName)); - howToImport.radioReplaceExisting->setChecked(true); - } else { - howToImport.radioReplaceExisting->hide(); - howToImport.newName->setText(schemaName); - } - if (howToImportDialog.exec()=3D=3DKDialog::Cancel) { - schemaName=3DQString(); - reask=3Dfalse; - } else { - if (howToImport.radioReplaceExisting->isChecked()) { - reask=3Dfalse; - } else if (howToImport.radioReplaceCurrent->isChecked()) { - schemaName=3DKateGlobal::self()->schemaManager()->list()[m_lastSch= ema]; - reask=3Dfalse; - } else if (howToImport.radioAsNew->isChecked()) { - schemaName=3DhowToImport.newName->text(); - if (KateGlobal::self()->schemaManager()->list().contains(schemaNam= e)) { - reask=3Dtrue; - } else reask=3Dfalse; - } else reask=3Dtrue; - } - } while (reask); - if (!schemaName.isEmpty()) { - kDebug(13030)<<"Importing schema:"<schemaManager()->list().contains(sch= emaName); - kDebug(13030)<<"schema exists?"<<(!asNew); - int schemaId; - if (asNew) { - newSchema(schemaName); - schemaId=3Dm_lastSchema; - } else { - schemaId=3DKateGlobal::self()->schemaManager()->list().indexOf(schem= aName); - } - schemaChanged(schemaId); - m_fontColorTab->importDefaults(fromSchemaName,schemaId,&cfg); - m_fontColorTab->apply(); - const int hlCount=3DKateHlManager::self()->highlights(); - QHash nameToId; - for(int i=3D0;ihlName(i),i); - } - - int cnt=3D0; - QProgressDialog progress(i18n("Importing schema"),i18n("Stop"),0,highl= ightings.count(),this); - progress.setWindowModality(Qt::WindowModal); - foreach(const QString& hl,highlightings) { - if (nameToId.contains(hl)) { - int i=3DnameToId[hl]; - m_highlightTab->importHl(fromSchemaName,schemaId,i,&cfg); - kDebug(13030)<<"hl imported:"<apply(); - schemaChanged(schemaId); - } -} - -KateSchemaConfigPage::~KateSchemaConfigPage () -{ - // just reload config from disc - KateGlobal::self()->schemaManager()->update (); -} - -void KateSchemaConfigPage::apply() -{ - m_colorTab->apply(); - m_fontTab->apply(); - m_fontColorTab->apply (); - m_highlightTab->apply (); - - // just sync the config - KateGlobal::self()->schemaManager()->schema (0).sync(); - - KateGlobal::self()->schemaManager()->update (); - - // clear all attributes - for (int i =3D 0; i < KateHlManager::self()->highlights(); ++i) - KateHlManager::self()->getHl (i)->clearAttributeArrays(); - - // than reload the whole stuff - KateRendererConfig::global()->setSchema (KateGlobal::self()->schemaManag= er()->name (defaultSchemaCombo->currentIndex())); - KateRendererConfig::global()->reloadSchema(); - - // sync the hl config for real - KateHlManager::self()->getKConfig()->sync (); -} - -void KateSchemaConfigPage::reload() -{ - // just reload the config from disc - KateGlobal::self()->schemaManager()->update (); - - // special for the highlighting stuff - m_fontColorTab->reload (); - - update (); - - defaultSchemaCombo->setCurrentIndex (KateGlobal::self()->schemaManager()= ->number (KateRendererConfig::global()->schema())); - - // initialize to the schema in the current document, or default schema - schemaCombo->setCurrentIndex( m_defaultSchema ); - schemaChanged( m_defaultSchema ); -} - -void KateSchemaConfigPage::reset() -{ - reload (); -} - -void KateSchemaConfigPage::defaults() -{ - reload (); -} - -void KateSchemaConfigPage::update () -{ - // soft update, no load from disk - KateGlobal::self()->schemaManager()->update (false); - - schemaCombo->clear (); - schemaCombo->addItems (KateGlobal::self()->schemaManager()->list ()); - - defaultSchemaCombo->clear (); - defaultSchemaCombo->addItems (KateGlobal::self()->schemaManager()->list = ()); - - schemaCombo->setCurrentIndex (0); - schemaChanged (0); - - schemaCombo->setEnabled (schemaCombo->count() > 0); -} - -void KateSchemaConfigPage::deleteSchema () -{ - int t =3D schemaCombo->currentIndex (); - - KateGlobal::self()->schemaManager()->removeSchema (t); - - update (); -} - -void KateSchemaConfigPage::newSchema (const QString& newName) -{ - QString t; - if (newName.isEmpty()) - t =3D KInputDialog::getText (i18n("Name for New Schema"), i18n ("Name:= "), i18n("New Schema"), 0, this); - else - t=3DnewName; - KateGlobal::self()->schemaManager()->addSchema (t); - - // soft update, no load from disk - KateGlobal::self()->schemaManager()->update (false); - int i =3D KateGlobal::self()->schemaManager()->list ().indexOf (t); - - update (); - if (i > -1) - { - schemaCombo->setCurrentIndex (i); - schemaChanged (i); - } -} - -void KateSchemaConfigPage::schemaChanged (int schema) -{ - btndel->setEnabled( schema > 1 ); - - m_colorTab->schemaChanged( schema ); - m_fontTab->schemaChanged( schema ); - m_fontColorTab->schemaChanged (schema); - m_highlightTab->schemaChanged (schema); - - m_lastSchema =3D schema; -} - -void KateSchemaConfigPage::newCurrentPage (int index) -{ - QWidget *w =3D m_tabWidget->widget(index); - if (w =3D=3D m_highlightTab) - m_highlightTab->schemaChanged (m_lastSchema); -} -//END KateSchemaConfigPage = //BEGIN SCHEMA ACTION -- the 'View->Schema' menu action void KateViewSchemaAction::init() diff --git a/part/schema/kateschema.h b/part/schema/kateschema.h index b268790..9f6504e 100644 --- a/part/schema/kateschema.h +++ b/part/schema/kateschema.h @@ -22,7 +22,6 @@ = #include "katehighlight.h" #include "katedialogs.h" -#include "katecolortreewidget.h" = #include #include @@ -114,162 +113,6 @@ class KateViewSchemaAction : public KActionMenu void setSchema(); }; = -// -// DIALOGS -// - -class KateSchemaConfigColorTab : public QWidget -{ - Q_OBJECT - - public: - KateSchemaConfigColorTab(); - ~KateSchemaConfigColorTab(); - - public Q_SLOTS: - void apply(); - void schemaChanged( int newSchema ); - - Q_SIGNALS: - void changed(); - = - private: - QVector colorItemList() const; - - private: - // multiple shemas may be edited. Hence, we need one ColorList for eac= h schema - QMap > m_schemas; - int m_currentSchema; - - KateColorTreeWidget* ui; -}; - -typedef QMap FontMap; // ### remove it - -class KateSchemaConfigFontTab : public QWidget -{ - Q_OBJECT - - public: - KateSchemaConfigFontTab(); - ~KateSchemaConfigFontTab(); - - public: - void readConfig (KConfig *config); - - public Q_SLOTS: - void apply(); - void schemaChanged( int newSchema ); - - Q_SIGNALS: - void changed(); - - private: - class KFontChooser *m_fontchooser; - FontMap m_fonts; - int m_schema; - - private Q_SLOTS: - void slotFontSelected( const QFont &font ); -}; - -class KateSchemaConfigFontColorTab : public QWidget -{ - Q_OBJECT - - public: - KateSchemaConfigFontColorTab(); - ~KateSchemaConfigFontColorTab(); - - Q_SIGNALS: - void changed(); - - public: - void schemaChanged (uint schema); - void reload (); - void apply (); - - KateAttributeList *attributeList (uint schema); - void exportDefaults(int schema, KConfig *cfg); - void importDefaults(const QString& schemaName, int schema, KConfig *cf= g); - private: - KateStyleTreeWidget* m_defaultStyles; - QHash m_defaultStyleLists; = -}; - -class KateSchemaConfigHighlightTab : public QWidget -{ - Q_OBJECT - - public: - explicit KateSchemaConfigHighlightTab(KateSchemaConfigFontColorTab *pa= ge =3D 0); - ~KateSchemaConfigHighlightTab(); - - void schemaChanged (int schema); - void reload (); - void apply (); - - Q_SIGNALS: - void changed(); - = - protected Q_SLOTS: - void hlChanged(int z); - public Q_SLOTS: - void exportHl(int schema=3D-1,int hl=3D-1,KConfig* cfg=3D0); - void importHl(const QString& fromSchemaName=3DQString(), int schema=3D= -1, int hl=3D-1, KConfig *cfg=3D0); - = - private: - KateSchemaConfigFontColorTab *m_defaults; - - KComboBox *hlCombo; - KateStyleTreeWidget *m_styles; - - int m_schema; - int m_hl; - - QHash > > m_hlDict; - public: - QList hlsForSchema(int schema); - bool loadAllHlsForSchema(int schema); -}; - -class KateSchemaConfigPage : public KateConfigPage -{ - Q_OBJECT - - public: - explicit KateSchemaConfigPage ( QWidget *parent); - ~KateSchemaConfigPage (); - - public Q_SLOTS: - void apply(); - void reload(); - void reset(); - void defaults(); - void exportFullSchema(); - void importFullSchema(); - private Q_SLOTS: - void update (); - void deleteSchema (); - void newSchema (const QString& newName=3DQString()); - void schemaChanged (int schema); - - void newCurrentPage(int); - - private: - int m_lastSchema; - int m_defaultSchema; - - class KTabWidget *m_tabWidget; - class QPushButton *btndel; - class KComboBox *defaultSchemaCombo; - class KComboBox *schemaCombo; - KateSchemaConfigColorTab *m_colorTab; - KateSchemaConfigFontTab *m_fontTab; - KateSchemaConfigFontColorTab *m_fontColorTab; - KateSchemaConfigHighlightTab *m_highlightTab; -}; - #endif = // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/part/schema/kateschema.cpp b/part/schema/kateschemaconfig.cpp similarity index 88% copy from part/schema/kateschema.cpp copy to part/schema/kateschemaconfig.cpp index 53c28e0..abe4636 100644 --- a/part/schema/kateschema.cpp +++ b/part/schema/kateschemaconfig.cpp @@ -2,6 +2,7 @@ Copyright (C) 2007, 2008 Matthew Woehlke Copyright (C) 2001-2003 Christoph Cullmann Copyright (C) 2002, 2003 Anders Lund + Copyright (C) 2012 Dominik Haumann = This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -19,15 +20,14 @@ */ = //BEGIN Includes -#include "kateschema.h" -#include "kateschema.moc" +#include "kateschemaconfig.h" +#include "kateschemaconfig.moc" = +#include "kateschema.h" #include "kateconfig.h" -#include "katedocument.h" #include "kateglobal.h" #include "kateview.h" #include "katerenderer.h" -#include "kateextendedattribute.h" #include "katestyletreewidget.h" #include "katecolortreewidget.h" = @@ -35,165 +35,17 @@ = #include #include -#include -#include -#include -#include #include -#include -#include -#include +#include #include -#include -#include -#include -#include -#include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include -#include + #include -#include -#include -#include -#include -#include -#include #include //END = = -//BEGIN KateSchemaManager -QString KateSchemaManager::normalSchema () -{ - return KGlobal::mainComponent().aboutData()->appName () + QString (" - N= ormal"); -} - -QString KateSchemaManager::printingSchema () -{ - return KGlobal::mainComponent().aboutData()->appName () + QString (" - P= rinting"); -} - -KateSchemaManager::KateSchemaManager () - : m_config ("kateschemarc", KConfig::NoGlobals) -{ - update (); -} - -KateSchemaManager::~KateSchemaManager () -{ -} - -// -// read the types from config file and update the internal list -// -void KateSchemaManager::update (bool readfromfile) -{ - if (readfromfile) - m_config.reparseConfiguration (); - - m_schemas =3D m_config.groupList(); - m_schemas.sort (); - - m_schemas.removeAll (printingSchema()); - m_schemas.removeAll (normalSchema()); - m_schemas.prepend (printingSchema()); - m_schemas.prepend (normalSchema()); -} - -// -// get the right group -// special handling of the default schemas ;) -// -KConfigGroup KateSchemaManager::schema (uint number) -{ - if ((number>1) && (number < (uint)m_schemas.count())) - return m_config.group (m_schemas[number]); - else if (number =3D=3D 1) - return m_config.group (printingSchema()); - else - return m_config.group (normalSchema()); -} - -void KateSchemaManager::addSchema (const QString &t) -{ - m_config.group(t).writeEntry("Color Background", KColorScheme(QPalette::= Active, KColorScheme::View).background().color()); - - update (false); -} - -void KateSchemaManager::removeSchema (uint number) -{ - if (number >=3D (uint)m_schemas.count()) - return; - - if (number < 2) - return; - - m_config.deleteGroup (name (number)); - - update (false); -} - -bool KateSchemaManager::validSchema (uint number) -{ - if (number < (uint)m_schemas.count()) - return true; - - return false; -} - -bool KateSchemaManager::validSchema (const QString &name) -{ - if (name =3D=3D normalSchema() || name =3D=3D printingSchema()) - return true; - - for (int i =3D 0; i < m_schemas.size(); ++i) - if (m_schemas[i] =3D=3D name) - return true; - - return false; -} - -uint KateSchemaManager::number (const QString &name) -{ - if (name =3D=3D normalSchema()) - return 0; - - if (name =3D=3D printingSchema()) - return 1; - - int i; - if ((i =3D m_schemas.indexOf(name)) > -1) - return i; - - return 0; -} - -QString KateSchemaManager::name (uint number) -{ - if ((number>1) && (number < (uint)m_schemas.count())) - return m_schemas[number]; - else if (number =3D=3D 1) - return printingSchema(); - - return normalSchema(); -} -//END - -// -// DIALOGS !!! -// - //BEGIN KateSchemaConfigColorTab -- 'Colors' tab KateSchemaConfigColorTab::KateSchemaConfigColorTab() { @@ -1237,74 +1089,4 @@ void KateSchemaConfigPage::newCurrentPage (int index) } //END KateSchemaConfigPage = -//BEGIN SCHEMA ACTION -- the 'View->Schema' menu action -void KateViewSchemaAction::init() -{ - m_group=3D0; - m_view =3D 0; - last =3D 0; - - connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow())); -} - -void KateViewSchemaAction::updateMenu (KateView *view) -{ - m_view =3D view; -} - -void KateViewSchemaAction::slotAboutToShow() -{ - KateView *view=3Dm_view; - int count =3D KateGlobal::self()->schemaManager()->list().count(); - - if (!m_group) { - m_group=3Dnew QActionGroup(menu()); - m_group->setExclusive(true); - - } - - for (int z=3D0; zschemaManager()->list().operato= r[](z); - - if (!names.contains(hlName)) - { - names << hlName; - QAction *a=3Dmenu()->addAction ( hlName, this, SLOT(setSchema())); - a->setData(hlName); - a->setCheckable(true); - a->setActionGroup(m_group); - //FIXME EXCLUSIVE - } - } - - if (!view) return; - - QString id=3Dview->renderer()->config()->schema(); - foreach(QAction *a,menu()->actions()) { - a->setChecked(a->data().toString()=3D=3Did); - - } -//FIXME -#if 0 - popupMenu()->setItemChecked (last, false); - popupMenu()->setItemChecked (view->renderer()->config()->schema()+1, tru= e); - - last =3D view->renderer()->config()->schema()+1; -#endif -} - -void KateViewSchemaAction::setSchema () { - QAction *action =3D qobject_cast(sender()); - - if (!action) return; - QString mode=3Daction->data().toString(); - - KateView *view=3Dm_view; - - if (view) - view->renderer()->config()->setSchema (mode); -} -//END SCHEMA ACTION - // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/part/schema/kateschema.h b/part/schema/kateschemaconfig.h similarity index 74% copy from part/schema/kateschema.h copy to part/schema/kateschemaconfig.h index b268790..d00eb67 100644 --- a/part/schema/kateschema.h +++ b/part/schema/kateschemaconfig.h @@ -1,6 +1,7 @@ /* This file is part of the KDE libraries Copyright (C) 2001-2003 Christoph Cullmann Copyright (C) 2002, 2003 Anders Lund + Copyright (C) 2012 Dominik Haumann = This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,8 +18,8 @@ Boston, MA 02110-1301, USA. */ = -#ifndef __KATE_SCHEMA_H__ -#define __KATE_SCHEMA_H__ +#ifndef __KATE_SCHEMA_CONFIG_H__ +#define __KATE_SCHEMA_CONFIG_H__ = #include "katehighlight.h" #include "katedialogs.h" @@ -34,89 +35,9 @@ class KateView; class KateStyleTreeWidget; = -class QAction; -class QActionGroup; class KComboBox; class KTabWidget; = -class KateSchemaManager -{ - public: - KateSchemaManager (); - ~KateSchemaManager (); - - /** - * Schema Config changed, update all renderers - */ - void update (bool readfromfile =3D true); - - /** - * return kconfig with right group set or set to Normal if not there - */ - KConfigGroup schema (uint number); - - void addSchema (const QString &t); - - void removeSchema (uint number); - - /** - * is this schema valid ? (does it exist ?) - */ - bool validSchema (uint number); - bool validSchema (const QString &name); - - /** - * if not found, defaults to 0 - */ - uint number (const QString &name); - - /** - * group names in the end, no i18n involved - */ - QString name (uint number); - - /** - * Don't modify, list with the names of the schemas (i18n name for the= default ones) - */ - const QStringList &list () { return m_schemas; } - - static QString normalSchema (); - static QString printingSchema (); - - private: - KConfig m_config; - QStringList m_schemas; -}; - - -class KateViewSchemaAction : public KActionMenu -{ - Q_OBJECT - - public: - KateViewSchemaAction(const QString& text, QObject *parent) - : KActionMenu(text, parent) { init(); } - - void updateMenu (KateView *view); - - private: - void init(); - - QPointer m_view; - QStringList names; - QActionGroup *m_group; - int last; - - public Q_SLOTS: - void slotAboutToShow(); - - private Q_SLOTS: - void setSchema(); -}; - -// -// DIALOGS -// = class KateSchemaConfigColorTab : public QWidget { diff --git a/part/utils/kateglobal.cpp b/part/utils/kateglobal.cpp index dec12dd..a830790 100644 --- a/part/utils/kateglobal.cpp +++ b/part/utils/kateglobal.cpp @@ -28,6 +28,7 @@ #include "katecmds.h" #include "katemodemanager.h" #include "kateschema.h" +#include "kateschemaconfig.h" #include "kateconfig.h" #include "katescriptmanager.h" #include "katecmd.h"