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
9801d84a
authored
Apr 20, 2022
by
castro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lisatud algne asendamine
parent
f6473bf1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
search.c
search.c
0 → 100644
View file @
9801d84a
#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);
}
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