Revision: 2853 http://geany.svn.sourceforge.net/geany/?rev=2853&view=rev Author: ntrel Date: 2008-08-04 14:07:49 +0000 (Mon, 04 Aug 2008)
Log Message: ----------- Fix build; currently auto-indentation doesn't support inserting tabs and spaces, only spaces. Also Tabs & Spaces cannot be detected yet when opening files. Default file templates still only use tabs. Add editor_get_indent_prefs() which should be used to get the right settings for a document/editor instead of reading any default prefs. This could also support project/filetype indentation prefs quite easily. Don't change per-document auto-indent setting after changing default auto-indentation type. Remove ui_radio_menu_item_*(), not good to use as they depended on the order of widget creation, so don't work well with Glade. Use RadioPrefEntry array instead.
Modified Paths: -------------- branches/custom-tab-width/ChangeLog branches/custom-tab-width/src/callbacks.c branches/custom-tab-width/src/callbacks.h branches/custom-tab-width/src/document.c branches/custom-tab-width/src/editor.c branches/custom-tab-width/src/editor.h branches/custom-tab-width/src/keyfile.c branches/custom-tab-width/src/main.c branches/custom-tab-width/src/prefs.c branches/custom-tab-width/src/ui_utils.c branches/custom-tab-width/src/ui_utils.h
Modified: branches/custom-tab-width/ChangeLog =================================================================== --- branches/custom-tab-width/ChangeLog 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/ChangeLog 2008-08-04 14:07:49 UTC (rev 2853) @@ -1,3 +1,22 @@ +2008-08-04 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/ui_utils.h, src/prefs.c, src/callbacks.c, src/callbacks.h, + src/keyfile.c, src/document.c, src/main.c, src/editor.c, + src/editor.h, src/ui_utils.c: + Fix build; currently auto-indentation doesn't support inserting tabs + and spaces, only spaces. Also Tabs & Spaces cannot be detected yet + when opening files. Default file templates still only use tabs. + Add editor_get_indent_prefs() which should be used to get the right + settings for a document/editor instead of reading any default prefs. + This could also support project/filetype indentation prefs quite + easily. + Don't change per-document auto-indent setting after changing default + auto-indentation type. + Remove ui_radio_menu_item_*(), not good to use as they depended on + the order of widget creation, so don't work well with Glade. Use + RadioPrefEntry array instead. + + 2008-07-31 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/interface.c, src/editor.h, geany.glade:
Modified: branches/custom-tab-width/src/callbacks.c =================================================================== --- branches/custom-tab-width/src/callbacks.c 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/callbacks.c 2008-08-04 14:07:49 UTC (rev 2853) @@ -1701,6 +1701,18 @@ }
+static void change_line_indent(GeanyEditor *editor, gboolean increase) +{ + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + ScintillaObject *sci = editor->sci; + gint line = sci_get_current_line(sci); + gint width = sci_get_line_indentation(sci, line); + + width += increase ? iprefs->width : -iprefs->width; + sci_set_line_indentation(sci, line, width); +} + + void on_menu_increase_indent1_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -1715,18 +1727,7 @@ } else { - gint line, ind_pos, old_pos, new_pos, step; - - old_pos = sci_get_current_position(doc->editor->sci); - line = sci_get_line_from_position(doc->editor->sci, old_pos); - ind_pos = sci_get_line_indent_position(doc->editor->sci, line); - /* when using tabs increase cur pos by 1, when using space increase it by tab_width */ - step = (doc->editor->use_tabs) ? 1 : editor_prefs.tab_width; - new_pos = (old_pos > ind_pos) ? old_pos + step : old_pos; - - sci_set_current_position(doc->editor->sci, ind_pos, TRUE); - sci_cmd(doc->editor->sci, SCI_TAB); - sci_set_current_position(doc->editor->sci, new_pos, TRUE); + change_line_indent(doc->editor, TRUE); } }
@@ -1745,25 +1746,7 @@ } else { - gint line, ind_pos, old_pos, new_pos, step, indent; - - old_pos = sci_get_current_position(doc->editor->sci); - line = sci_get_line_from_position(doc->editor->sci, old_pos); - ind_pos = sci_get_line_indent_position(doc->editor->sci, line); - step = (doc->editor->use_tabs) ? 1 : editor_prefs.tab_width; - new_pos = (old_pos >= ind_pos) ? old_pos - step : old_pos; - - if (ind_pos == sci_get_position_from_line(doc->editor->sci, line)) - return; - - sci_set_current_position(doc->editor->sci, ind_pos, TRUE); - indent = sci_get_line_indentation(doc->editor->sci, line); - indent -= editor_prefs.tab_width; - if (indent < 0) - indent = 0; - sci_set_line_indentation(doc->editor->sci, line, indent); - - sci_set_current_position(doc->editor->sci, new_pos, TRUE); + change_line_indent(doc->editor, FALSE); } }
@@ -2079,31 +2062,39 @@ }
-void -on_tabs1_activate (GtkMenuItem *menuitem, - gpointer user_data) +static void set_indent_type(GeanyIndentType type) { GeanyDocument *doc = document_get_current();
if (doc == NULL || ignore_callback) return;
- editor_set_use_tabs(doc->editor, TRUE); + editor_set_indent_type(doc->editor, type); ui_update_statusbar(doc, -1); }
void +on_tabs1_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + set_indent_type(GEANY_INDENT_TYPE_TABS); +} + + +void on_spaces1_activate (GtkMenuItem *menuitem, gpointer user_data) { - GeanyDocument *doc = document_get_current(); + set_indent_type(GEANY_INDENT_TYPE_SPACES); +}
- if (doc == NULL || ignore_callback) - return;
- editor_set_use_tabs(doc->editor, FALSE); - ui_update_statusbar(doc, -1); +void +on_tabs_and_spaces1_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + set_indent_type(GEANY_INDENT_TYPE_BOTH); }
Modified: branches/custom-tab-width/src/callbacks.h =================================================================== --- branches/custom-tab-width/src/callbacks.h 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/callbacks.h 2008-08-04 14:07:49 UTC (rev 2853) @@ -626,3 +626,7 @@ void on_find_document_usage1_activate (GtkMenuItem *menuitem, gpointer user_data); + +void +on_tabs_and_spaces1_activate (GtkMenuItem *menuitem, + gpointer user_data);
Modified: branches/custom-tab-width/src/document.c =================================================================== --- branches/custom-tab-width/src/document.c 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/document.c 2008-08-04 14:07:49 UTC (rev 2853) @@ -303,15 +303,18 @@ void document_apply_update_prefs(GeanyDocument *doc) { ScintillaObject *sci; + GeanyEditor *editor;
g_return_if_fail(doc != NULL);
- sci = doc->editor->sci; + 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);
- sci_set_tab_width(sci, editor_prefs.tab_width); + /* update indent width, tab width */ + editor_set_indent_type(editor, editor->indent_type);
sci_set_autoc_max_height(sci, editor_prefs.symbolcompletion_max_height);
@@ -321,8 +324,6 @@
sci_set_folding_margin_visible(sci, editor_prefs.folding);
- doc->editor->auto_indent = (editor_prefs.indent_mode != INDENT_NONE); - sci_assign_cmdkey(sci, SCK_HOME, editor_prefs.smart_home_key ? SCI_VCHOMEWRAP : SCI_HOMEWRAP); sci_assign_cmdkey(sci, SCK_END, SCI_LINEENDWRAP); @@ -571,7 +572,6 @@ if (text != NULL) sci_convert_eols(doc->editor->sci, file_prefs.default_eol_character);
- editor_set_use_tabs(doc->editor, editor_prefs.use_tabs); sci_set_undo_collection(doc->editor->sci, TRUE); sci_empty_undo_buffer(doc->editor->sci);
@@ -883,11 +883,18 @@ }
-static gboolean detect_use_tabs(ScintillaObject *sci) +static GeanyIndentType detect_indent_type(GeanyEditor *editor) { + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + ScintillaObject *sci = editor->sci; gint line; + gboolean use_tabs; gsize tabs = 0, spaces = 0;
+ /* TODO: tabs & spaces detection */ + if (iprefs->type == GEANY_INDENT_TYPE_BOTH) + return GEANY_INDENT_TYPE_BOTH; + for (line = 0; line < sci_get_line_count(sci); line++) { gint pos = sci_get_position_from_line(sci, line); @@ -905,34 +912,42 @@ } } if (spaces == 0 && tabs == 0) - return editor_prefs.use_tabs; + return iprefs->type;
/* Skew comparison by a factor of 2 in favour of default editor pref */ - if (editor_prefs.use_tabs) - return ! (spaces > tabs * 2); + if (iprefs->type == GEANY_INDENT_TYPE_TABS) + use_tabs = ! (spaces > tabs * 2); else - return (tabs > spaces * 2); + use_tabs = (tabs > spaces * 2); + + return use_tabs ? GEANY_INDENT_TYPE_TABS : GEANY_INDENT_TYPE_SPACES; }
-static void set_indentation(GeanyDocument *doc) +static void set_indentation(GeanyEditor *editor) { - /* force using tabs for indentation for Makefiles */ - if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_MAKE) - editor_set_use_tabs(doc->editor, TRUE); - /* force using spaces for indentation for Fortran 77 */ - else if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_F77) - editor_set_use_tabs(doc->editor, FALSE); - else if (! editor_prefs.detect_tab_mode) - editor_set_use_tabs(doc->editor, editor_prefs.use_tabs); - else - { /* detect & set tabs/spaces */ - gboolean use_tabs = detect_use_tabs(doc->editor->sci); + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
- if (use_tabs != editor_prefs.use_tabs) - ui_set_statusbar(TRUE, _("Setting %s indentation mode."), - (use_tabs) ? _("Tabs") : _("Spaces")); - editor_set_use_tabs(doc->editor, use_tabs); + switch (FILETYPE_ID(editor->document->file_type)) + { + case GEANY_FILETYPES_MAKE: + /* force using tabs for indentation for Makefiles */ + editor_set_indent_type(editor, GEANY_INDENT_TYPE_TABS); + break; + case GEANY_FILETYPES_F77: + /* force using spaces for indentation for Fortran 77 */ + editor_set_indent_type(editor, GEANY_INDENT_TYPE_SPACES); + break; + default: + if (iprefs->detect_type) + { /* detect & set tabs/spaces */ + GeanyIndentType type = detect_indent_type(editor); + + if (type != iprefs->type) + ui_set_statusbar(TRUE, _("Setting %s indentation mode."), + (type == GEANY_INDENT_TYPE_TABS) ? _("Tabs") : _("Spaces")); + editor_set_indent_type(editor, type); + } } }
@@ -1061,9 +1076,9 @@
/* set indentation settings after setting the filetype */ if (reload) - editor_set_use_tabs(doc->editor, doc->editor->use_tabs); /* resetup sci */ + editor_set_indent_type(doc->editor, doc->editor->indent_type); /* resetup sci */ else - set_indentation(doc); + set_indentation(doc->editor);
document_set_text_changed(doc, FALSE); /* also updates tab state */ ui_document_show_hide(doc); /* update the document menu */
Modified: branches/custom-tab-width/src/editor.c =================================================================== --- branches/custom-tab-width/src/editor.c 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/editor.c 2008-08-04 14:07:49 UTC (rev 2853) @@ -706,36 +706,82 @@ }
+static gint get_tab_width(const GeanyIndentPrefs *indent_prefs) +{ + if (indent_prefs->type == GEANY_INDENT_TYPE_BOTH) + return indent_prefs->tab_width; + + return indent_prefs->width; /* tab width = indent width */ +} + + /* Returns a string containing width chars of whitespace, filled with simple space - * characters or with the right number of tab characters, according to the - * use_tabs setting. (Result is filled with tabs *and* spaces if width isn't a multiple of + * characters or with the right number of tab characters, according to the indent prefs. + * (Result is filled with tabs *and* spaces if width isn't a multiple of * editor_prefs.tab_width). */ static gchar * -get_whitespace(gint width, gboolean use_tabs) +get_whitespace(const GeanyIndentPrefs *iprefs, gint width) { - gchar *str; - g_return_val_if_fail(width > 0, NULL);
- if (use_tabs) + if (iprefs->type == GEANY_INDENT_TYPE_SPACES) + { + return g_strnfill(width, ' '); + } + else { /* first fill text with tabs and fill the rest with spaces */ - gint tabs = width / editor_prefs.tab_width; - gint spaces = width % editor_prefs.tab_width; + const gint tab_width = get_tab_width(iprefs); + gint tabs = width / tab_width; + gint spaces = width % tab_width; gint len = tabs + spaces; + gchar *str;
str = g_malloc(len + 1);
memset(str, '\t', tabs); memset(str + tabs, ' ', spaces); str[len] = '\0'; + return str; } - else - str = g_strnfill(width, ' '); +}
- return str; + +static const GeanyIndentPrefs * +get_default_indent_prefs(void) +{ + /* In future this might depend on project or filetype. */ + return editor_prefs.indentation; }
+/** Get the indentation prefs for the editor. + * In future, the prefs might be different according to project or filetype. + * @warning Always get a fresh result instead of keeping a pointer to it if the editor + * settings may have changed, or if this function has been called for a different @a editor. */ +const GeanyIndentPrefs * +editor_get_indent_prefs(GeanyEditor *editor) +{ + static GeanyIndentPrefs iprefs; + + g_return_val_if_fail(editor != NULL, NULL); + + iprefs = *get_default_indent_prefs(); + + iprefs.type = editor->indent_type; + if (!editor->auto_indent) + iprefs.auto_indent_mode = GEANY_AUTOINDENT_NONE; + return &iprefs; +} + + +static gchar *get_single_indent(GeanyEditor *editor) +{ + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + + return get_whitespace(iprefs, iprefs->width); +} + + static void check_python_indent(GeanyEditor *editor, gint pos) { ScintillaObject *sci = editor->sci; @@ -745,9 +791,9 @@ if (sci_get_char_at(sci, last_char) == ':' && sci_get_style_at(sci, last_char) == SCE_P_OPERATOR) { - /* creates and inserts one tabulator sign or + /* creates and inserts one tab char or * whitespace of the amount of the tab width */ - gchar *text = get_whitespace(editor_prefs.tab_width, editor->use_tabs); + gchar *text = get_single_indent(editor); sci_add_text(sci, text); g_free(text); } @@ -763,10 +809,12 @@ /* simple indentation */ if (editor->auto_indent) { + gint auto_indent_mode = editor_get_indent_prefs(editor)->auto_indent_mode; + get_indent(editor, pos, FALSE); sci_add_text(sci, indent);
- if (editor_prefs.indent_mode > INDENT_BASIC && + if (auto_indent_mode > GEANY_AUTOINDENT_BASIC && FILETYPE_ID(editor->document->file_type) == GEANY_FILETYPES_PYTHON) check_python_indent(editor, pos); } @@ -808,20 +856,23 @@ }
-/* in place indentation of one tab or equivalent spaces */ -static void do_indent(gchar *buf, gsize len, guint *idx, gboolean use_tabs) +/* in place indentation of one tab or equivalent spaces. + * idx is the index into buf. */ +static void do_indent(const GeanyIndentPrefs *iprefs, gchar *buf, gsize len, guint *idx) { guint j = *idx;
- if (use_tabs) + if (iprefs->type == GEANY_INDENT_TYPE_TABS) { if (j < len - 1) /* leave room for a \0 terminator. */ buf[j++] = '\t'; } else - { /* insert as many spaces as a tab would take */ + { + /* insert as many spaces as an indent takes. + * TODO: insert tabs for GEANY_INDENT_TYPE_BOTH */ guint k; - for (k = 0; k < (guint) editor_prefs.tab_width && k < len - 1; k++) + for (k = 0; k < (guint) iprefs->width && k < len - 1; k++) buf[j++] = ' '; } *idx = j; @@ -836,6 +887,7 @@ guint i, len, j = 0; gint prev_line; gchar *linebuf; + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
prev_line = sci_get_line_from_position(sci, pos);
@@ -848,7 +900,7 @@ { if (linebuf[i] == ' ' || linebuf[i] == '\t') /* simple indentation */ indent[j++] = linebuf[i]; - else if (editor_prefs.indent_mode <= INDENT_BASIC) + else if (iprefs->auto_indent_mode <= GEANY_AUTOINDENT_BASIC) break; else if (use_this_line) break; @@ -861,7 +913,7 @@ * " { return bless({}, shift); }" (Perl) */ if (linebuf[i] == '{' && i == (len - 1)) { - do_indent(indent, sizeof(indent), &j, editor->use_tabs); + do_indent(iprefs, indent, sizeof(indent), &j); break; } else @@ -874,7 +926,7 @@ * e.g. for (...) { */ if (linebuf[k] == '{') { - do_indent(indent, sizeof(indent), &j, editor->use_tabs); + do_indent(iprefs, indent, sizeof(indent), &j); } break; } @@ -944,13 +996,14 @@ /* Called after typing '}'. */ void editor_close_block(GeanyDocument *doc, gint pos) { + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(doc->editor); gint x = 0, cnt = 0; gint line, line_len, eol_char_len; gchar *text, *line_buf; ScintillaObject *sci; gint line_indent, last_indent;
- if (editor_prefs.indent_mode < INDENT_CURRENTCHARS) + if (iprefs->auto_indent_mode < GEANY_AUTOINDENT_CURRENTCHARS) return; if (doc == NULL || doc->file_type == NULL) return; @@ -979,7 +1032,7 @@ if ((line_len - eol_char_len - 1) != cnt) return;
- if (editor_prefs.indent_mode == INDENT_MATCHBRACES) + if (iprefs->auto_indent_mode == GEANY_AUTOINDENT_MATCHBRACES) { gint start_brace = brace_match(sci, pos);
@@ -998,13 +1051,13 @@ /* fall through - unmatched brace (possibly because of TCL, PHP lexer bugs) */ }
- /* INDENT_CURRENTCHARS */ + /* GEANY_AUTOINDENT_CURRENTCHARS */ line_indent = sci_get_line_indentation(sci, line); last_indent = sci_get_line_indentation(sci, line - 1);
if (line_indent < last_indent) return; - line_indent -= editor_prefs.tab_width; + line_indent -= iprefs->width; line_indent = MAX(0, line_indent); sci_set_line_indentation(sci, line, line_indent); } @@ -1578,7 +1631,7 @@
get_indent(editor, pos, TRUE); lindent = g_strconcat(editor_get_eol_char(editor->document), indent, NULL); - whitespace = get_whitespace(editor_prefs.tab_width, editor->use_tabs); + whitespace = get_single_indent(editor);
/* remove the typed word, it will be added again by the used auto completion * (not really necessary but this makes the auto completion more flexible, @@ -1825,10 +1878,10 @@ }
/* get indent string for generated code */ - if (editor_prefs.indent_mode == INDENT_NONE) + if (editor->auto_indent) indent_str = g_strdup(""); else - indent_str = get_whitespace(editor_prefs.tab_width, editor->use_tabs); + indent_str = get_single_indent(editor);
table = g_strconcat("\n", indent, indent_str, "<tr>\n", indent, indent_str, indent_str, "<td>\n", @@ -2435,10 +2488,11 @@ gint cur_line = sci_get_current_line(sci); gint indent_pos = sci_get_line_indent_position(sci, cur_line); gint indent_len = sci_get_col_from_position(sci, indent_pos); + gint indent_width = editor_get_indent_prefs(editor)->width;
/* if there is one too many spaces, delete the last space, * to return to the indent used before the multiline comment was started. */ - if (indent_len % editor_prefs.tab_width == 1) + if (indent_len % indent_width == 1) SSM(sci, SCI_DELETEBACKNOTLINE, 0, 0); /* remove whitespace indent */ g_free(previous_line); return; @@ -2765,10 +2819,23 @@ }
+/* creates and inserts one tab or whitespace of the amount of the tab width */ void editor_insert_alternative_whitespace(GeanyEditor *editor) { - /* creates and inserts one tab or whitespace of the amount of the tab width */ - gchar *text = get_whitespace(editor_prefs.tab_width, ! editor->use_tabs); + gchar *text; + GeanyIndentPrefs iprefs = *editor_get_indent_prefs(editor); + + switch (iprefs.type) + { + case GEANY_INDENT_TYPE_TABS: + iprefs.type = GEANY_INDENT_TYPE_SPACES; + break; + case GEANY_INDENT_TYPE_SPACES: + case GEANY_INDENT_TYPE_BOTH: /* most likely we want a tab */ + iprefs.type = GEANY_INDENT_TYPE_TABS; + break; + } + text = get_whitespace(&iprefs, iprefs.width); sci_add_text(editor->sci, text); g_free(text); } @@ -3490,14 +3557,24 @@ }
-void editor_set_use_tabs(GeanyEditor *editor, gboolean use_tabs) +/* Also sets indent width, tab width. */ +void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type) { - g_return_if_fail(editor != NULL); + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + ScintillaObject *sci = editor->sci; + gboolean use_tabs = type != GEANY_INDENT_TYPE_SPACES;
- editor->use_tabs = use_tabs; - sci_set_use_tabs(editor->sci, use_tabs); - /* remove indent spaces on backspace, if using spaces to indent */ - SSM(editor->sci, SCI_SETBACKSPACEUNINDENTS, ! use_tabs, 0); + editor->indent_type = type; + sci_set_use_tabs(sci, use_tabs); + + if (type == GEANY_INDENT_TYPE_BOTH) + sci_set_tab_width(sci, iprefs->tab_width); + else + sci_set_tab_width(sci, iprefs->width); + SSM(sci, SCI_SETINDENT, iprefs->width, 0); + + /* remove indent spaces on backspace, if using any spaces to indent */ + SSM(sci, SCI_SETBACKSPACEUNINDENTS, type != GEANY_INDENT_TYPE_TABS, 0); }
@@ -3648,17 +3725,19 @@
GeanyEditor *editor_create(GeanyDocument *doc) { + const GeanyIndentPrefs *iprefs = get_default_indent_prefs(); GeanyEditor *editor = g_new0(GeanyEditor, 1);
editor->document = doc;
- editor->auto_indent = (editor_prefs.indent_mode != INDENT_NONE); + editor->sci = create_new_sci(doc); + editor_set_indent_type(editor, iprefs->type); + editor_set_font(editor, interface_prefs.editor_font); + + editor->auto_indent = (iprefs->auto_indent_mode != GEANY_AUTOINDENT_NONE); editor->line_wrapping = editor_prefs.line_wrapping; editor->scroll_percent = -1.0F; editor->line_breaking = FALSE; - - editor->sci = create_new_sci(doc); - editor_set_font(editor, interface_prefs.editor_font); return editor; }
@@ -3668,7 +3747,7 @@ static GeanyIndentPrefs indent_prefs;
memset(&editor_prefs, 0, sizeof(GeanyEditorPrefs)); - memset(&indent_prefs, 0, sizeof GeanyIndentPrefs); - editor_prefs->indentation = &indent_prefs; + memset(&indent_prefs, 0, sizeof(GeanyIndentPrefs)); + editor_prefs.indentation = &indent_prefs; }
Modified: branches/custom-tab-width/src/editor.h =================================================================== --- branches/custom-tab-width/src/editor.h 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/editor.h 2008-08-04 14:07:49 UTC (rev 2853) @@ -48,8 +48,8 @@ /** Whether to use tabs, spaces or both to indent. */ typedef enum { + GEANY_INDENT_TYPE_SPACES, /**< Spaces. */ GEANY_INDENT_TYPE_TABS, /**< Tabs. */ - GEANY_INDENT_TYPE_SPACES, /**< Spaces. */ GEANY_INDENT_TYPE_BOTH /**< Both. */ } GeanyIndentType;
Modified: branches/custom-tab-width/src/keyfile.c =================================================================== --- branches/custom-tab-width/src/keyfile.c 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/keyfile.c 2008-08-04 14:07:49 UTC (rev 2853) @@ -230,7 +230,7 @@ ft->name, doc->readonly, encodings_get_idx_from_charset(doc->encoding), - doc->editor->use_tabs, + doc->editor->indent_type, doc->editor->auto_indent, doc->editor->line_wrapping, doc->file_name); @@ -923,15 +923,15 @@ guint pos; const gchar *ft_name; gchar *locale_filename; - gint enc_idx; - gboolean ro, use_tabs, auto_indent, line_wrapping; + gint enc_idx, indent_type; + gboolean ro, auto_indent, line_wrapping; gboolean ret = FALSE;
pos = atoi(tmp[0]); ft_name = tmp[1]; ro = atoi(tmp[2]); enc_idx = atoi(tmp[3]); - use_tabs = atoi(tmp[4]); + indent_type = atoi(tmp[4]); auto_indent = atoi(tmp[5]); line_wrapping = atoi(tmp[6]); /* try to get the locale equivalent for the filename */ @@ -947,7 +947,7 @@
if (doc) { - editor_set_use_tabs(doc->editor, use_tabs); + editor_set_indent_type(doc->editor, indent_type); editor_set_line_wrapping(doc->editor, line_wrapping); doc->editor->auto_indent = auto_indent; ret = TRUE;
Modified: branches/custom-tab-width/src/main.c =================================================================== --- branches/custom-tab-width/src/main.c 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/main.c 2008-08-04 14:07:49 UTC (rev 2853) @@ -252,14 +252,6 @@ gtk_widget_hide(ui_widgets.statusbar); }
- ignore_callback = TRUE; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( - lookup_widget(main_widgets.window, "menu_line_wrapping1")), editor_prefs.line_wrapping); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( - lookup_widget(main_widgets.window, "menu_use_auto_indentation1")), - (editor_prefs.indent_mode != INDENT_NONE)); - ignore_callback = FALSE; - /* connect the toolbar dropdown menu for the new button */ gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON( lookup_widget(main_widgets.window, "menutoolbutton1")), ui_widgets.new_file_menu); @@ -794,12 +786,13 @@ main_init(); gtk_widget_set_size_request(main_widgets.window, GEANY_WINDOW_MINIMAL_WIDTH, GEANY_WINDOW_MINIMAL_HEIGHT); gtk_window_set_default_size(GTK_WINDOW(main_widgets.window), GEANY_WINDOW_DEFAULT_WIDTH, GEANY_WINDOW_DEFAULT_HEIGHT); + encodings_init(); + editor_init();
load_settings();
msgwin_init(); - editor_init(); build_init(); search_init(); ui_create_insert_menu_items();
Modified: branches/custom-tab-width/src/prefs.c =================================================================== --- branches/custom-tab-width/src/prefs.c 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/prefs.c 2008-08-04 14:07:49 UTC (rev 2853) @@ -166,29 +166,39 @@ }
+typedef struct RadioPrefEntry +{ + const gchar *widget_name; + gpointer setting; + gint value; +} +RadioPrefEntry; + static void radio_prefs_foreach(PrefCallbackAction action) { guint i; - /* Only add one widget per radio-group; the setting is the index of the selected radio item - * in the group. */ - PrefEntry items[] = + RadioPrefEntry items[] = { - {"radio_indent_spaces", &editor_prefs.indentation->type}, + {"radio_indent_spaces", &editor_prefs.indentation->type, GEANY_INDENT_TYPE_SPACES}, + {"radio_indent_tabs", &editor_prefs.indentation->type, GEANY_INDENT_TYPE_TABS}, + {"radio_indent_both", &editor_prefs.indentation->type, GEANY_INDENT_TYPE_BOTH}, };
for (i = 0; i < G_N_ELEMENTS(items); i++) { - PrefEntry *pe = &items[i]; + RadioPrefEntry *pe = &items[i]; GtkWidget *widget = lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); gint *setting = pe->setting;
switch (action) { case PREF_DISPLAY: - ui_radio_menu_item_set_active_index(GTK_RADIO_MENU_ITEM(widget), *setting); + if (*setting == pe->value) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); break; case PREF_UPDATE: - *setting = ui_radio_menu_item_get_active_index(GTK_RADIO_MENU_ITEM(widget)); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) + *setting = pe->value; break; } } @@ -200,7 +210,7 @@ guint i; PrefEntry items[] = { - {"combo_auto_indent_mode", &editor_prefs.indentation->type}, + {"combo_auto_indent_mode", &editor_prefs.indentation->auto_indent_mode}, };
for (i = 0; i < G_N_ELEMENTS(items); i++)
Modified: branches/custom-tab-width/src/ui_utils.c =================================================================== --- branches/custom-tab-width/src/ui_utils.c 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/ui_utils.c 2008-08-04 14:07:49 UTC (rev 2853) @@ -174,8 +174,19 @@ /* OVR = overwrite/overtype, INS = insert */ (sci_get_overtype(doc->editor->sci) ? _("OVR") : _("INS"))); g_string_append(stats_str, sp); - g_string_append(stats_str, - (doc->editor->use_tabs) ? _("TAB") : _("SP ")); /* SP = space */ + + switch (editor_get_indent_prefs(doc->editor)->type) + { + case GEANY_INDENT_TYPE_TABS: + g_string_append(stats_str, _("TAB")); + break; + case GEANY_INDENT_TYPE_SPACES: + g_string_append(stats_str, _("SP")); /* SP = space */ + break; + case GEANY_INDENT_TYPE_BOTH: + g_string_append(stats_str, _("T/S")); /* T/S = tabs and spaces */ + break; + } g_string_append(stats_str, sp); g_string_append_printf(stats_str, _("mode: %s"), editor_get_eol_char_name(doc)); @@ -687,6 +698,7 @@ { gchar *widget_name; GtkWidget *item; + const GeanyIndentPrefs *iprefs;
if (doc == NULL) doc = document_get_current(); @@ -704,12 +716,23 @@ GTK_CHECK_MENU_ITEM(lookup_widget(main_widgets.window, "line_breaking1")), doc->editor->line_breaking);
+ iprefs = editor_get_indent_prefs(doc->editor); + item = lookup_widget(main_widgets.window, "menu_use_auto_indentation1"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), doc->editor->auto_indent); gtk_widget_set_sensitive(item, - editor_prefs.indentation->auto_indent_mode != GEANY_AUTOINDENT_NONE); + iprefs->auto_indent_mode != GEANY_AUTOINDENT_NONE);
- item = lookup_widget(main_widgets.window, doc->editor->use_tabs ? "tabs1" : "spaces1"); + switch (iprefs->type) + { + case GEANY_INDENT_TYPE_SPACES: + widget_name = "spaces1"; break; + case GEANY_INDENT_TYPE_TABS: + widget_name = "tabs1"; break; + case GEANY_INDENT_TYPE_BOTH: + widget_name = "tabs_and_spaces1"; break; + } + item = lookup_widget(main_widgets.window, widget_name); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
gtk_check_menu_item_set_active( @@ -1508,41 +1531,3 @@ }
-void ui_radio_menu_item_set_active_index(GtkRadioMenuItem *widget, guint idx) -{ - GSList *item = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(widget)); - guint i; - - for (i = 0; item != NULL; item = g_slist_next(item), i++) - { - if (i == idx) - { - GtkCheckMenuItem *radio = item->data; - - gtk_check_menu_item_set_active(radio, TRUE); - return; - } - } - g_warning("Index %u is out of range for group of widget %s", - idx, gtk_widget_get_name(GTK_WIDGET(widget))); -} - - -guint ui_radio_menu_item_get_active_index(GtkRadioMenuItem *widget) -{ - GSList *item = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(widget)); - guint i; - - for (i = 0; item != NULL; item = g_slist_next(item), i++) - { - GtkCheckMenuItem *radio = item->data; - - if (gtk_check_menu_item_get_active(radio)) - return i; - } - g_warning("No active group item for widget %s", - gtk_widget_get_name(GTK_WIDGET(widget))); - return 0; -} - -
Modified: branches/custom-tab-width/src/ui_utils.h =================================================================== --- branches/custom-tab-width/src/ui_utils.h 2008-08-04 08:53:21 UTC (rev 2852) +++ branches/custom-tab-width/src/ui_utils.h 2008-08-04 14:07:49 UTC (rev 2853) @@ -151,10 +151,6 @@
void ui_table_add_row(GtkTable *table, gint row, ...) G_GNUC_NULL_TERMINATED;
-void ui_radio_menu_item_set_active_index(GtkRadioMenuItem *widget, guint index); - -guint ui_radio_menu_item_get_active_index(GtkRadioMenuItem *widget); - /* End of 'generic' functions */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.