• 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
  • utils
katetemplatehandler.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2004,2010 Joseph Wenninger <jowenn@kde.org>
4  * Copyright (C) 2009 Milian Wolff <mail@milianw.de>
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 as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef _KATE_TEMPLATE_HANDLER_H_
23 #define _KATE_TEMPLATE_HANDLER_H_
24 
25 #include <QtCore/QPointer>
26 #include <QtCore/QObject>
27 #include <QtCore/QMap>
28 #include <QtCore/QHash>
29 #include <QtCore/QString>
30 #include <QtCore/QList>
31 #include <QtCore/QRegExp>
32 
33 class KateDocument;
34 
35 class KateView;
36 
37 class KateUndoManager;
38 
39 class KateTemplateScript;
40 
41 namespace KTextEditor
42 {
43 
44 class MovingCursor;
45 
46 class MovingRange;
47 }
48 
73 class KateTemplateHandler: public QObject
74 {
75  Q_OBJECT
76 
77 public:
84  KateTemplateHandler(KateView *view,
85  const KTextEditor::Cursor& position,
86  const QString &templateString,
87  const QMap<QString, QString> &initialValues,
88  KateUndoManager* undoManager,
89  KateTemplateScript* templateScript);
90 
94  virtual ~KateTemplateHandler();
95 
96 protected:
112  virtual bool eventFilter(QObject* object, QEvent* event);
113 
114 private:
118  void insertText(const KTextEditor::Cursor& position, const QString& text);
119 
126  void handleTemplateString(const QMap<QString, QString> &initialValues);
127 
134  void setupEventHandler(KTextEditor::View* view);
135 
141  void jumpToPreviousRange();
142 
148  void jumpToNextRange();
149 
153  void setCurrentRange(KTextEditor::MovingRange* range);
154 
161  void syncMirroredRanges(KTextEditor::MovingRange* range);
162 
163 public:
164 
165  class MirrorBehaviour
166  {
167 
168  public:
169  MirrorBehaviour(); //clone
170  MirrorBehaviour(const QString &regexp, const QString &replacement, const QString &flags); //regexp
171  MirrorBehaviour(KateTemplateScript* templateScript, const QString& functionName, KateTemplateHandler* handler); //scripted
172  ~MirrorBehaviour();
173  QString getMirrorString(const QString &source);
174 
175  private:
176  enum Behaviour {
177  Clone = 0,
178  Regexp = 1,
179  Scripted = 2
180  };
181  Behaviour m_behaviour;
182  QString m_search;
183  QString m_replace;
184  QRegExp m_expr;
185  bool m_global;
186  KateTemplateScript* m_templateScript;
187  QString m_functionName;
188  KateTemplateHandler *m_handler;
189  };
190 
191 private:
192 
193  QHash<KTextEditor::MovingRange*, MirrorBehaviour> m_mirrorBehaviour;
194 
195 
200  void jumpToFinalCursorPosition();
201 
202  KateDocument *doc();
203 
204 private Q_SLOTS:
212  void cleanupAndExit();
213 
219  void slotTemplateInserted(KTextEditor::Document* document, const KTextEditor::Range& range);
223  void slotViewCreated(KTextEditor::Document* document, KTextEditor::View* view);
230  void slotTextChanged(KTextEditor::Document* document, const KTextEditor::Range& oldRange);
231 
235  void setEditWithUndo(const bool &enabled);
236 
237 public:
238  KateView* view();
239 
240 private:
242  KateView *m_view;
244  KateUndoManager *const m_undoManager;
254  QList<KTextEditor::MovingRange*> m_templateRanges;
255 
257  QMap<KTextEditor::MovingRange*, QList<KTextEditor::MovingRange*> > m_templateRangesChildren;
258  QMap<KTextEditor::MovingRange*, KTextEditor::MovingRange*> m_templateRangesChildToParent;
259 
262  KTextEditor::MovingRange *m_wholeTemplateRange;
264  KTextEditor::MovingCursor *m_finalCursorPosition;
266  KTextEditor::Cursor m_lastCaretPosition;
270  QList<KTextEditor::MovingRange*> m_uneditedRanges;
272  QList<KTextEditor::MovingRange*> m_masterRanges;
274  bool m_isMirroring;
276  bool m_editWithUndo;
278  bool m_jumping;
280  KateTemplateScript* m_templateScript;
281 
282  QList<KTextEditor::MovingRange*> m_spacersMovingRanges;
283 
284  bool m_initialRemodify;
285 };
286 
287 
288 #endif
289 
290 // kate: indent-mode cstyle; space-indent on; indent-width 2; replace-tabs on; replace-tabs on; replace-tabs on; replace-tabs on;
QEvent
QMap< QString, QString >
KateTemplateHandler
Inserts a template and offers advanced snippet features, like navigation and mirroring.
Definition: katetemplatehandler.h:73
KateTemplateHandler::MirrorBehaviour::getMirrorString
QString getMirrorString(const QString &source)
Definition: katetemplatehandler.cpp:1056
KateUndoManager
KateUndoManager implements a document's history.
Definition: kateundomanager.h:45
KateTemplateHandler::KateTemplateHandler
KateTemplateHandler(KateView *view, const KTextEditor::Cursor &position, const QString &templateString, const QMap< QString, QString > &initialValues, KateUndoManager *undoManager, KateTemplateScript *templateScript)
Setup the template handler, insert the template string.
Definition: katetemplatehandler.cpp:60
QObject::event
virtual bool event(QEvent *e)
QRegExp
QHash
QObject
KateTemplateHandler::MirrorBehaviour::~MirrorBehaviour
~MirrorBehaviour()
Definition: katetemplatehandler.cpp:1051
QString
QList< KTextEditor::MovingRange * >
KateTemplateHandler::eventFilter
virtual bool eventFilter(QObject *object, QEvent *event)
Provide keyboard interaction for the template handler.
Definition: katetemplatehandler.cpp:263
KateView
Definition: kateview.h:77
KateDocument
Definition: katedocument.h:74
KateTemplateHandler::view
KateView * view()
Definition: katetemplatehandler.cpp:1018
KateTemplateHandler::MirrorBehaviour::MirrorBehaviour
MirrorBehaviour()
Definition: katetemplatehandler.cpp:1025
KateTemplateScript
Definition: katetemplatescript.h:28
KateTemplateHandler::MirrorBehaviour
Definition: katetemplatehandler.h:165
KateTemplateHandler::~KateTemplateHandler
virtual ~KateTemplateHandler()
Cancels the template handler and cleans everything up.
Definition: katetemplatehandler.cpp:175
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