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
This commit is contained in:
Enrico Tröger 2008-09-21 16:43:45 +00:00
parent cf9ad9a3a0
commit 437fafd46e
8 changed files with 115 additions and 92 deletions

View File

@ -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:

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -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]);
}

View File

@ -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);
}

View File

@ -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);