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