From 63611f46c9ce80627db9b536e64e59ba892aee20 Mon Sep 17 00:00:00 2001 From: Romain de Laage Date: Mon, 15 Feb 2021 14:36:19 +0100 Subject: [PATCH] You can now change page --- include/gemgui.h | 2 +- include/gemparse.h | 2 +- src/gemgui.c | 6 +++--- src/gemparse.c | 4 ++-- src/main.c | 20 ++++++++++++-------- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/gemgui.h b/include/gemgui.h index 104a809..8ba5369 100644 --- a/include/gemgui.h +++ b/include/gemgui.h @@ -5,7 +5,7 @@ void addH1 (GtkWidget *root, char *line); void addH2 (GtkWidget *root, char *line); void addH3 (GtkWidget *root, char *line); void addLink (GtkWidget *root, char *url, char *text); -void addCode (GtkWidget *root, char *code, char *meta); +void addCode (GtkWidget *root, const char *code, char *meta); void addQuote (GtkWidget *root, char *quote); void addUList (GtkWidget *root, char *text); void addText (GtkWidget *root, char *text); diff --git a/include/gemparse.h b/include/gemparse.h index 48f7ad2..39eafe7 100644 --- a/include/gemparse.h +++ b/include/gemparse.h @@ -1,6 +1,6 @@ #ifndef _GEMPARSE_H #define _GEMPARSE_H -int parseFile (char *path); +int parseFile (const char *path); #endif diff --git a/src/gemgui.c b/src/gemgui.c index 7f25bee..c9c39fe 100644 --- a/src/gemgui.c +++ b/src/gemgui.c @@ -78,9 +78,9 @@ addLink (GtkWidget *root, } void -addCode (GtkWidget *root, - char *code, - char *meta) +addCode (GtkWidget *root, + const char *code, + char *meta) { gchar *markup = g_markup_printf_escaped ("%s", code); GtkWidget *label = gtk_label_new (NULL); diff --git a/src/gemparse.c b/src/gemparse.c index 594bd4d..a08727a 100644 --- a/src/gemparse.c +++ b/src/gemparse.c @@ -19,7 +19,7 @@ void addUList (const char *text); // general functions -int parseFile (char *path); +int parseFile (const char *path); #else @@ -29,7 +29,7 @@ extern char links[1024][20]; #endif int -parseFile (char *path) +parseFile (const char *path) { FILE *fileToParse = fopen (path, "r"); char line[4096]; diff --git a/src/main.c b/src/main.c index 5b4ea5f..d03a415 100644 --- a/src/main.c +++ b/src/main.c @@ -7,10 +7,13 @@ GtkWidget *render = NULL; GtkWidget *scrollbar = NULL; char links[1024][20]; +static void makeRender (const char *path); + static void loadPage (const char *link) { - printf("Loading page : %s\n", link); + makeRender (link); + gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_show_all, NULL); } void @@ -28,16 +31,17 @@ goAction (GtkWidget *widget, } static void -makeRender (char *path) +makeRender (const char *path) { - if (render != NULL) - gtk_widget_destroy (render); - - render = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + if (render == NULL) + { + render = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_container_add (GTK_CONTAINER (scrollbar), render); + } + else + gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL); parseFile (path); - - gtk_container_add (GTK_CONTAINER (scrollbar), render); } /* This function's goal is to build the main interface */