forked from qt-creator/qt-creator
EffectMaker: confirm save changes before opening an composition
Change-Id: I05659e4cdeba5dc5f437d2fb99bc3768c6a1522d Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -16,6 +16,16 @@ Item {
|
||||
property int moveToIdx: 0
|
||||
property bool previewAnimationRunning: false
|
||||
|
||||
// Invoked after save changes is done
|
||||
property var onSaveChangesCallback: () => {}
|
||||
|
||||
// Invoked from C++ side when open composition is requested and there are unsaved changes
|
||||
function promptToSaveBeforeOpen() {
|
||||
root.onSaveChangesCallback = () => { EffectMakerBackend.rootView.doOpenComposition() }
|
||||
|
||||
saveChangesDialog.open()
|
||||
}
|
||||
|
||||
SaveAsDialog {
|
||||
id: saveDialog
|
||||
anchors.centerIn: parent
|
||||
@@ -31,12 +41,12 @@ Item {
|
||||
saveDialog.clearOnClose = true
|
||||
saveDialog.open()
|
||||
} else {
|
||||
EffectMakerBackend.effectMakerModel.clear()
|
||||
root.onSaveChangesCallback()
|
||||
}
|
||||
}
|
||||
|
||||
onDiscard: {
|
||||
EffectMakerBackend.effectMakerModel.clear()
|
||||
root.onSaveChangesCallback()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +57,8 @@ Item {
|
||||
|
||||
EffectMakerTopBar {
|
||||
onAddClicked: {
|
||||
root.onSaveChangesCallback = () => { EffectMakerBackend.effectMakerModel.clear() }
|
||||
|
||||
if (EffectMakerBackend.effectMakerModel.hasUnsavedChanges)
|
||||
saveChangesDialog.open()
|
||||
else
|
||||
|
||||
@@ -7,17 +7,10 @@
|
||||
#include "effectmakernodesmodel.h"
|
||||
#include "effectmakerwidget.h"
|
||||
|
||||
#include "nodeinstanceview.h"
|
||||
#include "qmldesignerconstants.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QQmlContext>
|
||||
#include <QQmlEngine>
|
||||
#include <QQuickItem>
|
||||
#include <QQuickView>
|
||||
#include <QTimer>
|
||||
|
||||
namespace EffectMaker {
|
||||
|
||||
EffectMakerContext::EffectMakerContext(QWidget *widget)
|
||||
@@ -66,7 +59,7 @@ void EffectMakerView::customNotification([[maybe_unused]] const AbstractView *vi
|
||||
{
|
||||
if (identifier == "open_effectmaker_composition" && data.count() > 0) {
|
||||
const QString compositionPath = data[0].toString();
|
||||
m_widget->effectMakerModel()->openComposition(compositionPath);
|
||||
m_widget->openComposition(compositionPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
//#include "qmldesigner/designercore/imagecache/midsizeimagecacheprovider.h"
|
||||
#include "qmldesignerconstants.h"
|
||||
#include "qmldesignerplugin.h"
|
||||
#include "qqmlcontext.h"
|
||||
#include "theme.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -30,7 +29,9 @@
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QQmlContext>
|
||||
#include <QQmlEngine>
|
||||
#include <QQuickItem>
|
||||
#include <QTimer>
|
||||
|
||||
namespace EffectMaker {
|
||||
@@ -193,6 +194,21 @@ void EffectMakerWidget::initView()
|
||||
reloadQmlSource();
|
||||
}
|
||||
|
||||
void EffectMakerWidget::openComposition(const QString &path)
|
||||
{
|
||||
m_compositionPath = path;
|
||||
|
||||
if (effectMakerModel()->hasUnsavedChanges())
|
||||
QMetaObject::invokeMethod(quickWidget()->rootObject(), "promptToSaveBeforeOpen");
|
||||
else
|
||||
doOpenComposition();
|
||||
}
|
||||
|
||||
void EffectMakerWidget::doOpenComposition()
|
||||
{
|
||||
effectMakerModel()->openComposition(m_compositionPath);
|
||||
}
|
||||
|
||||
void EffectMakerWidget::reloadQmlSource()
|
||||
{
|
||||
const QString effectMakerQmlPath = qmlSourcesPath() + "/EffectMaker.qml";
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
void delayedUpdateModel();
|
||||
void updateModel();
|
||||
void initView();
|
||||
void openComposition(const QString &path);
|
||||
|
||||
StudioQuickWidget *quickWidget() const;
|
||||
QPointer<EffectMakerModel> effectMakerModel() const;
|
||||
@@ -46,6 +47,7 @@ public:
|
||||
|
||||
Q_INVOKABLE void addEffectNode(const QString &nodeQenPath);
|
||||
Q_INVOKABLE void focusSection(int section);
|
||||
Q_INVOKABLE void doOpenComposition();
|
||||
Q_INVOKABLE QRect screenRect() const;
|
||||
Q_INVOKABLE QPoint globalPos(const QPoint &point) const;
|
||||
|
||||
@@ -74,6 +76,7 @@ private:
|
||||
};
|
||||
|
||||
ImportScanData m_importScan;
|
||||
QString m_compositionPath;
|
||||
};
|
||||
|
||||
} // namespace EffectMaker
|
||||
|
||||
Reference in New Issue
Block a user