Commit 6f678b1e by hounas

Delete ceditor.c

parent e803ec5c
Showing with 0 additions and 109 deletions
#include <gtk/gtk.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
// Uuenda näidatud rida ja veergu kursori asukoha järgi
void UuendaRidaVeerg(GtkTextBuffer *Puhver, GtkStatusbar *StatusBar)
{
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
g_free(Tekst);
}
// 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));
}
int main(int argc, char **argv)
{
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
// 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);
// 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
// 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);
gtk_widget_show_all(Aken); // Näita akent
UuendaRidaVeerg(Puhver, GTK_STATUSBAR(StatusBar)); // Esimene uuendus
gtk_main();
return 0;
}
\ No newline at end of file
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