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