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

Kate

katemodeconfigpage.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE libraries and the Kate part.
00002  *
00003  *  Copyright (C) 2001-2010 Christoph Cullmann <cullmann@kde.org>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Library General Public License
00016  *  along with this library; see the file COPYING.LIB.  If not, write to
00017  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  *  Boston, MA 02110-1301, USA.
00019  */
00020 
00021 //BEGIN Includes
00022 #include "katemodeconfigpage.h"
00023 #include "katemodeconfigpage.moc"
00024 
00025 #include "katedocument.h"
00026 #include "kateconfig.h"
00027 #include "kateview.h"
00028 #include "kateglobal.h"
00029 #include "kateautoindent.h"
00030 #include "katesyntaxmanager.h"
00031 #include "katesyntaxdocument.h"
00032 
00033 #include "ui_filetypeconfigwidget.h"
00034 
00035 #include <kconfig.h>
00036 #include <kmimetype.h>
00037 #include <kmimetypechooser.h>
00038 #include <kdebug.h>
00039 #include <kicon.h>
00040 #include <knuminput.h>
00041 #include <klocale.h>
00042 #include <kmenu.h>
00043 
00044 #include <QtCore/QRegExp>
00045 #include <QtGui/QCheckBox>
00046 #include <QtGui/QComboBox>
00047 #include <QtGui/QGroupBox>
00048 
00049 #include <QtGui/QLabel>
00050 #include <QtGui/QLayout>
00051 #include <QtGui/QPushButton>
00052 #include <QtGui/QToolButton>
00053 #include <kvbox.h>
00054 
00055 #define KATE_FT_HOWMANY 1024
00056 //END Includes
00057 
00058 ModeConfigPage::ModeConfigPage( QWidget *parent )
00059   : KateConfigPage( parent )
00060 {
00061   m_lastType = -1;
00062 
00063   // This will let us have more separation between this page and
00064   // the KTabWidget edge (ereslibre)
00065   QVBoxLayout *layout = new QVBoxLayout;
00066   QWidget *newWidget = new QWidget(this);
00067 
00068   ui = new Ui::FileTypeConfigWidget();
00069   ui->setupUi( newWidget );
00070 
00071  ui->cmbHl->addItem(i18n("<Unchanged>"), QVariant(""));
00072  for( int i = 0; i < KateHlManager::self()->highlights(); i++) {
00073     if (KateHlManager::self()->hlSection(i).length() > 0)
00074       ui->cmbHl->addItem(KateHlManager::self()->hlSection(i) + QString ("/")
00075           + KateHlManager::self()->hlNameTranslated(i), QVariant(KateHlManager::self()->hlName(i)));
00076     else
00077       ui->cmbHl->addItem(KateHlManager::self()->hlNameTranslated(i), QVariant(KateHlManager::self()->hlName(i)));
00078   }
00079 
00080   QStringList indentationModes;
00081   indentationModes << i18n ("Use Default");
00082   indentationModes << KateAutoIndent::listModes();
00083   ui->cmbIndenter->addItems (indentationModes);
00084 
00085   connect( ui->cmbFiletypes, SIGNAL(activated(int)), this, SLOT(typeChanged(int)) );
00086   connect( ui->btnNew, SIGNAL(clicked()), this, SLOT(newType()) );
00087   connect( ui->btnDelete, SIGNAL(clicked()), this, SLOT(deleteType()) );
00088   ui->btnMimeTypes->setIcon(KIcon("tools-wizard"));
00089   connect(ui->btnMimeTypes, SIGNAL(clicked()), this, SLOT(showMTDlg()));
00090   connect( ui->btnDownload, SIGNAL(clicked()), this, SLOT(hlDownload()) );
00091 
00092   reload();
00093 
00094   connect( ui->edtName, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00095   connect( ui->edtSection, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00096   connect( ui->edtVariables, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00097   connect( ui->edtFileExtensions, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00098   connect( ui->edtMimeTypes, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00099   connect( ui->sbPriority, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
00100   connect( ui->cmbHl, SIGNAL(activated(int)), this, SLOT(slotChanged()) );
00101   connect( ui->cmbIndenter, SIGNAL(activated(int)), this, SLOT(slotChanged()) );
00102 
00103   layout->addWidget(newWidget);
00104   setLayout(layout);
00105 }
00106 
00107 ModeConfigPage::~ModeConfigPage ()
00108 {
00109   qDeleteAll (m_types);
00110   delete ui;
00111 }
00112 
00113 void ModeConfigPage::apply()
00114 {
00115   if (!hasChanged())
00116     return;
00117 
00118   save ();
00119 
00120   KateGlobal::self()->modeManager()->save(m_types);
00121 }
00122 
00123 void ModeConfigPage::reload()
00124 {
00125   qDeleteAll (m_types);
00126   m_types.clear();
00127 
00128   // deep copy...
00129   foreach (KateFileType *type, KateGlobal::self()->modeManager()->list())
00130   {
00131     KateFileType *t = new KateFileType ();
00132     *t = *type;
00133     m_types.append (t);
00134   }
00135 
00136   update ();
00137 }
00138 
00139 void ModeConfigPage::reset()
00140 {
00141   reload ();
00142 }
00143 
00144 void ModeConfigPage::defaults()
00145 {
00146   reload ();
00147 }
00148 
00149 void ModeConfigPage::update ()
00150 {
00151   m_lastType = -1;
00152 
00153   ui->cmbFiletypes->clear ();
00154 
00155   foreach (KateFileType *type, m_types) {
00156     QString typeName = i18nc("Language", type->name.toUtf8());
00157     if (type->section.length() > 0)
00158       ui->cmbFiletypes->addItem(type->section + QString ("/") + typeName);
00159     else
00160       ui->cmbFiletypes->addItem(typeName);
00161   }
00162 
00163   ui->cmbFiletypes->setCurrentIndex (0);
00164 
00165   typeChanged (0);
00166 
00167   ui->cmbFiletypes->setEnabled (ui->cmbFiletypes->count() > 0);
00168 }
00169 
00170 void ModeConfigPage::deleteType ()
00171 {
00172   int type = ui->cmbFiletypes->currentIndex ();
00173 
00174   if (type > -1 && type < m_types.count())
00175   {
00176     delete m_types[type];
00177     m_types.removeAt(type);
00178     update ();
00179   }
00180 }
00181 
00182 void ModeConfigPage::newType ()
00183 {
00184   QString newN = i18n("New Filetype");
00185 
00186   for (int i = 0; i < m_types.count(); ++i) {
00187     KateFileType *type = m_types.at(i);
00188     if (type->name == newN)
00189     {
00190       ui->cmbFiletypes->setCurrentIndex (i);
00191       typeChanged (i);
00192       return;
00193     }
00194   }
00195 
00196   KateFileType *newT = new KateFileType ();
00197   newT->priority = 0;
00198   newT->name = newN;
00199   newT->hlGenerated = false;
00200 
00201   m_types.prepend (newT);
00202 
00203   update ();
00204 }
00205 
00206 void ModeConfigPage::save ()
00207 {
00208   if (m_lastType != -1)
00209   {
00210     m_types[m_lastType]->name = ui->edtName->text ();
00211     m_types[m_lastType]->section = ui->edtSection->text ();
00212     m_types[m_lastType]->varLine = ui->edtVariables->text ();
00213     m_types[m_lastType]->wildcards = ui->edtFileExtensions->text().split (';', QString::SkipEmptyParts);
00214     m_types[m_lastType]->mimetypes = ui->edtMimeTypes->text().split (';', QString::SkipEmptyParts);
00215     m_types[m_lastType]->priority = ui->sbPriority->value();
00216     m_types[m_lastType]->hl = ui->cmbHl->itemData(ui->cmbHl->currentIndex()).toString();
00217     
00218     if (ui->cmbIndenter->currentIndex() > 0)
00219       m_types[m_lastType]->indenter = KateAutoIndent::modeName (ui->cmbIndenter->currentIndex() - 1);
00220     else
00221       m_types[m_lastType]->indenter = "";
00222   }
00223 }
00224 
00225 void ModeConfigPage::typeChanged (int type)
00226 {
00227   save ();
00228     
00229   ui->cmbHl->setEnabled (true);
00230   ui->btnDelete->setEnabled (true);
00231   ui->edtName->setEnabled (true);
00232   ui->edtSection->setEnabled (true);
00233 
00234   if (type > -1 && type < m_types.count())
00235   {
00236     KateFileType *t = m_types.at(type);
00237 
00238     ui->gbProperties->setTitle (i18n("Properties of %1",  ui->cmbFiletypes->currentText()));
00239 
00240     ui->gbProperties->setEnabled (true);
00241     ui->btnDelete->setEnabled (true);
00242 
00243     ui->edtName->setText(t->name);
00244     ui->edtSection->setText(t->section);
00245     ui->edtVariables->setText(t->varLine);
00246     ui->edtFileExtensions->setText(t->wildcards.join (";"));
00247     ui->edtMimeTypes->setText(t->mimetypes.join (";"));
00248     ui->sbPriority->setValue(t->priority);
00249     
00250     ui->cmbHl->setEnabled (!t->hlGenerated);
00251     ui->btnDelete->setEnabled (!t->hlGenerated);
00252     ui->edtName->setEnabled (!t->hlGenerated);
00253     ui->edtSection->setEnabled (!t->hlGenerated);
00254 
00255     // activate current hl...
00256     for (int i = 0; i < ui->cmbHl->count(); ++i)
00257       if (ui->cmbHl->itemData (i).toString() == t->hl)
00258         ui->cmbHl->setCurrentIndex (i);
00259         
00260     // activate the right indenter
00261     int indenterIndex = 0;
00262     if (!t->indenter.isEmpty())
00263       indenterIndex = KateAutoIndent::modeNumber (t->indenter) + 1;
00264     ui->cmbIndenter->setCurrentIndex (indenterIndex);
00265   }
00266   else
00267   {
00268     ui->gbProperties->setTitle (i18n("Properties"));
00269 
00270     ui->gbProperties->setEnabled (false);
00271     ui->btnDelete->setEnabled (false);
00272 
00273     ui->edtName->clear();
00274     ui->edtSection->clear();
00275     ui->edtVariables->clear();
00276     ui->edtFileExtensions->clear();
00277     ui->edtMimeTypes->clear();
00278     ui->sbPriority->setValue(0);
00279     ui->cmbHl->setCurrentIndex (0);
00280     ui->cmbIndenter->setCurrentIndex (0);
00281   }
00282 
00283   m_lastType = type;
00284 }
00285 
00286 void ModeConfigPage::showMTDlg()
00287 {
00288   QString text = i18n("Select the MimeTypes you want for this file type.\nPlease note that this will automatically edit the associated file extensions as well.");
00289   QStringList list = ui->edtMimeTypes->text().split( QRegExp("\\s*;\\s*"), QString::SkipEmptyParts );
00290   KMimeTypeChooserDialog d( i18n("Select Mime Types"), text, list, "text", this );
00291   if ( d.exec() == KDialog::Accepted ) {
00292     // do some checking, warn user if mime types or patterns are removed.
00293     // if the lists are empty, and the fields not, warn.
00294     ui->edtFileExtensions->setText( d.chooser()->patterns().join(";") );
00295     ui->edtMimeTypes->setText( d.chooser()->mimeTypes().join(";") );
00296   }
00297 }
00298 
00299 void ModeConfigPage::hlDownload()
00300 {
00301   KateHlDownloadDialog diag(this,"hlDownload",true);
00302   diag.exec();
00303 }
00304 
00305 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal