QCodeEdit  2.2
qsnippet_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #ifndef _QSNIPPET_P_H_
17 #define _QSNIPPET_P_H_
18 
24 #include "qsnippet.h"
25 #include "qsnippetpatternloader.h"
26 
27 #include "qeditor.h"
28 #include "qdocument.h"
29 #include "qdocumentcursor.h"
30 #include "qdocumentcommand.h"
31 
33 {
34  public:
36  virtual ~QSnippetInsertionCommand();
37 
38  void addPlaceHolder(const QEditor::PlaceHolder& ph);
39 
40  virtual void addCommand(QDocumentCommand *c);
41  virtual void removeCommand(QDocumentCommand *c);
42 
43  virtual void redo();
44  virtual void undo();
45 
46  private:
47  QEditor *m_editor;
48  QDocumentCursor m_cursor;
49  QList<QEditor::PlaceHolder> m_placeHolders;
50 };
51 
52 #define Q_SNIPPET(T) \
53  friend class Loader; \
54  public: \
55  class Loader : public QSnippetPatternLoader \
56  { \
57  public: \
58  virtual QString type() const { return ""#T; } \
59  virtual QSnippet* loadSnippet(const QString& pattern) const \
60  { \
61  T *snip = new T(this); \
62  snip->m_pattern = pattern; \
63  bool ok = reloadSnippet(snip, pattern); \
64  if ( !ok ) { delete snip; snip = 0; } \
65  return snip; \
66  } \
67  virtual bool reloadSnippet(QSnippet* snip, const QString& pattern) const \
68  { return T::loadSnippet(snip, pattern); } \
69  }; \
70  inline T(const QSnippetPatternLoader *pl) : QSnippet(pl) {} \
71  private: \
72 
73 
74 namespace QCE
75 {
76  namespace Snippets
77  {
78  class PlainText : public QSnippet
79  {
80  Q_SNIPPET(PlainText)
81 
82  public:
83  virtual void insert(QEditor *e) const;
84 
85  static bool loadSnippet(QSnippet *snip, const QString& pattern);
86 
87  QString m_data;
88  };
89 
90  class Simple : public QSnippet
91  {
92  Q_SNIPPET(Simple)
93 
94  public:
95  struct Anchor
96  {
97  Anchor() : lineOffset(0), columnOffset(0) {}
98 
99  int lineOffset;
100  int columnOffset;
101  };
102 
103  struct PlaceHolder : public Anchor
104  {
105  PlaceHolder() : length(-1) {}
106 
107  int length;
108  QString defaultValue;
109  QList<Anchor> mirrors;
110  QList<int> unresolvedMirrors;
111  };
112 
113  virtual void insert(QEditor *e) const;
114 
115  static bool loadSnippet(QSnippet *snip, const QString& pattern);
116 
117  QString m_base;
118  QList<PlaceHolder> m_placeHolders;
119  };
120  }
121 }
122 
123 #endif