Commit bf4c75a8 by karudu

Lisatud teksti otsingu/asendamise riba

parent 2bb9f0a0
Showing with 132 additions and 0 deletions
...@@ -16,6 +16,8 @@ typedef struct ...@@ -16,6 +16,8 @@ typedef struct
GtkSourceBuffer *Puhver; // Vahekaardi tekstipuhver GtkSourceBuffer *Puhver; // Vahekaardi tekstipuhver
GtkWidget *ScrollWindow; // Tekstiakna scroll GtkWidget *ScrollWindow; // Tekstiakna scroll
GtkWidget *StatusBar; // Status bar GtkWidget *StatusBar; // Status bar
GtkWidget *search_entry; // Otsingu tekst entry
GtkWidget *replace_entry; // Asendamise tekst entry
GtkSourceLanguageManager *LangManager; // Süntaksi värvimise asjad GtkSourceLanguageManager *LangManager; // Süntaksi värvimise asjad
GtkSourceLanguage *Language; GtkSourceLanguage *Language;
......
#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);
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 iter;
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));
last_pos = gtk_text_buffer_get_mark (buffer, "last_pos");
if (last_pos == NULL)
return;
gtk_text_buffer_get_start_iter (buffer, &iter);
asenda (GTK_TEXT_VIEW (Tab->TextView), replace, text, &iter);
}
#ifndef SEARCH_H
#define SEARCH_H
#include "ceditor.h"
#ifdef SOURCEVIEW
#include <gtksourceview/gtksource.h>
#endif
void find (GtkTextView *text_view, const gchar *text, 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);
#endif // SEARCH_H
...@@ -153,6 +153,30 @@ void LisaTab(ui *UI) ...@@ -153,6 +153,30 @@ void LisaTab(ui *UI)
g_free(FondiNimi); g_free(FondiNimi);
} }
// Otsing
GtkWidget *hbox = gtk_hbox_new (FALSE, 2);
Tab->search_entry = gtk_entry_new ();
GtkWidget *Otsi_nupp = gtk_button_new_with_label ("Otsi"); // Otsi nupp
g_signal_connect (G_OBJECT (Otsi_nupp), "clicked",
G_CALLBACK (Otsi_nupp_vajutatud), &UI->Tabid[TabidN]);
GtkWidget *Jargmine_nupp = gtk_button_new_with_label ("Järgmine"); // Järmine nupp
g_signal_connect (G_OBJECT (Jargmine_nupp), "clicked",
G_CALLBACK (Jargmine_nupp_vajutatud), &UI->Tabid[TabidN]);
// Teksti asendamine
Tab->replace_entry = gtk_entry_new ();
GtkWidget *Asenda_nupp =gtk_button_new_with_label ("Asenda"); // Asenda teksti nupp
gtk_box_pack_start (GTK_BOX (hbox), Tab->search_entry, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), Otsi_nupp, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), Jargmine_nupp, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), Tab->replace_entry, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), Asenda_nupp, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (Asenda_nupp), "clicked",
G_CALLBACK (Asenda_nupp_vajutatud), &UI->Tabid[TabidN]);
// Scroll window // Scroll window
Tab->ScrollWindow = gtk_scrolled_window_new(NULL, NULL); // Loo scroll aken Tab->ScrollWindow = gtk_scrolled_window_new(NULL, NULL); // Loo scroll aken
gtk_container_add(GTK_CONTAINER(Tab->ScrollWindow), Tab->TextView); // Scroll aknasse läheb tekstiaken gtk_container_add(GTK_CONTAINER(Tab->ScrollWindow), Tab->TextView); // Scroll aknasse läheb tekstiaken
...@@ -168,6 +192,7 @@ void LisaTab(ui *UI) ...@@ -168,6 +192,7 @@ void LisaTab(ui *UI)
// Box // Box
Tab->Box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); // Vertikaalne box, 0px vahe Tab->Box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); // Vertikaalne box, 0px vahe
gtk_box_pack_start(GTK_BOX(Tab->Box), hbox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(Tab->Box), Tab->ScrollWindow, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(Tab->Box), Tab->ScrollWindow, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(Tab->Box), Tab->StatusBar, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(Tab->Box), Tab->StatusBar, FALSE, FALSE, 0);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "ceditor.h" #include "ceditor.h"
#include "statusbar.h" #include "statusbar.h"
#include "search.h"
#include "textview.h" #include "textview.h"
void LisaTab(ui *UI); void LisaTab(ui *UI);
......
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