From: Jean-Baptiste Mardelle Date: Sat, 26 Sep 2009 22:21:27 +0000 (+0000) Subject: Add revert action to revert project to last saved version: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=fbc2fc841df015ffc0fddaba4842b622d982cbc9;p=kdenlive Add revert action to revert project to last saved version: http://www.kdenlive.org/mantis/view.php?id=1063 svn path=/trunk/kdenlive/; revision=3942 --- diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 01585755..fbab57bc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -176,9 +176,10 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent addDockWidget(Qt::TopDockWidgetArea, m_transitionConfigDock); KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile()); - m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)), - actionCollection()); + m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)), actionCollection()); readOptions(); + m_fileRevert = KStandardAction::revert(this, SLOT(slotRevert()), actionCollection()); + m_fileRevert->setEnabled(false); //slotDetectAudioDriver(); @@ -1251,6 +1252,7 @@ void MainWindow::slotRunWizard() void MainWindow::newFile(bool showProjectSettings) { if (!m_timelineArea->isEnabled()) return; + m_fileRevert->setEnabled(false); QString profileName; KUrl projectFolder; QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()); @@ -1300,7 +1302,7 @@ void MainWindow::activateDocument() connectDocument(currentTab, currentDoc); } -void MainWindow::closeCurrentDocument() +void MainWindow::closeCurrentDocument(bool saveChanges) { QWidget *w = m_timelineArea->currentWidget(); if (!w) return; @@ -1310,7 +1312,7 @@ void MainWindow::closeCurrentDocument() m_timelineArea->setCurrentIndex(ix); TrackView *tabToClose = (TrackView *) w; KdenliveDoc *docToClose = tabToClose->document(); - if (docToClose && docToClose->isModified()) { + if (docToClose && docToClose->isModified() && saveChanges) { switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document?"))) { case KMessageBox::Yes : // save document here. If saving fails, return false; @@ -1365,6 +1367,7 @@ bool MainWindow::saveFileAs(const QString &outputFileName) m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path()); m_activeDocument->setModified(false); m_fileOpenRecent->addUrl(KUrl(outputFileName)); + m_fileRevert->setEnabled(true); return true; } @@ -1460,6 +1463,7 @@ void MainWindow::openFile(const KUrl &url) void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) { if (!m_timelineArea->isEnabled()) return; + m_fileRevert->setEnabled(true); KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, this); if (stale == NULL) { stale = new KAutoSaveFile(url, doc); @@ -2849,7 +2853,12 @@ void MainWindow::slotRemoveFocus() statusBar()->clearFocus(); } - - +void MainWindow::slotRevert() +{ + if (KMessageBox::warningContinueCancel(this, i18n("This will delete all changes made since you last saved your project. Are you sure you want to continue?"), i18n("Revert to last saved version")) == KMessageBox::Cancel) return; + KUrl url = m_activeDocument->url(); + closeCurrentDocument(false); + doOpenFile(url, NULL); +} #include "mainwindow.moc" diff --git a/src/mainwindow.h b/src/mainwindow.h index dad8b34e..b953edf2 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -157,6 +157,7 @@ private: #endif /* NO_JOGSHUTTLE */ KRecentFilesAction *m_fileOpenRecent; + KAction *m_fileRevert; KAction *m_projectSearch; KAction *m_projectSearchNext; @@ -239,7 +240,7 @@ private slots: void slotZoomIn(); void slotZoomOut(); void slotFitZoom(); - void closeCurrentDocument(); + void closeCurrentDocument(bool saveChanges = true); void slotDeleteTimelineClip(); void slotAddClipMarker(); void slotDeleteClipMarker(); @@ -315,6 +316,7 @@ private slots: void slotCleanProject(); void slotSetZoom(int value); void slotUpdateClipMarkers(DocClipBase *clip); + void slotRevert(); signals: Q_SCRIPTABLE void abortRenderJob(const QString &url);