Kate
katehighlightmenu.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 "katehighlightmenu.h" 00021 #include "katehighlightmenu.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 //END Includes 00053 00054 KateHighlightingMenu::~KateHighlightingMenu() 00055 { 00056 qDeleteAll (subMenus); 00057 } 00058 00059 void KateHighlightingMenu::init() 00060 { 00061 m_doc = 0; 00062 00063 connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow())); 00064 } 00065 00066 void KateHighlightingMenu::updateMenu (KateDocument *doc) 00067 { 00068 m_doc = doc; 00069 } 00070 00071 void KateHighlightingMenu::slotAboutToShow() 00072 { 00073 for (int z=0; z < KateHlManager::self()->highlights(); z++) 00074 { 00075 QString hlName = KateHlManager::self()->hlNameTranslated (z); 00076 QString hlSection = KateHlManager::self()->hlSection (z); 00077 00078 if (!KateHlManager::self()->hlHidden(z)) 00079 { 00080 if ( !hlSection.isEmpty() && !names.contains(hlName) ) 00081 { 00082 if (!subMenusName.contains(hlSection)) 00083 { 00084 subMenusName << hlSection; 00085 QMenu *qmenu = new QMenu ('&'+hlSection); 00086 subMenus.append(qmenu); 00087 menu()->addMenu( qmenu ); 00088 } 00089 00090 int m = subMenusName.indexOf (hlSection); 00091 names << hlName; 00092 QAction *a=subMenus.at(m)->addAction( '&' + hlName, this, SLOT(setHl())); 00093 a->setData(KateHlManager::self()->hlName (z)); 00094 a->setCheckable(true); 00095 subActions.append(a); 00096 } 00097 else if (!names.contains(hlName)) 00098 { 00099 names << hlName; 00100 QAction *a=menu()->addAction ( '&' + hlName, this, SLOT(setHl())); 00101 a->setData(KateHlManager::self()->hlName (z)); 00102 a->setCheckable(true); 00103 subActions.append(a); 00104 } 00105 } 00106 } 00107 00108 if (!m_doc) return; 00109 QString mode=m_doc->highlightingMode(); 00110 for (int i=0;i<subActions.count();i++) { 00111 subActions[i]->setChecked(subActions[i]->data().toString()==mode); 00112 } 00113 } 00114 00115 void KateHighlightingMenu::setHl () 00116 { 00117 if (!m_doc || !sender()) return; 00118 QAction *action=qobject_cast<QAction*>(sender()); 00119 if (!action) return; 00120 QString mode=action->data().toString(); 00121 m_doc->setHighlightingMode(mode); 00122 } 00123 00124 // kate: space-indent on; indent-width 2; replace-tabs on;