[gtk] Remove copy of CelestiaCore::runScript (Closes: #456)

pull/3/head
Hleb Valoshka 2019-10-19 12:29:47 +03:00
parent 1ab6b27f3f
commit 779ad3c5c1
2 changed files with 36 additions and 65 deletions

View File

@ -23,7 +23,6 @@
#include <celengine/body.h>
#include <celengine/simulation.h>
#include <celestia/cmdparser.h>
#include <celengine/render.h>
#include <celestia/celestiacore.h>
#include <celestia/imagecapture.h>
@ -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<string>* 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);
}
}

View File

@ -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";