Commit 8240521d by karudu

Lisatud uus search kood + asendamise fix

parent bf4c75a8
Showing with 51 additions and 52 deletions
#include "search.h"
GtkTextIter mstart, mend;
int Asendatud = 0;
//Funktsioon tekstiaknast sna leidmiseks
void find (GtkTextView *text_view, const gchar *text, GtkTextIter *iter)
{
GtkTextIter mstart, mend;
GtkTextBuffer *buffer;
GtkTextMark *last_pos;
gboolean found;
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)
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
Asendatud = 0;
}
}
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;
if(Asendatud == 0)
{
GtkTextBuffer *buffer;
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
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);
}
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
Asendatud = 1;
}
}
// funktsioon selleks kui search nuppu vajutatakse
void Otsi_nupp_vajutatud (GtkWidget *search_button, tab *Tab)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
const gchar *text;
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)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextMark *last_pos;
GtkTextIter iter;
text = gtk_entry_get_text (GTK_ENTRY (Tab->search_entry));
const gchar *text;
GtkTextBuffer *buffer;
GtkTextMark *last_pos;
GtkTextIter iter;
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
if (last_pos == NULL)
return;
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 +76,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, &iter); // funktsioon asendab text-i replace-ga
}
......@@ -2,11 +2,9 @@
#define SEARCH_H
#include "ceditor.h"
#ifdef SOURCEVIEW
#include <gtksourceview/gtksource.h>
#endif
void find (GtkTextView *text_view, const gchar *text, GtkTextIter *iter);
void asenda (GtkTextView *text_view, const gchar *replace, GtkTextIter *iter);
void Otsi_nupp_vajutatud (GtkWidget *search_button, tab *Tab);
void Jargmine_nupp_vajutatud (GtkWidget *next_button, tab *Tab);
void Asenda_nupp_vajutatud (GtkWidget *asenda_nupp, tab *Tab);
......
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