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

Kate

katemodemenu.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 "katemodemenu.h"
00021 #include "katemodemenu.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 <kiconloader.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 void KateModeMenu::init()
00057 {
00058   m_doc = 0;
00059 
00060   connect( menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( setType( QAction* ) ) );
00061 
00062   connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
00063 }
00064 
00065 KateModeMenu::~ KateModeMenu( )
00066 {
00067   qDeleteAll(subMenus);
00068 }
00069 
00070 void KateModeMenu::updateMenu (KTextEditor::Document *doc)
00071 {
00072   m_doc = (KateDocument *)doc;
00073 }
00074 
00075 void KateModeMenu::slotAboutToShow()
00076 {
00077   KateDocument *doc=m_doc;
00078   int count = KateGlobal::self()->modeManager()->list().count();
00079 
00080   for (int z=0; z<count; z++)
00081   {
00082     QString hlName = KateGlobal::self()->modeManager()->list().at(z)->name;
00083     QString hlSection = KateGlobal::self()->modeManager()->list().at(z)->section;
00084 
00085     if ( !hlSection.isEmpty() && !names.contains(hlName) )
00086     {
00087       if (!subMenusName.contains(hlSection))
00088       {
00089         subMenusName << hlSection;
00090         QMenu *qmenu = new QMenu (hlSection);
00091         connect( qmenu, SIGNAL( triggered( QAction* ) ), this, SLOT( setType( QAction* ) ) );
00092         subMenus.append(qmenu);
00093         menu()->addMenu (qmenu);
00094       }
00095 
00096       int m = subMenusName.indexOf (hlSection);
00097       names << hlName;
00098       QAction *action = subMenus.at(m)->addAction ( hlName );
00099       action->setCheckable( true );
00100       action->setData( hlName );
00101     }
00102     else if (!names.contains(hlName))
00103     {
00104       names << hlName;
00105 
00106       disconnect( menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( setType( QAction* ) ) );
00107       connect( menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( setType( QAction* ) ) );
00108 
00109       QAction *action = menu()->addAction ( hlName );
00110       action->setCheckable( true );
00111       action->setData( hlName );
00112     }
00113   }
00114 
00115   if (!doc) return;
00116 
00117   for (int i=0;i<subMenus.count();i++)
00118   {
00119     QList<QAction*> actions = subMenus.at( i )->actions();
00120     for ( int j = 0; j < actions.count(); ++j )
00121       actions[ j ]->setChecked( false );
00122   }
00123 
00124   QList<QAction*> actions = menu()->actions();
00125   for ( int i = 0; i < actions.count(); ++i )
00126     actions[ i ]->setChecked( false );
00127 
00128   if (doc->fileType().isEmpty() || doc->fileType() == "Normal") {
00129     for ( int i = 0; i < actions.count(); ++i ) {
00130       if ( actions[ i ]->data().toString() == "Normal" )
00131         actions[ i ]->setChecked( true );
00132     }
00133   } else {
00134     if (!doc->fileType().isEmpty())
00135     {
00136       const KateFileType& t = KateGlobal::self()->modeManager()->fileType(doc->fileType());
00137       int i = subMenusName.indexOf (t.section);
00138       if (i >= 0 && subMenus.at(i)) {
00139         QList<QAction*> actions = subMenus.at( i )->actions();
00140         for ( int j = 0; j < actions.count(); ++j ) {
00141           if ( actions[ j ]->data().toString() == doc->fileType() )
00142             actions[ j ]->setChecked( true );
00143         }
00144       } else {
00145         QList<QAction*> actions = menu()->actions();
00146         for ( int j = 0; j < actions.count(); ++j ) {
00147           if ( actions[ j ]->data().toString().isEmpty() )
00148             actions[ j ]->setChecked( true );
00149         }
00150       }
00151     }
00152   }
00153 }
00154 
00155 void KateModeMenu::setType (QAction *action)
00156 {
00157   KateDocument *doc=m_doc;
00158 
00159   if (doc) {
00160     doc->updateFileType(action->data().toString(), true);
00161   }
00162 }
00163 
00164 // 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