Commit 7c7921d2 by castro

Uuendatud search.c

Kommenteeritud ja parandatud sõnade asedamine, asendab nüüd sõna sellest asukohast, kus sõna on highlight-itud
parent ee23d7ee
Showing with 31 additions and 35 deletions
#include "search.h"
GtkTextIter mstart, mend;
//Funktsioon tekstiaknast sna leidmiseks
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);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); // Vtab teksti tekstiaknast puhvrina
found = gtk_text_iter_forward_search (iter, text, 0, &mstart, &mend, NULL); // Otsib text-i ja omistab mstart text-i algusesse ja mend text-i lppu
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_select_range (buffer, &mstart, &mend); // Leiab mstart iter-i ja mend iter-i asukohad puhvris
last_pos = gtk_text_buffer_create_mark (buffer, "last_pos", &mend, FALSE); // Koostab puhvris marki mend asukohal
gtk_text_view_scroll_mark_onscreen(text_view, last_pos); // Highlight-ib tekstiaknas sna
}
}
void asenda (GtkTextView *text_view, const gchar *replace, const gchar *text, GtkTextIter *iter)
//Funktsioon tekstiaknas sna asendamiseks
void asenda (GtkTextView *text_view, const gchar *replace, 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);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); // Vtab teksti tekstiaknast puhvrina
gtk_text_buffer_select_range (buffer, &mstart, &mend); // Leiab mstart iter-i ja mend iter-i asukohad puhvris
gtk_text_buffer_delete (buffer, &mstart, &mend); // Kustutab puhvrist mstart ja mend iter-ite vahel oleva teksti
gtk_text_buffer_insert (buffer, &mstart, replace, -1); // Lisab mstart ja mend iter-ite vahele asendamise kastist oleva teksti
if (found)
{
gtk_text_buffer_select_range (buffer, &mstart, &mend);
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)
......@@ -41,12 +38,12 @@ void Otsi_nupp_vajutatud (GtkWidget *search_button, tab *Tab)
GtkTextBuffer *buffer;
GtkTextIter iter;
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry));
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry)); // Vtab otsingu kastist oleva teksti ja omistab selle text-ile
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (Tab->TextView));
gtk_text_buffer_get_start_iter (buffer, &iter);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (Tab->TextView)); // Vtab teksti kirjutamis aknast puhvrina
gtk_text_buffer_get_start_iter (buffer, &iter); // Koostab iter-i puhvri alguses
find (GTK_TEXT_VIEW (Tab->TextView), text, &iter);
find (GTK_TEXT_VIEW (Tab->TextView), text, &iter); // Funktsioon leiab tekstiaknast text-i sna
}
// funktsioon selleks kui jargmine_nupp vajutatakse
void Jargmine_nupp_vajutatud (GtkWidget *next_button, tab *Tab)
......@@ -56,18 +53,17 @@ void Jargmine_nupp_vajutatud (GtkWidget *next_button, tab *Tab)
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");
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry)); // Vtab otsingu kastist oleva teksti ja omistab selle text-ile
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (Tab->TextView)); // Vtab teksti tekstiaknast puhvrina
last_pos = gtk_text_buffer_get_mark (buffer, "last_pos"); // Koostab puhvris marki
if (last_pos == NULL)
return;
gtk_text_buffer_get_iter_at_mark (buffer, &iter, last_pos);
find (GTK_TEXT_VIEW (Tab->TextView), text, &iter);
gtk_text_buffer_get_iter_at_mark (buffer, &iter, last_pos); // Koostab iter-i mark-i asukohal
find (GTK_TEXT_VIEW (Tab->TextView), text, &iter); // Funktsioon leiab tekstiaknast text-i sna
}
//funktsioon selleks kui asenda nuppu vajutatakse
void Asenda_nupp_vajutatud (GtkWidget *asenda_nupp, tab *Tab)
{
const gchar *text, *replace;
......@@ -75,17 +71,17 @@ void Asenda_nupp_vajutatud (GtkWidget *asenda_nupp, tab *Tab)
GtkTextMark *last_pos;
GtkTextIter iter;
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry));
replace = gtk_entry_get_text (GTK_ENTRY (Tab->replace_entry));
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry)); // Otsingusse siestatud tekst
replace = gtk_entry_get_text (GTK_ENTRY (Tab->replace_entry)); // Tekst, mis asub asendamise teksti kastis
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (Tab->TextView));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (Tab->TextView)); // Vtab teksti tekstiaknast puhvrina
last_pos = gtk_text_buffer_get_mark (buffer, "last_pos");
last_pos = gtk_text_buffer_get_mark (buffer, "last_pos"); // Koostab puhvris marki
if (last_pos == NULL)
return;
gtk_text_buffer_get_start_iter (buffer, &iter);
asenda (GTK_TEXT_VIEW (Tab->TextView), replace, text, &iter);
gtk_text_buffer_get_iter_at_mark (buffer, &iter, last_pos); // Koostab iteri mark-i asukohal
asenda (GTK_TEXT_VIEW (Tab->TextView), replace, text, &iter); // funktsioon asendab text-i replace-ga
}
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