Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
karudu
/
C-editor
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8240521d
authored
Apr 26, 2022
by
karudu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lisatud uus search kood + asendamise fix
parent
bf4c75a8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
52 deletions
search.c
search.h
search.c
View file @
8240521d
#include "search.h"
#include "search.h"
GtkTextIter
mstart
,
mend
;
int
Asendatud
=
0
;
//Funktsioon tekstiaknast sna leidmiseks
void
find
(
GtkTextView
*
text_view
,
const
gchar
*
text
,
GtkTextIter
*
iter
)
void
find
(
GtkTextView
*
text_view
,
const
gchar
*
text
,
GtkTextIter
*
iter
)
{
{
GtkTextIter
mstart
,
mend
;
GtkTextBuffer
*
buffer
;
GtkTextBuffer
*
buffer
;
GtkTextMark
*
last_pos
;
GtkTextMark
*
last_pos
;
gboolean
found
;
gboolean
found
;
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
text_view
));
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
);
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
);
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
);
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
);
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
;
if
(
Asendatud
==
0
)
GtkTextBuffer
*
buffer
;
{
GtkTextMark
*
last_pos
;
GtkTextBuffer
*
buffer
;
gboolean
found
;
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
text_view
));
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
);
if
(
found
)
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_select_range
(
buffer
,
&
mstart
,
&
mend
);
gtk_text_buffer_insert
(
buffer
,
&
mstart
,
replace
,
-
1
);
// Lisab mstart ja mend iter-ite vahele asendamise kastist oleva teksti
gtk_text_buffer_delete
(
buffer
,
&
mstart
,
&
mend
);
gtk_text_buffer_insert
(
buffer
,
&
mstart
,
replace
,
-
1
)
;
Asendatud
=
1
;
}
}
}
}
// funktsioon selleks kui search nuppu vajutatakse
// funktsioon selleks kui search nuppu vajutatakse
void
Otsi_nupp_vajutatud
(
GtkWidget
*
search_button
,
tab
*
Tab
)
void
Otsi_nupp_vajutatud
(
GtkWidget
*
search_button
,
tab
*
Tab
)
{
{
const
gchar
*
text
;
const
gchar
*
text
;
GtkTextBuffer
*
buffer
;
GtkTextBuffer
*
buffer
;
GtkTextIter
iter
;
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
));
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
Tab
->
TextView
));
// Vtab teksti kirjutamis aknast puhvrina
gtk_text_buffer_get_start_iter
(
buffer
,
&
iter
);
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
// funktsioon selleks kui jargmine_nupp vajutatakse
void
Jargmine_nupp_vajutatud
(
GtkWidget
*
next_button
,
tab
*
Tab
)
void
Jargmine_nupp_vajutatud
(
GtkWidget
*
next_button
,
tab
*
Tab
)
{
{
const
gchar
*
text
;
const
gchar
*
text
;
GtkTextBuffer
*
buffer
;
GtkTextBuffer
*
buffer
;
GtkTextMark
*
last_pos
;
GtkTextMark
*
last_pos
;
GtkTextIter
iter
;
GtkTextIter
iter
;
text
=
gtk_entry_get_text
(
GTK_ENTRY
(
Tab
->
search_entry
));
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
Tab
->
TextView
));
text
=
gtk_entry_get_text
(
GTK_ENTRY
(
Tab
->
search_entry
));
// Vtab otsingu kastist oleva teksti ja omistab selle text-ile
last_pos
=
gtk_text_buffer_get_mark
(
buffer
,
"last_pos"
);
if
(
last_pos
==
NULL
)
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
Tab
->
TextView
));
// Vtab teksti tekstiaknast puhvrina
return
;
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
);
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
);
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
)
void
Asenda_nupp_vajutatud
(
GtkWidget
*
asenda_nupp
,
tab
*
Tab
)
{
{
const
gchar
*
text
,
*
replace
;
const
gchar
*
text
,
*
replace
;
...
@@ -75,17 +76,17 @@ void Asenda_nupp_vajutatud (GtkWidget *asenda_nupp, tab *Tab)
...
@@ -75,17 +76,17 @@ void Asenda_nupp_vajutatud (GtkWidget *asenda_nupp, tab *Tab)
GtkTextMark
*
last_pos
;
GtkTextMark
*
last_pos
;
GtkTextIter
iter
;
GtkTextIter
iter
;
text
=
gtk_entry_get_text
(
GTK_ENTRY
(
Tab
->
search_entry
));
text
=
gtk_entry_get_text
(
GTK_ENTRY
(
Tab
->
search_entry
));
// Otsingusse siestatud tekst
replace
=
gtk_entry_get_text
(
GTK_ENTRY
(
Tab
->
replace_entry
));
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
)
if
(
last_pos
==
NULL
)
return
;
return
;
gtk_text_buffer_get_
start_iter
(
buffer
,
&
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
);
asenda
(
GTK_TEXT_VIEW
(
Tab
->
TextView
),
replace
,
&
iter
);
// funktsioon asendab text-i replace-ga
}
}
search.h
View file @
8240521d
...
@@ -2,11 +2,9 @@
...
@@ -2,11 +2,9 @@
#define SEARCH_H
#define SEARCH_H
#include "ceditor.h"
#include "ceditor.h"
#ifdef SOURCEVIEW
#include <gtksourceview/gtksource.h>
#endif
void
find
(
GtkTextView
*
text_view
,
const
gchar
*
text
,
GtkTextIter
*
iter
);
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
Otsi_nupp_vajutatud
(
GtkWidget
*
search_button
,
tab
*
Tab
);
void
Jargmine_nupp_vajutatud
(
GtkWidget
*
next_button
,
tab
*
Tab
);
void
Jargmine_nupp_vajutatud
(
GtkWidget
*
next_button
,
tab
*
Tab
);
void
Asenda_nupp_vajutatud
(
GtkWidget
*
asenda_nupp
,
tab
*
Tab
);
void
Asenda_nupp_vajutatud
(
GtkWidget
*
asenda_nupp
,
tab
*
Tab
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment