Kate
katemodemenu.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 "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
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