Support individual files and folders in log output.
[anjuta-git-plugin.git] / plugins / editor / text_editor_prefs.c
blobe5ea1cbdcd9cdf253ce3a35517107ef56b5a84da
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 prefs.c
4 Copyright (C) 2000 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 #include <libanjuta/anjuta-preferences.h>
21 #include <libanjuta/anjuta-debug.h>
23 #include "properties.h"
24 #include "text_editor_prefs.h"
25 #include "text_editor_cbs.h"
27 #define GTK
28 #undef PLAT_GTK
29 #define PLAT_GTK 1
30 #include "Scintilla.h"
31 #include "SciLexer.h"
32 #include "ScintillaWidget.h"
34 #include "lexer.h"
35 #include "aneditor.h"
37 /* Editor preferences notifications */
39 #if 0
41 typedef {
42 TextEditor *te;
43 gchar *key;
44 GCallback proxy;
45 gpointer proxy_data;
46 gboolean is_string;
47 } PrefPassedData;
49 static PrefPassedData*
50 pref_passed_data_new (TextEditor *te, const gchar *key, gboolean is_string,
51 GCallback *proxy, gponter proxy_data)
53 PrefPassedData *pd = g_new0(PrefPassedData, 1);
54 pd->te = te;
55 pd->key = g_strdup (key);
56 pd->proxy = proxy;
57 pd->is_string = is_string;
58 pd->data1 = data1;
59 pd->data2 = data2;
60 pd->data3 = data3;
61 pd->data4 = data4;
64 static void
65 pref_gconf_notify (GConfClient *gclient, guint cnxn_id,
66 GConfEntry *entry, gpointer user_data)
68 PrefPassedData *pd = (PrefPassedData*)user_data;
69 if (!is_string)
70 set_n_get_prop_int (pd->te, pd->key);
71 else
72 set_n_get_prop_string (pd->te, pd->key);
73 if (pd->proxy)
74 (pd->proxy)(data1, data2, data3, data4);
77 #endif
79 static gint
80 set_n_get_prop_int (TextEditor *te, const gchar *key)
82 gint val;
83 AnjutaPreferences *pr;
84 pr = te->preferences;
85 val = anjuta_preferences_get_int (pr, key);
86 sci_prop_set_int_with_key (text_editor_get_props (), key, val);
87 return val;
90 static gchar *
91 set_n_get_prop_string (TextEditor *te, const gchar *key)
93 gchar *val;
94 AnjutaPreferences *pr;
95 pr = te->preferences;
96 val = anjuta_preferences_get (pr, key);
97 sci_prop_set_with_key (text_editor_get_props (), key, val);
98 return val;
101 static void
102 on_gconf_notify_disable_hilite (GConfClient *gclient, guint cnxn_id,
103 GConfEntry *entry, gpointer user_data)
105 TextEditor *te;
107 te = TEXT_EDITOR (user_data);
108 set_n_get_prop_int (te, DISABLE_SYNTAX_HILIGHTING);
109 text_editor_hilite (te, TRUE);
112 static void
113 on_gconf_notify_zoom_factor (GConfClient *gclient, guint cnxn_id,
114 GConfEntry *entry, gpointer user_data)
116 TextEditor *te;
117 gint zoom_factor;
119 te = TEXT_EDITOR (user_data);
120 zoom_factor = set_n_get_prop_int (te, TEXT_ZOOM_FACTOR);
121 text_editor_set_zoom_factor (te, zoom_factor);
124 static void
125 on_gconf_notify_tab_size (GConfClient *gclient, guint cnxn_id,
126 GConfEntry *entry, gpointer user_data)
128 TextEditor *te;
129 gint tab_size;
131 te = TEXT_EDITOR (user_data);
132 tab_size = set_n_get_prop_int (te, TAB_SIZE);
133 text_editor_command (te, ANE_SETTABSIZE, tab_size, 0);
136 static void
137 on_gconf_notify_use_tab_for_indentation (GConfClient *gclient, guint cnxn_id,
138 GConfEntry *entry, gpointer user_data)
140 TextEditor *te;
141 gboolean use_tabs;
143 te = TEXT_EDITOR (user_data);
144 use_tabs = set_n_get_prop_int (te, USE_TABS);
145 text_editor_command (te, ANE_SETUSETABFORINDENT, use_tabs, 0);
146 // text_editor_scintilla_command (te, SCI_SETTABWIDTH, use_tabs, 0);
149 #if 0
150 static void
151 on_gconf_notify_automatic_indentation (GConfClient *gclient, guint cnxn_id,
152 GConfEntry *entry, gpointer user_data)
154 TextEditor *te;
155 gboolean indent_automatic;
157 te = TEXT_EDITOR (user_data);
158 indent_automatic = set_n_get_prop_int (te, INDENT_AUTOMATIC);
159 text_editor_command (te, ANE_SETAUTOINDENTATION, indent_automatic, 0);
161 #endif
163 static void
164 on_gconf_notify_indent_size (GConfClient *gclient, guint cnxn_id,
165 GConfEntry *entry, gpointer user_data)
167 TextEditor *te;
168 gint indent_size;
170 te = TEXT_EDITOR (user_data);
171 indent_size = set_n_get_prop_int (te, INDENT_SIZE);
172 text_editor_command (te, ANE_SETINDENTSIZE, indent_size, 0);
175 static void
176 on_gconf_notify_wrap_bookmarks (GConfClient *gclient, guint cnxn_id,
177 GConfEntry *entry, gpointer user_data)
179 TextEditor *te;
180 gboolean state;
182 te = TEXT_EDITOR (user_data);
183 state = set_n_get_prop_int (te, WRAP_BOOKMARKS);
184 text_editor_command (te, ANE_SETWRAPBOOKMARKS, state, 0);
187 static void
188 on_gconf_notify_braces_check (GConfClient *gclient, guint cnxn_id,
189 GConfEntry *entry, gpointer user_data)
191 TextEditor *te;
192 gboolean state;
194 te = TEXT_EDITOR (user_data);
195 state = set_n_get_prop_int (te, BRACES_CHECK);
196 text_editor_command (te, ANE_SETINDENTBRACESCHECK, state, 0);
199 #if 0
200 static void
201 on_gconf_notify_indent_opening (GConfClient *gclient, guint cnxn_id,
202 GConfEntry *entry, gpointer user_data)
204 TextEditor *te;
205 gboolean state;
207 te = TEXT_EDITOR (user_data);
208 state = set_n_get_prop_int (te, INDENT_OPENING);
209 text_editor_command (te, ANE_SETINDENTOPENING, state, 0);
212 static void
213 on_gconf_notify_indent_closing (GConfClient *gclient, guint cnxn_id,
214 GConfEntry *entry, gpointer user_data)
216 TextEditor *te;
217 gboolean state;
219 te = TEXT_EDITOR (user_data);
220 state = set_n_get_prop_int (te, INDENT_CLOSING);
221 text_editor_command (te, ANE_SETINDENTCLOSING, state, 0);
224 #endif
226 static void
227 on_gconf_notify_indent_maintain (GConfClient *gclient, guint cnxn_id,
228 GConfEntry *entry, gpointer user_data)
230 TextEditor *te;
231 gboolean state;
233 te = TEXT_EDITOR (user_data);
234 state = set_n_get_prop_int (te, INDENT_MAINTAIN);
235 text_editor_command (te, ANE_SETINDENTMAINTAIN, state, 0);
238 static void
239 on_gconf_notify_tab_indents (GConfClient *gclient, guint cnxn_id,
240 GConfEntry *entry, gpointer user_data)
242 TextEditor *te;
243 gboolean state;
245 te = TEXT_EDITOR (user_data);
246 state = set_n_get_prop_int (te, TAB_INDENTS);
247 text_editor_command (te, ANE_SETTABINDENTS, state, 0);
250 static void
251 on_gconf_notify_backspace_unindents (GConfClient *gclient, guint cnxn_id,
252 GConfEntry *entry, gpointer user_data)
254 TextEditor *te;
255 gboolean state;
257 te = TEXT_EDITOR (user_data);
258 state = set_n_get_prop_int (te, BACKSPACE_UNINDENTS);
259 text_editor_command (te, ANE_SETBACKSPACEUNINDENTS, state, 0);
262 static void
263 on_gconf_notify_view_eols (GConfClient *gclient, guint cnxn_id,
264 GConfEntry *entry, gpointer user_data)
266 TextEditor *te;
267 gboolean state;
269 te = TEXT_EDITOR (user_data);
270 state = set_n_get_prop_int (te, VIEW_EOL);
271 text_editor_command (te, ANE_VIEWEOL, state, 0);
274 static void
275 on_gconf_notify_view_whitespaces (GConfClient *gclient, guint cnxn_id,
276 GConfEntry *entry, gpointer user_data)
278 TextEditor *te;
279 gboolean state;
281 te = TEXT_EDITOR (user_data);
282 state = set_n_get_prop_int (te, VIEW_WHITE_SPACES);
283 text_editor_command (te, ANE_VIEWSPACE, state, 0);
286 static void
287 on_gconf_notify_view_linewrap (GConfClient *gclient, guint cnxn_id,
288 GConfEntry *entry, gpointer user_data)
290 TextEditor *te;
291 gboolean state;
293 te = TEXT_EDITOR (user_data);
294 state = set_n_get_prop_int (te, VIEW_LINE_WRAP);
295 text_editor_command (te, ANE_LINEWRAP, state, 0);
298 static void
299 on_gconf_notify_view_indentation_guides (GConfClient *gclient, guint cnxn_id,
300 GConfEntry *entry, gpointer user_data)
302 TextEditor *te;
303 gboolean state;
305 te = TEXT_EDITOR (user_data);
306 state = set_n_get_prop_int (te, VIEW_INDENTATION_GUIDES);
307 text_editor_command (te, ANE_VIEWGUIDES, state, 0);
310 static void
311 on_gconf_notify_view_folds (GConfClient *gclient, guint cnxn_id,
312 GConfEntry *entry, gpointer user_data)
314 TextEditor *te;
315 gboolean state;
317 te = TEXT_EDITOR (user_data);
318 state = set_n_get_prop_int (te, VIEW_FOLD_MARGIN);
319 text_editor_command (te, ANE_FOLDMARGIN, state, 0);
322 static void
323 on_gconf_notify_view_markers (GConfClient *gclient, guint cnxn_id,
324 GConfEntry *entry, gpointer user_data)
326 TextEditor *te;
327 gboolean state;
329 te = TEXT_EDITOR (user_data);
330 state = set_n_get_prop_int (te, VIEW_MARKER_MARGIN);
331 text_editor_command (te, ANE_SELMARGIN, state, 0);
334 static void
335 on_gconf_notify_view_linenums (GConfClient *gclient, guint cnxn_id,
336 GConfEntry *entry, gpointer user_data)
338 TextEditor *te;
339 gboolean state;
341 te = TEXT_EDITOR (user_data);
342 state = set_n_get_prop_int (te, VIEW_LINENUMBERS_MARGIN);
343 text_editor_command (te, ANE_LINENUMBERMARGIN, state, 0);
344 /* text_editor_set_line_number_width (te); */
347 static void
348 on_gconf_notify_fold_symbols (GConfClient *gclient, guint cnxn_id,
349 GConfEntry *entry, gpointer user_data)
351 TextEditor *te;
352 gchar *symbols;
354 te = TEXT_EDITOR (user_data);
355 symbols = set_n_get_prop_string (te, FOLD_SYMBOLS);
356 text_editor_command (te, ANE_SETFOLDSYMBOLS, (long)symbols, 0);
357 g_free (symbols);
360 static void
361 on_gconf_notify_fold_underline (GConfClient *gclient, guint cnxn_id,
362 GConfEntry *entry, gpointer user_data)
364 TextEditor *te;
365 gboolean state;
367 te = TEXT_EDITOR (user_data);
368 state = set_n_get_prop_int (te, FOLD_UNDERLINE);
369 text_editor_command (te, ANE_SETFOLDUNDERLINE, state, 0);
372 static void
373 on_gconf_notify_edge_column (GConfClient *gclient, guint cnxn_id,
374 GConfEntry *entry, gpointer user_data)
376 TextEditor *te;
377 gint size;
379 te = TEXT_EDITOR (user_data);
380 size = set_n_get_prop_int (te, EDGE_COLUMN);
381 text_editor_command (te, ANE_SETEDGECOLUMN, size, 0);
384 #define REGISTER_NOTIFY(key, func) \
385 notify_id = anjuta_preferences_notify_add (te->preferences, \
386 key, func, te, NULL); \
387 te->gconf_notify_ids = g_list_prepend (te->gconf_notify_ids, \
388 GUINT_TO_POINTER (notify_id));
390 void
391 text_editor_prefs_init (TextEditor *te)
393 gint val;
394 guint notify_id;
396 /* Sync prefs from gconf to props */
397 set_n_get_prop_int (te, TAB_SIZE);
398 set_n_get_prop_int (te, TEXT_ZOOM_FACTOR);
399 set_n_get_prop_int (te, INDENT_SIZE);
400 set_n_get_prop_int (te, USE_TABS);
401 set_n_get_prop_int (te, DISABLE_SYNTAX_HILIGHTING);
402 /* set_n_get_prop_int (te, INDENT_AUTOMATIC); */
403 set_n_get_prop_int (te, WRAP_BOOKMARKS);
404 set_n_get_prop_int (te, BRACES_CHECK);
406 set_n_get_prop_int (te, INDENT_OPENING);
407 set_n_get_prop_int (te, INDENT_CLOSING);
410 /* This one is special */
411 val = set_n_get_prop_int (te, INDENT_MAINTAIN);
412 if (val)
413 sci_prop_set_int_with_key (te->props_base, INDENT_MAINTAIN".*", 1);
414 else
415 sci_prop_set_with_key (te->props_base, INDENT_MAINTAIN".*", "");
417 set_n_get_prop_int (te, TAB_INDENTS);
418 set_n_get_prop_int (te, BACKSPACE_UNINDENTS);
420 set_n_get_prop_int (te, VIEW_EOL);
421 set_n_get_prop_int (te, VIEW_LINE_WRAP);
422 set_n_get_prop_int (te, VIEW_WHITE_SPACES);
423 set_n_get_prop_int (te, VIEW_INDENTATION_GUIDES);
424 set_n_get_prop_int (te, VIEW_FOLD_MARGIN);
425 set_n_get_prop_int (te, VIEW_MARKER_MARGIN);
426 set_n_get_prop_int (te, VIEW_LINENUMBERS_MARGIN);
427 g_free (set_n_get_prop_string (te, FOLD_SYMBOLS));
428 set_n_get_prop_int (te, FOLD_UNDERLINE);
429 set_n_get_prop_int (te, EDGE_COLUMN);
431 /* Register gconf notifications */
432 REGISTER_NOTIFY (TAB_SIZE, on_gconf_notify_tab_size);
433 REGISTER_NOTIFY (TEXT_ZOOM_FACTOR, on_gconf_notify_zoom_factor);
434 REGISTER_NOTIFY (INDENT_SIZE, on_gconf_notify_indent_size);
435 REGISTER_NOTIFY (USE_TABS, on_gconf_notify_use_tab_for_indentation);
436 REGISTER_NOTIFY (DISABLE_SYNTAX_HILIGHTING, on_gconf_notify_disable_hilite);
437 /* REGISTER_NOTIFY (INDENT_AUTOMATIC, on_gconf_notify_automatic_indentation); */
438 REGISTER_NOTIFY (WRAP_BOOKMARKS, on_gconf_notify_wrap_bookmarks);
439 REGISTER_NOTIFY (BRACES_CHECK, on_gconf_notify_braces_check);
441 REGISTER_NOTIFY (INDENT_OPENING, on_gconf_notify_indent_opening);
442 REGISTER_NOTIFY (INDENT_CLOSING, on_gconf_notify_indent_closing);
444 REGISTER_NOTIFY (INDENT_MAINTAIN, on_gconf_notify_indent_maintain);
445 REGISTER_NOTIFY (TAB_INDENTS, on_gconf_notify_tab_indents);
446 REGISTER_NOTIFY (BACKSPACE_UNINDENTS, on_gconf_notify_backspace_unindents);
447 REGISTER_NOTIFY (VIEW_EOL, on_gconf_notify_view_eols);
448 REGISTER_NOTIFY (VIEW_LINE_WRAP, on_gconf_notify_view_linewrap);
449 REGISTER_NOTIFY (VIEW_WHITE_SPACES, on_gconf_notify_view_whitespaces);
450 REGISTER_NOTIFY (VIEW_INDENTATION_GUIDES, on_gconf_notify_view_indentation_guides);
451 REGISTER_NOTIFY (VIEW_FOLD_MARGIN, on_gconf_notify_view_folds);
452 REGISTER_NOTIFY (VIEW_MARKER_MARGIN, on_gconf_notify_view_markers);
453 REGISTER_NOTIFY (VIEW_LINENUMBERS_MARGIN, on_gconf_notify_view_linenums);
454 REGISTER_NOTIFY (FOLD_SYMBOLS, on_gconf_notify_fold_symbols);
455 REGISTER_NOTIFY (FOLD_UNDERLINE, on_gconf_notify_fold_underline);
456 REGISTER_NOTIFY (EDGE_COLUMN, on_gconf_notify_edge_column);
459 void
460 text_editor_prefs_finalize (TextEditor *te)
462 GList *node;
463 node = te->gconf_notify_ids;
464 while (node)
466 anjuta_preferences_notify_remove (te->preferences,
467 GPOINTER_TO_UINT (node->data));
468 node = g_list_next (node);
470 g_list_free (te->gconf_notify_ids);
471 te->gconf_notify_ids = NULL;