• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • mode
katemodemenu.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2001-2010 Christoph Cullmann <cullmann@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 //BEGIN Includes
22 #include "katemodemenu.h"
23 #include "katemodemenu.moc"
24 
25 #include "katedocument.h"
26 #include "kateconfig.h"
27 #include "kateview.h"
28 #include "kateglobal.h"
29 #include "katesyntaxmanager.h"
30 #include "katesyntaxdocument.h"
31 
32 #include "ui_filetypeconfigwidget.h"
33 
34 #include <kconfig.h>
35 #include <kmimetype.h>
36 #include <kmimetypechooser.h>
37 #include <kdebug.h>
38 #include <kiconloader.h>
39 #include <knuminput.h>
40 #include <klocale.h>
41 #include <kmenu.h>
42 
43 #include <QtCore/QRegExp>
44 #include <QtGui/QCheckBox>
45 #include <QtGui/QComboBox>
46 #include <QtGui/QGroupBox>
47 
48 #include <QtGui/QLabel>
49 #include <QtGui/QLayout>
50 #include <QtGui/QPushButton>
51 #include <QtGui/QToolButton>
52 #include <kvbox.h>
53 
54 #define KATE_FT_HOWMANY 1024
55 //END Includes
56 
57 void KateModeMenu::init()
58 {
59  m_doc = 0;
60 
61  connect( menu(), SIGNAL(triggered(QAction*)), this, SLOT(setType(QAction*)) );
62 
63  connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
64 
65  m_actionGroup = new QActionGroup(menu());
66 }
67 
68 KateModeMenu::~KateModeMenu( )
69 {
70  qDeleteAll(subMenus);
71 }
72 
73 void KateModeMenu::updateMenu (KTextEditor::Document *doc)
74 {
75  m_doc = static_cast<KateDocument *>(doc);
76 }
77 
78 void KateModeMenu::slotAboutToShow()
79 {
80  KateDocument *doc=m_doc;
81  int count = KateGlobal::self()->modeManager()->list().count();
82 
83  for (int z=0; z<count; z++)
84  {
85  QString nameRaw = KateGlobal::self()->modeManager()->list().at(z)->name;
86  QString hlName = KateGlobal::self()->modeManager()->list().at(z)->nameTranslated();
87  QString hlSection = KateGlobal::self()->modeManager()->list().at(z)->sectionTranslated();
88 
89  if ( !hlSection.isEmpty() && !names.contains(hlName) )
90  {
91  if (!subMenusName.contains(hlSection))
92  {
93  subMenusName << hlSection;
94  QMenu *qmenu = new QMenu (hlSection);
95  connect( qmenu, SIGNAL(triggered(QAction*)), this, SLOT(setType(QAction*)) );
96  subMenus.append(qmenu);
97  menu()->addMenu (qmenu);
98  }
99 
100  int m = subMenusName.indexOf (hlSection);
101  names << hlName;
102  QAction *action = subMenus.at(m)->addAction ( hlName );
103  m_actionGroup->addAction(action);
104  action->setCheckable( true );
105  action->setData( nameRaw );
106  }
107  else if (!names.contains(hlName))
108  {
109  names << hlName;
110 
111  disconnect( menu(), SIGNAL(triggered(QAction*)), this, SLOT(setType(QAction*)) );
112  connect( menu(), SIGNAL(triggered(QAction*)), this, SLOT(setType(QAction*)) );
113 
114  QAction *action = menu()->addAction ( hlName );
115  m_actionGroup->addAction(action);
116  action->setCheckable( true );
117  action->setData( nameRaw );
118  }
119  }
120 
121  if (!doc) return;
122 
123  for (int i=0;i<subMenus.count();i++)
124  {
125  QList<QAction*> actions = subMenus.at( i )->actions();
126  for ( int j = 0; j < actions.count(); ++j )
127  actions[ j ]->setChecked( false );
128  }
129 
130  QList<QAction*> actions = menu()->actions();
131  for ( int i = 0; i < actions.count(); ++i )
132  actions[ i ]->setChecked( false );
133 
134  if (doc->fileType().isEmpty() || doc->fileType() == "Normal") {
135  for ( int i = 0; i < actions.count(); ++i ) {
136  if ( actions[ i ]->data().toString() == "Normal" )
137  actions[ i ]->setChecked( true );
138  }
139  } else {
140  if (!doc->fileType().isEmpty())
141  {
142  const KateFileType& t = KateGlobal::self()->modeManager()->fileType(doc->fileType());
143  int i = subMenusName.indexOf (t.section);
144  if (i >= 0 && subMenus.at(i)) {
145  QList<QAction*> actions = subMenus.at( i )->actions();
146  for ( int j = 0; j < actions.count(); ++j ) {
147  if ( actions[ j ]->data().toString() == doc->fileType() )
148  actions[ j ]->setChecked( true );
149  }
150  } else {
151  QList<QAction*> actions = menu()->actions();
152  for ( int j = 0; j < actions.count(); ++j ) {
153  if ( actions[ j ]->data().toString().isEmpty() )
154  actions[ j ]->setChecked( true );
155  }
156  }
157  }
158  }
159 }
160 
161 void KateModeMenu::setType (QAction *action)
162 {
163  KateDocument *doc=m_doc;
164 
165  if (doc) {
166  doc->updateFileType(action->data().toString(), true);
167  }
168 }
169 
170 // kate: space-indent on; indent-width 2; replace-tabs on;
kateview.h
KateDocument::updateFileType
void updateFileType(const QString &newType, bool user=false)
Definition: katedocument.cpp:4503
KateGlobal::modeManager
KateModeManager * modeManager()
global mode manager used to manage the modes centrally
Definition: kateglobal.h:292
KateFileType::section
QString section
Definition: katemodemanager.h:39
QActionGroup
QAction::data
QVariant data() const
QList::at
const T & at(int i) const
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
katedocument.h
KateModeMenu::slotAboutToShow
void slotAboutToShow()
Definition: katemodemenu.cpp:78
KateDocument::fileType
QString fileType() const
Definition: katedocument.h:939
QActionGroup::addAction
QAction * addAction(QAction *action)
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:465
katemodemenu.h
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
katesyntaxmanager.h
kateglobal.h
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
katesyntaxdocument.h
QString
QList< QAction * >
QAction::setData
void setData(const QVariant &userData)
KateFileType
Definition: katemodemanager.h:34
QMenu
KateDocument
Definition: katedocument.h:74
QAction::setCheckable
void setCheckable(bool)
KateModeMenu::~KateModeMenu
~KateModeMenu()
Definition: katemodemenu.cpp:68
KateModeMenu::updateMenu
void updateMenu(KTextEditor::Document *doc)
Definition: katemodemenu.cpp:73
QAction
QStringList::indexOf
int indexOf(const QRegExp &rx, int from) const
KateModeManager::list
const QList< KateFileType * > & list() const
Don't modify.
Definition: katemodemanager.h:93
kateconfig.h
QVariant::toString
QString toString() const
KateModeManager::fileType
QString fileType(KateDocument *doc, const QString &fileToReadFrom)
get the right fileType for the given document -1 if none found !
Definition: katemodemanager.cpp:205
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal