Revision: 1649 http://svn.sourceforge.net/geany/?rev=1649&view=rev Author: eht16 Date: 2007-06-27 12:36:43 -0700 (Wed, 27 Jun 2007)
Log Message: ----------- Change signature of sci_replace_sel() to take a const gchar*. Move code to insert a colour to document.c Let the code also work on Windows (untested).
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/document.c trunk/src/document.h trunk/src/sciwrappers.c trunk/src/sciwrappers.h trunk/src/win32.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-06-27 19:07:03 UTC (rev 1648) +++ trunk/ChangeLog 2007-06-27 19:36:43 UTC (rev 1649) @@ -4,6 +4,11 @@ Add palette to Colour Chooser Dialog. Fix picking colours starting with '#'. Replace existing selection with chosen colour. + * src/callbacks.c, src/document.c, src/document.h, src/sciwrappers.c, + src/sciwrappers.h, src/win32.c: + Change signature of sci_replace_sel() to take a const gchar*. + Move code to insert a colour to document.c + Let the code also work on Windows (untested).
2007-06-27 Nick Treleaven nick.treleaven@btinternet.com
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2007-06-27 19:07:03 UTC (rev 1648) +++ trunk/src/callbacks.c 2007-06-27 19:36:43 UTC (rev 1649) @@ -994,27 +994,7 @@ GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(app->open_colorsel)->colorsel), &color);
hex = utils_get_hex_from_color(&color); - // add the selected colour into the doc, prefer #... format unless there is a selection - // starting with 0x... - if (sci_can_copy(doc_list[idx].sci)) - { - gint start = sci_get_selection_start(doc_list[idx].sci); - gchar *replacement = hex; - - 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); - replacement++; // skip the leading '#' - } - 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, hex); + document_insert_colour(idx, hex); g_free(hex); }
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2007-06-27 19:07:03 UTC (rev 1648) +++ trunk/src/document.c 2007-06-27 19:36:43 UTC (rev 1649) @@ -2245,3 +2245,29 @@ }
+/* Inserts the given colour (format should be #...), if there is a selection starting with 0x... + * the replacement starts also 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); + replacement++; // skip the leading '#' + } + 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); +}
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2007-06-27 19:07:03 UTC (rev 1648) +++ trunk/src/document.h 2007-06-27 19:36:43 UTC (rev 1649) @@ -246,4 +246,6 @@
void document_colourise_new();
+void document_insert_colour(gint idx, const gchar *colour); + #endif
Modified: trunk/src/sciwrappers.c =================================================================== --- trunk/src/sciwrappers.c 2007-06-27 19:07:03 UTC (rev 1648) +++ trunk/src/sciwrappers.c 2007-06-27 19:36:43 UTC (rev 1649) @@ -466,7 +466,7 @@ }
-void sci_replace_sel(ScintillaObject* sci, gchar* text) +void sci_replace_sel(ScintillaObject* sci, const gchar* text) { SSM(sci, SCI_REPLACESEL,0, (sptr_t) text); }
Modified: trunk/src/sciwrappers.h =================================================================== --- trunk/src/sciwrappers.h 2007-06-27 19:07:03 UTC (rev 1648) +++ trunk/src/sciwrappers.h 2007-06-27 19:36:43 UTC (rev 1649) @@ -79,7 +79,7 @@
gint sci_get_selection_start (ScintillaObject* sci); gint sci_get_selection_end (ScintillaObject* sci); -void sci_replace_sel (ScintillaObject* sci, gchar* text); +void sci_replace_sel (ScintillaObject* sci, const gchar* text); gint sci_get_selection_mode (ScintillaObject* sci); void sci_set_selection_mode (ScintillaObject* sci, gint mode); gint sci_get_pos_at_line_sel_start(ScintillaObject*sci, gint line);
Modified: trunk/src/win32.c =================================================================== --- trunk/src/win32.c 2007-06-27 19:07:03 UTC (rev 1648) +++ trunk/src/win32.c 2007-06-27 19:36:43 UTC (rev 1649) @@ -397,7 +397,7 @@ (guint) (utils_scale_round(GetGValue(rgb_current), 255)), (guint) (utils_scale_round(GetBValue(rgb_current), 255)));
- sci_add_text(doc_list[idx].sci, hex); + document_insert_colour(idx, hex); } g_free(hex); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.