Skip to content

Commit

Permalink
Merge pull request #337 from ntrel/project-line-wrap
Browse files Browse the repository at this point in the history
Project line wrapping pref
  • Loading branch information
ntrel committed Sep 29, 2014
2 parents 2b98487 + bbf63d1 commit 9eb865d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
16 changes: 16 additions & 0 deletions data/geany.glade
Original file line number Diff line number Diff line change
Expand Up @@ -9029,6 +9029,22 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="check_line_wrapping1">
<property name="label" translatable="yes">Line wrapping</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">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.</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
Expand Down
15 changes: 11 additions & 4 deletions src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ 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;
}


static const GeanyEditorPrefs *
get_default_prefs(void)
{
Expand All @@ -415,6 +421,7 @@ 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();
return &eprefs;
}

Expand Down Expand Up @@ -4755,7 +4762,7 @@ static gboolean register_named_icon(ScintillaObject *sci, guint id, const gchar
* @note The @c "sci-notify" signal is connected separately. */
static ScintillaObject *create_new_sci(GeanyEditor *editor)
{
ScintillaObject *sci;
ScintillaObject *sci;

sci = SCINTILLA(scintilla_new());

Expand All @@ -4774,7 +4781,7 @@ static ScintillaObject *create_new_sci(GeanyEditor *editor)
setup_sci_keys(sci);

sci_set_symbol_margin(sci, editor_prefs.show_markers_margin);
sci_set_lines_wrapped(sci, editor_prefs.line_wrapping);
sci_set_lines_wrapped(sci, editor->line_wrapping);
sci_set_caret_policy_x(sci, CARET_JUMPS | CARET_EVEN, 0);
/*sci_set_caret_policy_y(sci, CARET_JUMPS | CARET_EVEN, 0);*/
SSM(sci, SCI_AUTOCSETSEPARATOR, '\n', 0);
Expand Down Expand Up @@ -4843,7 +4850,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_prefs.line_wrapping;
editor->line_wrapping = editor_get_line_wrapping();
editor->scroll_percent = -1.0F;
editor->line_breaking = FALSE;

Expand Down Expand Up @@ -4982,7 +4989,7 @@ void editor_set_indentation_guides(GeanyEditor *editor)
}


/* Apply just the prefs that can change in the Preferences dialog */
/* Apply non-document prefs that can change in the Preferences dialog */
void editor_apply_update_prefs(GeanyEditor *editor)
{
ScintillaObject *sci;
Expand Down
25 changes: 17 additions & 8 deletions src/project.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ static gboolean write_config(gboolean emit_signal)
g_key_file_set_string_list(config, "project", "file_patterns",
(const gchar**) p->file_patterns, g_strv_length(p->file_patterns));

// editor settings
g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->priv->long_line_behaviour);
g_key_file_set_integer(config, "long line marker", "long_line_column", p->priv->long_line_column);

Expand Down Expand Up @@ -1245,22 +1246,29 @@ void project_apply_prefs(void)
}


static void add_stash_group(StashGroup *group)
static void add_stash_group(StashGroup *group, gboolean apply_defaults)
{
GKeyFile *kf;

stash_groups = g_slist_prepend(stash_groups, group);
if (!apply_defaults)
return;

kf = g_key_file_new();
stash_group_load_from_key_file(group, kf);
g_key_file_free(kf);
}


static void init_stash_prefs(void)
{
StashGroup *group;
GKeyFile *kf;

group = stash_group_new("indentation");
/* copy global defaults */
indentation = *editor_get_indent_prefs(NULL);
stash_group_set_use_defaults(group, FALSE);
add_stash_group(group);
add_stash_group(group, FALSE);

stash_group_add_spin_button_integer(group, &indentation.width,
"indent_width", 4, "spin_indent_width_project");
Expand Down Expand Up @@ -1289,11 +1297,12 @@ static void init_stash_prefs(void)
"strip_trailing_spaces", file_prefs.strip_trailing_spaces, "check_trailing_spaces1");
stash_group_add_toggle_button(group, &priv.replace_tabs,
"replace_tabs", file_prefs.replace_tabs, "check_replace_tabs1");
add_stash_group(group);
/* apply defaults */
kf = g_key_file_new();
stash_group_load_from_key_file(group, kf);
g_key_file_free(kf);
add_stash_group(group, TRUE);

group = stash_group_new("editor");
stash_group_add_toggle_button(group, &priv.line_wrapping,
"line_wrapping", editor_prefs.line_wrapping, "check_line_wrapping1");
add_stash_group(group, TRUE);
}


Expand Down
1 change: 1 addition & 0 deletions src/projectprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct GeanyProjectPrivate
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;

Expand Down

0 comments on commit 9eb865d

Please sign in to comment.