From adb0e762792c23674633b8513f4106b82aa38d15 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Tue, 10 Mar 2015 17:45:50 +0100 Subject: [PATCH] PoC: Add menu item to load script --- src/bindings/Guile.cxx | 8 ++++++++ src/bindings/Guile.hxx | 7 +++++++ src/bindings/Interpreter.hxx | 7 +++++++ src/gui/Mainwindow.cxx | 16 +++++++++++++++- src/gui/Mainwindow.hxx | 3 +++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/bindings/Guile.cxx b/src/bindings/Guile.cxx index 57d32bd..fcc1083 100644 --- a/src/bindings/Guile.cxx +++ b/src/bindings/Guile.cxx @@ -54,3 +54,11 @@ int GuileInterpreter::evaluate(const std::string& command, return 0; } + +int GuileInterpreter::loadFile(const std::string& filename, + std::ostream& stdout, + std::ostream& stderr, + std::string& result) { + return evaluate("(load \"" + filename + "\")", + stdout, stderr, result); +} diff --git a/src/bindings/Guile.hxx b/src/bindings/Guile.hxx index 5de6908..7c45a95 100644 --- a/src/bindings/Guile.hxx +++ b/src/bindings/Guile.hxx @@ -13,6 +13,13 @@ public: std::ostream& stdout, std::ostream& stderr, std::string& result); + + int loadFile(const std::string& filename, + std::ostream& stdout, + std::ostream& stderr, + std::string& result); + + std::string fileExtension() const {return "scm";} private: SCM guile_output_port; SCM guile_error_port; diff --git a/src/bindings/Interpreter.hxx b/src/bindings/Interpreter.hxx index a8d9ad9..648301b 100644 --- a/src/bindings/Interpreter.hxx +++ b/src/bindings/Interpreter.hxx @@ -10,6 +10,13 @@ public: std::ostream& stdout, std::ostream& stderr, std::string& result) = 0; + + virtual int loadFile(const std::string& filename, + std::ostream& stdout, + std::ostream& stderr, + std::string& result) = 0; + + virtual std::string fileExtension() const = 0; private: }; diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index a42d3f4..9d8e45f 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -46,9 +46,23 @@ Mainwindow::Mainwindow(InformationManager* mgr) fileMenu->addSeparator(); fileMenu->addAction(exitAction); - scripting = new ScriptingDock(new GuileInterpreter, tr("Scripting"), this); + QMenu* interpretermenu = menuBar()->addMenu(tr("&Interpreter")); + + interpreter["GUILE"] = new GuileInterpreter; + scripting = new ScriptingDock(interpreter["GUILE"], tr("Scripting"), this); scripting->setAllowedAreas(Qt::BottomDockWidgetArea); addDockWidget(Qt::BottomDockWidgetArea, scripting); + QAction* guileLoad = new QAction(tr("&GUILE"), this); + interpretermenu->addAction(guileLoad); + connect(guileLoad, &QAction::triggered, + [&]() { + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Script"), "", + tr("Binaries") + " (*." + + interpreter["GUILE"]->fileExtension().c_str() + ")"); + std::stringstream a, b; + std::string c; + interpreter["GUILE"]->loadFile(fileName.toStdString(), a, b, c); + }); listWidget = new QTreeWidget(); listWidget->setColumnCount(1); diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index f89f3ce..8b46404 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,7 @@ class InformationManager; class FunctionWidget; class BasicBlockWidget; class ScriptingDock; +class Interpreter; class Mainwindow : public QMainWindow { Q_OBJECT @@ -53,6 +55,7 @@ private: std::map objects_list; std::map objects_list_by_address; std::vector group_list; + std::map interpreter; InformationManager* manager; log4cxx::LoggerPtr logger; -- 2.39.5