Revision: 5431 http://geany.svn.sourceforge.net/geany/?rev=5431&view=rev Author: ntrel Date: 2010-11-23 17:25:58 +0000 (Tue, 23 Nov 2010)
Log Message: ----------- Add editor_get_prefs() instead of editor_get_long_line_*() functions. This general function can be extended to support various project and document overrides.
Modified Paths: -------------- trunk/ChangeLog trunk/src/editor.c trunk/src/editor.h trunk/src/keybindings.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-11-23 16:23:22 UTC (rev 5430) +++ trunk/ChangeLog 2010-11-23 17:25:58 UTC (rev 5431) @@ -15,6 +15,10 @@ doc/geany.html: Add gio_unsafe_save_backup hidden pref (patch by Lex Trotman, thanks). + * src/keybindings.c, src/editor.c, src/editor.h: + Add editor_get_prefs() instead of editor_get_long_line_*() + functions. This general function can be extended to support + various project and document overrides.
2010-11-22 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2010-11-23 16:23:22 UTC (rev 5430) +++ trunk/src/editor.c 2010-11-23 17:25:58 UTC (rev 5431) @@ -373,7 +373,7 @@ }
-gint editor_get_long_line_type(void) +static gint editor_get_long_line_type(void) { if (app->project) switch (app->project->long_line_behaviour) @@ -393,7 +393,7 @@ }
-gint editor_get_long_line_column(void) +static gint editor_get_long_line_column(void) { if (app->project && app->project->long_line_behaviour != 1 /* use global settings */) return app->project->long_line_column; @@ -402,6 +402,44 @@ }
+static const GeanyEditorPrefs * +get_default_prefs(void) +{ + static GeanyEditorPrefs eprefs; + + eprefs = editor_prefs; + + /* project overrides */ + eprefs.indentation = (GeanyIndentPrefs*)editor_get_indent_prefs(NULL); + eprefs.long_line_global_type = editor_get_long_line_type(); + eprefs.long_line_global_column = editor_get_long_line_column(); + return &eprefs; +} + + +/* Gets the prefs for the editor. + * Prefs can be different according to project or filetype. + * @warning Always get a fresh result instead of keeping a pointer to it if the editor/project + * settings may have changed, or if this function has been called for a different editor. + * @param editor The editor, or @c NULL to get the default prefs. + * @return The prefs. */ +const GeanyEditorPrefs *editor_get_prefs(GeanyEditor *editor) +{ + static GeanyEditorPrefs eprefs; + const GeanyEditorPrefs *dprefs = get_default_prefs(); + + /* Return the address of the default prefs to allow returning default and editor + * pref pointers without invalidating the contents of either. */ + if (editor == NULL) + return dprefs; + + eprefs = *dprefs; + eprefs.indentation = (GeanyIndentPrefs*)editor_get_indent_prefs(editor); + /* add other editor & document overrides as needed */ + return &eprefs; +} + + void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers) { ScintillaObject *sci; @@ -1136,7 +1174,7 @@
/** Gets the indentation prefs for the editor. - * In future, the prefs might be different according to project or filetype. + * Prefs can be different according to project or filetype. * @warning Always get a fresh result instead of keeping a pointer to it if the editor/project * settings may have changed, or if this function has been called for a different editor. * @param editor The editor, or @c NULL to get the default indent prefs.
Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2010-11-23 16:23:22 UTC (rev 5430) +++ trunk/src/editor.h 2010-11-23 17:25:58 UTC (rev 5431) @@ -104,14 +104,14 @@ * Some of these can be overridden per document or per project. */ typedef struct GeanyEditorPrefs { - GeanyIndentPrefs *indentation; /*< Default indentation prefs. @see editor_get_indent_prefs(). */ + GeanyIndentPrefs *indentation; /* Default indentation prefs. Use editor_get_indent_prefs(). */ gboolean show_white_space; gboolean show_indent_guide; gboolean show_line_endings; - /* 0 - line, 1 - background. This setting may be overriden when a project is opened. Use - * @c editor_get_long_line_type(). */ + /* 0 - line, 1 - background, 2 - disabled. + * This setting may be overriden when a project is opened. Use @c editor_get_prefs(). */ gint long_line_global_type; - /* This setting may be overriden when a project is opened. Use @c editor_get_long_line_column(). */ + /* This setting may be overriden when a project is opened. Use @c editor_get_prefs(). */ gint long_line_global_column; gchar *long_line_color; gboolean show_markers_margin; /* view menu */ @@ -229,10 +229,8 @@
void editor_snippets_free(void);
-/* 0 - line, 1 - background, 2 - disabled */ -gint editor_get_long_line_type(void); +const GeanyEditorPrefs *editor_get_prefs(GeanyEditor *editor);
-gint editor_get_long_line_column(void);
/* General editing functions */
Modified: trunk/src/keybindings.c =================================================================== --- trunk/src/keybindings.c 2010-11-23 16:23:22 UTC (rev 5430) +++ trunk/src/keybindings.c 2010-11-23 17:25:58 UTC (rev 5431) @@ -2321,16 +2321,17 @@ ScintillaObject *sci = editor->sci; gboolean sel; gint column = -1; + const GeanyEditorPrefs *eprefs = editor_get_prefs(editor);
if (editor->line_breaking) { /* use line break column if enabled */ - column = editor_prefs.line_break_column; + column = eprefs->line_break_column; } - else if (editor_get_long_line_type() != 2) + else if (eprefs->long_line_global_type != 2) { /* use long line if enabled */ - column = editor_get_long_line_column(); + column = eprefs->long_line_global_column; } else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.