• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

katemodeconfigpage.cpp

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