Browse Source

- Clear code model when project changes (#1262).

- Small changes.
cl-refactor
yann300 10 years ago
parent
commit
cdb4e84bfb
  1. 2
      mix/CodeModel.h
  2. 10
      mix/qml/ProjectModel.qml
  3. 5
      mix/qml/StateListModel.qml
  4. 1
      mix/qml/js/ProjectModel.js

2
mix/CodeModel.h

@ -164,6 +164,8 @@ public:
/// Find a contract by document id /// Find a contract by document id
/// @returns CompiledContract object or null if not found /// @returns CompiledContract object or null if not found
Q_INVOKABLE CompiledContract* contractByDocumentId(QString _documentId) const; Q_INVOKABLE CompiledContract* contractByDocumentId(QString _documentId) const;
/// Reset code model
Q_INVOKABLE void reset() { reset(QVariantMap()); }
signals: signals:
/// Emited on compilation state change /// Emited on compilation state change

10
mix/qml/ProjectModel.qml

@ -64,7 +64,7 @@ Item {
Connections { Connections {
target: appContext target: appContext
onAppLoaded: { onAppLoaded: {
if (projectSettings.lastProjectPath) if (projectSettings.lastProjectPath && projectSettings.lastProjectPath !== "")
projectModel.loadProject(projectSettings.lastProjectPath) projectModel.loadProject(projectSettings.lastProjectPath)
} }
} }
@ -130,6 +130,14 @@ Item {
id: projectStateListModel id: projectStateListModel
} }
Connections
{
target: projectModel
onProjectClosed: {
projectSettings.lastProjectPath = "";
}
}
Settings { Settings {
id: projectSettings id: projectSettings
property string lastProjectPath; property string lastProjectPath;

5
mix/qml/StateListModel.qml

@ -134,6 +134,7 @@ Item {
onProjectClosed: { onProjectClosed: {
stateListModel.clear(); stateListModel.clear();
stateList = []; stateList = [];
codeModel.reset();
} }
onProjectLoading: stateListModel.loadStatesFromProject(projectData); onProjectLoading: stateListModel.loadStatesFromProject(projectData);
onProjectSaving: { onProjectSaving: {
@ -148,6 +149,7 @@ Item {
state.title = qsTr("Default"); state.title = qsTr("Default");
projectData.states = [ state ]; projectData.states = [ state ];
projectData.defaultStateIndex = 0; projectData.defaultStateIndex = 0;
stateListModel.loadStatesFromProject(projectData);
} }
} }
@ -264,6 +266,7 @@ Item {
defaultStateIndex--; defaultStateIndex--;
save(); save();
} }
function save() { function save() {
@ -284,6 +287,8 @@ Item {
else else
defaultStateIndex = 0; defaultStateIndex = 0;
var items = projectData.states; var items = projectData.states;
stateListModel.clear();
stateList = [];
for(var i = 0; i < items.length; i++) { for(var i = 0; i < items.length; i++) {
var item = fromPlainStateItem(items[i]); var item = fromPlainStateItem(items[i]);
stateListModel.append(item); stateListModel.append(item);

1
mix/qml/js/ProjectModel.js

@ -105,7 +105,6 @@ function loadProject(path) {
contractSources[doc.documentId] = fileIo.readFile(doc.path); contractSources[doc.documentId] = fileIo.readFile(doc.path);
} }
codeModel.reset(contractSources); codeModel.reset(contractSources);
} }
function addFile(fileName) { function addFile(fileName) {

Loading…
Cancel
Save