static void ide_editor_frame_actions_replace (GSimpleAction *action, GVariant *state, gpointer user_data) { IdeEditorFrame *self = user_data; GtkSourceSearchContext *search_context; GtkSourceSearchSettings *search_settings; const gchar *replace_text; gchar *unescaped_replace_text; const gchar *search_text; GError *error = NULL; GtkTextIter start; GtkTextIter end; GtkTextBuffer *buffer; gint occurrence_position; g_assert (IDE_IS_EDITOR_FRAME (self)); search_context = ide_source_view_get_search_context (self->source_view); g_assert (search_context != NULL); search_settings = gtk_source_search_context_get_settings (search_context); search_text = gtk_source_search_settings_get_search_text (search_settings); replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry)); if (ide_str_empty0 (search_text) || replace_text == NULL) return; unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_text); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view)); gtk_text_buffer_get_selection_bounds (buffer, &start, &end); occurrence_position = gtk_source_search_context_get_occurrence_position (search_context, &start, &end); if (occurrence_position > 0) { /* Temporarily disable updating the search position label to prevent flickering */ g_signal_handler_block (buffer, self->cursor_moved_handler); gtk_source_search_context_replace2 (search_context, &start, &end, unescaped_replace_text, -1, &error); /* Re-enable updating the search position label. The next-search-result action * below will cause it to update. */ g_signal_handler_unblock (buffer, self->cursor_moved_handler); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); } ide_widget_action (GTK_WIDGET (self), "frame", "next-search-result", NULL); } g_free (unescaped_replace_text); }
static void ide_editor_frame_actions_replace_all (GSimpleAction *action, GVariant *state, gpointer user_data) { IdeEditorFrame *self = user_data; GtkSourceSearchContext *search_context; GtkSourceSearchSettings *search_settings; const gchar *replace_text; gchar *unescaped_replace_text; const gchar *search_text; GError *error = NULL; GtkSourceCompletion *completion; g_assert (IDE_IS_EDITOR_FRAME (self)); search_context = ide_source_view_get_search_context (self->source_view); g_assert (search_context != NULL); search_settings = gtk_source_search_context_get_settings (search_context); search_text = gtk_source_search_settings_get_search_text (search_settings); replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry)); if (ide_str_empty0 (search_text) || replace_text == NULL) return; /* Temporarily disabling auto completion makes replace more efficient. */ completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (self->source_view)); gtk_source_completion_block_interactive (completion); unescaped_replace_text = gtk_source_utils_unescape_search_text (replace_text); gtk_source_search_context_replace_all (search_context, unescaped_replace_text, -1, &error); gtk_source_completion_unblock_interactive (completion); if (error != NULL) { g_warning ("%s", error->message); g_clear_error (&error); } g_free (unescaped_replace_text); }
static gboolean search_text_transform_to (GBinding *binding, const GValue *from_value, GValue *to_value, gpointer user_data) { IdeEditorFrame *self = user_data; g_assert (IDE_IS_EDITOR_FRAME (self)); g_assert (from_value != NULL); g_assert (to_value != NULL); if (g_value_get_string (from_value) == NULL) { g_value_set_string (to_value, ""); } else { const gchar *entry_text = g_value_get_string (from_value); GtkSourceSearchContext *search_context; GtkSourceSearchSettings *search_settings; search_context = ide_source_view_get_search_context (self->source_view); search_settings = gtk_source_search_context_get_settings (search_context); if (gtk_source_search_settings_get_regex_enabled (search_settings)) { g_value_set_string (to_value, entry_text); } else { gchar *unescaped_entry_text; unescaped_entry_text = gtk_source_utils_unescape_search_text (entry_text); g_value_set_string (to_value, unescaped_entry_text); g_free (unescaped_entry_text); } } return TRUE; }