Revision: 2588 http://geany.svn.sourceforge.net/geany/?rev=2588&view=rev Author: eht16 Date: 2008-05-15 06:43:29 -0700 (Thu, 15 May 2008)
Log Message: ----------- Move several editing related functions from document.c to editor.c. Fix two compiler warnings about non-literal format strings.
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/document.c trunk/src/document.h trunk/src/editor.c trunk/src/editor.h trunk/src/keybindings.c trunk/src/keyfile.c trunk/src/main.c trunk/src/prefs.c trunk/src/tools.c trunk/src/treeviews.c trunk/src/ui_utils.c trunk/src/utils.c trunk/src/utils.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/ChangeLog 2008-05-15 13:43:29 UTC (rev 2588) @@ -1,3 +1,10 @@ +2008-05-15 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/*.c src/*.h: + Move several editing related functions from document.c to editor.c. + Fix two compiler warnings about non-literal format strings. + + 2008-05-14 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* geany.glade, src/document.c, src/document.h, src/editor.c,
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/callbacks.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -814,7 +814,7 @@ { gint idx = document_get_cur_idx();
- document_replace_tabs(idx); + editor_replace_tabs(idx); }
@@ -971,7 +971,7 @@ { gint idx = document_get_cur_idx(); if (! DOC_IDX_VALID(idx)) return; - document_set_line_wrapping(idx, ! doc_list[idx].line_wrapping); + editor_set_line_wrapping(idx, ! doc_list[idx].line_wrapping); } }
@@ -1496,7 +1496,7 @@ { gint idx = document_get_cur_idx();
- document_fold_all(idx); + editor_fold_all(idx); }
@@ -1506,7 +1506,7 @@ { gint idx = document_get_cur_idx();
- document_unfold_all(idx); + editor_unfold_all(idx); }
@@ -2046,7 +2046,7 @@ { gint idx = document_get_cur_idx();
- document_set_use_tabs(idx, TRUE); + editor_set_use_tabs(idx, TRUE); ui_update_statusbar(idx, -1); }
@@ -2057,7 +2057,7 @@ { gint idx = document_get_cur_idx();
- document_set_use_tabs(idx, FALSE); + editor_set_use_tabs(idx, FALSE); ui_update_statusbar(idx, -1); }
@@ -2068,7 +2068,7 @@ { gint idx = document_get_cur_idx();
- document_strip_trailing_spaces(idx); + editor_strip_trailing_spaces(idx); }
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/document.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -282,30 +282,6 @@ }
-void document_set_use_tabs(gint idx, gboolean use_tabs) -{ - document *doc = &doc_list[idx]; - - g_return_if_fail(DOC_IDX_VALID(idx)); - - doc->use_tabs = use_tabs; - sci_set_use_tabs(doc->sci, use_tabs); - /* remove indent spaces on backspace, if using spaces to indent */ - SSM(doc->sci, SCI_SETBACKSPACEUNINDENTS, ! use_tabs, 0); -} - - -void document_set_line_wrapping(gint idx, gboolean wrap) -{ - document *doc = &doc_list[idx]; - - g_return_if_fail(DOC_IDX_VALID(idx)); - - doc->line_wrapping = wrap; - sci_set_lines_wrapped(doc->sci, wrap); -} - - /* Apply just the prefs that can change in the Preferences dialog */ void document_apply_update_prefs(gint idx) { @@ -483,7 +459,7 @@
pfd = pango_font_description_from_string(prefs.editor_font); fname = g_strdup_printf("!%s", pango_font_description_get_family(pfd)); - document_set_font(new_idx, fname, pango_font_description_get_size(pfd) / PANGO_SCALE); + editor_set_font(new_idx, fname, pango_font_description_get_size(pfd) / PANGO_SCALE); pango_font_description_free(pfd); g_free(fname);
@@ -613,7 +589,7 @@ if (text != NULL) sci_convert_eols(doc_list[idx].sci, prefs.default_eol_character);
- document_set_use_tabs(idx, editor_prefs.use_tabs); + editor_set_use_tabs(idx, editor_prefs.use_tabs); sci_set_undo_collection(doc_list[idx].sci, TRUE); sci_empty_undo_buffer(doc_list[idx].sci);
@@ -863,9 +839,9 @@ tmp_enc_idx == GEANY_ENCODING_UTF_7 || /* filter out UTF-7/8 and None where no NULL bytes */ tmp_enc_idx == GEANY_ENCODING_NONE)) /* are allowed */ { - gchar *warn_msg = _("The file "%s" could not be opened properly and has been truncated. " - "This can occur if the file contains a NULL byte. " - "Be aware that saving it can cause data loss.\nThe file was set to read-only."); +#define warn_msg _("The file "%s" could not be opened properly and has been truncated. " \ + "This can occur if the file contains a NULL byte. " \ + "Be aware that saving it can cause data loss.\nThe file was set to read-only.")
if (main_status.main_window_realized) dialogs_show_msgbox(GTK_MESSAGE_WARNING, warn_msg, utf8_filename); @@ -1061,10 +1037,10 @@ g_free(filedata.data);
if (reload) - document_set_use_tabs(idx, doc_list[idx].use_tabs); /* resetup sci */ + editor_set_use_tabs(idx, doc_list[idx].use_tabs); /* resetup sci */ else if (! editor_prefs.detect_tab_mode) - document_set_use_tabs(idx, editor_prefs.use_tabs); + editor_set_use_tabs(idx, editor_prefs.use_tabs); else { /* detect & set tabs/spaces */ gboolean use_tabs = detect_use_tabs(doc_list[idx].sci); @@ -1072,7 +1048,7 @@ if (use_tabs != editor_prefs.use_tabs) ui_set_statusbar(TRUE, _("Setting %s indentation mode."), (use_tabs) ? _("Tabs") : _("Spaces")); - document_set_use_tabs(idx, use_tabs); + editor_set_use_tabs(idx, use_tabs); }
sci_set_undo_collection(doc_list[idx].sci, TRUE); @@ -1437,11 +1413,11 @@ }
/* replaces tabs by spaces */ - if (prefs.replace_tabs) document_replace_tabs(idx); + if (prefs.replace_tabs) editor_replace_tabs(idx); /* strip trailing spaces */ - if (prefs.strip_trailing_spaces) document_strip_trailing_spaces(idx); + if (prefs.strip_trailing_spaces) editor_strip_trailing_spaces(idx); /* ensure the file has a newline at the end */ - if (prefs.final_new_line) document_ensure_final_newline(idx); + if (prefs.final_new_line) editor_ensure_final_newline(idx);
len = sci_get_length(doc_list[idx].sci) + 1; if (doc_list[idx].has_bom && encodings_is_unicode_charset(doc_list[idx].encoding)) @@ -1859,7 +1835,7 @@ first_line = sci_get_line_from_position(doc_list[idx].sci, selection_start); /* Find the last line with chars selected (not EOL char) */ last_line = sci_get_line_from_position(doc_list[idx].sci, - selection_end - utils_get_eol_char_len(idx)); + selection_end - editor_get_eol_char_len(idx)); last_line = MAX(first_line, last_line); for (line = first_line; line < (first_line + selected_lines); line++) { @@ -1945,21 +1921,6 @@ }
-void document_set_font(gint idx, const gchar *font_name, gint size) -{ - gint style; - - for (style = 0; style <= 127; style++) - sci_set_font(doc_list[idx].sci, style, font_name, size); - /* line number and braces */ - sci_set_font(doc_list[idx].sci, STYLE_LINENUMBER, font_name, size); - sci_set_font(doc_list[idx].sci, STYLE_BRACELIGHT, font_name, size); - sci_set_font(doc_list[idx].sci, STYLE_BRACEBAD, font_name, size); - /* zoom to 100% to prevent confusion */ - sci_zoom_off(doc_list[idx].sci); -} - - void document_update_tag_list(gint idx, gboolean update) { /* We must call treeviews_update_tag_list() before returning, @@ -2144,152 +2105,6 @@ }
-gchar *document_get_eol_mode(gint idx) -{ - if (idx == -1) return '\0'; - - switch (sci_get_eol_mode(doc_list[idx].sci)) - { - case SC_EOL_CRLF: return _("Win (CRLF)"); break; - case SC_EOL_CR: return _("Mac (CR)"); break; - case SC_EOL_LF: - default: return _("Unix (LF)"); break; - } -} - - -static void fold_all(gint idx, gboolean want_fold) -{ - gint lines, first, i; - - if (! DOC_IDX_VALID(idx) || ! editor_prefs.folding) return; - - lines = sci_get_line_count(doc_list[idx].sci); - first = sci_get_first_visible_line(doc_list[idx].sci); - - for (i = 0; i < lines; i++) - { - gint level = sci_get_fold_level(doc_list[idx].sci, i); - if (level & SC_FOLDLEVELHEADERFLAG) - { - if (sci_get_fold_expanded(doc_list[idx].sci, i) == want_fold) - sci_toggle_fold(doc_list[idx].sci, i); - } - } - editor_scroll_to_line(doc_list[idx].sci, first, 0.0F); -} - - -void document_unfold_all(gint idx) -{ - fold_all(idx, FALSE); -} - - -void document_fold_all(gint idx) -{ - fold_all(idx, TRUE); -} - - -void document_replace_tabs(gint idx) -{ - gint search_pos, pos_in_line, current_tab_true_length; - gint tab_len; - gchar *tab_str; - struct TextToFind ttf; - - if (! DOC_IDX_VALID(idx)) return; - - sci_start_undo_action(doc_list[idx].sci); - tab_len = sci_get_tab_width(doc_list[idx].sci); - ttf.chrg.cpMin = 0; - ttf.chrg.cpMax = sci_get_length(doc_list[idx].sci); - ttf.lpstrText = (gchar*) "\t"; - - while (TRUE) - { - search_pos = sci_find_text(doc_list[idx].sci, SCFIND_MATCHCASE, &ttf); - if (search_pos == -1) - break; - - pos_in_line = sci_get_col_from_position(doc_list[idx].sci,search_pos); - current_tab_true_length = tab_len - (pos_in_line % tab_len); - tab_str = g_strnfill(current_tab_true_length, ' '); - sci_target_start(doc_list[idx].sci, search_pos); - sci_target_end(doc_list[idx].sci, search_pos + 1); - sci_target_replace(doc_list[idx].sci, tab_str, FALSE); - ttf.chrg.cpMin = search_pos + current_tab_true_length - 1; /* next search starts after replacement */ - ttf.chrg.cpMax += current_tab_true_length - 1; /* update end of range now text has changed */ - g_free(tab_str); - } - sci_end_undo_action(doc_list[idx].sci); -} - - -void document_strip_line_trailing_spaces(gint idx, gint line) -{ - gint line_start = sci_get_position_from_line(doc_list[idx].sci, line); - gint line_end = sci_get_line_end_position(doc_list[idx].sci, line); - gint i = line_end - 1; - gchar ch = sci_get_char_at(doc_list[idx].sci, i); - - while ((i >= line_start) && ((ch == ' ') || (ch == '\t'))) - { - i--; - ch = sci_get_char_at(doc_list[idx].sci, i); - } - if (i < (line_end-1)) - { - sci_target_start(doc_list[idx].sci, i + 1); - sci_target_end(doc_list[idx].sci, line_end); - sci_target_replace(doc_list[idx].sci, "", FALSE); - } -} - - -void document_strip_trailing_spaces(gint idx) -{ - gint max_lines = sci_get_line_count(doc_list[idx].sci); - gint line; - - sci_start_undo_action(doc_list[idx].sci); - - for (line = 0; line < max_lines; line++) - { - document_strip_line_trailing_spaces(idx, line); - } - sci_end_undo_action(doc_list[idx].sci); -} - - -void document_ensure_final_newline(gint idx) -{ - gint max_lines = sci_get_line_count(doc_list[idx].sci); - gboolean append_newline = (max_lines == 1); - gint end_document = sci_get_position_from_line(doc_list[idx].sci, max_lines); - - if (max_lines > 1) - { - append_newline = end_document > sci_get_position_from_line(doc_list[idx].sci, max_lines - 1); - } - if (append_newline) - { - const gchar *eol = "\n"; - switch (sci_get_eol_mode(doc_list[idx].sci)) - { - case SC_EOL_CRLF: - eol = "\r\n"; - break; - case SC_EOL_CR: - eol = "\r"; - break; - } - sci_insert_text(doc_list[idx].sci, end_document, eol); - } -} - - /** * Sets the encoding of a %document. * This function only set the encoding of the %document, it does not any conversions. The new @@ -2554,7 +2369,7 @@
/* Gets the status colour of the document, or NULL if default widget * colouring should be used. */ -GdkColor *document_get_status(gint idx) +GdkColor *document_get_status_color(gint idx) { static GdkColor red = {0, 0xFFFF, 0, 0}; static GdkColor green = {0, 0, 0x7FFF, 0}; @@ -2647,35 +2462,6 @@ }
-/* Inserts the given colour (format should be #...), if there is a selection starting with 0x... - * the replacement will also start with 0x... */ -void document_insert_colour(gint idx, const gchar *colour) -{ - g_return_if_fail(DOC_IDX_VALID(idx)); - - if (sci_can_copy(doc_list[idx].sci)) - { - gint start = sci_get_selection_start(doc_list[idx].sci); - const gchar *replacement = colour; - - if (sci_get_char_at(doc_list[idx].sci, start) == '0' && - sci_get_char_at(doc_list[idx].sci, start + 1) == 'x') - { - sci_set_selection_start(doc_list[idx].sci, start + 2); - sci_set_selection_end(doc_list[idx].sci, start + 8); - replacement++; /* skip the leading "0x" */ - } - else if (sci_get_char_at(doc_list[idx].sci, start - 1) == '#') - { /* double clicking something like #00ffff may only select 00ffff because of wordchars */ - replacement++; /* so skip the '#' to only replace the colour value */ - } - sci_replace_sel(doc_list[idx].sci, replacement); - } - else - sci_add_text(doc_list[idx].sci, colour); -} - - gint document_clone(gint old_idx, const gchar *utf8_filename) { /* create a new file and copy file content and properties */
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/document.h 2008-05-15 13:43:29 UTC (rev 2588) @@ -154,26 +154,22 @@
void document_finalize(void);
- void document_set_text_changed(gint idx);
void document_apply_update_prefs(gint idx);
- gboolean document_remove(guint page_num);
gboolean document_account_for_unsaved(void);
gboolean document_close_all(void);
- gint document_new_file_if_non_open();
gint document_new_file(const gchar *filename, filetype *ft, const gchar *text);
gint document_clone(gint old_idx, const gchar *utf8_filename);
- gint document_open_file(const gchar *locale_filename, gboolean readonly, filetype *ft, const gchar *forced_enc);
@@ -192,7 +188,6 @@
gboolean document_save_file(gint idx, gboolean force);
- gboolean document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards, @@ -207,26 +202,10 @@ void document_replace_sel(gint idx, const gchar *find_text, const gchar *replace_text, gint flags, gboolean escaped_chars);
-void document_set_font(gint idx, const gchar *font_name, gint size); - void document_update_tag_list(gint idx, gboolean update);
void document_set_filetype(gint idx, filetype *type);
-gchar *document_get_eol_mode(gint idx); - -void document_fold_all(gint idx); - -void document_unfold_all(gint idx); - -void document_replace_tabs(gint idx); - -void document_strip_line_trailing_spaces(gint idx, gint line); - -void document_strip_trailing_spaces(gint idx); - -void document_ensure_final_newline(gint idx); - void document_set_encoding(gint idx, const gchar *new_encoding);
@@ -263,16 +242,10 @@
void document_undo_add(gint idx, guint type, gpointer data);
-GdkColor *document_get_status(gint idx); +GdkColor *document_get_status_color(gint idx);
void document_delay_colourise(void);
void document_colourise_new(void);
-void document_insert_colour(gint idx, const gchar *colour); - -void document_set_use_tabs(gint idx, gboolean use_tabs); - -void document_set_line_wrapping(gint idx, gboolean wrap); - #endif
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/editor.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -36,6 +36,7 @@ #include "SciLexer.h" #include "geany.h"
+#include "support.h" #include "editor.h" #include "document.h" #include "filetypes.h" @@ -240,7 +241,7 @@ gint indent_size = sci_get_line_indentation(sci, line);
/* break the line after the space */ - sci_insert_text(sci, pos + 1, utils_get_eol_char(idx)); + sci_insert_text(sci, pos + 1, editor_get_eol_char(idx));
if (doc->auto_indent) sci_set_line_indentation(sci, line + 1, indent_size); @@ -582,7 +583,7 @@ static void check_python_indent(gint idx, gint pos) { document *doc = &doc_list[idx]; - gint last_char = pos - utils_get_eol_char_len(idx) - 1; + gint last_char = pos - editor_get_eol_char_len(idx) - 1;
/* add extra indentation for Python after colon */ if (sci_get_char_at(doc->sci, last_char) == ':' && @@ -626,7 +627,7 @@
if (editor_prefs.newline_strip) { /* strip the trailing spaces on the previous line */ - document_strip_line_trailing_spaces(idx, line - 1); + editor_strip_line_trailing_spaces(idx, line - 1); } }
@@ -807,7 +808,7 @@ line_len = sci_get_line_length(sci, line); /* set eol_char_len to 0 if on last line, because there is no EOL char */ eol_char_len = (line == (SSM(sci, SCI_GETLINECOUNT, 0, 0) - 1)) ? 0 : - utils_get_eol_char_len(document_find_by_sci(sci)); + editor_get_eol_char_len(document_find_by_sci(sci));
/* check that the line is empty, to not kill text in the line */ line_buf = sci_get_line(sci, line); @@ -1281,7 +1282,7 @@
/* get the indentation */ if (doc_list[idx].auto_indent) get_indent(&doc_list[idx], pos, TRUE); - eol = g_strconcat(utils_get_eol_char(idx), indent, NULL); + eol = g_strconcat(editor_get_eol_char(idx), indent, NULL);
construct = g_strdup_printf("%s\end%s{%s}", eol, full_cmd, env);
@@ -1368,7 +1369,7 @@ }
get_indent(&doc_list[idx], pos, TRUE); - lindent = g_strconcat(utils_get_eol_char(idx), indent, NULL); + lindent = g_strconcat(editor_get_eol_char(idx), indent, NULL); whitespace = get_whitespace(editor_prefs.tab_width, doc_list[idx].use_tabs);
/* remove the typed word, it will be added again by the used auto completion @@ -1618,7 +1619,7 @@
if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) return;
- eol = utils_get_eol_char(idx); + eol = editor_get_eol_char(idx); str_begin = g_strdup_printf("%s%s", doc_list[idx].file_type->comment_open, eol); str_end = g_strdup_printf("%s%s", doc_list[idx].file_type->comment_close, eol);
@@ -1693,7 +1694,7 @@ first_line = sci_get_line_from_position(doc_list[idx].sci, sel_start); /* Find the last line with chars selected (not EOL char) */ last_line = sci_get_line_from_position(doc_list[idx].sci, - sel_end - utils_get_eol_char_len(idx)); + sel_end - editor_get_eol_char_len(idx)); last_line = MAX(first_line, last_line); } else @@ -1817,7 +1818,7 @@ } else { - gint eol_len = utils_get_eol_char_len(idx); + gint eol_len = editor_get_eol_char_len(idx); sci_set_selection_start(doc_list[idx].sci, sel_start - co_len - eol_len); sci_set_selection_end(doc_list[idx].sci, sel_end - co_len - eol_len); } @@ -1852,7 +1853,7 @@ sci_get_selection_start(doc_list[idx].sci)); /* Find the last line with chars selected (not EOL char) */ last_line = sci_get_line_from_position(doc_list[idx].sci, - sci_get_selection_end(doc_list[idx].sci) - utils_get_eol_char_len(idx)); + sci_get_selection_end(doc_list[idx].sci) - editor_get_eol_char_len(idx)); last_line = MAX(first_line, last_line);
/* detection of HTML vs PHP code, if non-PHP set filetype to XML */ @@ -1981,7 +1982,7 @@ } else { - gint eol_len = utils_get_eol_char_len(idx); + gint eol_len = editor_get_eol_char_len(idx); if (count_uncommented > 0) { sci_set_selection_start(doc_list[idx].sci, sel_start - co_len - eol_len); @@ -2021,7 +2022,7 @@ first_line = sci_get_line_from_position(doc_list[idx].sci, sel_start); /* Find the last line with chars selected (not EOL char) */ last_line = sci_get_line_from_position(doc_list[idx].sci, - sel_end - utils_get_eol_char_len(idx)); + sel_end - editor_get_eol_char_len(idx)); last_line = MAX(first_line, last_line); } else @@ -2136,7 +2137,7 @@ } else { - gint eol_len = utils_get_eol_char_len(idx); + gint eol_len = editor_get_eol_char_len(idx); sci_set_selection_start(doc_list[idx].sci, sel_start + co_len + eol_len); sci_set_selection_end(doc_list[idx].sci, sel_end + co_len + eol_len); } @@ -2181,7 +2182,7 @@ static void auto_multiline(gint idx, gint pos) { ScintillaObject *sci = doc_list[idx].sci; - gint style = SSM(sci, SCI_GETSTYLEAT, pos - 1 - utils_get_eol_char_len(idx), 0); + gint style = SSM(sci, SCI_GETSTYLEAT, pos - 1 - editor_get_eol_char_len(idx), 0); gint lexer = SSM(sci, SCI_GETLEXER, 0, 0);
if ((lexer == SCLEX_CPP && (style == SCE_C_COMMENT || style == SCE_C_COMMENTDOC)) || @@ -2684,7 +2685,7 @@ first_line = sci_get_line_from_position(doc_list[idx].sci, first_sel_start); /* Find the last line with chars selected (not EOL char) */ last_line = sci_get_line_from_position(doc_list[idx].sci, - first_sel_end - utils_get_eol_char_len(idx)); + first_sel_end - editor_get_eol_char_len(idx)); last_line = MAX(first_line, last_line);
if (pos == -1) @@ -2738,7 +2739,7 @@ first_line = sci_get_line_from_position(doc_list[idx].sci, sel_start); /* Find the last line with chars selected (not EOL char) */ last_line = sci_get_line_from_position(doc_list[idx].sci, - sel_end - utils_get_eol_char_len(idx)); + sel_end - editor_get_eol_char_len(idx)); last_line = MAX(first_line, last_line);
if (pos == -1) @@ -2904,7 +2905,7 @@
/* skip blank lines */ if ((start + 1) == end || - sci_get_line_length(doc_list[idx].sci, line) == utils_get_eol_char_len(idx)) + sci_get_line_length(doc_list[idx].sci, line) == editor_get_eol_char_len(idx)) return;
/* don't set the indicator on whitespace */ @@ -2948,4 +2949,244 @@ }
+/* Inserts the given colour (format should be #...), if there is a selection starting with 0x... + * the replacement will also start with 0x... */ +void editor_insert_color(gint idx, const gchar *colour) +{ + g_return_if_fail(DOC_IDX_VALID(idx));
+ if (sci_can_copy(doc_list[idx].sci)) + { + gint start = sci_get_selection_start(doc_list[idx].sci); + const gchar *replacement = colour; + + if (sci_get_char_at(doc_list[idx].sci, start) == '0' && + sci_get_char_at(doc_list[idx].sci, start + 1) == 'x') + { + sci_set_selection_start(doc_list[idx].sci, start + 2); + sci_set_selection_end(doc_list[idx].sci, start + 8); + replacement++; /* skip the leading "0x" */ + } + else if (sci_get_char_at(doc_list[idx].sci, start - 1) == '#') + { /* double clicking something like #00ffff may only select 00ffff because of wordchars */ + replacement++; /* so skip the '#' to only replace the colour value */ + } + sci_replace_sel(doc_list[idx].sci, replacement); + } + else + sci_add_text(doc_list[idx].sci, colour); +} + + +const gchar *editor_get_eol_char_name(gint idx) +{ + if (! DOC_IDX_VALID(idx)) + return ""; + + switch (sci_get_eol_mode(doc_list[idx].sci)) + { + case SC_EOL_CRLF: return _("Win (CRLF)"); break; + case SC_EOL_CR: return _("Mac (CR)"); break; + default: return _("Unix (LF)"); break; + } +} + + +/* returns the end-of-line character(s) length of the specified editor */ +gint editor_get_eol_char_len(gint idx) +{ + if (! DOC_IDX_VALID(idx)) + return 0; + + switch (sci_get_eol_mode(doc_list[idx].sci)) + { + case SC_EOL_CRLF: return 2; break; + default: return 1; break; + } +} + + +/* returns the end-of-line character(s) of the specified editor */ +const gchar *editor_get_eol_char(gint idx) +{ + if (! DOC_IDX_VALID(idx)) + return ""; + + switch (sci_get_eol_mode(doc_list[idx].sci)) + { + case SC_EOL_CRLF: return "\r\n"; break; + case SC_EOL_CR: return "\r"; break; + default: return "\n"; break; + } +} + + +static void fold_all(gint idx, gboolean want_fold) +{ + gint lines, first, i; + + if (! DOC_IDX_VALID(idx) || ! editor_prefs.folding) return; + + lines = sci_get_line_count(doc_list[idx].sci); + first = sci_get_first_visible_line(doc_list[idx].sci); + + for (i = 0; i < lines; i++) + { + gint level = sci_get_fold_level(doc_list[idx].sci, i); + if (level & SC_FOLDLEVELHEADERFLAG) + { + if (sci_get_fold_expanded(doc_list[idx].sci, i) == want_fold) + sci_toggle_fold(doc_list[idx].sci, i); + } + } + editor_scroll_to_line(doc_list[idx].sci, first, 0.0F); +} + + +void editor_unfold_all(gint idx) +{ + fold_all(idx, FALSE); +} + + +void editor_fold_all(gint idx) +{ + fold_all(idx, TRUE); +} + + +void editor_replace_tabs(gint idx) +{ + gint search_pos, pos_in_line, current_tab_true_length; + gint tab_len; + gchar *tab_str; + struct TextToFind ttf; + + if (! DOC_IDX_VALID(idx)) return; + + sci_start_undo_action(doc_list[idx].sci); + tab_len = sci_get_tab_width(doc_list[idx].sci); + ttf.chrg.cpMin = 0; + ttf.chrg.cpMax = sci_get_length(doc_list[idx].sci); + ttf.lpstrText = (gchar*) "\t"; + + while (TRUE) + { + search_pos = sci_find_text(doc_list[idx].sci, SCFIND_MATCHCASE, &ttf); + if (search_pos == -1) + break; + + pos_in_line = sci_get_col_from_position(doc_list[idx].sci,search_pos); + current_tab_true_length = tab_len - (pos_in_line % tab_len); + tab_str = g_strnfill(current_tab_true_length, ' '); + sci_target_start(doc_list[idx].sci, search_pos); + sci_target_end(doc_list[idx].sci, search_pos + 1); + sci_target_replace(doc_list[idx].sci, tab_str, FALSE); + ttf.chrg.cpMin = search_pos + current_tab_true_length - 1; /* next search starts after replacement */ + ttf.chrg.cpMax += current_tab_true_length - 1; /* update end of range now text has changed */ + g_free(tab_str); + } + sci_end_undo_action(doc_list[idx].sci); +} + + +void editor_strip_line_trailing_spaces(gint idx, gint line) +{ + gint line_start = sci_get_position_from_line(doc_list[idx].sci, line); + gint line_end = sci_get_line_end_position(doc_list[idx].sci, line); + gint i = line_end - 1; + gchar ch = sci_get_char_at(doc_list[idx].sci, i); + + while ((i >= line_start) && ((ch == ' ') || (ch == '\t'))) + { + i--; + ch = sci_get_char_at(doc_list[idx].sci, i); + } + if (i < (line_end-1)) + { + sci_target_start(doc_list[idx].sci, i + 1); + sci_target_end(doc_list[idx].sci, line_end); + sci_target_replace(doc_list[idx].sci, "", FALSE); + } +} + + +void editor_strip_trailing_spaces(gint idx) +{ + gint max_lines = sci_get_line_count(doc_list[idx].sci); + gint line; + + sci_start_undo_action(doc_list[idx].sci); + + for (line = 0; line < max_lines; line++) + { + editor_strip_line_trailing_spaces(idx, line); + } + sci_end_undo_action(doc_list[idx].sci); +} + + +void editor_ensure_final_newline(gint idx) +{ + gint max_lines = sci_get_line_count(doc_list[idx].sci); + gboolean append_newline = (max_lines == 1); + gint end_document = sci_get_position_from_line(doc_list[idx].sci, max_lines); + + if (max_lines > 1) + { + append_newline = end_document > sci_get_position_from_line(doc_list[idx].sci, max_lines - 1); + } + if (append_newline) + { + const gchar *eol = "\n"; + switch (sci_get_eol_mode(doc_list[idx].sci)) + { + case SC_EOL_CRLF: + eol = "\r\n"; + break; + case SC_EOL_CR: + eol = "\r"; + break; + } + sci_insert_text(doc_list[idx].sci, end_document, eol); + } +} + + +void editor_set_font(gint idx, const gchar *font_name, gint size) +{ + gint style; + + for (style = 0; style <= 127; style++) + sci_set_font(doc_list[idx].sci, style, font_name, size); + /* line number and braces */ + sci_set_font(doc_list[idx].sci, STYLE_LINENUMBER, font_name, size); + sci_set_font(doc_list[idx].sci, STYLE_BRACELIGHT, font_name, size); + sci_set_font(doc_list[idx].sci, STYLE_BRACEBAD, font_name, size); + /* zoom to 100% to prevent confusion */ + sci_zoom_off(doc_list[idx].sci); +} + + +void editor_set_line_wrapping(gint idx, gboolean wrap) +{ + document *doc = &doc_list[idx]; + + g_return_if_fail(DOC_IDX_VALID(idx)); + + doc->line_wrapping = wrap; + sci_set_lines_wrapped(doc->sci, wrap); +} + + +void editor_set_use_tabs(gint idx, gboolean use_tabs) +{ + document *doc = &doc_list[idx]; + + g_return_if_fail(DOC_IDX_VALID(idx)); + + doc->use_tabs = use_tabs; + sci_set_use_tabs(doc->sci, use_tabs); + /* remove indent spaces on backspace, if using spaces to indent */ + SSM(doc->sci, SCI_SETBACKSPACEUNINDENTS, ! use_tabs, 0); +}
Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/editor.h 2008-05-15 13:43:29 UTC (rev 2588) @@ -175,4 +175,30 @@
void editor_clear_indicators(gint idx);
+void editor_set_font(gint idx, const gchar *font_name, gint size); + +const gchar *editor_get_eol_char_name(gint idx); + +gint editor_get_eol_char_len(gint idx); + +const gchar *editor_get_eol_char(gint idx); + +void editor_fold_all(gint idx); + +void editor_unfold_all(gint idx); + +void editor_replace_tabs(gint idx); + +void editor_strip_line_trailing_spaces(gint idx, gint line); + +void editor_strip_trailing_spaces(gint idx); + +void editor_ensure_final_newline(gint idx); + +void editor_insert_color(gint idx, const gchar *colour); + +void editor_set_use_tabs(gint idx, gboolean use_tabs); + +void editor_set_line_wrapping(gint idx, gboolean wrap); + #endif
Modified: trunk/src/keybindings.c =================================================================== --- trunk/src/keybindings.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/keybindings.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -1068,14 +1068,14 @@ { gint idx = document_get_cur_idx(); if (idx == -1 || ! doc_list[idx].is_valid) return; - document_fold_all(idx); + editor_fold_all(idx); }
static void cb_func_menu_unfoldall(G_GNUC_UNUSED guint key_id) { gint idx = document_get_cur_idx(); if (idx == -1 || ! doc_list[idx].is_valid) return; - document_unfold_all(idx); + editor_unfold_all(idx); }
static void cb_func_build_action(guint key_id)
Modified: trunk/src/keyfile.c =================================================================== --- trunk/src/keyfile.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/keyfile.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -846,8 +846,8 @@
if (DOC_IDX_VALID(new_idx)) { - document_set_use_tabs(new_idx, use_tabs); - document_set_line_wrapping(new_idx, line_wrapping); + editor_set_use_tabs(new_idx, use_tabs); + editor_set_line_wrapping(new_idx, line_wrapping); doc_list[new_idx].auto_indent = auto_indent; ret = TRUE; }
Modified: trunk/src/main.c =================================================================== --- trunk/src/main.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/main.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -689,7 +689,7 @@ } else { - const gchar *msg = _("Could not find file '%s'."); +#define msg _("Could not find file '%s'.")
g_printerr(msg, filename); /* also print to the terminal */ g_printerr("\n");
Modified: trunk/src/prefs.c =================================================================== --- trunk/src/prefs.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/prefs.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -822,7 +822,7 @@ for (i = 0; i < doc_array->len; i++) { if (doc_list[i].is_valid) - document_set_use_tabs(i, editor_prefs.use_tabs); + editor_set_use_tabs(i, editor_prefs.use_tabs); } } } @@ -978,7 +978,7 @@ { document_apply_update_prefs(i); if (! editor_prefs.folding) - document_unfold_all(i); + editor_unfold_all(i); } } ui_document_show_hide(-1);
Modified: trunk/src/tools.c =================================================================== --- trunk/src/tools.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/tools.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -42,6 +42,7 @@ #include "tools.h" #include "support.h" #include "document.h" +#include "editor.h" #include "sciwrappers.h" #include "utils.h" #include "ui_utils.h" @@ -721,7 +722,7 @@ GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(ui_widgets.open_colorsel)->colorsel), &color);
hex = utils_get_hex_from_color(&color); - document_insert_colour(idx, hex); + editor_insert_color(idx, hex); g_free(hex); } #endif
Modified: trunk/src/treeviews.c =================================================================== --- trunk/src/treeviews.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/treeviews.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -309,7 +309,7 @@ void treeviews_openfiles_update(gint idx) { gchar *basename; - GdkColor *color = document_get_status(idx); + GdkColor *color = document_get_status_color(idx);
if (prefs.sidebar_openfiles_fullpath) basename = DOC_FILENAME(idx);
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/ui_utils.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -163,7 +163,7 @@ (doc_list[idx].use_tabs) ? _("TAB") : _("SP ")); /* SP = space */ g_string_append(stats_str, sp); g_string_append_printf(stats_str, _("mode: %s"), - document_get_eol_mode(idx)); + editor_get_eol_char_name(idx)); g_string_append(stats_str, sp); g_string_append_printf(stats_str, _("encoding: %s %s"), (doc_list[idx].encoding) ? doc_list[idx].encoding : _("unknown"), @@ -260,7 +260,7 @@ { if (doc_list[i].sci) { - document_set_font(i, fname, size); + editor_set_font(i, fname, size); } } pango_font_description_free(font_desc); @@ -1195,7 +1195,7 @@ * document status. */ void ui_update_tab_status(gint idx) { - GdkColor *color = document_get_status(idx); + GdkColor *color = document_get_status_color(idx);
/* NULL color will reset to default */ gtk_widget_modify_fg(doc_list[idx].tab_label, GTK_STATE_NORMAL, color);
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/utils.c 2008-05-15 13:43:29 UTC (rev 2588) @@ -641,34 +641,6 @@ }
-/* returns the end-of-line character(s) length of the specified editor */ -gint utils_get_eol_char_len(gint idx) -{ - if (idx == -1) return 0; - - switch (sci_get_eol_mode(doc_list[idx].sci)) - { - case SC_EOL_CRLF: return 2; break; - default: return 1; break; - } -} - - -/* returns the end-of-line character(s) of the specified editor */ -const gchar *utils_get_eol_char(gint idx) -{ - if (idx == -1) return '\0'; - - switch (sci_get_eol_mode(doc_list[idx].sci)) - { - case SC_EOL_CRLF: return "\r\n"; break; - case SC_EOL_CR: return "\r"; break; - case SC_EOL_LF: - default: return "\n"; break; - } -} - - const gchar *utils_get_eol_name(gint eol_mode) { switch (eol_mode)
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2008-05-14 17:58:56 UTC (rev 2587) +++ trunk/src/utils.h 2008-05-15 13:43:29 UTC (rev 2588) @@ -68,10 +68,6 @@
gint utils_get_current_function(gint idx, const gchar **tagname);
-gint utils_get_eol_char_len(gint idx); - -const gchar *utils_get_eol_char(gint idx); - const gchar *utils_get_eol_name(gint eol_mode);
gboolean utils_atob(const gchar *str);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.