Kate
katehighlightmenu.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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/QPushButton>
00049 #include <QtGui/QToolButton>
00050 #include <kvbox.h>
00051
00052
00053 KateHighlightingMenu::~KateHighlightingMenu()
00054 {
00055 qDeleteAll (subMenus);
00056 }
00057
00058 void KateHighlightingMenu::init()
00059 {
00060 m_doc = 0;
00061
00062 connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
00063 }
00064
00065 void KateHighlightingMenu::updateMenu (KateDocument *doc)
00066 {
00067 m_doc = doc;
00068 }
00069
00070 void KateHighlightingMenu::slotAboutToShow()
00071 {
00072 for (int z=0; z < KateHlManager::self()->highlights(); z++)
00073 {
00074 QString hlName = KateHlManager::self()->hlNameTranslated (z);
00075 QString hlSection = KateHlManager::self()->hlSection (z);
00076
00077 if (!KateHlManager::self()->hlHidden(z))
00078 {
00079 if ( !hlSection.isEmpty() && !names.contains(hlName) )
00080 {
00081 if (!subMenusName.contains(hlSection))
00082 {
00083 subMenusName << hlSection;
00084 QMenu *qmenu = new QMenu ('&'+hlSection);
00085 subMenus.append(qmenu);
00086 menu()->addMenu( qmenu );
00087 }
00088
00089 int m = subMenusName.indexOf (hlSection);
00090 names << hlName;
00091 QAction *a=subMenus.at(m)->addAction( '&' + hlName, this, SLOT(setHl()));
00092 a->setData(KateHlManager::self()->hlName (z));
00093 a->setCheckable(true);
00094 subActions.append(a);
00095 }
00096 else if (!names.contains(hlName))
00097 {
00098 names << hlName;
00099 QAction *a=menu()->addAction ( '&' + hlName, this, SLOT(setHl()));
00100 a->setData(KateHlManager::self()->hlName (z));
00101 a->setCheckable(true);
00102 subActions.append(a);
00103 }
00104 }
00105 }
00106
00107 if (!m_doc) return;
00108 QString mode=m_doc->highlightingMode();
00109 for (int i=0;i<subActions.count();i++) {
00110 subActions[i]->setChecked(subActions[i]->data().toString()==mode);
00111 }
00112 }
00113
00114 void KateHighlightingMenu::setHl ()
00115 {
00116 if (!m_doc || !sender()) return;
00117 QAction *action=qobject_cast<QAction*>(sender());
00118 if (!action) return;
00119 QString mode=action->data().toString();
00120 m_doc->setHighlightingMode(mode);
00121
00122
00123 m_doc->setDontChangeHlOnSave();
00124 }
00125
00126