Commit 19189bd0 authored by Gaël Bonithon's avatar Gaël Bonithon Committed by Matthew Brush

Small fixup and cleaning following !1

parent ea81a06b
Pipeline #973 passed with stages
in 1 minute and 47 seconds
......@@ -27,6 +27,7 @@ enum {
MOUSEPAD_RESPONSE_CLEAR,
MOUSEPAD_RESPONSE_CLOSE,
MOUSEPAD_RESPONSE_DONT_SAVE,
MOUSEPAD_RESPONSE_ENTRY_CHANGED,
MOUSEPAD_RESPONSE_FIND,
MOUSEPAD_RESPONSE_JUMP_TO,
MOUSEPAD_RESPONSE_OK,
......
......@@ -224,8 +224,9 @@ mousepad_document_finalize (GObject *object)
/* release the file */
g_object_unref (G_OBJECT (document->file));
/* release the buffer reference */
/* release the buffer reference and the search context reference */
g_object_unref (G_OBJECT (document->buffer));
g_object_unref (G_OBJECT (document->search_context));
(*G_OBJECT_CLASS (mousepad_document_parent_class)->finalize) (object);
}
......
......@@ -370,6 +370,17 @@ mousepad_replace_dialog_response (GtkWidget *widget,
else
flags |= MOUSEPAD_SEARCH_FLAGS_ITER_SEL_END;
}
else if (response_id == MOUSEPAD_RESPONSE_ENTRY_CHANGED)
{
/* select the first match */
flags |= MOUSEPAD_SEARCH_FLAGS_ACTION_SELECT;
/* start at the 'beginning' of the selection */
if (flags & MOUSEPAD_SEARCH_FLAGS_DIR_BACKWARD)
flags |= MOUSEPAD_SEARCH_FLAGS_ITER_SEL_END;
else
flags |= MOUSEPAD_SEARCH_FLAGS_ITER_SEL_START;
}
else if (response_id == MOUSEPAD_RESPONSE_REPLACE)
{
/* replace matches */
......@@ -410,7 +421,7 @@ static void
mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog)
{
const gchar *text;
gboolean sensitive;
gboolean sensitive = TRUE;
gboolean replace_all;
replace_all = MOUSEPAD_SETTING_GET_BOOLEAN (SEARCH_REPLACE_ALL);
......@@ -425,15 +436,13 @@ mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog)
/* get the search entry text */
text = gtk_entry_get_text (GTK_ENTRY (dialog->search_entry));
if (text != NULL && *text != '\0')
{
/* do an invisible search to give the user some visible feedback */
gtk_dialog_response (GTK_DIALOG (dialog), MOUSEPAD_RESPONSE_FIND);
/* if the search entry text has changed, behaves like the search bar entry: find as you type
* else, it is likely to be an invisible search */
if (text != NULL)
gtk_dialog_response (GTK_DIALOG (dialog), MOUSEPAD_RESPONSE_ENTRY_CHANGED);
/* buttons are sensitive */
sensitive = TRUE;
}
else
/* update replace dialog */
if (text == NULL || *text == '\0')
{
/* not text, means no error */
mousepad_util_entry_error (dialog->search_entry, FALSE);
......
......@@ -636,7 +636,7 @@ mousepad_util_search (GtkSourceSearchContext *search_context,
GtkSourceSearchSettings *search_settings;
GtkTextBuffer *buffer, *selection_buffer;
GtkTextIter start, end, iter, bstart, fend, biter, fiter;
const gchar *selected_text;
gchar *selected_text;
gint counter = 0;
gboolean found;
......@@ -686,7 +686,7 @@ mousepad_util_search (GtkSourceSearchContext *search_context,
/* set the counter, ensuring the buffer is fully scanned if needed (searching in both
* directions leads faster to a full scan) */
counter = gtk_source_search_context_get_occurrences_count (search_context);
if (counter == -1 && (flags & MOUSEPAD_SEARCH_FLAGS_ENTIRE_AREA))
if (counter == -1 && (flags & MOUSEPAD_SEARCH_FLAGS_ENTIRE_AREA) && *string != '\0')
{
gtk_source_search_settings_set_wrap_around (search_settings, TRUE);
if (! found)
......@@ -709,7 +709,7 @@ mousepad_util_search (GtkSourceSearchContext *search_context,
gtk_source_search_settings_set_wrap_around (search_settings,
(flags & MOUSEPAD_SEARCH_FLAGS_WRAP_AROUND));
}
else if (counter == -1 && ! (flags & MOUSEPAD_SEARCH_FLAGS_ENTIRE_AREA))
else if (counter == -1)
counter = found;
/* handle the action */
......@@ -753,6 +753,14 @@ mousepad_util_search (GtkSourceSearchContext *search_context,
/* thawn buffer notifications */
g_object_thaw_notify (G_OBJECT (buffer));
/* cleanup */
if (flags & MOUSEPAD_SEARCH_FLAGS_AREA_SELECTION)
{
g_object_unref (G_OBJECT (selection_buffer));
g_object_unref (G_OBJECT (search_context));
g_free (selected_text);
}
return counter;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment