summaryrefslogtreecommitdiffstats
path: root/src/kile/kileedit.h
blob: bd1ce232c8ff82aac860b2a972613aa3958cac43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/***************************************************************************
    date                 : Feb 20 2007
    version              : 0.45
    email                : holger.danielsson@versanet.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KILEEDIT_H
#define KILEEDIT_H

#include <tqobject.h>
#include <tqregexp.h>
#include <tqmap.h>
#include <tqstring.h>
#include <tqstringlist.h>

#include <kate/document.h>

#include "kilestructurewidget.h"
#include "codecompletion.h"
#include "latexcmd.h"         

/**
  *@author Holger Danielsson
  */

class KileInfo;
namespace KileAction { class TagData; }

namespace KileDocument
{
  
class EditorExtension : public TQObject
{
	Q_OBJECT
  

public:
	EditorExtension(KileInfo *);
	~EditorExtension();

	enum EnvType { EnvNone, EnvList, EnvTab, EnvCrTab };

	enum SelectMode { smTex, smLetter, smWord, smNospace };

	void readConfig(void);

	void insertTag(const KileAction::TagData& data, Kate::View *view);

	TQString getTextLineReal(Kate::Document *doc, uint row);
	void gotoBullet(bool backwards, Kate::View *view = 0L);

	void gotoEnvironment(bool backwards, Kate::View *view = 0L);
	void matchEnvironment(Kate::View *view = 0L);
	void closeEnvironment(Kate::View *view = 0L);
	void closeAllEnvironments(Kate::View *view = 0L);
	void selectEnvironment(bool inside, Kate::View *view = 0L);
	void deleteEnvironment(bool inside, Kate::View *view = 0L);
	TQString autoIndentEnvironment() { return m_envAutoIndent; }

	void gotoTexgroup(bool backwards, Kate::View *view = 0L);
	void selectTexgroup(bool inside, Kate::View *view = 0L);
	void deleteTexgroup(bool inside, Kate::View *view = 0L);

	const TQStringList doubleQuotesList() { return m_quoteList; }
	
	// get current word
	bool getCurrentWord(Kate::Document *doc,uint row,uint col, SelectMode mode,TQString &word,uint &x1,uint &x2);
	TQString getEnvironmentText(uint &row, uint &col, TQString &name, Kate::View *view = 0L);
	bool hasEnvironment(Kate::View *view = 0L);

	// complete environment
	bool eventInsertEnvironment(Kate::View *view);

	// mathgroup
	TQString getMathgroupText(uint &row, uint &col, Kate::View *view = 0L);
	bool hasMathgroup(Kate::View *view = 0L);
	
public slots:
	void insertIntelligentNewline(Kate::View *view = 0L);

	void selectEnvInside() { selectEnvironment(true); }
	void selectEnvOutside() { selectEnvironment(false); }
	void deleteEnvInside() { deleteEnvironment(true); }
	void deleteEnvOutside() {deleteEnvironment(false); }
	void gotoBeginEnv() { gotoEnvironment(true); }
	void gotoEndEnv() { gotoEnvironment(false); }
	void matchEnv() { matchEnvironment(); }
	void closeEnv() {closeEnvironment(); }
	void closeAllEnv() {closeAllEnvironments(); }
	
	void selectTexgroupInside() { selectTexgroup(true); }
	void selectTexgroupOutside() { selectTexgroup(false); }
	void deleteTexgroupInside() { deleteTexgroup(true); }
	void deleteTexgroupOutside() { deleteTexgroup(false); }
	void gotoBeginTexgroup() { gotoTexgroup(true); }
	void gotoEndTexgroup() { gotoTexgroup(false); }
	void matchTexgroup(Kate::View *view = 0L);
	void closeTexgroup(Kate::View *view = 0L);

	void selectParagraph(Kate::View *view = 0L);
	void selectLine(Kate::View *view = 0L);
	void selectWord(SelectMode mode = smTex, Kate::View *view = 0L);
	void deleteParagraph(Kate::View *view = 0L);
	void deleteEndOfLine(Kate::View *view = 0L);
	void deleteWord(SelectMode mode = smTex, Kate::View *view = 0L);

	void selectMathgroup(Kate::View *view = 0L);
	void deleteMathgroup(Kate::View *view = 0L);

	void nextBullet(Kate::View* view = 0L);
	void prevBullet(Kate::View* view = 0L);
	void insertBullet(Kate::View* view = 0L);

	void gotoLine(Kate::View *view = 0L);
	void gotoNextParagraph(Kate::View *view = 0L);
	void gotoPrevParagraph(Kate::View *view = 0L);

	void gotoNextSectioning();
	void gotoPrevSectioning();
	void sectioningCommand(KileListViewItem *item, int id);

