From 437fafd46e92e603e305ec0d377bea31da368594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 21 Sep 2008 16:43:45 +0000 Subject: [PATCH] Move document_apply_update_prefs() in editor.c. Refactor get_indent_guides_from_lexer() from sciwrappers.c in editor_set_indentation_guides(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2979 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 9 +++++ src/document.c | 39 +------------------ src/document.h | 2 - src/editor.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ src/editor.h | 4 ++ src/prefs.c | 2 +- src/sciwrappers.c | 53 +------------------------- src/sciwrappers.h | 2 +- 8 files changed, 115 insertions(+), 92 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84de5c5c..f9b46e20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-09-21 Enrico Tröger + + * document.c, document.h, editor.c, editor.h, prefs.c, sciwrappers.c, + sciwrappers.h: + Move document_apply_update_prefs() in editor.c. + Refactor get_indent_guides_from_lexer() from sciwrappers.c in + editor_set_indentation_guides(). + + 2008-09-19 Nick Treleaven * src/sciwrappers.c: diff --git a/src/document.c b/src/document.c index 142ac28a..f4b014f1 100644 --- a/src/document.c +++ b/src/document.c @@ -299,41 +299,6 @@ void document_set_text_changed(GeanyDocument *doc, gboolean changed) } -/* Apply just the prefs that can change in the Preferences dialog */ -void document_apply_update_prefs(GeanyDocument *doc) -{ - ScintillaObject *sci; - GeanyEditor *editor; - - g_return_if_fail(doc != NULL); - - editor = doc->editor; - sci = editor->sci; - - sci_set_mark_long_lines(sci, editor_prefs.long_line_type, - editor_prefs.long_line_column, editor_prefs.long_line_color); - - /* update indent width, tab width */ - editor_set_indent_type(editor, editor->indent_type); - sci_set_tab_indents(sci, editor_prefs.use_tab_to_indent); - - sci_set_autoc_max_height(sci, editor_prefs.symbolcompletion_max_height); - - sci_set_indentation_guides(sci, editor_prefs.show_indent_guide); - sci_set_visible_white_spaces(sci, editor_prefs.show_white_space); - sci_set_visible_eols(sci, editor_prefs.show_line_endings); - - sci_set_folding_margin_visible(sci, editor_prefs.folding); - - /* (dis)allow scrolling past end of document */ - sci_set_scroll_stop_at_last_line(sci, editor_prefs.scroll_stop_at_last_line); - - sci_assign_cmdkey(sci, SCK_HOME, - editor_prefs.smart_home_key ? SCI_VCHOMEWRAP : SCI_HOMEWRAP); - sci_assign_cmdkey(sci, SCK_END, SCI_LINEENDWRAP); -} - - /* Sets is_valid to FALSE and initializes some members to NULL, to mark it uninitialized. * The flag is_valid is set to TRUE in document_create(). */ static void init_doc_struct(GeanyDocument *new_doc) @@ -427,7 +392,7 @@ static GeanyDocument *document_create(const gchar *utf8_filename) this->editor = editor_create(this); - document_apply_update_prefs(this); + editor_apply_update_prefs(this->editor); treeviews_openfiles_add(this); /* sets this->iter */ @@ -2168,7 +2133,7 @@ void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type) doc->tm_file = NULL; } highlighting_set_styles(doc->editor->sci, type->id); - sci_set_indentation_guides(doc->editor->sci, editor_prefs.show_indent_guide); + editor_set_indentation_guides(doc->editor); build_menu_update(doc); queue_colourise(doc); } diff --git a/src/document.h b/src/document.h index b35c7015..865b2ad1 100644 --- a/src/document.h +++ b/src/document.h @@ -170,8 +170,6 @@ void document_init_doclist(void); void document_finalize(void); -void document_apply_update_prefs(GeanyDocument *doc); - gboolean document_remove_page(guint page_num); gboolean document_close(GeanyDocument *doc); diff --git a/src/editor.c b/src/editor.c index 21d91e8f..4576574a 100644 --- a/src/editor.c +++ b/src/editor.c @@ -3845,3 +3845,99 @@ void editor_init(void) editor_prefs.indentation = &indent_prefs; } + +/** TODO: Should these be user-defined instead of hard-coded? */ +void editor_set_indentation_guides(GeanyEditor *editor) +{ + gint mode; + gint lexer; + + g_return_if_fail(editor != NULL); + + if (! editor_prefs.show_indent_guide) + { + sci_set_indentation_guides(editor->sci, SC_IV_NONE); + return; + } + + lexer = sci_get_lexer(editor->sci); + switch (lexer) + { + /* Lines added/removed are prefixed with +/- characters, so + * those lines will not be shown with any indentation guides. + * It can be distracting that only a few of lines in a diff/patch + * file will show the guides. */ + case SCLEX_DIFF: + mode = SC_IV_NONE; + + /* These languages use indentation for control blocks; the "look forward" method works + * best here */ + case SCLEX_PYTHON: + case SCLEX_HASKELL: + case SCLEX_MAKEFILE: + case SCLEX_ASM: + case SCLEX_SQL: + case SCLEX_PROPERTIES: + case SCLEX_FORTRAN: /* Is this the best option for Fortran? */ + case SCLEX_CAML: + mode = SC_IV_LOOKFORWARD; + + /* C-like (structured) languages benefit from the "look both" method */ + case SCLEX_CPP: + case SCLEX_HTML: + case SCLEX_XML: + case SCLEX_PERL: + case SCLEX_LATEX: + case SCLEX_LUA: + case SCLEX_PASCAL: + case SCLEX_RUBY: + case SCLEX_TCL: + case SCLEX_F77: + case SCLEX_CSS: + case SCLEX_BASH: + case SCLEX_VHDL: + case SCLEX_FREEBASIC: + case SCLEX_D: + case SCLEX_OMS: + mode = SC_IV_LOOKBOTH; + default: + mode = SC_IV_REAL; + } + + sci_set_indentation_guides(editor->sci, mode); +} + + +/* Apply just the prefs that can change in the Preferences dialog */ +void editor_apply_update_prefs(GeanyEditor *editor) +{ + ScintillaObject *sci; + + g_return_if_fail(editor != NULL); + + sci = editor->sci; + + sci_set_mark_long_lines(sci, editor_prefs.long_line_type, + editor_prefs.long_line_column, editor_prefs.long_line_color); + + /* update indent width, tab width */ + editor_set_indent_type(editor, editor->indent_type); + sci_set_tab_indents(sci, editor_prefs.use_tab_to_indent); + + sci_set_autoc_max_height(sci, editor_prefs.symbolcompletion_max_height); + + editor_set_indentation_guides(editor); + + sci_set_visible_white_spaces(sci, editor_prefs.show_white_space); + sci_set_visible_eols(sci, editor_prefs.show_line_endings); + + sci_set_folding_margin_visible(sci, editor_prefs.folding); + + /* (dis)allow scrolling past end of document */ + sci_set_scroll_stop_at_last_line(sci, editor_prefs.scroll_stop_at_last_line); + + sci_assign_cmdkey(sci, SCK_HOME, + editor_prefs.smart_home_key ? SCI_VCHOMEWRAP : SCI_HOMEWRAP); + sci_assign_cmdkey(sci, SCK_END, SCI_LINEENDWRAP); +} + diff --git a/src/editor.h b/src/editor.h index cb95f80c..6b6d10be 100644 --- a/src/editor.h +++ b/src/editor.h @@ -239,4 +239,8 @@ void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap); gboolean editor_goto_pos(GeanyEditor *editor, gint pos, gboolean mark); +void editor_set_indentation_guides(GeanyEditor *editor); + +void editor_apply_update_prefs(GeanyEditor *editor); + #endif diff --git a/src/prefs.c b/src/prefs.c index 92994ac7..9a41dee5 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -1130,7 +1130,7 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) { if (documents[i]->is_valid) { - document_apply_update_prefs(documents[i]); + editor_apply_update_prefs(documents[i]->editor); if (! editor_prefs.folding) editor_unfold_all(documents[i]); } diff --git a/src/sciwrappers.c b/src/sciwrappers.c index 8b9d0778..14a008a0 100644 --- a/src/sciwrappers.c +++ b/src/sciwrappers.c @@ -707,58 +707,9 @@ void sci_set_savepoint(ScintillaObject *sci) SSM(sci, SCI_SETSAVEPOINT, 0, 0); } -/* Should these be user-defined instead of hard-coded? */ -static gint get_indent_guides_from_lexer(gint lexer) +void sci_set_indentation_guides(ScintillaObject *sci, gint mode) { - switch (lexer) - { - /* Lines added/removed are prefixed with +/- characters, so - * those lines will not be shown with any indentation guides. - * It can be distracting that only a few of lines in a diff/patch - * file will show the guides. */ - case SCLEX_DIFF: - return SC_IV_NONE; - - /* These languages use indentation for control blocks; the "look forward" method works - * best here */ - case SCLEX_PYTHON: - case SCLEX_HASKELL: - case SCLEX_MAKEFILE: - case SCLEX_ASM: - case SCLEX_SQL: - case SCLEX_PROPERTIES: - case SCLEX_FORTRAN: /* Is this the best option for Fortran? */ - case SCLEX_CAML: - return SC_IV_LOOKFORWARD; - - /* C-like (structured) languages benefit from the "look both" method */ - case SCLEX_CPP: - case SCLEX_HTML: - case SCLEX_XML: - case SCLEX_PERL: - case SCLEX_LATEX: - case SCLEX_LUA: - case SCLEX_PASCAL: - case SCLEX_RUBY: - case SCLEX_TCL: - case SCLEX_F77: - case SCLEX_CSS: - case SCLEX_BASH: - case SCLEX_VHDL: - case SCLEX_FREEBASIC: - case SCLEX_D: - case SCLEX_OMS: - return SC_IV_LOOKBOTH; - } - - return SC_IV_REAL; -} - -void sci_set_indentation_guides(ScintillaObject *sci, gboolean enable) -{ - gint lexer = sci_get_lexer(sci); - SSM(sci, SCI_SETINDENTATIONGUIDES, - (enable ? get_indent_guides_from_lexer(lexer) : SC_IV_NONE), 0); + SSM(sci, SCI_SETINDENTATIONGUIDES, mode, 0); } diff --git a/src/sciwrappers.h b/src/sciwrappers.h index 933c78b0..5f0d9ab9 100644 --- a/src/sciwrappers.h +++ b/src/sciwrappers.h @@ -118,7 +118,7 @@ void sci_set_tab_width (ScintillaObject * sci, gint width); gint sci_get_tab_width (ScintillaObject * sci); gchar sci_get_char_at (ScintillaObject * sci, gint pos); void sci_set_savepoint (ScintillaObject * sci); -void sci_set_indentation_guides (ScintillaObject * sci, gboolean enable); +void sci_set_indentation_guides (ScintillaObject * sci, gint mode); void sci_use_popup (ScintillaObject * sci, gboolean enable); void sci_goto_pos (ScintillaObject * sci, gint pos, gboolean unfold); void sci_set_search_anchor (ScintillaObject * sci);