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
d0313963
authored
Mar 04, 2022
by
karudu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Failide salvestamine
parent
76a271c2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
3 deletions
ceditor.c
ceditor.c
View file @
d0313963
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#endif
#endif
/* TODO
/* TODO
Failide
salvestamine
Uus fail, nimeta
salvestamine
Scrollbar
Scrollbar
*/
*/
...
@@ -39,6 +39,7 @@ void TekstMarkSet(GtkTextBuffer *Puhver, const GtkTextIter *new_location, GtkTex
...
@@ -39,6 +39,7 @@ void TekstMarkSet(GtkTextBuffer *Puhver, const GtkTextIter *new_location, GtkTex
void
AvaFail
(
GtkWidget
*
Nupp
,
gpointer
Data
)
void
AvaFail
(
GtkWidget
*
Nupp
,
gpointer
Data
)
{
{
GtkTextBuffer
*
Puhver
=
GTK_TEXT_BUFFER
(
Data
);
GtkWidget
*
Dialog
=
gtk_file_chooser_dialog_new
(
"Ava fail"
,
NULL
,
GTK_FILE_CHOOSER_ACTION_OPEN
,
GtkWidget
*
Dialog
=
gtk_file_chooser_dialog_new
(
"Ava fail"
,
NULL
,
GTK_FILE_CHOOSER_ACTION_OPEN
,
"Tühista"
,
GTK_RESPONSE_CANCEL
,
"Tühista"
,
GTK_RESPONSE_CANCEL
,
"Ava"
,
GTK_RESPONSE_ACCEPT
,
NULL
);
"Ava"
,
GTK_RESPONSE_ACCEPT
,
NULL
);
...
@@ -47,13 +48,13 @@ void AvaFail(GtkWidget *Nupp, gpointer Data)
...
@@ -47,13 +48,13 @@ void AvaFail(GtkWidget *Nupp, gpointer Data)
{
{
char
*
Nimi
=
gtk_file_chooser_get_filename
(
GTK_FILE_CHOOSER
(
Dialog
));
char
*
Nimi
=
gtk_file_chooser_get_filename
(
GTK_FILE_CHOOSER
(
Dialog
));
gchar
*
Sisu
;
gchar
*
Sisu
;
GError
*
Viga
;
GError
*
Viga
=
NULL
;
// TODO paremad veateated
// TODO paremad veateated
if
(
g_file_get_contents
(
Nimi
,
&
Sisu
,
NULL
,
&
Viga
))
if
(
g_file_get_contents
(
Nimi
,
&
Sisu
,
NULL
,
&
Viga
))
{
{
if
(
g_utf8_validate
(
Sisu
,
-
1
,
NULL
))
if
(
g_utf8_validate
(
Sisu
,
-
1
,
NULL
))
{
{
gtk_text_buffer_set_text
(
GTK_TEXT_BUFFER
(
Data
)
,
Sisu
,
-
1
);
gtk_text_buffer_set_text
(
Puhver
,
Sisu
,
-
1
);
}
else
printf
(
"g_utf8_validate viga
\n
"
);
}
else
printf
(
"g_utf8_validate viga
\n
"
);
g_free
(
Sisu
);
g_free
(
Sisu
);
}
}
...
@@ -67,6 +68,35 @@ void AvaFail(GtkWidget *Nupp, gpointer Data)
...
@@ -67,6 +68,35 @@ void AvaFail(GtkWidget *Nupp, gpointer Data)
gtk_widget_destroy
(
Dialog
);
gtk_widget_destroy
(
Dialog
);
}
}
void
SalvestaFail
(
GtkWidget
*
Nupp
,
gpointer
Data
)
{
GtkTextBuffer
*
Puhver
=
GTK_TEXT_BUFFER
(
Data
);
GtkWidget
*
Dialog
=
gtk_file_chooser_dialog_new
(
"Salvesta fail"
,
NULL
,
GTK_FILE_CHOOSER_ACTION_SAVE
,
"Tühista"
,
GTK_RESPONSE_CANCEL
,
"Salvesta"
,
GTK_RESPONSE_ACCEPT
,
NULL
);
gint
Vastus
=
gtk_dialog_run
(
GTK_DIALOG
(
Dialog
));
if
(
Vastus
==
GTK_RESPONSE_ACCEPT
)
{
char
*
Nimi
=
gtk_file_chooser_get_filename
(
GTK_FILE_CHOOSER
(
Dialog
));
gchar
*
Sisu
;
GtkTextIter
TekstA
,
TekstL
;
gtk_text_buffer_get_start_iter
(
Puhver
,
&
TekstA
);
gtk_text_buffer_get_end_iter
(
Puhver
,
&
TekstL
);
Sisu
=
gtk_text_buffer_get_text
(
Puhver
,
&
TekstA
,
&
TekstL
,
TRUE
);
gtk_text_buffer_set_modified
(
Puhver
,
FALSE
);
GError
*
Viga
=
NULL
;
if
(
g_file_set_contents
(
Nimi
,
Sisu
,
-
1
,
&
Viga
)
==
FALSE
)
{
printf
(
"Viga faili salvestamisel: %s
\n
"
,
Viga
->
message
);
g_error_free
(
Viga
);
}
g_free
(
Nimi
);
g_free
(
Sisu
);
}
gtk_widget_destroy
(
Dialog
);
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
gtk_init
(
&
argc
,
&
argv
);
gtk_init
(
&
argc
,
&
argv
);
...
@@ -114,6 +144,7 @@ int main(int argc, char **argv)
...
@@ -114,6 +144,7 @@ int main(int argc, char **argv)
g_signal_connect
(
FailMenuAva
,
"activate"
,
G_CALLBACK
(
AvaFail
),
Puhver
);
g_signal_connect
(
FailMenuAva
,
"activate"
,
G_CALLBACK
(
AvaFail
),
Puhver
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
FailMenuSalvesta
);
// Fail->Salvesta
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
),
FailMenuSalvestaN
);
// Fail->Salvesta nimega
g_signal_connect
(
FailMenuSalvestaN
,
"activate"
,
G_CALLBACK
(
SalvestaFail
),
Puhver
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
gtk_separator_menu_item_new
());
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
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
FailMenu
),
FailMenuValju
);
// Fail->Välju
g_signal_connect
(
FailMenuValju
,
"activate"
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
g_signal_connect
(
FailMenuValju
,
"activate"
,
G_CALLBACK
(
gtk_main_quit
),
NULL
);
...
...
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