	bool insertDoubleQuotes();
	void initDoubleQuotes();

	void insertIntelligentTabulator();
private:

	enum EnvTag { EnvBegin, EnvEnd };

	enum EnvPos { EnvLeft, EnvInside, EnvRight };

	enum MathTag { mmNoMathMode, mmMathDollar, mmMathParen, mmDisplaymathParen, mmMathEnv, mmDisplaymathEnv };

	struct EnvData 
	{
		uint row;
		uint col;
		TQString name;
		uint len;
		EnvPos cpos;
		EnvTag tag;
		EnvType type;
	};

	struct MathData 
	{
		uint row;
		uint col;
		uint len;
		uint numdollar;
		MathTag tag;
		TQString envname;
	};

	struct BracketData
	{
		uint row;
		uint col;
		bool open;
	};

	TQRegExp m_reg;
	bool m_overwritemode;
	TQString m_envAutoIndent;

	// change cursor position
	bool increaseCursorPosition(Kate::Document *doc, uint &row, uint &col);
	bool decreaseCursorPosition(Kate::Document *doc, uint &row, uint &col);

	// check position
	bool isValidBackslash(Kate::Document *doc, uint row, uint col);
	bool isCommentPosition(Kate::Document *doc, uint row, uint col);
	bool isEnvironmentPosition(Kate::Document *doc, uint row, uint col,EnvData &env);

	// find environment tags
	bool findBeginEnvironment(Kate::Document *doc, uint row, uint col,EnvData &env);
	bool findEndEnvironment(Kate::Document *doc, uint row, uint col,EnvData &env);
	bool findEnvironmentTag(Kate::Document *doc, uint row, uint col,EnvData &env, bool backwards=false);
	bool findOpenedEnvironment(uint &row,uint &col, TQString &envname, Kate::View *view);
	TQStringList findOpenedEnvironmentList(Kate::View *view, bool position = false);

	// get current environment
	bool getEnvironment(bool inside, EnvData &envbegin, EnvData &envend,Kate::View *view);
	bool expandSelectionEnvironment(bool inside, Kate::View *view);

	// find brackets
	bool isBracketPosition(Kate::Document *doc, uint row, uint col, BracketData &bracket);
	bool findOpenBracket(Kate::Document *doc, uint row, uint col, BracketData &bracket);
	bool findCloseBracket(Kate::Document *doc, uint row, uint col, BracketData &bracket);
	bool findCloseBracketTag(Kate::Document *doc, uint row, uint col,BracketData &bracket);
	bool findOpenBracketTag(Kate::Document *doc, uint row, uint col, BracketData &bracket);

	// find math tags
	bool isOpeningMathTagPosition(Kate::Document *doc, uint row, uint col, MathData &mathdata);
	bool isClosingMathTagPosition(Kate::Document *doc, uint row, uint col, MathData &mathdata);
	bool findOpenMathTag(Kate::Document *doc, uint row, uint col, TQRegExp &reg, MathData &mathdata);
	bool findCloseMathTag(Kate::Document *doc, uint row, uint col, TQRegExp &reg, MathData &mathdata);
	bool checkMathtags(const MathData &begin,const MathData &end);

	// mathgroup
	bool getMathgroup(Kate::View *view, uint &row1, uint &col1, uint &row2, uint &col2);

	// get current Texgroup
	bool getTexgroup(bool inside, BracketData &open, BracketData &close, Kate::View *view);

	// find current paragraph
	bool findCurrentTexParagraph(uint &startline, uint &endline, Kate::View *view);

	// sectioning commands
	void gotoSectioning(bool backwards, Kate::View *view = 0L);
	bool findEndOfDocument(Kate::Document *doc, uint row,uint col, uint &rowFound, uint &colFound);

	// check environment type
	KileDocument::LatexCommands *m_latexCommands;	
	bool shouldCompleteEnv(const TQString &envname, Kate::View *view);
	TQString getWhiteSpace(const TQString &s);

	// verbatim text
	bool insideVerb(Kate::View *view);
	bool insideVerbatim(Kate::View *view);

	// complete environments
	TQRegExp m_regexpEnter;
	
	// double Quotes
	bool m_dblQuotes;
	TQStringList m_quoteList;
	TQString m_leftDblQuote, m_rightDblQuote;
	
	// help
	void readHelpList(TQString const &filename);

	Kate::View *determineView(Kate::View *);

	KileInfo	*m_ki;

//code completion
public slots:
	void completeWord();
	void completeEnvironment();
	void completeAbbreviation();

public:
	CodeCompletion* complete() const { return m_complete; }

private:
	CodeCompletion	*m_complete;
};

}

#endif