From e566aae6b2218eb1d3689340c3d9eebc0b96cbf4 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 2 Oct 2014 17:50:39 +0100 Subject: [PATCH] Add project prefs for line breaking column & multiline comments --- data/geany.glade | 152 ++++++++++++++++++++++++++++++++++++++----- src/editor.c | 19 +++--- src/editor.h | 7 +- src/project.c | 5 ++ src/projectprivate.h | 14 ++-- 5 files changed, 161 insertions(+), 36 deletions(-) diff --git a/data/geany.glade b/data/geany.glade index cb8cbd63..bc2c552b 100644 --- a/data/geany.glade +++ b/data/geany.glade @@ -8883,6 +8883,140 @@ False 5 10 + + + True + False + 0 + none + + + True + False + 12 + + + True + False + + + Line wrapping + True + True + False + Wrap the line at the window border and continue it on the next line. Note: line wrapping has a high performance cost for large documents so should be disabled on slow machines. + True + True + + + False + False + 0 + + + + + True + False + 12 + + + True + False + Line breaking column: + + + False + False + 0 + + + + + True + True + False + False + True + True + adjustment1 + 1 + True + + + False + True + 1 + + + + + False + True + 1 + + + + + + + + + + + + True + False + <b>Features</b> + True + + + + + False + True + 0 + + + + + True + False + 0 + none + + + True + False + 12 + + + Automatic continuation of multi-line comments + True + True + False + Continue automatically multi-line comments in languages like C, C++ and Java when a new line is entered inside such a comment + True + True + + + + + + + True + False + <b>Completions</b> + True + + + + + False + True + 1 + + True @@ -9026,23 +9160,7 @@ False True - 0 - - - - - Line wrapping - True - True - False - Wrap the line at the window border and continue it on the next line. Note: line wrapping has a high performance cost for large documents so should be disabled on slow machines. - True - True - - - False - False - 0 + 2 diff --git a/src/editor.c b/src/editor.c index 724488e7..91245b4b 100644 --- a/src/editor.c +++ b/src/editor.c @@ -404,11 +404,8 @@ static gint editor_get_long_line_column(void) } -static gboolean editor_get_line_wrapping(void) -{ - return app->project ? app->project->priv->line_wrapping : editor_prefs.line_wrapping; -} - +#define get_project_pref(id)\ + (app->project ? app->project->priv->id : editor_prefs.id) static const GeanyEditorPrefs * get_default_prefs(void) @@ -421,7 +418,9 @@ get_default_prefs(void) eprefs.indentation = (GeanyIndentPrefs*)editor_get_indent_prefs(NULL); eprefs.long_line_type = editor_get_long_line_type(); eprefs.long_line_column = editor_get_long_line_column(); - eprefs.line_wrapping = editor_get_line_wrapping(); + eprefs.line_wrapping = get_project_pref(line_wrapping); + eprefs.line_break_column = get_project_pref(line_break_column); + eprefs.auto_continue_multiline = get_project_pref(auto_continue_multiline); return &eprefs; } @@ -560,11 +559,11 @@ static void check_line_breaking(GeanyEditor *editor, gint pos) lstart = sci_get_position_from_line(sci, line); /* use column instead of position which might be different with multibyte characters */ - if (col < editor_prefs.line_break_column) + if (col < get_project_pref(line_break_column)) return; /* look for the last space before line_break_column */ - pos = MIN(pos, lstart + editor_prefs.line_break_column); + pos = MIN(pos, lstart + get_project_pref(line_break_column)); while (pos > lstart) { @@ -1241,7 +1240,7 @@ static void on_new_line_added(GeanyEditor *editor) insert_indent_after_line(editor, line - 1); } - if (editor_prefs.auto_continue_multiline) + if (get_project_pref(auto_continue_multiline)) { /* " * " auto completion in multiline C/C++/D/Java comments */ auto_multiline(editor, line); } @@ -4850,7 +4849,7 @@ GeanyEditor *editor_create(GeanyDocument *doc) doc->editor = editor; /* needed in case some editor functions/callbacks expect it */ editor->auto_indent = (iprefs->auto_indent_mode != GEANY_AUTOINDENT_NONE); - editor->line_wrapping = editor_get_line_wrapping(); + editor->line_wrapping = get_project_pref(line_wrapping); editor->scroll_percent = -1.0F; editor->line_breaking = FALSE; diff --git a/src/editor.h b/src/editor.h index ebd6968f..5c04a739 100644 --- a/src/editor.h +++ b/src/editor.h @@ -112,17 +112,15 @@ GeanyIndentPrefs; /** Default prefs when creating a new editor window. * Some of these can be overridden per document or per project. */ -/* See editor_get_prefs(). */ +/* @warning Use @c editor_get_prefs() instead to include project overrides. */ typedef struct GeanyEditorPrefs { 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, 2 - disabled. - * This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */ + /* 0 - line, 1 - background, 2 - disabled. */ gint long_line_type; - /* This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */ gint long_line_column; gchar *long_line_color; gboolean show_markers_margin; /* view menu */ @@ -154,7 +152,6 @@ typedef struct GeanyEditorPrefs gboolean completion_drops_rest_of_word; gchar *color_scheme; gint show_virtual_space; - /* This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */ gboolean long_line_enabled; gint autocompletion_update_freq; } diff --git a/src/project.c b/src/project.c index e5fca486..0e1100b3 100644 --- a/src/project.c +++ b/src/project.c @@ -1302,6 +1302,11 @@ static void init_stash_prefs(void) group = stash_group_new("editor"); stash_group_add_toggle_button(group, &priv.line_wrapping, "line_wrapping", editor_prefs.line_wrapping, "check_line_wrapping1"); + stash_group_add_spin_button_integer(group, &priv.line_break_column, + "line_break_column", editor_prefs.line_break_column, "spin_line_break1"); + stash_group_add_toggle_button(group, &priv.auto_continue_multiline, + "auto_continue_multiline", editor_prefs.auto_continue_multiline, + "check_auto_multiline1"); add_stash_group(group, TRUE); } diff --git a/src/projectprivate.h b/src/projectprivate.h index c7f338f9..5d64fdf1 100644 --- a/src/projectprivate.h +++ b/src/projectprivate.h @@ -31,15 +31,21 @@ G_BEGIN_DECLS typedef struct GeanyProjectPrivate { - struct GeanyIndentPrefs *indentation; + // file prefs gboolean final_new_line; gboolean strip_trailing_spaces; gboolean replace_tabs; gboolean ensure_convert_new_lines; + + // editor prefs + struct GeanyIndentPrefs *indentation; + gboolean line_wrapping; + gint line_break_column; + gboolean auto_continue_multiline; + gint long_line_behaviour; /* 0 - disabled, 1 - follow global settings, 2 - enabled (custom) */ + gint long_line_column; /* Long line marker position. */ + GPtrArray *build_filetypes_list; /* Project has custom filetype builds for these. */ - gint long_line_behaviour; /* 0 - disabled, 1 - follow global settings, 2 - enabled (custom) */ - gint long_line_column; /* Long line marker position. */ - gboolean line_wrapping; } GeanyProjectPrivate;