summaryrefslogtreecommitdiffstats
path: root/src/kile/kiledocumentinfo.h
blob: 69941328eb85960ab30da5485edd064b99efe6ef (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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/*************************************************************************************
    begin                : Sun Jul 20 2003
    copyright            : (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)
                           (C) 2006 by Michel Ludwig (michel.ludwig@kdemail.net)
 *************************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 KILEDOCUMENTINFO_H
#define KILEDOCUMENTINFO_H

#include <kate/document.h>
#include "kiledebug.h"
#include <tdelistview.h>
#include <kurl.h>
#include <kdialogbase.h>
#include <latexcmd.h>

#include "kileconstants.h"
#include "kileextensions.h"

#define TEX_CAT0 '\\'
#define TEX_CAT1 '{'
#define TEX_CAT2 '}'
#define TEX_CAT3 '$'
#define TEX_CAT4 '&'
#define TEX_CAT6 '#'
#define TEX_CAT7 '^'
#define TEX_CAT8 '_'
#define TEX_CAT13 '~'
#define TEX_CAT14 '%'

#define SIZE_STAT_ARRAY 6

namespace KileStruct
{
	//Different types of elements in the structure view
	enum
	{
		None = 0x1, Label = 0x2, Sect = 0x4, Input = 0x8,
		BibItem = 0x10, Bibliography = 0x20, Package = 0x40, NewCommand = 0x80,
		Graphics = 0x100, Reference = 0x200, BeginEnv = 0x400, EndEnv = 0x800,
		BeginFloat = 0x1000, EndFloat = 0x2000,  Caption = 0x4000, BeamerFrame = 0x8000,
		BeamerBeginFrame = 0x10000, BeamerEndFrame = 0x20000, BeamerFrametitle = 0x40000, BeamerBeginBlock = 0x80000,
		ToDo = 0x100000, FixMe = 0x200000, NewEnvironment = 0x400000
	};

	//Different levels (in the parent-child hierarchy) in the structure view
	enum
	{
		Hidden = -4, NotSpecified = -3, Object = -2, File = -1
	};
}

/**
 * A convenience class to store info about how LaTeX elements should appear in the
 * structure view. A TQMap<TQString, KileStructData> should be created, so that the
 * actual LaTeX elements can be mapped to this class.
 **/
class KileStructData
{
public:
	KileStructData(int lvl = 0, int tp = KileStruct::None, TQString px = TQString(), TQString fldr = "root" )  : level(lvl), type(tp), pix(px), folder(fldr) {}
	/** At which level the element should be visible **/
	int				level;
	/** The type of element (see @ref KileStruct) **/
	int 			type;
	/** The name of the icon that goes with this element. The icon is located using SmallIcon(pix). **/
	TQString 	pix, folder;
};

/**
 * KileDocument::Info is a decorator class for the Document class. We can't derive a class from an interface
 * without implementing the interface, a decorator class is a way to add some functionality to the Document class.
 **/

namespace KileDocument
{

struct BracketResult
{
	BracketResult() : option(TQString()), value(TQString()), line(0), col(0) {}
	TQString option, value;
	int line, col;
};

struct TodoResult
{
	int type;
	uint colTag;
	uint colComment;
	TQString comment;
};

class Info : public TQObject
{
	TQ_OBJECT
  

public:
	static bool containsInvalidCharacters(const KURL&);
	static KURL repairInvalidCharacters(const KURL&, bool checkForFileExistence = true);
	static KURL repairExtension(const KURL&, bool checkForFileExistence = true);
	static KURL makeValidTeXURL(const KURL & url, bool istexfile, bool checkForFileExistence = true);
	static KURL renameIfExist(const KURL& url);

public:
	Info();
	~Info();

	const TQStringList* labels() const{ return &m_labels; }
	const TQStringList* bibItems() const { return &m_bibItems; }
	const TQStringList* dependencies() const {return &m_deps; }
	const TQStringList* bibliographies() const { return &m_bibliography; }
	const TQStringList* packages() const { return &m_packages; }
	const TQStringList* newCommands() const { return &m_newCommands; }

	TQString lastModifiedFile(const TQStringList *list = 0L);

	bool openStructureLabels() { return m_openStructureLabels; }
	bool openStructureReferences() { return m_openStructureReferences; }
	bool openStructureBibitems() { return m_openStructureBibitems; }
	bool openStructureTodo() { return m_openStructureTodo; }

	bool showStructureLabels() { return m_showStructureLabels; }


	const TQString & preamble() const { return m_preamble; }

	virtual bool isLaTeXRoot() { return m_bIsRoot; }

	virtual KURL url();

	virtual void updateStructLevelInfo();

	void setBaseDirectory(const KURL& url);
	const KURL& getBaseDirectory() const;

	virtual bool isTextDocument();
	virtual Type getType();

	/**
	 * Returns a file filter suitable for loading and saving files of this class' type.
	 **/
	virtual TQString getFileFilter() const;

	virtual bool isDocumentTypePromotionAllowed();
	void setDocumentTypePromotionAllowed(bool b);

public slots:
	/**
	 * Never call this function directly, use KileWidget::Structure::update(KileDocument::Info *, bool) instead
	 **/
	virtual void updateStruct();
	virtual void updateBibItems();

signals:
	void urlChanged(KileDocument::Info* info, const KURL& url);
	void isrootChanged(bool);

	void foundItem(const TQString &title, uint line, uint column, int type, int level, uint startline, uint startcol,
	               const TQString & pix, const TQString & folder);
	void doneUpdating();
	void depChanged();
	void completed(KileDocument::Info* info);

protected slots:
	void slotCompleted();

protected:
	void count(const TQString line, long *stat);

protected:
	enum State
	{
		stStandard=0, stComment=1, stControlSequence=3, stControlSymbol=4,
	 	stCommand=5,stEnvironment=6
	};

protected:
	bool						m_bIsRoot;
	TQStringList					m_labels;
	TQStringList					m_bibItems;
	TQStringList					m_deps, m_depsPrev;
	TQStringList					m_bibliography;
	TQStringList					m_packages;
	TQStringList					m_newCommands;
	TQString						m_preamble;
	TQMap<TQString,KileStructData>			m_dictStructLevel;
	KURL						m_url;
	TDEConfig						*m_config;
	bool m_showStructureLabels;
	bool m_showStructureBibitems;
	bool m_showStructureGraphics;
	bool m_showStructureFloats;
	bool m_showStructureReferences;
	bool m_showStructureInputFiles;
	bool m_showStructureTodo;
	bool m_showSectioningLabels;
	bool m_openStructureLabels;
	bool m_openStructureReferences;
	bool m_openStructureBibitems;
	bool m_openStructureTodo;
	KURL						m_baseDirectory;
	bool						documentTypePromotionAllowed;
	Extensions *m_extensions;
};


/**
 * The URL of a text document is managed directly by the corresponding Kate::Document.
 **/
class TextInfo : public Info
{
	TQ_OBJECT
  
public:
	/**
	 * @param defaultHighlightMode the highlight mode that will be set automatically
	 *                             once a new document is installed
	 **/
	TextInfo(Kate::Document *doc, Extensions *extensions, const TQString& defaultHighlightMode = TQString());
	virtual ~TextInfo();

	/**
	 * @returns the document for which this class is a decorator
	 **/
	const Kate::Document* getDoc() const;
	Kate::Document* getDoc();
	void setDoc(Kate::Document *doc);
	void detach();

	/**
	 * Used by @ref KileDocInfoDlg to display statistics of the Document.
	 * @returns an array with some statistical data of the document.
	 * The array is filled as follows: [0] = #c in words, [1] = #c in latex commands and environments,
	   [2] = #c whitespace, [3] = #words, [4] = # latex_commands, [5] = latex_environments **/

	virtual const long* getStatistics();

	/**
	 * @returns the URL of the Kate::Document.
	 **/
	virtual KURL url();

	virtual Type getType();

	bool isTextDocument();

	void setHighlightMode(const TQString & highlight = TQString());

	void setDefaultHightlightMode(const TQString& string);

	/**
	 * "Overridden" method that installs custom event filters by using the "installEventFilters"
	 * method.
	 * @warning Only this method should be used to create new views for text documents !
	 * @return NULL if no document is set (m_doc == NULL)
	 **/
	KTextEditor::View* createView(TQWidget *parent, const char *name=0);

protected slots:
	void slotFileNameChanged();

protected:
	Kate::Document			*m_doc;
	long				*m_arStatistics;
	TQString				m_defaultHighlightMode;

	TQString matchBracket(TQChar c, uint &, uint &);
	TQString getTextline(uint line, TodoResult &todo);
	void searchTodoComment(const TQString &s, uint startpos, TodoResult &todo);

	/**
	 * Installs an event filter on a view. Subclasses can override this method to
	 * provide custom event filters. The default implementation does nothing. Whenever this
	 * method is overridden, "removeInstalledEventFilters" should be overridden as well.
	 * @param view the view that is considered
	 **/
	virtual void installEventFilters(KTextEditor::View *view);

	/**
	 * Removes the event filters that were previously installed by the "installEventFilters"
	 * function. Subclasses can override this method to remove custom event filters. The
	 * default implementation does nothing.
	 * @param view the view that is considered
	 **/
	virtual void removeInstalledEventFilters(KTextEditor::View *view);

	/**
	 * Installs the event filters on all the views that are currently open for the
	 * managed document object. The function "installEventFilters(KTextEditor::View *view)
	 * function is used for a specific view.
	 **/
	void installEventFilters();

	/**
	 * Removes the event filters from all the views that are currently open for the
	 * managed document object. The function "removeInstalledEventFilters(KTextEditor::View *view)
	 * function is used for a specific view.
	 **/
	void removeInstalledEventFilters();
};



class LaTeXInfo : public TextInfo
{
	TQ_OBJECT
  

public:
	/**
	 * @param eventFilter the event filter that will be installed on managed documents
	 **/
	LaTeXInfo(Kate::Document *doc, Extensions *extensions, LatexCommands *commands, const TQObject* eventFilter);
	virtual ~LaTeXInfo();

	virtual Type getType();

	virtual TQString getFileFilter() const;

public slots:
	virtual void updateStruct();

protected:
	LatexCommands *m_commands;
	const TQObject *m_eventFilter;

	virtual void updateStructLevelInfo();
	virtual void checkChangedDeps();
	/**
	 * Installs a custom event filter.
	 **/
	virtual void installEventFilters(KTextEditor::View *view);

	/**
	 * Revmoves the custom event filter.
	 **/
	virtual void removeInstalledEventFilters(KTextEditor::View *view);

private:
	BracketResult matchBracket(uint &, uint &);
};



class BibInfo : public TextInfo
{
	TQ_OBJECT
  

public:
	BibInfo (Kate::Document *doc, Extensions *extensions, LatexCommands* commands);
	virtual ~BibInfo();

	virtual bool isLaTeXRoot();

	virtual Type getType();

	virtual TQString getFileFilter() const;

public slots:
	virtual void updateStruct();
};

class ScriptInfo : public TextInfo
{
	TQ_OBJECT
  

public:
	ScriptInfo(Kate::Document *doc, Extensions *extensions);
	virtual ~ScriptInfo();

	virtual bool isLaTeXRoot();

	virtual Type getType();

	virtual TQString getFileFilter() const;
};

}
#endif