Revision: 964 http://svn.sourceforge.net/geany/?rev=964&view=rev Author: ntrel Date: 2006-11-03 07:09:13 -0800 (Fri, 03 Nov 2006)
Log Message: ----------- Scroll matching selection to 1/3 of the view when searching. Add sci_scroll_to_line(); remove sci_goto_line_scroll(). Show 'not found' message on status bar also when enter is pressed in the search bar.
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/document.c trunk/src/document.h trunk/src/keybindings.c trunk/src/sci_cb.c trunk/src/sciwrappers.c trunk/src/sciwrappers.h trunk/src/search.c trunk/src/utils.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/ChangeLog 2006-11-03 15:09:13 UTC (rev 964) @@ -3,6 +3,14 @@ * src/msgwindow.c: Don't set error indicators when clicking on an error message if the document has been modified. + * src/notebook.c: Focus the current document after clicking on a tab. + * src/utils.c, src/keybindings.c, src/callbacks.c, src/sci_cb.c, + src/sciwrappers.c, src/search.c, src/sciwrappers.h, src/document.c, + src/document.h: + Scroll matching selection to 1/3 of the view when searching. + Add sci_scroll_to_line(); remove sci_goto_line_scroll(). + Show 'not found' message on status bar also when enter is pressed in + the search bar.
2006-11-02 Enrico Tröger enrico.troeger@uvena.de
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/callbacks.c 2006-11-03 15:09:13 UTC (rev 964) @@ -547,7 +547,7 @@ gint idx = document_get_cur_idx();
setup_find_next(GTK_EDITABLE(entry)); - document_search_bar_find(idx, search_data.text, 0, FALSE, FALSE); + document_search_bar_find(idx, search_data.text, 0, FALSE); }
@@ -559,7 +559,7 @@ gint idx = document_get_cur_idx();
setup_find_next(editable); - document_search_bar_find(idx, search_data.text, 0, FALSE, TRUE); + document_search_bar_find(idx, search_data.text, 0, TRUE); }
@@ -573,7 +573,7 @@ GtkWidget *entry = lookup_widget(GTK_WIDGET(app->window), "entry1");
setup_find_next(GTK_EDITABLE(entry)); - document_search_bar_find(idx, search_data.text, 0, TRUE, FALSE); + document_search_bar_find(idx, search_data.text, 0, FALSE); }
@@ -1303,7 +1303,8 @@
if (search_data.text) { - document_find_text(idx, search_data.text, search_data.flags, search_data.backwards); + document_find_text(idx, search_data.text, search_data.flags, + search_data.backwards, TRUE); } }
@@ -1320,7 +1321,8 @@ utils_beep(); //Can't reverse search order for a regex (find next ignores search backwards) else { - document_find_text(idx, search_data.text, search_data.flags, !search_data.backwards); + document_find_text(idx, search_data.text, search_data.flags, + !search_data.backwards, TRUE); } }
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/document.c 2006-11-03 15:09:13 UTC (rev 964) @@ -710,7 +710,8 @@
if (cl_options.goto_line >= 0) { // goto line which was specified on command line and then undefine the line - sci_goto_line_scroll(doc_list[idx].sci, cl_options.goto_line - 1, 0.25); + sci_goto_line(doc_list[idx].sci, cl_options.goto_line - 1, TRUE); + sci_scroll_to_line(doc_list[idx].sci, -1, 0.5); cl_options.goto_line = -1; } else if (pos >= 0) @@ -912,8 +913,7 @@
/* special search function, used from the find entry in the toolbar */ -void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean find_button, - gboolean inc) +void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc) { gint start_pos, search_pos; struct TextToFind ttf; @@ -942,11 +942,11 @@ { sci_set_selection_start(doc_list[idx].sci, ttf.chrgText.cpMin); sci_set_selection_end(doc_list[idx].sci, ttf.chrgText.cpMax); - sci_scroll_caret(doc_list[idx].sci); + sci_scroll_to_line(doc_list[idx].sci, -1, 0.3); } else { - if (find_button) + if (! inc) { gchar *msg = g_strdup_printf(_(""%s" was not found."), text); ui_set_statusbar(msg, FALSE); @@ -961,7 +961,8 @@ /* General search function, used from the find dialog. * Returns -1 on failure or the start position of the matching text. * Will skip past any selection, ignoring it. */ -gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards) +gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards, + gboolean scroll) { gint selection_end, selection_start, search_pos;
@@ -988,7 +989,8 @@
if (search_pos != -1) { - sci_scroll_caret(doc_list[idx].sci); + if (scroll) + sci_scroll_to_line(doc_list[idx].sci, -1, 0.3); } else { @@ -1012,7 +1014,7 @@ { gint ret; sci_goto_pos(doc_list[idx].sci, (search_backwards) ? sci_len : 0, TRUE); - ret = document_find_text(idx, text, flags, search_backwards); + ret = document_find_text(idx, text, flags, search_backwards, scroll); if (ret == -1) // return to original cursor position if not found sci_goto_pos(doc_list[idx].sci, selection_end, FALSE); return ret; @@ -1040,7 +1042,7 @@ if (selection_end == selection_start) { // no selection so just find the next match - document_find_text(idx, find_text, flags, search_backwards); + document_find_text(idx, find_text, flags, search_backwards, TRUE); return -1; } // there's a selection so go to the start before finding to search through it @@ -1050,7 +1052,7 @@ else sci_goto_pos(doc_list[idx].sci, selection_start, TRUE);
- search_pos = document_find_text(idx, find_text, flags, search_backwards); + search_pos = document_find_text(idx, find_text, flags, search_backwards, TRUE); // return if the original selected text did not match (at the start of the selection) if (search_pos != selection_start) return -1;
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/document.h 2006-11-03 15:09:13 UTC (rev 964) @@ -139,12 +139,12 @@ gboolean document_save_file(gint idx, gboolean force);
/* special search function, used from the find entry in the toolbar */ -void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean find_button, - gboolean inc); +void document_search_bar_find(gint idx, const gchar *text, gint flags, gboolean inc);
/* General search function, used from the find dialog. * Returns -1 on failure or the start position of the matching text. */ -gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards); +gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search_backwards, + gboolean scroll);
gint document_replace_text(gint idx, const gchar *find_text, const gchar *replace_text, gint flags, gboolean search_backwards);
Modified: trunk/src/keybindings.c =================================================================== --- trunk/src/keybindings.c 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/keybindings.c 2006-11-03 15:09:13 UTC (rev 964) @@ -721,9 +721,8 @@ new_pos = sci_find_bracematch(doc_list[idx].sci, pos); if (new_pos != -1) { - gint line = sci_get_line_from_position(doc_list[idx].sci, new_pos); - sci_goto_line_scroll(doc_list[idx].sci, line, 0.5); - sci_goto_pos(doc_list[idx].sci, new_pos, FALSE); // set also the cursor the brace + sci_goto_pos(doc_list[idx].sci, new_pos, TRUE); // set the cursor at the brace + sci_scroll_to_line(doc_list[idx].sci, -1, 0.5); } }
Modified: trunk/src/sci_cb.c =================================================================== --- trunk/src/sci_cb.c 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/sci_cb.c 2006-11-03 15:09:13 UTC (rev 964) @@ -1195,7 +1195,7 @@ if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) return;
// remove comment open chars - pos = document_find_text(idx, doc_list[idx].file_type->comment_open, 0, TRUE); + pos = document_find_text(idx, doc_list[idx].file_type->comment_open, 0, TRUE, FALSE); SSM(doc_list[idx].sci, SCI_DELETEBACK, 0, 0);
// check whether the line is empty and can be deleted @@ -1208,7 +1208,7 @@ g_free(linebuf);
// remove comment close chars - pos = document_find_text(idx, doc_list[idx].file_type->comment_close, 0, FALSE); + pos = document_find_text(idx, doc_list[idx].file_type->comment_close, 0, FALSE, FALSE); SSM(doc_list[idx].sci, SCI_DELETEBACK, 0, 0);
// check whether the line is empty and can be deleted
Modified: trunk/src/sciwrappers.c =================================================================== --- trunk/src/sciwrappers.c 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/sciwrappers.c 2006-11-03 15:09:13 UTC (rev 964) @@ -666,6 +666,31 @@ }
+void sci_scroll_lines(ScintillaObject *sci, gint lines) +{ + SSM(sci, SCI_LINESCROLL, 0, lines); +} + + +/* Scroll the view to make line appear at percent_of_view. + * line can be -1 to use the current position. */ +void sci_scroll_to_line(ScintillaObject *sci, gint line, gfloat percent_of_view) +{ + gint vis1, los, delta; + + if (line == -1) + line = sci_get_current_line(sci, -1); + + // sci 'visible line' != file line number + vis1 = SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0); + vis1 = SSM(sci, SCI_DOCLINEFROMVISIBLE, vis1, 0); + los = SSM(sci, SCI_LINESONSCREEN, 0, 0); + delta = (line - vis1) - los * percent_of_view; + sci_scroll_lines(sci, delta); + sci_scroll_caret(sci); //ensure visible, in case of excessive folding/wrapping +} + + gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text) { return SSM(sci, SCI_SEARCHNEXT, flags, (sptr_t) text ); @@ -698,21 +723,6 @@ }
-void sci_goto_line_scroll(ScintillaObject *sci, gint line, gdouble percent_of_view) -{ - gint vis1, los, delta; - - sci_goto_line(sci, line, TRUE); - // sci 'visible line' != file line number - vis1 = SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0); - vis1 = SSM(sci, SCI_DOCLINEFROMVISIBLE, vis1, 0); - los = SSM(sci, SCI_LINESONSCREEN, 0, 0); - delta = (line - vis1) - los * percent_of_view; - sci_scroll_lines(sci, delta); - sci_scroll_caret(sci); //ensure visible, in case of excessive folding/wrapping -} - - void sci_marker_delete_all(ScintillaObject *sci, gint marker) { SSM(sci, SCI_MARKERDELETEALL, marker, 0); @@ -812,11 +822,6 @@ SSM(sci, SCI_SETKEYWORDS, k, (sptr_t) text); }
-void sci_scroll_lines(ScintillaObject *sci, gint lines) -{ - SSM(sci, SCI_LINESCROLL, 0, lines); -} - void sci_set_readonly(ScintillaObject *sci, gboolean readonly) { SSM(sci, SCI_SETREADONLY, readonly, 0);
Modified: trunk/src/sciwrappers.h =================================================================== --- trunk/src/sciwrappers.h 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/sciwrappers.h 2006-11-03 15:09:13 UTC (rev 964) @@ -123,12 +123,13 @@ void sci_set_search_anchor (ScintillaObject * sci); void sci_set_anchor (ScintillaObject * sci, gint pos); void sci_scroll_caret (ScintillaObject * sci); +void sci_scroll_lines (ScintillaObject * sci, gint lines); +void sci_scroll_to_line (ScintillaObject * sci, gint line, gfloat percent_of_view); gint sci_search_next (ScintillaObject * sci, gint flags, const gchar *text); gint sci_search_prev (ScintillaObject * sci, gint flags, const gchar *text); gint sci_find_text (ScintillaObject * sci, gint flags, struct TextToFind *ttf); void sci_set_font (ScintillaObject * sci, gint style, const gchar* font, gint size); void sci_goto_line (ScintillaObject * sci, gint line, gboolean ensure_visibility); -void sci_goto_line_scroll (ScintillaObject * sci, gint line, gdouble percent_of_view); void sci_marker_delete_all (ScintillaObject * sci, gint marker); gint sci_get_style_at (ScintillaObject * sci, gint position); void sci_set_symbol_margin (ScintillaObject * sci, gboolean set); @@ -147,7 +148,6 @@ void sci_target_end (ScintillaObject * sci, gint end); gint sci_target_replace (ScintillaObject * sci, const gchar *text, gboolean regex); void sci_set_keywords (ScintillaObject * sci, gint k, gchar *text); -void sci_scroll_lines (ScintillaObject * sci, gint lines); gint sci_get_lexer (ScintillaObject * sci); void sci_set_readonly (ScintillaObject * sci, gboolean readonly); gboolean sci_get_readonly (ScintillaObject * sci);
Modified: trunk/src/search.c =================================================================== --- trunk/src/search.c 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/search.c 2006-11-03 15:09:13 UTC (rev 964) @@ -753,7 +753,7 @@ case GEANY_RESPONSE_FIND: case GEANY_RESPONSE_FIND_PREVIOUS: document_find_text(idx, search_data.text, search_data.flags, - (response == GEANY_RESPONSE_FIND_PREVIOUS)); + (response == GEANY_RESPONSE_FIND_PREVIOUS), TRUE); check_close = FALSE; break;
@@ -848,7 +848,8 @@ gint rep = document_replace_text(idx, find, replace, search_flags_re, search_backwards_re); if (rep != -1) - document_find_text(idx, find, search_flags_re, search_backwards_re); + document_find_text(idx, find, search_flags_re, search_backwards_re, + TRUE); break; } case GEANY_RESPONSE_REPLACE: @@ -859,7 +860,7 @@ } case GEANY_RESPONSE_FIND: { - document_find_text(idx, find, search_flags_re, search_backwards_re); + document_find_text(idx, find, search_flags_re, search_backwards_re, TRUE); break; } case GEANY_RESPONSE_REPLACE_IN_FILE:
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2006-11-03 15:03:57 UTC (rev 963) +++ trunk/src/utils.c 2006-11-03 15:09:13 UTC (rev 964) @@ -303,7 +303,8 @@ sci_marker_delete_all(doc_list[idx].sci, 0); sci_set_marker_at_line(doc_list[idx].sci, line, TRUE, 0);
- sci_goto_line_scroll(doc_list[idx].sci, line, 0.25); + sci_goto_line(doc_list[idx].sci, line, TRUE); + sci_scroll_to_line(doc_list[idx].sci, -1, 0.25);
// finally switch to the page page_num = gtk_notebook_page_num(GTK_NOTEBOOK(app->notebook), GTK_WIDGET(doc_list[idx].sci));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.