Add editor_get_prefs() instead of editor_get_long_line_*()

functions. This general function can be extended to support
various project and document overrides.



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5431 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2010-11-23 17:25:58 +00:00
parent 3a3d8815a3
commit a29d75af2c
4 changed files with 54 additions and 13 deletions

View File

@ -15,6 +15,10 @@
doc/geany.html: doc/geany.html:
Add gio_unsafe_save_backup hidden pref (patch by Lex Trotman, Add gio_unsafe_save_backup hidden pref (patch by Lex Trotman,
thanks). 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> 2010-11-22 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

View File

@ -373,7 +373,7 @@ static gboolean is_style_php(gint style)
} }
gint editor_get_long_line_type(void) static gint editor_get_long_line_type(void)
{ {
if (app->project) if (app->project)
switch (app->project->long_line_behaviour) switch (app->project->long_line_behaviour)
@ -393,7 +393,7 @@ gint editor_get_long_line_type(void)
} }
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 */) if (app->project && app->project->long_line_behaviour != 1 /* use global settings */)
return app->project->long_line_column; return app->project->long_line_column;
@ -402,6 +402,44 @@ gint editor_get_long_line_column(void)
} }
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) void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers)
{ {
ScintillaObject *sci; ScintillaObject *sci;
@ -1136,7 +1174,7 @@ get_default_indent_prefs(void)
/** Gets the indentation prefs for the editor. /** 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 * @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. * 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. * @param editor The editor, or @c NULL to get the default indent prefs.

View File

@ -104,14 +104,14 @@ GeanyIndentPrefs;
* Some of these can be overridden per document or per project. */ * Some of these can be overridden per document or per project. */
typedef struct GeanyEditorPrefs 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_white_space;
gboolean show_indent_guide; gboolean show_indent_guide;
gboolean show_line_endings; gboolean show_line_endings;
/* 0 - line, 1 - background. This setting may be overriden when a project is opened. Use /* 0 - line, 1 - background, 2 - disabled.
* @c editor_get_long_line_type(). */ * This setting may be overriden when a project is opened. Use @c editor_get_prefs(). */
gint long_line_global_type; 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; gint long_line_global_column;
gchar *long_line_color; gchar *long_line_color;
gboolean show_markers_margin; /* view menu */ gboolean show_markers_margin; /* view menu */
@ -229,10 +229,8 @@ void editor_snippets_init(void);
void editor_snippets_free(void); void editor_snippets_free(void);
/* 0 - line, 1 - background, 2 - disabled */ const GeanyEditorPrefs *editor_get_prefs(GeanyEditor *editor);
gint editor_get_long_line_type(void);
gint editor_get_long_line_column(void);
/* General editing functions */ /* General editing functions */

View File

@ -2321,16 +2321,17 @@ static void reflow_paragraph(GeanyEditor *editor)
ScintillaObject *sci = editor->sci; ScintillaObject *sci = editor->sci;
gboolean sel; gboolean sel;
gint column = -1; gint column = -1;
const GeanyEditorPrefs *eprefs = editor_get_prefs(editor);
if (editor->line_breaking) if (editor->line_breaking)
{ {
/* use line break column if enabled */ /* 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 */ /* use long line if enabled */
column = editor_get_long_line_column(); column = eprefs->long_line_global_column;
} }
else else
{ {