Revision: 2979 http://geany.svn.sourceforge.net/geany/?rev=2979&view=rev Author: eht16 Date: 2008-09-21 16:43:45 +0000 (Sun, 21 Sep 2008)
Log Message: ----------- Move document_apply_update_prefs() in editor.c. Refactor get_indent_guides_from_lexer() from sciwrappers.c in editor_set_indentation_guides().
Modified Paths: -------------- trunk/ChangeLog trunk/src/document.c trunk/src/document.h trunk/src/editor.c trunk/src/editor.h trunk/src/prefs.c trunk/src/sciwrappers.c trunk/src/sciwrappers.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-09-21 14:21:13 UTC (rev 2978) +++ trunk/ChangeLog 2008-09-21 16:43:45 UTC (rev 2979) @@ -1,3 +1,12 @@ +2008-09-21 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * 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 <nick(dot)treleaven(at)btinternet(dot)com>
* src/sciwrappers.c:
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2008-09-21 14:21:13 UTC (rev 2978) +++ trunk/src/document.c 2008-09-21 16:43:45 UTC (rev 2979) @@ -299,41 +299,6 @@ }
-/* 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 @@
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 @@ 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); }
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2008-09-21 14:21:13 UTC (rev 2978) +++ trunk/src/document.h 2008-09-21 16:43:45 UTC (rev 2979) @@ -170,8 +170,6 @@
void document_finalize(void);
-void document_apply_update_prefs(GeanyDocument *doc); - gboolean document_remove_page(guint page_num);
gboolean document_close(GeanyDocument *doc);
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2008-09-21 14:21:13 UTC (rev 2978) +++ trunk/src/editor.c 2008-09-21 16:43:45 UTC (rev 2979) @@ -3845,3 +3845,99 @@ 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); +} +
Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2008-09-21 14:21:13 UTC (rev 2978) +++ trunk/src/editor.h 2008-09-21 16:43:45 UTC (rev 2979) @@ -239,4 +239,8 @@
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
Modified: trunk/src/prefs.c =================================================================== --- trunk/src/prefs.c 2008-09-21 14:21:13 UTC (rev 2978) +++ trunk/src/prefs.c 2008-09-21 16:43:45 UTC (rev 2979) @@ -1130,7 +1130,7 @@ { 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]); }
Modified: trunk/src/sciwrappers.c =================================================================== --- trunk/src/sciwrappers.c 2008-09-21 14:21:13 UTC (rev 2978) +++ trunk/src/sciwrappers.c 2008-09-21 16:43:45 UTC (rev 2979) @@ -707,61 +707,12 @@ 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; + SSM(sci, SCI_SETINDENTATIONGUIDES, mode, 0); }
-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); -}
- void sci_use_popup(ScintillaObject *sci, gboolean enable) { SSM(sci, SCI_USEPOPUP, enable, 0);
Modified: trunk/src/sciwrappers.h =================================================================== --- trunk/src/sciwrappers.h 2008-09-21 14:21:13 UTC (rev 2978) +++ trunk/src/sciwrappers.h 2008-09-21 16:43:45 UTC (rev 2979) @@ -118,7 +118,7 @@ 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);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.