1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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"
30 #include "Scintilla.h"
32 #include "ScintillaWidget.h"
37 /* Editor preferences notifications */
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);
55 pd
->key
= g_strdup (key
);
57 pd
->is_string
= is_string
;
65 pref_gconf_notify (GConfClient
*gclient
, guint cnxn_id
,
66 GConfEntry
*entry
, gpointer user_data
)
68 PrefPassedData
*pd
= (PrefPassedData
*)user_data
;
70 set_n_get_prop_int (pd
->te
, pd
->key
);
72 set_n_get_prop_string (pd
->te
, pd
->key
);
74 (pd
->proxy
)(data1
, data2
, data3
, data4
);
80 set_n_get_prop_int (TextEditor
*te
, const gchar
*key
)
83 AnjutaPreferences
*pr
;
85 val
= anjuta_preferences_get_int (pr
, key
);
86 sci_prop_set_int_with_key (text_editor_get_props (), key
, val
);
91 set_n_get_prop_string (TextEditor
*te
, const gchar
*key
)
94 AnjutaPreferences
*pr
;
96 val
= anjuta_preferences_get (pr
, key
);
97 sci_prop_set_with_key (text_editor_get_props (), key
, val
);
102 on_gconf_notify_disable_hilite (GConfClient
*gclient
, guint cnxn_id
,
103 GConfEntry
*entry
, gpointer user_data
)
107 te
= TEXT_EDITOR (user_data
);
108 set_n_get_prop_int (te
, DISABLE_SYNTAX_HILIGHTING
);
109 text_editor_hilite (te
, TRUE
);
113 on_gconf_notify_zoom_factor (GConfClient
*gclient
, guint cnxn_id
,
114 GConfEntry
*entry
, gpointer user_data
)
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
);
125 on_gconf_notify_tab_size (GConfClient
*gclient
, guint cnxn_id
,
126 GConfEntry
*entry
, gpointer user_data
)
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);
137 on_gconf_notify_use_tab_for_indentation (GConfClient
*gclient
, guint cnxn_id
,
138 GConfEntry
*entry
, gpointer user_data
)
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);
151 on_gconf_notify_automatic_indentation (GConfClient
*gclient
, guint cnxn_id
,
152 GConfEntry
*entry
, gpointer user_data
)
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);
164 on_gconf_notify_indent_size (GConfClient
*gclient
, guint cnxn_id
,
165 GConfEntry
*entry
, gpointer user_data
)
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);
176 on_gconf_notify_wrap_bookmarks (GConfClient
*gclient
, guint cnxn_id
,
177 GConfEntry
*entry
, gpointer user_data
)
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);
188 on_gconf_notify_braces_check (GConfClient
*gclient
, guint cnxn_id
,
189 GConfEntry
*entry
, gpointer user_data
)
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);
201 on_gconf_notify_indent_opening (GConfClient
*gclient
, guint cnxn_id
,
202 GConfEntry
*entry
, gpointer user_data
)
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);
213 on_gconf_notify_indent_closing (GConfClient
*gclient
, guint cnxn_id
,
214 GConfEntry
*entry
, gpointer user_data
)
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);
227 on_gconf_notify_indent_maintain (GConfClient
*gclient
, guint cnxn_id
,
228 GConfEntry
*entry
, gpointer user_data
)
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);
239 on_gconf_notify_tab_indents (GConfClient
*gclient
, guint cnxn_id
,
240 GConfEntry
*entry
, gpointer user_data
)
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);
251 on_gconf_notify_backspace_unindents (GConfClient
*gclient
, guint cnxn_id
,
252 GConfEntry
*entry
, gpointer user_data
)
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);
263 on_gconf_notify_view_eols (GConfClient
*gclient
, guint cnxn_id
,
264 GConfEntry
*entry
, gpointer user_data
)
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);
275 on_gconf_notify_view_whitespaces (GConfClient
*gclient
, guint cnxn_id
,
276 GConfEntry
*entry
, gpointer user_data
)
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);
287 on_gconf_notify_view_linewrap (GConfClient
*gclient
, guint cnxn_id
,
288 GConfEntry
*entry
, gpointer user_data
)
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);
299 on_gconf_notify_view_indentation_guides (GConfClient
*gclient
, guint cnxn_id
,
300 GConfEntry
*entry
, gpointer user_data
)
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);
311 on_gconf_notify_view_folds (GConfClient
*gclient
, guint cnxn_id
,
312 GConfEntry
*entry
, gpointer user_data
)
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);
323 on_gconf_notify_view_markers (GConfClient
*gclient
, guint cnxn_id
,
324 GConfEntry
*entry
, gpointer user_data
)
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);
335 on_gconf_notify_view_linenums (GConfClient
*gclient
, guint cnxn_id
,
336 GConfEntry
*entry
, gpointer user_data
)
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); */
348 on_gconf_notify_fold_symbols (GConfClient
*gclient
, guint cnxn_id
,
349 GConfEntry
*entry
, gpointer user_data
)
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);
361 on_gconf_notify_fold_underline (GConfClient
*gclient
, guint cnxn_id
,
362 GConfEntry
*entry
, gpointer user_data
)
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);
373 on_gconf_notify_edge_column (GConfClient
*gclient
, guint cnxn_id
,
374 GConfEntry
*entry
, gpointer user_data
)
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));
391 text_editor_prefs_init (TextEditor
*te
)
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
);
413 sci_prop_set_int_with_key (te
->props_base
, INDENT_MAINTAIN
".*", 1);
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
);
460 text_editor_prefs_finalize (TextEditor
*te
)
463 node
= te
->gconf_notify_ids
;
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
;