Commit 9801d84a by castro

Lisatud algne asendamine

parent f6473bf1
Showing with 95 additions and 0 deletions
#include "search.h"
void find (GtkTextView *text_view, const gchar *text, GtkTextIter *iter)
{
GtkTextIter mstart, mend;
GtkTextBuffer *buffer;
GtkTextMark *last_pos;
gboolean found;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
found = gtk_text_iter_forward_search (iter, text, 0, &mstart, &mend, NULL);
if (found)
{
gtk_text_buffer_select_range (buffer, &mstart, &mend);
last_pos = gtk_text_buffer_create_mark (buffer, "last_pos", &mend, FALSE);
gtk_text_view_scroll_mark_onscreen(text_view, last_pos);
}
}
void asenda (GtkTextView *text_view, const gchar *replace, const gchar *text, GtkTextIter *iter)
{
GtkTextIter mstart, mend;
GtkTextBuffer *buffer;
GtkTextMark *last_pos;
gboolean found;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
found = gtk_text_iter_forward_search (iter, text, 0, &mstart, &mend, NULL);
if (found)
{
gtk_text_buffer_select_range (buffer, &mstart, &mend);
last_pos = gtk_text_buffer_create_mark (buffer, "last_pos", &mend, FALSE);
gtk_text_view_scroll_mark_onscreen(text_view, last_pos);
}
gtk_text_buffer_delete (buffer, &mstart, &mend);
gtk_text_buffer_insert (buffer, &mstart, replace, -1);
}
// funktsioon selleks kui search nuppu vajutatakse
void Otsi_nupp_vajutatud (GtkWidget *search_button, tab *Tab)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (Tab->TextView));
gtk_text_buffer_get_start_iter (buffer, &iter);
find (GTK_TEXT_VIEW (Tab->TextView), text, &iter);
}
// funktsioon selleks kui jargmine_nupp vajutatakse
void Jargmine_nupp_vajutatud (GtkWidget *next_button, tab *Tab)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextMark *last_pos;
GtkTextIter iter;
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (Tab->TextView));
last_pos = gtk_text_buffer_get_mark (buffer, "last_pos");
if (last_pos == NULL)
return;
gtk_text_buffer_get_iter_at_mark (buffer, &iter, last_pos);
find (GTK_TEXT_VIEW (Tab->TextView), text, &iter);
}
void Asenda_nupp_vajutatud (GtkWidget *asenda_nupp, tab *Tab)
{
const gchar *text, *replace;
GtkTextBuffer *buffer;
GtkTextMark *last_pos;
GtkTextIter *mstart, *mend, iter;
gboolean found;
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry));
replace = gtk_entry_get_text (GTK_ENTRY (Tab->replace_entry));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (Tab->TextView));
gtk_text_buffer_get_start_iter (buffer, &iter);
last_pos = gtk_text_buffer_get_mark (buffer, "last_pos");
if (last_pos == NULL)
return;
asenda (GTK_TEXT_VIEW (Tab->TextView), replace, text, &iter);
//gtk_text_buffer_insert (buffer, mstart, replace, -1);
}
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 sign in to comment