From 779ad3c5c19579bfc70f9039ba718d51f024f928 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Sat, 19 Oct 2019 12:29:47 +0300 Subject: [PATCH] [gtk] Remove copy of CelestiaCore::runScript (Closes: #456) --- src/celestia/gtk/actions.cpp | 57 +----------------------------------- src/celestia/gtk/main.cpp | 44 ++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 65 deletions(-) diff --git a/src/celestia/gtk/actions.cpp b/src/celestia/gtk/actions.cpp index bdc57c0f..d64daa7f 100644 --- a/src/celestia/gtk/actions.cpp +++ b/src/celestia/gtk/actions.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -1060,61 +1059,7 @@ static void openScript(const char* filename, AppData* app) { /* If you got here, a path and file has been specified. * filename contains full path to specified file. */ - ContentType type = DetermineFileType(filename); - - if (type == Content_CelestiaScript) - { - app->core->runScript(filename); - } - else if (type == Content_CelestiaLegacyScript) - { - ifstream scriptfile(filename); - if (!scriptfile.good()) - { - GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "Error opening script file."); - gtk_dialog_run(GTK_DIALOG(errBox)); - gtk_widget_destroy(errBox); - } - else - { - CommandParser parser(scriptfile); - CommandSequence* script = parser.parse(); - if (script == NULL) - { - const vector* errors = parser.getErrors(); - const char* errorMsg = ""; - if (errors->size() > 0) - errorMsg = (*errors)[0].c_str(); - GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, "%s", - errorMsg); - gtk_dialog_run(GTK_DIALOG(errBox)); - gtk_widget_destroy(errBox); - } - else - { - /* Cancel any running script */ - app->core->cancelScript(); - app->core->runScript(script); - } - } - } - else - { - GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "Bad File Type. Use *.(cel|celx|clx)."); - gtk_dialog_run(GTK_DIALOG(errBox)); - gtk_widget_destroy(errBox); - } + app->core->runScript(filename); } } diff --git a/src/celestia/gtk/main.cpp b/src/celestia/gtk/main.cpp index 77d3454f..763358ca 100644 --- a/src/celestia/gtk/main.cpp +++ b/src/celestia/gtk/main.cpp @@ -211,26 +211,52 @@ void GtkWatcher::notifyChange(CelestiaCore*, int property) /* END Watcher */ +class GtkAlerter : public CelestiaCore::Alerter +{ +private: + AppData* app; + +public: + GtkAlerter() = delete; + GtkAlerter(AppData* _app) : app(_app) {}; + ~GtkAlerter() = default; + GtkAlerter(const GtkAlerter&) = delete; + GtkAlerter(GtkAlerter&&) = delete; + GtkAlerter& operator=(const GtkAlerter&) = delete; + GtkAlerter& operator=(GtkAlerter&&) = delete; + + void fatalError(const std::string& errorMsg) + { + GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, "%s", + errorMsg.c_str()); + gtk_dialog_run(GTK_DIALOG(errBox)); + gtk_widget_destroy(errBox); + } +}; + /* CALLBACK: Event "realize" on the main GL area. Things that go here are those * that require the glArea to be set up. */ static void initRealize(GtkWidget* widget, AppData* app) { GLenum glewErr = glewInit(); - { - if (GLEW_OK != glewErr) - { + if (GLEW_OK != glewErr) + { GtkWidget *message; - message = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "Celestia was unable to initialize OpenGL extensions. Graphics quality will be reduced. Only Basic render path will be available."); + message = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Celestia was unable to initialize OpenGL."); gtk_dialog_run(GTK_DIALOG(message)); gtk_widget_destroy(message); - } } + app->core->setAlerter(new GtkAlerter(app)); + if (!app->core->initRenderer()) { cerr << "Failed to initialize renderer.\n";