Add default file

This commit is contained in:
Romain de Laage 2021-02-14 16:19:39 +01:00
parent baa727b2a4
commit ec73d8f6cc
Signed by: rdelaage
GPG Key ID: 534845FADDF0C329
2 changed files with 20 additions and 8 deletions

View File

@ -1,7 +1,9 @@
#include <stdio.h>
#include <string.h>
#ifndef TESTGEMPARSE
#include <gtk/gtk.h>
#include "../include/gemgui.h"
#endif
#ifdef TESTGEMPARSE
@ -32,7 +34,16 @@ parseFile (char *path)
char line[4096];
if (fileToParse == NULL)
{
#ifdef TESTGEMPARSE
printf("error");
#else
addH1 (render, "An error occured");
addText (render, "Can't open the file");
addCode (render, path, NULL);
#endif
return 1;
}
while (fgets (line, 4096, fileToParse) != NULL)
{

View File

@ -27,21 +27,22 @@ goAction (GtkWidget *widget,
}
static void
makeRender (void)
makeRender (char *path)
{
if (render != NULL)
gtk_widget_destroy (render);
render = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
parseFile ("test.gmi");
parseFile (path);
gtk_container_add (GTK_CONTAINER (scrollbar), render);
}
/* This function's goal is to build the main interface */
static void
build_interface (GtkWidget *window)
build_interface (GtkWidget *window,
char *path)
{
GtkWidget *pathBar;
GtkWidget *headerBar;
@ -64,7 +65,7 @@ build_interface (GtkWidget *window)
gtk_container_add (GTK_CONTAINER (headerBar), pathBar);
gtk_container_add (GTK_CONTAINER (headerBar), goButtonBox);
makeRender ();
makeRender (path);
}
/* This function's goal is to create the window then show it */
@ -75,9 +76,9 @@ activate (GtkApplication *app,
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "MDViewer");
gtk_window_set_title (GTK_WINDOW (window), "Scorpius");
gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
build_interface (window);
build_interface (window, (char *)user_data);
gtk_widget_show_all (window);
}
@ -89,8 +90,8 @@ main (int argc,
int status;
app = gtk_application_new ("ovh.rdelaage.mdviewer", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run(G_APPLICATION (app), argc, argv);
g_signal_connect (app, "activate", G_CALLBACK (activate), (argc >= 2) ? argv[1] : "readme.gmi");
status = g_application_run(G_APPLICATION (app), 1, argv);
g_object_unref (app);
return status;