diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index ff631208b..e932a33b1 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -22,7 +22,6 @@ * - KeyEventManager */ -#include #include #include #include @@ -32,6 +31,8 @@ #include "CodeModel.h" #include "FileIo.h" #include "ClientModel.h" +#include "CodeEditorExtensionManager.h" +#include "Exceptions.h" #include "AppContext.h" using namespace dev; @@ -47,21 +48,31 @@ AppContext::AppContext(QQmlApplicationEngine* _engine) m_codeModel.reset(new CodeModel(this)); m_clientModel.reset(new ClientModel(this)); m_fileIo.reset(new FileIo()); +} + +AppContext::~AppContext() +{ +} + +void AppContext::load() +{ m_applicationEngine->rootContext()->setContextProperty("appContext", this); qmlRegisterType("org.ethereum.qml", 1, 0, "FileIo"); + m_applicationEngine->rootContext()->setContextProperty("codeModel", m_codeModel.get()); + m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get()); QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml")); QObject* projectModel = projectModelComponent.create(); if (projectModelComponent.isError()) - throw std::runtime_error("Error loading ProjectModel: " + projectModelComponent.errorString().toStdString()); - QQmlEngine::setObjectOwnership(projectModel, QQmlEngine::JavaScriptOwnership); + { + QmlLoadException exception; + for (auto const& e : projectModelComponent.errors()) + exception << QmlErrorInfo(e); + BOOST_THROW_EXCEPTION(exception); + } m_applicationEngine->rootContext()->setContextProperty("projectModel", projectModel); - m_applicationEngine->rootContext()->setContextProperty("codeModel", m_codeModel.get()); - m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get()); - -} - -AppContext::~AppContext() -{ + qmlRegisterType("CodeEditorExtensionManager", 1, 0, "CodeEditorExtensionManager"); + m_applicationEngine->load(QUrl("qrc:/qml/main.qml")); + appLoaded(); } QQmlApplicationEngine* AppContext::appEngine() diff --git a/mix/AppContext.h b/mix/AppContext.h index dec3b319e..e959397f7 100644 --- a/mix/AppContext.h +++ b/mix/AppContext.h @@ -60,6 +60,8 @@ class AppContext: public QObject public: AppContext(QQmlApplicationEngine* _engine); virtual ~AppContext(); + /// Load the UI from qml files + void load(); /// Get the current QQMLApplicationEngine instance. QQmlApplicationEngine* appEngine(); /// Get code model diff --git a/mix/Exceptions.cpp b/mix/Exceptions.cpp new file mode 100644 index 000000000..08f59f7ef --- /dev/null +++ b/mix/Exceptions.cpp @@ -0,0 +1,31 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file Exceptions.cpp + * @author Arkadiy Paronyan arkadiy@ethdev.com + * @date 2015 + * Ethereum IDE client. + */ + +#include +#include +#include "Exceptions.h" + +std::ostream& operator<<(std::ostream& _out, QQmlError const& _error) +{ + _out << _error.toString().toStdString(); + return _out; +} diff --git a/mix/Exceptions.h b/mix/Exceptions.h new file mode 100644 index 000000000..2a3d813eb --- /dev/null +++ b/mix/Exceptions.h @@ -0,0 +1,45 @@ +/* + This file is part of cpp-ethereum. + + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . +*/ +/** @file Exceptions.h + * @author Arkadiy Paronyan arkadiy@ethdev.com + * @date 2015 + * Ethereum IDE client. + */ + +#pragma once + +#include +#include + +class QTextDocument; +class QQmlError; + +namespace dev +{ +namespace mix +{ + +struct QmlLoadException: virtual Exception {}; +struct FileIoException: virtual Exception {}; + +typedef boost::error_info QmlErrorInfo; +typedef boost::error_info FileError; + +} +} + +std::ostream& operator<<(std::ostream& _out, QQmlError const& _error); diff --git a/mix/FileIo.cpp b/mix/FileIo.cpp index fed9909e6..e5a3e5364 100644 --- a/mix/FileIo.cpp +++ b/mix/FileIo.cpp @@ -20,7 +20,6 @@ * Ethereum IDE client. */ -#include #include #include #include diff --git a/mix/MixApplication.cpp b/mix/MixApplication.cpp index 2cdc4b30d..3b5cfe85d 100644 --- a/mix/MixApplication.cpp +++ b/mix/MixApplication.cpp @@ -21,7 +21,6 @@ #include #include -#include "CodeEditorExtensionManager.h" #include "MixApplication.h" #include "AppContext.h" @@ -32,10 +31,8 @@ using namespace dev::mix; MixApplication::MixApplication(int _argc, char* _argv[]): QApplication(_argc, _argv), m_engine(new QQmlApplicationEngine()), m_appContext(new AppContext(m_engine.get())) { - qmlRegisterType("CodeEditorExtensionManager", 1, 0, "CodeEditorExtensionManager"); QObject::connect(this, SIGNAL(lastWindowClosed()), context(), SLOT(quitApplication())); //use to kill ApplicationContext and other stuff - m_engine->load(QUrl("qrc:/qml/main.qml")); - m_appContext->appLoaded(); + m_appContext->load(); } MixApplication::~MixApplication() diff --git a/mix/main.cpp b/mix/main.cpp index 90099555f..4f2c901b4 100644 --- a/mix/main.cpp +++ b/mix/main.cpp @@ -20,11 +20,24 @@ * Ethereum IDE client. */ +#include #include "MixApplication.h" +#include "Exceptions.h" using namespace dev::mix; int main(int _argc, char* _argv[]) { - MixApplication app(_argc, _argv); - return app.exec(); + try + { + MixApplication app(_argc, _argv); + return app.exec(); + } + catch (boost::exception const& _e) + { + std::cerr << boost::diagnostic_information(_e); + } + catch (std::exception const& _e) + { + std::cerr << _e.what(); + } } diff --git a/mix/qml/ProjectModel.qml b/mix/qml/ProjectModel.qml index 4ffa4a8b0..91a4a97ca 100644 --- a/mix/qml/ProjectModel.qml +++ b/mix/qml/ProjectModel.qml @@ -44,7 +44,7 @@ Item { target: appContext onAppLoaded: { if (projectSettings.lastProjectPath) - loadProject(projectSettings.lastProjectPath) + projectModel.loadProject(projectSettings.lastProjectPath) } }