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
bf4c75a8
authored
Apr 21, 2022
by
karudu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lisatud teksti otsingu/asendamise riba
parent
2bb9f0a0
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
0 deletions
ceditor.h
search.c
search.h
tab.c
tab.h
ceditor.h
View file @
bf4c75a8
...
...
@@ -16,6 +16,8 @@ typedef struct
GtkSourceBuffer
*
Puhver
;
// Vahekaardi tekstipuhver
GtkWidget
*
ScrollWindow
;
// Tekstiakna scroll
GtkWidget
*
StatusBar
;
// Status bar
GtkWidget
*
search_entry
;
// Otsingu tekst entry
GtkWidget
*
replace_entry
;
// Asendamise tekst entry
GtkSourceLanguageManager
*
LangManager
;
// Süntaksi värvimise asjad
GtkSourceLanguage
*
Language
;
...
...
search.c
0 → 100644
View file @
bf4c75a8
#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
);
}
search.h
0 → 100644
View file @
bf4c75a8
#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
tab.c
View file @
bf4c75a8
...
...
@@ -153,6 +153,30 @@ void LisaTab(ui *UI)
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
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
...
...
@@ -168,6 +192,7 @@ void LisaTab(ui *UI)
// Box
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
->
StatusBar
,
FALSE
,
FALSE
,
0
);
...
...
tab.h
View file @
bf4c75a8
...
...
@@ -3,6 +3,7 @@
#include "ceditor.h"
#include "statusbar.h"
#include "search.h"
#include "textview.h"
void
LisaTab
(
ui
*
UI
);
...
...
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