Support individual files and folders in log output.
[anjuta-git-plugin.git] / plugins / editor / aneditor-priv.h
blob145d795001d805f302a1e504a740374526f59b61
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 aneditor-priv.h
4 Copyright (C) 2004 Naba Kumar
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef __ANEDITOR_PRIV_H__
21 #define __ANEDITOR_PRIV_H__
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <stdlib.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <stdio.h>
31 #include <fcntl.h>
32 #include <stdarg.h>
33 #include <sys/stat.h>
34 #include <time.h>
35 #include <unistd.h>
36 #include <locale.h>
38 #include <gnome.h>
40 #define GTK
41 #include "Platform.h"
42 #include "PropSet.h"
43 #include "Accessor.h"
44 #include "WindowAccessor.h"
45 #include "KeyWords.h"
46 #include "Scintilla.h"
47 #include "ScintillaWidget.h"
48 #include "SciLexer.h"
49 #include "lexer.h"
50 #include "properties_cxx.h"
51 #include "properties.h"
52 #include "aneditor.h"
54 #include <libanjuta/resources.h>
56 #include "tm_tagmanager.h"
58 #include <string>
59 #include <memory>
61 using namespace std;
63 // #include "debugger.h"
65 #if 0
67 #include "sv_unknown.xpm"
68 #include "sv_class.xpm"
69 #include "sv_function.xpm"
70 #include "sv_macro.xpm"
71 #include "sv_private_fun.xpm"
72 #include "sv_private_var.xpm"
73 #include "sv_protected_fun.xpm"
74 #include "sv_protected_var.xpm"
75 #include "sv_public_fun.xpm"
76 #include "sv_public_var.xpm"
77 #include "sv_struct.xpm"
78 #include "sv_variable.xpm"
80 #endif
82 // #define DEBUG
84 #define ANE_MARKER_BOOKMARK 0
85 #define MAX_PATH 260
86 #define MAXIMUM(x, y) ((x>y)?x:y)
87 #define MINIMUM(x,y) ((x<y)?x:y)
89 #define MAX_AUTOCOMPLETE_WORDS 50 /* Maximum number of autocomplete words to show */
91 /* Colour has mysteriously vanished from scintilla */
92 /* Using the substitute */
93 typedef class ColourDesired Colour;
95 template<int sz>
96 class EntryMemory {
97 SString entries[sz];
98 public:
99 void Insert(SString s) {
100 for (int i=0;i<sz;i++) {
101 if (entries[i] == s) {
102 for (int j=i;j>0;j--) {
103 entries[j] = entries[j-1];
105 entries[0] = s;
106 return;
109 for (int k=sz-1;k>0;k--) {
110 entries[k] = entries[k-1];
112 entries[0] = s;
114 int Length() const {
115 int len = 0;
116 for (int i=0;i<sz;i++)
117 if (entries[i].length())
118 len++;
119 return len;
121 SString At(int n)const {
122 return entries[n];
126 typedef EntryMemory<10> ComboMemory;
128 struct StyleAndWords {
129 int styleNumber;
130 SString words;
131 bool IsEmpty() { return words.length() == 0; }
132 bool IsSingleChar() { return words.length() == 1; }
135 // will contain the parameters for the recursive function completion
136 typedef struct _CallTipNode {
137 int startCalltipWord;
138 int def_index;
139 int max_def;
140 SString functionDefinition[20];
141 int rootlen;
142 int start_pos; // start position in editor
143 int call_tip_start_pos; // start position in calltip
145 } CallTipNode, *CallTipNode_ptr;
147 // Related to Utf8_16::encodingType but with additional values at end
148 enum UniMode {
149 uni8Bit=0, uni16BE=1, uni16LE=2, uniUTF8=3,
150 uniCookie=4
153 // Codes representing the effect a line has on indentation.
154 enum IndentationStatus {
155 isNone, // no effect on indentation
156 isBlockStart, // indentation block begin such as "{" or VB "function"
157 isBlockEnd, // indentation end indicator such as "}" or VB "end"
158 isKeyWordStart // Keywords that cause indentation
161 class AnEditor {
163 protected:
164 char fileName[MAX_PATH+20]; // filename kept here temporarily
166 ComboMemory memFinds;
167 ComboMemory memReplaces;
168 ComboMemory memFiles;
170 int characterSet;
171 SString language;
172 int lexLanguage;
173 SString overrideExtension; // User has chosen to use a particular language
174 enum {numWordLists=5};
175 GtkAccelGroup* accelGroup;
177 int indentSize;
179 bool indentOpening;
180 bool indentClosing;
183 bool indentMaintain;
185 int statementLookback;
186 StyleAndWords statementIndent;
187 StyleAndWords statementEnd;
188 StyleAndWords blockStart;
189 StyleAndWords blockEnd;
190 enum { noPPC, ppcStart, ppcMiddle, ppcEnd, ppcDummy }; ///< Indicate the kind of preprocessor condition line
191 char preprocessorSymbol; ///< Preprocessor symbol (in C: #)
192 WordList preprocCondStart; ///< List of preprocessor conditional start keywords (in C: if ifdef ifndef)
193 WordList preprocCondMiddle; ///< List of preprocessor conditional middle keywords (in C: else elif)
194 WordList preprocCondEnd; ///< List of preprocessor conditional end keywords (in C: endif)
197 Window wEditor;
199 SciFnDirect fnEditor;
200 long ptrEditor;
201 SciFnDirect fnOutput;
202 long ptrOutput;
203 bool tbVisible;
204 bool tabVisible;
205 bool tabMultiLine;
206 bool sbVisible;
207 int visHeightTools;
208 int visHeightTab;
209 int visHeightStatus;
210 int visHeightEditor;
211 int heightBar;
213 int heightOutput;
214 int heightOutputStartDrag;
215 Point ptStartDrag;
216 bool capturedMouse;
217 bool firstPropertiesRead;
218 bool splitVertical;
219 bool bufferedDraw;
220 bool bracesCheck;
221 bool bracesSloppy;
222 int bracesStyle;
223 int braceCount;
224 SString sbValue;
225 bool wrapLine;
226 bool isReadOnly;
228 bool indentationWSVisible;
230 bool autoCompleteIgnoreCase;
231 bool callTipIgnoreCase;
232 bool autoCCausedByOnlyOne;
233 SString calltipWordCharacters;
234 SString calltipEndDefinition;
235 SString autoCompleteStartCharacters;
236 SString autoCompleteFillUpCharacters;
237 SString wordCharacters;
238 int startCalltipWord;
240 GQueue *call_tip_node_queue;
241 CallTipNode call_tip_node;
243 GCompletion *autocompletion;
245 // needed for calltips caret moving
246 int lastPos;
248 bool margin;
249 int marginWidth;
250 enum { marginWidthDefault = 20};
252 bool foldMargin;
253 int foldMarginWidth;
254 enum { foldMarginWidthDefault = 14};
256 bool lineNumbers;
257 int lineNumbersWidth;
258 enum { lineNumbersWidthDefault = 40};
260 bool usePalette;
261 bool clearBeforeExecute;
262 bool allowMenuActions;
263 bool isDirty;
265 bool calltipShown;
266 //bool debugTipOn;
267 static AnEditorID focusedID;
268 friend void aneditor_set_focused_ed_ID(AnEditorID id);
269 //friend void eval_output_arrived_for_aneditor(GList* lines, gpointer data);
271 PropSetFile *props;
273 int LengthDocument();
274 int GetCaretInLine();
275 void GetLine(SString & text, int line = -1);
276 int GetFullLine(SString & text, int line = -1);
277 void GetRange(Window &win, int start, int end, char *text);
279 int IsLinePreprocessorCondition(const char *line);
280 bool FindMatchingPreprocessorCondition(int &curLine, int direction,
281 int condEnd1, int condEnd2);
282 bool FindMatchingPreprocCondPosition(bool isForward, int &mppcAtCaret,
283 int &mppcMatch);
285 bool FindMatchingBracePosition(bool editor, int &braceAtCaret,
286 int &braceOpposite, bool sloppy);
287 void BraceMatch(bool editor);
289 bool GetCurrentWord(char* buffer, int maxlength);
290 bool GetWordBeforeCarat(char* buffer, int maxlength);
292 bool FindWordInRegion(char *buffer, int maxlength, SString &linebuf,
293 int current);
294 bool GetWordAtPosition(char* buffer, int maxlength, int pos);
296 void IndentationIncrease();
297 void IndentationDecrease();
299 void ClearDocument();
300 void CountLineEnds(int &linesCR, int &linesLF, int &linesCRLF);
301 CharacterRange GetSelection();
302 void SelectionWord(char *word, int len);
303 void WordSelect();
304 void LineSelect();
305 void SelectionIntoProperties();
306 long Find (long flags, char* text);
307 bool HandleXml(char ch);
308 SString FindOpenXmlTag(const char sel[], int nSize);
309 void GoMatchingBrace(bool select);
310 void GetRange(guint start, guint end, gchar *text, gboolean styled);
311 bool StartCallTip_new();
312 void ContinueCallTip_new();
313 void SaveCallTip();
314 void ResumeCallTip(bool pop_from_stack = true);
315 void ShutDownCallTip();
316 void SetCallTipDefaults( );
317 void CompleteCallTip();
319 // TMTag ** FindTypeInLocalWords(GPtrArray *CurrentFileTags, const char *root,
320 // const bool type, int *retptr, int *count);
321 //bool SendAutoCompleteRecordsFields(const GPtrArray *CurrentFileTags,
322 // const char *ScanType);
323 // bool StartAutoCompleteRecordsFields(char ch);
324 // bool StartAutoComplete();
325 // bool StartAutoCompleteWord(int autoShowCount);
326 bool StartBlockComment();
327 bool CanBeCommented(bool box_stream);
328 bool StartBoxComment();
329 bool StartStreamComment();
330 // SString GetMode(SString language);
331 // bool InsertCustomIndent();
333 // unsigned int GetLinePartsInStyle(int line, int style1, int style2,
334 // SString sv[], int len);
335 void SetLineIndentation(int line, int indent);
336 int GetLineIndentation(int line);
337 int GetLineIndentPosition(int line);
338 // IndentationStatus GetIndentState(int line);
339 // int IndentOfBlockProper(int line);
340 // int IndentOfBlock(int line);
341 void MaintainIndentation(char ch);
342 // void AutomaticIndentation(char ch);
343 void CharAdded(char ch);
344 void FoldChanged(int line, int levelNow, int levelPrev);
345 void FoldChanged(int position);
346 void Expand(int &line, bool doExpand, bool force=false,
347 int visLevels=0, int level=-1);
348 bool MarginClick(int position,int modifiers);
349 //void HandleDwellStart(int mousePos);
350 void Notify(SCNotification *notification);
351 static void NotifySignal(GtkWidget *w, gint wParam, gpointer lParam,
352 AnEditor *scitew);
354 int KeyPress (unsigned int state, unsigned int keyval);
355 static gint KeyPressEvent(GtkWidget *w, GdkEventKey *event,
356 AnEditor *editor);
358 void BookmarkToggle( int lineno = -1 );
359 void BookmarkFirst();
360 void BookmarkPrev();
361 void BookmarkNext();
362 void BookmarkLast();
363 void BookmarkClear();
365 void AssignKey(int key, int mods, int cmd);
366 StyleAndWords GetStyleAndWords(const char *base);
367 void SetOneStyle(Window &win, int style, const char *s);
368 void SetStyleFor(Window &win, const char *language);
369 SString ExtensionFileName();
370 void Command(int command, unsigned long wParam, long lparam);
371 void ForwardPropertyToEditor(const char *key);
372 SString FindLanguageProperty(const char *pattern,
373 const char *defaultValue="");
374 void ReadPropertiesInitial();
375 void ReadProperties(const char* fileForExt);
376 long SendEditor(unsigned int msg, unsigned long wParam=0, long lParam=0);
377 long SendEditorString(unsigned int msg, unsigned long wParam,
378 const char *s);
379 void SetOverrideLanguage(int ID);
380 void ViewWhitespace(bool view);
381 bool RangeIsAllWhitespace(int start, int end);
382 void SaveToHTML(const char *saveName);
383 void SaveToRTF(const char *saveName);
384 void SetSelection(int anchor, int currentPos);
385 int GetLineLength(int line);
386 int GetCurrentLineNumber();
387 int GetCurrentScrollPosition();
388 void FoldOpenAll();
389 void FoldCloseAll();
390 void FoldCode(bool expanding);
391 void FoldToggle();
392 void SelectBlock ();
393 int GetBlockStartLine(int lineno = -1);
394 int GetBlockEndLine(int lineno = -1);
395 void GotoBlockStart();
396 void GotoBlockEnd();
397 void EnsureRangeVisible(int posStart, int posEnd);
398 void SetAccelGroup(GtkAccelGroup* acl);
399 int GetBookmarkLine( const int nLineStart );
400 void DefineMarker(int marker, int makerType, Colour fore, Colour back);
401 void SetLineWrap(bool wrap);
402 void SetReadOnly(bool readonly);
403 void SetFoldSymbols(SString fold_symbols);
404 bool iswordcharforsel(char ch);
406 public:
408 AnEditor(PropSetFile* p);
409 ~AnEditor();
410 WindowID GetID() { return wEditor.GetID(); }
411 long Command(int cmdID, long wParam, long lParam);
413 void FocusInEvent(GtkWidget* widget);
414 void FocusOutEvent(GtkWidget* widget);
416 void EvalOutputArrived(GList* lines, int textPos,
417 const string &expression);
418 void EndDebugEval();
420 void SetParent(AnEditor *parent);
423 class ExpressionEvaluationTipInfo
424 // Utility class to help displaying expression values in tips.
426 public:
427 AnEditor *editor;
428 int textPos;
429 string expression;
431 ExpressionEvaluationTipInfo(AnEditor *e, int pos, const string &expr)
432 : editor(e), textPos(pos), expression(expr) {}
435 #endif