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
7d8b28dc
authored
Mar 23, 2022
by
Castro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
töötav otsingu bar
parent
0b24014e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
141 deletions
ceditor.h
search.c
search.h
tab.c
tab.h
ui.h
ceditor.h
View file @
7d8b28dc
...
...
@@ -17,6 +17,7 @@ typedef struct
GtkTextView
*
Puhver
;
// Vahekaardi tekstipuhver
GtkWidget
*
ScrollWindow
;
// Tekstiakna scroll
GtkWidget
*
StatusBar
;
// Status bar
GtkWidget
*
search_entry
;
}
tab
;
typedef
struct
...
...
search.c
View file @
7d8b28dc
#include
<gtk/gtk.h>
#include
"search.h"
/* TODO
Failide avamine
Failide salvestamine
*/
#ifdef SOURCEVIEW
#include <gtksourceview/gtksource.h>
#endif
#ifdef SOURCEVIEW
#define PEALKIRI "CEditor SourceView"
#else
#define PEALKIRI "CEditor TextView"
#endif
//struckt Otsi_akna jaoks
typedef
struct
_App
{
GtkWidget
*
text_view
;
GtkWidget
*
search_entry
;
}
App
;
// Uuenda näidatud rida ja veergu kursori asukoha järgi
void
UuendaRidaVeerg
(
GtkTextBuffer
*
Puhver
,
GtkStatusbar
*
StatusBar
)
void
find
(
GtkTextView
*
text_view
,
const
gchar
*
text
,
GtkTextIter
*
iter
)
{
GtkTextIter
Iter
;
// Leia kursori asukoht
gtk_text_buffer_get_iter_at_mark
(
Puhver
,
&
Iter
,
gtk_text_buffer_get_insert
(
Puhver
));
// Võta selle rida ja veerg
gint
Rida
=
gtk_text_iter_get_line
(
&
Iter
);
gint
Veerg
=
gtk_text_iter_get_line_offset
(
&
Iter
);
gtk_statusbar_pop
(
StatusBar
,
0
);
// Võta eelmine tekst ära
gchar
*
Tekst
=
g_strdup_printf
(
"%d:%d"
,
Rida
+
1
,
Veerg
+
1
);
// Loo string rea ja veeruga
gtk_statusbar_push
(
StatusBar
,
0
,
Tekst
);
// Näita teksti
GtkTextIter
mstart
,
mend
;
GtkTextBuffer
*
buffer
;
gboolean
found
;
g_free
(
Tekst
);
}
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
text_view
)
);
found
=
gtk_text_iter_forward_search
(
iter
,
text
,
0
,
&
mstart
,
&
mend
,
NULL
);
// Kutsutakse copy/paste lohistamise korral, praegu lihtsalt uuendab rida/veergu
void
TekstMarkSet
(
GtkTextBuffer
*
Puhver
,
const
GtkTextIter
*
new_location
,
GtkTextMark
*
Mark
,
gpointer
Data
)
{
UuendaRidaVeerg
(
Puhver
,
GTK_STATUSBAR
(
Data
));
if
(
found
)
{
gtk_text_buffer_select_range
(
buffer
,
&
mstart
,
&
mend
);
gtk_text_buffer_create_mark
(
buffer
,
"last_pos"
,
&
mend
,
FALSE
);
}
}
// funktsioon selleks kui search nuppu vajutatakse
void
Otsi_nupp_vajutatud
(
GtkWidget
*
Otsi_nupp
,
App
*
app
)
void
Otsi_nupp_vajutatud
(
GtkWidget
*
search_button
,
tab
*
Tab
)
{
const
gchar
*
text
;
GtkTextBuffer
*
buffer
;
GtkTextIter
iter
;
GtkTextIter
mstart
,
mend
;
gboolean
found
;
text
=
gtk_entry_get_text
(
GTK_ENTRY
(
app
->
search_entry
));
text
=
gtk_entry_get_text
(
GTK_ENTRY
(
Tab
->
search_entry
));
/* Get the buffer associated with the text view widget. */
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
app
->
text_view
));
/* Search from the start from buffer for text. */
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
Tab
->
TextView
));
gtk_text_buffer_get_start_iter
(
buffer
,
&
iter
);
found
=
gtk_text_iter_forward_search
(
&
iter
,
text
,
0
,
&
mstart
,
&
mend
,
NULL
);
if
(
found
)
{
/* If found, hilight the text. */
gtk_text_buffer_select_range
(
buffer
,
&
mstart
,
&
mend
);
}
find
(
GTK_TEXT_VIEW
(
Tab
->
TextView
),
text
,
&
iter
);
}
int
main
(
int
argc
,
char
**
argv
)
// funktsioon selleks kui jargmine_nupp vajutatakse
void
Jargmine_nupp_vajutatud
(
GtkWidget
*
next_button
,
tab
*
Tab
)
{
gtk_init
(
&
argc
,
&
argv
);
// Aken
GtkWidget
*
Aken
=
gtk_window_new
(
GTK_WINDOW_TOPLEVEL
);
// Loo aken
gtk_window_set_position
(
GTK_WINDOW
(
Aken
),
GTK_WIN_POS_CENTER
);
// Aken ekraani keskel
gtk_window_set_default_size
(
GTK_WINDOW
(
Aken
),
800
,
600
);
// Akna suurus
gtk_window_set_title
(
GTK_WINDOW
(
Aken
),
PEALKIRI
);
// Pealkiri
// Close nupu callback
g_signal_connect_swapped
(
G_OBJECT
(
Aken
),
"destroy"
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
// Box
GtkWidget
*
Box
=
gtk_box_new
(
GTK_ORIENTATION_VERTICAL
,
0
);
// Vertikaalne box, 0px vahe
gtk_container_add
(
GTK_CONTAINER
(
Aken
),
Box
);
// Pane box aknasse
// Menu bar
GtkWidget
*
MenuBar
=
gtk_menu_bar_new
();
// Loo menu bar
GtkWidget
*
FailMenuNupp
=
gtk_menu_item_new_with_label
(
"Fail"
);
// Fail
GtkWidget
*
AboutMenuNupp
=
gtk_menu_item_new_with_label
(
"About"
);
// About
GtkWidget
*
FailMenu
=
gtk_menu_new
();
// Fail menüü
GtkWidget
*
FailMenuUus
=
gtk_menu_item_new_with_label
(
"Uus"
);
// Fail->Uus
GtkWidget
*
FailMenuAva
=
gtk_menu_item_new_with_label
(
"Ava"
);
// Fail->Ava
GtkWidget
*
FailMenuSalvesta
=
gtk_menu_item_new_with_label
(
"Salvesta"
);
// Fail->Salvesta
GtkWidget
*
FailMenuSalvestaN
=
gtk_menu_item_new_with_label
(
"Salvesta nimega"
);
// Fail->Salvesta nimega
GtkWidget
*
FailMenuValju
=
gtk_menu_item_new_with_label
(
"Välju"
);
// Fail->Välju
// Search
GtkWidget
*
Otsi_nupp
=
gtk_button_new_with_label
(
"Otsi"
);
// Otsi nupp
GtkWidget
*
Otsi_aken
=
gtk_scrolled_window_new
(
NULL
,
NULL
);
// Otsi aken
gtk_scrolled_window_set_policy
(
GTK_SCROLLED_WINDOW
(
Otsi_aken
),
GTK_POLICY_AUTOMATIC
,
GTK_POLICY_AUTOMATIC
);
App
app
;
gtk_box_pack_start
(
GTK_BOX
(
Box
),
Otsi_nupp
,
FALSE
,
FALSE
,
0
);
app
.
search_entry
=
gtk_entry_new
();
gtk_box_pack_start
(
GTK_BOX
(
Box
),
app
.
search_entry
,
TRUE
,
TRUE
,
0
);
g_signal_connect
(
G_OBJECT
(
Otsi_nupp
),
"clicked"
,
G_CALLBACK
(
Otsi_nupp_vajutatud
),
&
app
);
// Menüü nupud menu bar'i
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
MenuBar
),
FailMenuNupp
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
MenuBar
),
AboutMenuNupp
);
// Menüüd nuppudesse
gtk_menu_item_set_submenu
(
GTK_MENU_ITEM
(
FailMenuNupp
),
FailMenu
);
// Fail menüü
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
FailMenuUus
);
// Fail->Uus
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
FailMenuAva
);
// Fail->Ava
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
FailMenuSalvesta
);
// Fail->Salvesta
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
FailMenuSalvestaN
);
// Fail->Salvesta nimega
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
gtk_separator_menu_item_new
());
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
FailMenuValju
);
// Fail->Välju
g_signal_connect
(
G_OBJECT
(
FailMenuValju
),
"activate"
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
// Pane menubar box'i
gtk_box_pack_start
(
GTK_BOX
(
Box
),
MenuBar
,
FALSE
,
FALSE
,
0
);
// paneb Otsi_aken boxi
gtk_box_pack_start
(
GTK_BOX
(
Box
),
Otsi_aken
,
TRUE
,
TRUE
,
0
);
app
.
text_view
=
gtk_text_view_new
();
gtk_container_add
(
GTK_CONTAINER
(
Otsi_aken
),
app
.
text_view
);
const
gchar
*
text
;
GtkTextBuffer
*
buffer
;
GtkTextMark
*
last_pos
;
GtkTextIter
iter
;
// Tekstiaken
#ifdef SOURCEVIEW
GtkWidget
*
View
=
gtk_source_view_new
();
// Loo tekstiaken
#else
GtkWidget
*
View
=
gtk_text_view_new
();
// Loo tekstiaken
#endif
gtk_box_pack_start
(
GTK_BOX
(
Box
),
View
,
TRUE
,
TRUE
,
0
);
// Pane tekstiaken box'i
text
=
gtk_entry_get_text
(
GTK_ENTRY
(
Tab
->
search_entry
));
// Teksti puhver
GtkTextBuffer
*
Puhver
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
View
));
// Tekstiakna teksti puhver
buffer
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
Tab
->
TextView
));
// Status bar
GtkWidget
*
StatusBar
=
gtk_statusbar_new
();
// Loo status bar
gtk_box_pack_start
(
GTK_BOX
(
Box
),
StatusBar
,
FALSE
,
FALSE
,
0
);
// Pane statusbar box'i
// Teksti muutuse callback, uuendab rida/veergu
g_signal_connect
(
Puhver
,
"changed"
,
G_CALLBACK
(
UuendaRidaVeerg
),
StatusBar
);
// Copy/paste lohistamise callback, uuendab samuti
g_signal_connect_object
(
Puhver
,
"mark_set"
,
G_CALLBACK
(
TekstMarkSet
),
StatusBar
,
0
);
last_pos
=
gtk_text_buffer_get_mark
(
buffer
,
"last_pos"
);
if
(
last_pos
==
NULL
)
return
;
gtk_widget_show_all
(
Aken
);
// Näita akent
UuendaRidaVeerg
(
Puhver
,
GTK_STATUSBAR
(
StatusBar
));
// Esimene uuendus
gtk_text_buffer_get_iter_at_mark
(
buffer
,
&
iter
,
last_pos
);
find
(
GTK_TEXT_VIEW
(
Tab
->
TextView
),
text
,
&
iter
);
}
gtk_main
();
return
0
;
}
search.h
0 → 100644
View file @
7d8b28dc
#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
*
app
);
void
Jargmine_nupp_vajutatud
(
GtkWidget
*
next_button
,
tab
*
app
);
#endif // SEARCH_H
tab.c
View file @
7d8b28dc
...
...
@@ -27,12 +27,34 @@ void LisaTab(ui *UI)
#endif
Tab
->
Puhver
=
gtk_text_view_get_buffer
(
GTK_TEXT_VIEW
(
Tab
->
TextView
));
// Tekstiakna teksti puhver
// Otsing
GtkWidget
*
vbox
=
gtk_vbox_new
(
FALSE
,
2
);
gtk_container_add
(
GTK_CONTAINER
(
Tab
->
Aken
),
vbox
);
GtkWidget
*
hbox
=
gtk_hbox_new
(
FALSE
,
2
);
gtk_box_pack_start
(
GTK_BOX
(
vbox
),
hbox
,
FALSE
,
FALSE
,
0
);
Tab
->
search_entry
=
gtk_entry_new
();
gtk_box_pack_start
(
GTK_BOX
(
hbox
),
Tab
->
search_entry
,
TRUE
,
TRUE
,
0
);
GtkWidget
*
Otsi_nupp
=
gtk_button_new_with_label
(
"Otsi"
);
// Otsi nupp
gtk_box_pack_start
(
GTK_BOX
(
hbox
),
Otsi_nupp
,
FALSE
,
FALSE
,
0
);
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
gtk_box_pack_start
(
GTK_BOX
(
hbox
),
Jargmine_nupp
,
FALSE
,
FALSE
,
0
);
g_signal_connect
(
G_OBJECT
(
Jargmine_nupp
),
"clicked"
,
G_CALLBACK
(
Jargmine_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
gtk_scrolled_window_set_policy
(
GTK_SCROLLED_WINDOW
(
Tab
->
ScrollWindow
),
GTK_POLICY_AUTOMATIC
,
GTK_POLICY_AUTOMATIC
);
// Konfigureerimine
gtk_scrolled_window_set_shadow_type
(
GTK_SCROLLED_WINDOW
(
Tab
->
ScrollWindow
),
GTK_SHADOW_ETCHED_IN
);
gtk_box_pack_start
(
GTK_BOX
(
vbox
),
Tab
->
ScrollWindow
,
TRUE
,
TRUE
,
0
);
// Status bar
Tab
->
StatusBar
=
gtk_statusbar_new
();
// Teksti muutuse callback, uuendab rida/veergu
...
...
@@ -42,7 +64,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
),
Tab
->
ScrollWindow
,
TRUE
,
TRUE
,
0
);
gtk_box_pack_start
(
GTK_BOX
(
Tab
->
Box
),
vbox
,
TRUE
,
TRUE
,
0
);
gtk_box_pack_start
(
GTK_BOX
(
Tab
->
Box
),
Tab
->
StatusBar
,
FALSE
,
FALSE
,
0
);
// Pealkiri
...
...
tab.h
View file @
7d8b28dc
...
...
@@ -4,6 +4,7 @@
#include "ceditor.h"
#include "statusbar.h"
#include "textview.h"
#include "search.h"
void
LisaTab
(
ui
*
UI
);
void
KustutaTab
(
ui
*
UI
,
int
Indeks
);
...
...
ui.h
View file @
7d8b28dc
...
...
@@ -4,6 +4,7 @@
#include "ceditor.h"
#include "tab.h"
#include "menubar.h"
#include "search.h"
#ifdef SOURCEVIEW
#define PEALKIRI "CEditor SourceView"
...
...
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