• Skip to content
  • Skip to link menu
KDE 4.2 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   connect( ui->cmbFiletypes, SIGNAL(activated(int)), this, SLOT(typeChanged(int)) );
00078   connect( ui->btnNew, SIGNAL(clicked()), this, SLOT(newType()) );
00079   connect( ui->btnDelete, SIGNAL(clicked()), this, SLOT(deleteType()) );
00080   ui->btnMimeTypes->setIcon(KIcon("tools-wizard"));
00081   connect(ui->btnMimeTypes, SIGNAL(clicked()), this, SLOT(showMTDlg()));
00082   connect( ui->btnDownload, SIGNAL(clicked()), this, SLOT(hlDownload()) );
00083 
00084   reload();
00085 
00086   connect( ui->edtName, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00087   connect( ui->edtSection, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00088   connect( ui->edtVariables, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00089   connect( ui->edtFileExtensions, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00090   connect( ui->edtMimeTypes, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotChanged() ) );
00091   connect( ui->sbPriority, SIGNAL( valueChanged ( int ) ), this, SLOT( slotChanged() ) );
00092   connect( ui->cmbHl, SIGNAL(activated(int)), this, SLOT(slotChanged()) );
00093 
00094   layout->addWidget(newWidget);
00095   setLayout(layout);
00096 }
00097 
00098 ModeConfigPage::~ModeConfigPage ()
00099 {
00100   qDeleteAll (m_types);
00101 }
00102 
00103 void ModeConfigPage::apply()
00104 {
00105   if (!hasChanged())
00106     return;
00107 
00108   save ();
00109 
00110   KateGlobal::self()->modeManager()->save(m_types);
00111 }
00112 
00113 void ModeConfigPage::reload()
00114 {
00115   qDeleteAll (m_types);
00116   m_types.clear();
00117 
00118   // deep copy...
00119   foreach (KateFileType *type, KateGlobal::self()->modeManager()->list())
00120   {
00121     KateFileType *t = new KateFileType ();
00122     *t = *type;
00123     m_types.append (t);
00124   }
00125 
00126   update ();
00127 }
00128 
00129 void ModeConfigPage::reset()
00130 {
00131   reload ();
00132 }
00133 
00134 void ModeConfigPage::defaults()
00135 {
00136   reload ();
00137 }
00138 
00139 void ModeConfigPage::update ()
00140 {
00141   m_lastType = -1;
00142 
00143   ui->cmbFiletypes->clear ();
00144 
00145   foreach (KateFileType *type, m_types) {
00146     QString typeName = i18nc("Language", type->name.toUtf8());
00147     if (type->section.length() > 0)
00148       ui->cmbFiletypes->addItem(type->section + QString ("/") + typeName);
00149     else
00150       ui->cmbFiletypes->addItem(typeName);
00151   }
00152 
00153   ui->cmbFiletypes->setCurrentIndex (0);
00154 
00155   typeChanged (0);
00156 
00157   ui->cmbFiletypes->setEnabled (ui->cmbFiletypes->count() > 0);
00158 }
00159 
00160 void ModeConfigPage::deleteType ()
00161 {
00162   int type = ui->cmbFiletypes->currentIndex ();
00163 
00164   if (type > -1 && type < m_types.count())
00165   {
00166     delete m_types[type];
00167     m_types.removeAt(type);
00168     update ();
00169   }
00170 }
00171 
00172 void ModeConfigPage::newType ()
00173 {
00174   QString newN = i18n("New Filetype");
00175 
00176   for (int i = 0; i < m_types.count(); ++i) {
00177     KateFileType *type = m_types.at(i);
00178     if (type->name == newN)
00179     {
00180       ui->cmbFiletypes->setCurrentIndex (i);
00181       typeChanged (i);
00182       return;
00183     }
00184   }
00185 
00186   KateFileType *newT = new KateFileType ();
00187   newT->priority = 0;
00188   newT->name = newN;
00189   newT->hlGenerated = false;
00190 
00191   m_types.prepend (newT);
00192 
00193   update ();
00194 }
00195 
00196 void ModeConfigPage::save ()
00197 {
00198   if (m_lastType != -1)
00199   {
00200     m_types[m_lastType]->name = ui->edtName->text ();
00201     m_types[m_lastType]->section = ui->edtSection->text ();
00202     m_types[m_lastType]->varLine = ui->edtVariables->text ();
00203     m_types[m_lastType]->wildcards = ui->edtFileExtensions->text().split (';', QString::SkipEmptyParts);
00204     m_types[m_lastType]->mimetypes = ui->edtMimeTypes->text().split (';', QString::SkipEmptyParts);
00205     m_types[m_lastType]->priority = ui->sbPriority->value();
00206     m_types[m_lastType]->hl = ui->cmbHl->itemData(ui->cmbHl->currentIndex()).toString();
00207   }
00208 }
00209 
00210 void ModeConfigPage::typeChanged (int type)
00211 {
00212   save ();
00213     
00214   ui->cmbHl->setEnabled (true);
00215   ui->btnDelete->setEnabled (true);
00216   ui->edtName->setEnabled (true);
00217   ui->edtSection->setEnabled (true);
00218 
00219   if (type > -1 && type < m_types.count())
00220   {
00221     KateFileType *t = m_types.at(type);
00222 
00223     ui->gbProperties->setTitle (i18n("Properties of %1",  ui->cmbFiletypes->currentText()));
00224 
00225     ui->gbProperties->setEnabled (true);
00226     ui->btnDelete->setEnabled (true);
00227 
00228     ui->edtName->setText(t->name);
00229     ui->edtSection->setText(t->section);
00230     ui->edtVariables->setText(t->varLine);
00231     ui->edtFileExtensions->setText(t->wildcards.join (";"));
00232     ui->edtMimeTypes->setText(t->mimetypes.join (";"));
00233     ui->sbPriority->setValue(t->priority);
00234     
00235     ui->cmbHl->setEnabled (!t->hlGenerated);
00236     ui->btnDelete->setEnabled (!t->hlGenerated);
00237     ui->edtName->setEnabled (!t->hlGenerated);
00238     ui->edtSection->setEnabled (!t->hlGenerated);
00239 
00240     // activate current hl...
00241     for (int i = 0; i < ui->cmbHl->count(); ++i)
00242       if (ui->cmbHl->itemData (i).toString() == t->hl)
00243         ui->cmbHl->setCurrentIndex (i);
00244   }
00245   else
00246   {
00247     ui->gbProperties->setTitle (i18n("Properties"));
00248 
00249     ui->gbProperties->setEnabled (false);
00250     ui->btnDelete->setEnabled (false);
00251 
00252     ui->edtName->clear();
00253     ui->edtSection->clear();
00254     ui->edtVariables->clear();
00255     ui->edtFileExtensions->clear();
00256     ui->edtMimeTypes->clear();
00257     ui->sbPriority->setValue(0);
00258     ui->cmbHl->setCurrentIndex (0);
00259   }
00260 
00261   m_lastType = type;
00262 }
00263 
00264 void ModeConfigPage::showMTDlg()
00265 {
00266   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.");
00267   QStringList list = ui->edtMimeTypes->text().split( QRegExp("\\s*;\\s*"), QString::SkipEmptyParts );
00268   KMimeTypeChooserDialog d( i18n("Select Mime Types"), text, list, "text", this );
00269   if ( d.exec() == KDialog::Accepted ) {
00270     // do some checking, warn user if mime types or patterns are removed.
00271     // if the lists are empty, and the fields not, warn.
00272     ui->edtFileExtensions->setText( d.chooser()->patterns().join(";") );
00273     ui->edtMimeTypes->setText( d.chooser()->mimeTypes().join(";") );
00274   }
00275 }
00276 
00277 void ModeConfigPage::hlDownload()
00278 {
00279   KateHlDownloadDialog diag(this,"hlDownload",true);
00280   diag.exec();
00281 }
00282 
00283 // 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
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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