Commit 76a271c2 by karudu

Failide avamine

parent ba71144c
Showing with 46 additions and 15 deletions
#include <gtk/gtk.h>
#ifdef SOURCEVIEW
#include <gtksourceview/gtksource.h>
#endif
/* TODO
Failide avamine
Failide salvestamine
Scrollbar
*/
#ifdef SOURCEVIEW
#include <gtksourceview/gtksource.h>
#endif
#ifdef SOURCEVIEW
#define PEALKIRI "CEditor SourceView"
#else
#define PEALKIRI "CEditor TextView"
......@@ -38,6 +37,36 @@ void TekstMarkSet(GtkTextBuffer *Puhver, const GtkTextIter *new_location, GtkTex
UuendaRidaVeerg(Puhver, GTK_STATUSBAR(Data));
}
void AvaFail(GtkWidget *Nupp, gpointer Data)
{
GtkWidget *Dialog = gtk_file_chooser_dialog_new("Ava fail", NULL, GTK_FILE_CHOOSER_ACTION_OPEN,
"Tühista", GTK_RESPONSE_CANCEL,
"Ava", 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;
GError *Viga;
// TODO paremad veateated
if(g_file_get_contents(Nimi, &Sisu, NULL, &Viga))
{
if(g_utf8_validate(Sisu, -1, NULL))
{
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(Data), Sisu, -1);
} else printf("g_utf8_validate viga\n");
g_free(Sisu);
}
else
{
printf("Viga faili avamisel: %s\n", Viga->message);
g_error_free(Viga);
}
g_free(Nimi);
}
gtk_widget_destroy(Dialog);
}
int main(int argc, char **argv)
{
gtk_init(&argc, &argv);
......@@ -54,6 +83,16 @@ int main(int argc, char **argv)
GtkWidget *Box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); // Vertikaalne box, 0px vahe
gtk_container_add(GTK_CONTAINER(Aken), Box); // Pane box aknasse
// Tekstiaken
#ifdef SOURCEVIEW
GtkWidget *View = gtk_source_view_new(); // Loo tekstiaken
#else
GtkWidget *View = gtk_text_view_new(); // Loo tekstiaken
#endif
// Teksti puhver
GtkTextBuffer *Puhver = gtk_text_view_get_buffer(GTK_TEXT_VIEW(View)); // Tekstiakna teksti puhver
// Menu bar
GtkWidget *MenuBar = gtk_menu_bar_new(); // Loo menu bar
GtkWidget *FailMenuNupp = gtk_menu_item_new_with_label("Fail"); // Fail
......@@ -72,25 +111,17 @@ int main(int argc, char **argv)
// Fail menüü
gtk_menu_shell_append(GTK_MENU_SHELL(FailMenu), FailMenuUus); // Fail->Uus
gtk_menu_shell_append(GTK_MENU_SHELL(FailMenu), FailMenuAva); // Fail->Ava
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), 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);
g_signal_connect(FailMenuValju, "activate", G_CALLBACK(gtk_main_quit), NULL);
// Pane menubar box'i
gtk_box_pack_start(GTK_BOX(Box), MenuBar, FALSE, FALSE, 0);
// 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
// Teksti puhver
GtkTextBuffer *Puhver = gtk_text_view_get_buffer(GTK_TEXT_VIEW(View)); // Tekstiakna teksti puhver
// 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment