Browse Source

change ProjectModel to be a context property instead of a singleton to

work around issue #809
cl-refactor
arkpar 10 years ago
parent
commit
aeff8b3a4d
  1. 10
      mix/AppContext.cpp
  2. 3
      mix/qml/CodeEditorView.qml
  3. 17
      mix/qml/ProjectList.qml
  4. 2
      mix/qml/ProjectModel.qml
  5. 5
      mix/qml/StateList.qml
  6. 29
      mix/qml/main.qml

10
mix/AppContext.cpp

@ -22,16 +22,17 @@
* - KeyEventManager
*/
#include <stdexcept>
#include <QDebug>
#include <QMessageBox>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlApplicationEngine>
#include <libwebthree/WebThree.h>
#include "CodeModel.h"
#include "FileIo.h"
#include "ClientModel.h"
#include "AppContext.h"
#include <libwebthree/WebThree.h>
using namespace dev;
using namespace dev::eth;
@ -48,7 +49,12 @@ AppContext::AppContext(QQmlApplicationEngine* _engine)
m_fileIo.reset(new FileIo());
m_applicationEngine->rootContext()->setContextProperty("appContext", this);
qmlRegisterType<FileIo>("org.ethereum.qml", 1, 0, "FileIo");
qmlRegisterSingletonType(QUrl("qrc:/qml/ProjectModel.qml"), "org.ethereum.qml.ProjectModel", 1, 0, "ProjectModel");
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);
m_applicationEngine->rootContext()->setContextProperty("projectModel", projectModel);
m_applicationEngine->rootContext()->setContextProperty("codeModel", m_codeModel.get());
m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get());

3
mix/qml/CodeEditorView.qml

@ -2,7 +2,6 @@ import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0
import org.ethereum.qml.ProjectModel 1.0
Item {
@ -40,7 +39,7 @@ Item {
}
Connections {
target: ProjectModel
target: projectModel
onDocumentOpened: {
openDocument(document);
}

17
mix/qml/ProjectList.qml

@ -2,7 +2,6 @@ import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0
import org.ethereum.qml.ProjectModel 1.0
Item {
property bool renameMode: false;
@ -11,16 +10,16 @@ Item {
Text {
Layout.fillWidth: true
color: "blue"
text: ProjectModel.projectData ? ProjectModel.projectData.title : ""
text: projectModel.projectData ? projectModel.projectData.title : ""
horizontalAlignment: Text.AlignHCenter
visible: !ProjectModel.isEmpty;
visible: !projectModel.isEmpty;
}
ListView {
id: projectList
Layout.fillWidth: true
Layout.fillHeight: true
model: ProjectModel.listModel
model: projectModel.listModel
delegate: renderDelegate
highlight: Rectangle {
@ -31,8 +30,8 @@ Item {
clip: true
onCurrentIndexChanged: {
if (currentIndex >= 0 && currentIndex < ProjectModel.listModel.count)
ProjectModel.openDocument(ProjectModel.listModel.get(currentIndex).documentId);
if (currentIndex >= 0 && currentIndex < projectModel.listModel.count)
projectModel.openDocument(projectModel.listModel.get(currentIndex).documentId);
}
}
Menu {
@ -46,7 +45,7 @@ Item {
MenuItem {
text: qsTr("Delete")
onTriggered: {
ProjectModel.removeDocument(projectList.model.get(projectList.currentIndex).documentId);
projectModel.removeDocument(projectList.model.get(projectList.currentIndex).documentId);
}
}
}
@ -103,7 +102,7 @@ Item {
function close(accept) {
renameMode = false;
if (accept)
ProjectModel.renameDocument(projectList.model.get(projectList.currentIndex).documentId, textInput.text);
projectModel.renameDocument(projectList.model.get(projectList.currentIndex).documentId, textInput.text);
}
}
MouseArea {
@ -119,7 +118,7 @@ Item {
}
}
Connections {
target: ProjectModel
target: projectModel
onProjectLoaded: {
projectList.currentIndex = 0;
}

2
mix/qml/ProjectModel.qml

@ -1,5 +1,3 @@
pragma Singleton
import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Layouts 1.0

5
mix/qml/StateList.qml

@ -3,7 +3,6 @@ import QtQuick.Controls.Styles 1.1
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.1
import org.ethereum.qml.ProjectModel 1.0
Rectangle {
color: "#ededed"
@ -16,7 +15,7 @@ Rectangle {
property var stateList: []
Connections {
target: ProjectModel
target: projectModel
onProjectClosed: {
stateListModel.clear();
}
@ -91,7 +90,7 @@ Rectangle {
}
function save() {
ProjectModel.saveProject();
projectModel.saveProject();
}
}

29
mix/qml/main.qml

@ -5,7 +5,6 @@ import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
import CodeEditorExtensionManager 1.0
import org.ethereum.qml.ProjectModel 1.0
ApplicationWindow {
id: mainApplication
@ -101,7 +100,7 @@ ApplicationWindow {
text: qsTr("&New project")
shortcut: "Ctrl+N"
enabled: true;
onTriggered: ProjectModel.createProject();
onTriggered: projectModel.createProject();
}
Action {
@ -109,54 +108,54 @@ ApplicationWindow {
text: qsTr("&Open project")
shortcut: "Ctrl+O"
enabled: true;
onTriggered: ProjectModel.browseProject();
onTriggered: projectModel.browseProject();
}
Action {
id: addNewJsFileAction
text: qsTr("New JavaScript file")
shortcut: "Ctrl+Alt+J"
enabled: !ProjectModel.isEmpty
onTriggered: ProjectModel.newJsFile();
enabled: !projectModel.isEmpty
onTriggered: projectModel.newJsFile();
}
Action {
id: addNewHtmlFileAction
text: qsTr("New HTML file")
shortcut: "Ctrl+Alt+H"
enabled: !ProjectModel.isEmpty
onTriggered: ProjectModel.newHtmlFile();
enabled: !projectModel.isEmpty
onTriggered: projectModel.newHtmlFile();
}
Action {
id: addNewContractAction
text: qsTr("New contract")
shortcut: "Ctrl+Alt+C"
enabled: !ProjectModel.isEmpty
onTriggered: ProjectModel.newContract();
enabled: !projectModel.isEmpty
onTriggered: projectModel.newContract();
}
Action {
id: addExistingFileAction
text: qsTr("Add existing file")
shortcut: "Ctrl+Alt+A"
enabled: !ProjectModel.isEmpty
onTriggered: ProjectModel.addExistingFile();
enabled: !projectModel.isEmpty
onTriggered: projectModel.addExistingFile();
}
Action {
id: saveAllFilesAction
text: qsTr("Save all")
shortcut: "Ctrl+S"
enabled: !ProjectModel.isEmpty
onTriggered: ProjectModel.saveAll();
enabled: !projectModel.isEmpty
onTriggered: projectModel.saveAll();
}
Action {
id: closeProjectAction
text: qsTr("Close project")
shortcut: "Ctrl+W"
enabled: !ProjectModel.isEmpty
onTriggered: ProjectModel.closeProject();
enabled: !projectModel.isEmpty
onTriggered: projectModel.closeProject();
}
}

Loading…
Cancel
Save