Kate
katemodemenu.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries and the Kate part. 00002 * 00003 * Copyright (C) 2001-2010 Christoph Cullmann <cullmann@kde.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 //BEGIN Includes 00022 #include "katemodemenu.h" 00023 #include "katemodemenu.moc" 00024 00025 #include "katedocument.h" 00026 #include "kateconfig.h" 00027 #include "kateview.h" 00028 #include "kateglobal.h" 00029 #include "katesyntaxmanager.h" 00030 #include "katesyntaxdocument.h" 00031 00032 #include "ui_filetypeconfigwidget.h" 00033 00034 #include <kconfig.h> 00035 #include <kmimetype.h> 00036 #include <kmimetypechooser.h> 00037 #include <kdebug.h> 00038 #include <kiconloader.h> 00039 #include <knuminput.h> 00040 #include <klocale.h> 00041 #include <kmenu.h> 00042 00043 #include <QtCore/QRegExp> 00044 #include <QtGui/QCheckBox> 00045 #include <QtGui/QComboBox> 00046 #include <QtGui/QGroupBox> 00047 00048 #include <QtGui/QLabel> 00049 #include <QtGui/QLayout> 00050 #include <QtGui/QPushButton> 00051 #include <QtGui/QToolButton> 00052 #include <kvbox.h> 00053 00054 #define KATE_FT_HOWMANY 1024 00055 //END Includes 00056 00057 void KateModeMenu::init() 00058 { 00059 m_doc = 0; 00060 00061 connect( menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( setType( QAction* ) ) ); 00062 00063 connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow())); 00064 00065 m_actionGroup = new QActionGroup(menu()); 00066 } 00067 00068 KateModeMenu::~KateModeMenu( ) 00069 { 00070 qDeleteAll(subMenus); 00071 } 00072 00073 void KateModeMenu::updateMenu (KTextEditor::Document *doc) 00074 { 00075 m_doc = (KateDocument *)doc; 00076 } 00077 00078 void KateModeMenu::slotAboutToShow() 00079 { 00080 KateDocument *doc=m_doc; 00081 int count = KateGlobal::self()->modeManager()->list().count(); 00082 00083 for (int z=0; z<count; z++) 00084 { 00085 QString hlName = KateGlobal::self()->modeManager()->list().at(z)->name; 00086 QString hlSection = KateGlobal::self()->modeManager()->list().at(z)->section; 00087 00088 if ( !hlSection.isEmpty() && !names.contains(hlName) ) 00089 { 00090 if (!subMenusName.contains(hlSection)) 00091 { 00092 subMenusName << hlSection; 00093 QMenu *qmenu = new QMenu (hlSection); 00094 connect( qmenu, SIGNAL( triggered( QAction* ) ), this, SLOT( setType( QAction* ) ) ); 00095 subMenus.append(qmenu); 00096 menu()->addMenu (qmenu); 00097 } 00098 00099 int m = subMenusName.indexOf (hlSection); 00100 names << hlName; 00101 QAction *action = subMenus.at(m)->addAction ( hlName ); 00102 m_actionGroup->addAction(action); 00103 action->setCheckable( true ); 00104 action->setData( hlName ); 00105 } 00106 else if (!names.contains(hlName)) 00107 { 00108 names << hlName; 00109 00110 disconnect( menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( setType( QAction* ) ) ); 00111 connect( menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( setType( QAction* ) ) ); 00112 00113 QAction *action = menu()->addAction ( hlName ); 00114 m_actionGroup->addAction(action); 00115 action->setCheckable( true ); 00116 action->setData( hlName ); 00117 } 00118 } 00119 00120 if (!doc) return; 00121 00122 for (int i=0;i<subMenus.count();i++) 00123 { 00124 QList<QAction*> actions = subMenus.at( i )->actions(); 00125 for ( int j = 0; j < actions.count(); ++j ) 00126 actions[ j ]->setChecked( false ); 00127 } 00128 00129 QList<QAction*> actions = menu()->actions(); 00130 for ( int i = 0; i < actions.count(); ++i ) 00131 actions[ i ]->setChecked( false ); 00132 00133 if (doc->fileType().isEmpty() || doc->fileType() == "Normal") { 00134 for ( int i = 0; i < actions.count(); ++i ) { 00135 if ( actions[ i ]->data().toString() == "Normal" ) 00136 actions[ i ]->setChecked( true ); 00137 } 00138 } else { 00139 if (!doc->fileType().isEmpty()) 00140 { 00141 const KateFileType& t = KateGlobal::self()->modeManager()->fileType(doc->fileType()); 00142 int i = subMenusName.indexOf (t.section); 00143 if (i >= 0 && subMenus.at(i)) { 00144 QList<QAction*> actions = subMenus.at( i )->actions(); 00145 for ( int j = 0; j < actions.count(); ++j ) { 00146 if ( actions[ j ]->data().toString() == doc->fileType() ) 00147 actions[ j ]->setChecked( true ); 00148 } 00149 } else { 00150 QList<QAction*> actions = menu()->actions(); 00151 for ( int j = 0; j < actions.count(); ++j ) { 00152 if ( actions[ j ]->data().toString().isEmpty() ) 00153 actions[ j ]->setChecked( true ); 00154 } 00155 } 00156 } 00157 } 00158 } 00159 00160 void KateModeMenu::setType (QAction *action) 00161 { 00162 KateDocument *doc=m_doc; 00163 00164 if (doc) { 00165 doc->updateFileType(action->data().toString(), true); 00166 } 00167 } 00168 00169 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference