• 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
  • schema
kateschema.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2007, 2008 Matthew Woehlke <mw_triad@users.sourceforge.net>
3  Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org>
4  Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
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 "kateschema.h"
23 #include "kateschema.moc"
24 
25 #include "kateconfig.h"
26 #include "kateglobal.h"
27 #include "kateview.h"
28 #include "katerenderer.h"
29 
30 #include <kcolorscheme.h>
31 #include <klocale.h>
32 #include <kdebug.h>
33 #include <kmenu.h>
34 #include <kconfiggroup.h>
35 //END
36 
37 //BEGIN KateSchemaManager
38 KateSchemaManager::KateSchemaManager ()
39  : m_config ("kateschemarc", KConfig::NoGlobals)
40 {
41 }
42 
43 KConfigGroup KateSchemaManager::schema (const QString &name)
44 {
45  return m_config.group (name);
46 }
47 
48 KateSchema KateSchemaManager::schemaData (const QString &name)
49 {
50  KConfigGroup cg (schema (name));
51  KateSchema schema;
52  schema.rawName = name;
53  schema.shippedDefaultSchema = cg.readEntry ("ShippedDefaultSchema", 0);
54  return schema;
55 }
56 
57 static bool schemasCompare (const KateSchema &s1, const KateSchema &s2)
58 {
59  if (s1.shippedDefaultSchema > s2.shippedDefaultSchema)
60  return true;
61 
62  return s1.translatedName().localeAwareCompare(s1.translatedName()) < 0;
63 }
64 
65 QList<KateSchema> KateSchemaManager::list ()
66 {
67  QList<KateSchema> schemas;
68  Q_FOREACH (QString s, m_config.groupList())
69  schemas.append (schemaData (s));
70 
71  // sort: prio given by default schema and name
72  qSort(schemas.begin(), schemas.end(), schemasCompare);
73 
74  return schemas;
75 }
76 //END
77 
78 //BEGIN SCHEMA ACTION -- the 'View->Schema' menu action
79 void KateViewSchemaAction::init()
80 {
81  m_group=0;
82  m_view = 0;
83  last = 0;
84 
85  connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
86 }
87 
88 void KateViewSchemaAction::updateMenu (KateView *view)
89 {
90  m_view = view;
91 }
92 
93 void KateViewSchemaAction::slotAboutToShow()
94 {
95  KateView *view=m_view;
96 
97  QList<KateSchema> schemas = KateGlobal::self()->schemaManager()->list ();
98 
99  if (!m_group) {
100  m_group=new QActionGroup(menu());
101  m_group->setExclusive(true);
102 
103  }
104 
105  for (int z=0; z< schemas.count(); z++)
106  {
107  QString hlName = schemas[z].translatedName();
108 
109  if (!names.contains(hlName))
110  {
111  names << hlName;
112  QAction *a=menu()->addAction ( hlName, this, SLOT(setSchema()));
113  a->setData(schemas[z].rawName);
114  a->setCheckable(true);
115  a->setActionGroup(m_group);
116  }
117  }
118 
119  if (!view) return;
120 
121  QString id=view->renderer()->config()->schema();
122  foreach(QAction *a,menu()->actions()) {
123  a->setChecked(a->data().toString()==id);
124 
125  }
126 }
127 
128 void KateViewSchemaAction::setSchema () {
129  QAction *action = qobject_cast<QAction*>(sender());
130 
131  if (!action) return;
132  QString mode=action->data().toString();
133 
134  KateView *view=m_view;
135 
136  if (view)
137  view->renderer()->config()->setSchema (mode);
138 }
139 //END SCHEMA ACTION
140 
141 // kate: space-indent on; indent-width 2; replace-tabs on;
KateRendererConfig::setSchema
void setSchema(const QString &schema)
Definition: kateconfig.cpp:2183
kateview.h
KateSchema
Definition: kateschema.h:33
QString::localeAwareCompare
int localeAwareCompare(const QString &other) const
KateView::renderer
KateRenderer * renderer()
Definition: kateview.cpp:1664
QActionGroup
katerenderer.h
QAction::setChecked
void setChecked(bool)
QAction::data
QVariant data() const
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
KateViewSchemaAction::slotAboutToShow
void slotAboutToShow()
Definition: kateschema.cpp:93
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:465
KateSchema::translatedName
QString translatedName() const
construct translated name for shipped schemas
Definition: kateschema.h:42
KateSchemaManager::KateSchemaManager
KateSchemaManager()
Definition: kateschema.cpp:38
KateSchema::rawName
QString rawName
Definition: kateschema.h:36
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
kateschema.h
KateRenderer::config
KateRendererConfig * config() const
Configuration.
Definition: katerenderer.h:362
KateSchemaManager::schemaData
KateSchema schemaData(const QString &name)
return schema data for on schema
Definition: kateschema.cpp:48
kateglobal.h
KateViewSchemaAction::updateMenu
void updateMenu(KateView *view)
Definition: kateschema.cpp:88
QString
KateSchema::shippedDefaultSchema
int shippedDefaultSchema
Definition: kateschema.h:37
QList
KateView
Definition: kateview.h:77
QAction::setData
void setData(const QVariant &userData)
QList::end
iterator end()
KateGlobal::schemaManager
KateSchemaManager * schemaManager()
manager for the katepart schemas
Definition: kateglobal.h:298
KateSchemaManager::list
QList< KateSchema > list()
Constructs list of schemas atm known in config object.
Definition: kateschema.cpp:65
QAction::setCheckable
void setCheckable(bool)
KateSchemaManager::schema
KConfigGroup schema(const QString &name)
return kconfiggroup for the given schema
Definition: kateschema.cpp:43
KateRendererConfig::schema
const QString & schema() const
Definition: kateconfig.cpp:2175
schemasCompare
static bool schemasCompare(const KateSchema &s1, const KateSchema &s2)
Definition: kateschema.cpp:57
QAction::setActionGroup
void setActionGroup(QActionGroup *group)
QAction
QActionGroup::setExclusive
void setExclusive(bool)
kateconfig.h
QVariant::toString
QString toString() const
QList::begin
iterator begin()
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