diff --git a/include/ui.h b/include/ui.h index 3468bb4..a05c20d 100644 --- a/include/ui.h +++ b/include/ui.h @@ -133,6 +133,7 @@ void ui_model_loading(GObject *source_object, GAsyncResult *result, GemGraphClientWindow *self); +void ui_debug_model_loading (GemGraphClientWindow *self, const char *file); // // General events // diff --git a/src/ui/application.c b/src/ui/application.c index 11e5d47..4a6ac6a 100644 --- a/src/ui/application.c +++ b/src/ui/application.c @@ -71,7 +71,10 @@ static void gem_graph_client_application_activate(GApplication *app) "application", app, NULL); + // Launch with sidebar off + ui_toggle_sidebar(); ui_set_stack(HOME_MODE); + ui_debug_model_loading(window, "data/models/dimers random walk.xml"); gtk_window_present(window); } diff --git a/src/ui/events.c b/src/ui/events.c index 4e053de..55040d1 100644 --- a/src/ui/events.c +++ b/src/ui/events.c @@ -23,6 +23,7 @@ */ #include +#include #include "../../include/base.h" #include "../../include/graphics.h" @@ -325,7 +326,7 @@ void ui_model_loading(GObject *source_object, size_t length = 0; GError *error = NULL; - char *basename = g_file_get_basename(file); + char *basenamestr = g_file_get_basename(file); // Gives you the contents of the file as a byte array, or // set the error argument @@ -343,14 +344,14 @@ void ui_model_loading(GObject *source_object, error->message); ui_send_internal_notification("Unable to open file !"); g_free(error); - g_free(basename); + g_free(basenamestr); g_free(content); return; } - if (model_init(content, length, basename) == false) { + if (model_init(content, length, basenamestr) == false) { ui_send_internal_notification("Error while loading the model"); - g_free(basename); + g_free(basenamestr); g_free(content); return; } @@ -363,10 +364,43 @@ void ui_model_loading(GObject *source_object, ui_enable_action("togglesidebar"); ui_set_stack(RUN_MODE); - g_free(basename); + g_free(basenamestr); g_free(content); } +void ui_debug_model_loading (GemGraphClientWindow *self, const char *file) +{ + char *content = NULL; + size_t length = 0; + char *basenamestr = basename(file); + + content = read_file (file); + length = strlen (content); + + /* // In case of error, print a warning to the standard error output */ + /* if (error != NULL) { */ + /* g_printerr("Unable to open ā€œ%sā€: %s\n", */ + /* g_file_peek_path(file), */ + /* error->message); */ + /* ui_send_internal_notification("Unable to open file !"); */ + /* return; */ + /* } */ + + if (model_init(content, length, basenamestr) == false) { + ui_send_internal_notification("Error while loading the model"); + return; + } + + ui_enable_action("closefile"); + ui_enable_action("savefile"); + ui_enable_action("runmode"); + ui_enable_action("editmode"); + ui_enable_action("presentmode"); + ui_enable_action("togglesidebar"); + ui_set_stack(RUN_MODE); + ui_toggle_sidebar(); +} + /* -------------------------------------------------------------------------- */ /* diff --git a/src/ui/window.c b/src/ui/window.c index a92df9b..c709c94 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -123,9 +123,6 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self) { gtk_widget_init_template(GTK_WIDGET(self)); window = self; - - // Launch with sidebar off - ui_toggle_sidebar(); } /* -------------------------------------------------------------------------- */