diff --git a/global/global.cpp b/global/global.cpp index 7bde452fa..171f2f34f 100644 --- a/global/global.cpp +++ b/global/global.cpp @@ -166,18 +166,11 @@ void OliveGlobal::SetNativeStyling(QWidget *w) #endif } -void OliveGlobal::LoadProject(const QString &fn, bool autorecovery, bool clear) +void OliveGlobal::LoadProject(const QString &fn, bool autorecovery) { - // Normally, the user will be closing the previous project to load a new one, but just in case the user - // is importing a new project - - if (clear) { - new_project(); - } - LoadDialog ld(olive::MainWindow); - LoadThread* lt = new LoadThread(fn, autorecovery, clear); + LoadThread* lt = new LoadThread(fn, autorecovery); connect(&ld, SIGNAL(cancel()), lt, SLOT(cancel())); connect(lt, SIGNAL(success()), &ld, SLOT(accept())); connect(lt, SIGNAL(error()), &ld, SLOT(reject())); @@ -188,37 +181,43 @@ void OliveGlobal::LoadProject(const QString &fn, bool autorecovery, bool clear) ld.exec(); } +void OliveGlobal::ClearProject() +{ + // clear graph editor + panel_graph_editor->set_row(nullptr); + + // clear effects panel + panel_effect_controls->Clear(true); + + // clear existing project + olive::Global->set_sequence(nullptr); + panel_footage_viewer->set_media(nullptr); + + // clear project contents (footage, sequences, etc.) + panel_project->clear(); + + // clear undo stack + olive::UndoStack.clear(); + + // empty current project filename + update_project_filename(""); + + // full update of all panels + update_ui(false); + + // set to unmodified + olive::Global->set_modified(false); +} + void OliveGlobal::ImportProject(const QString &fn) { - LoadProject(fn, false, false); + LoadProject(fn, false); + set_modified(true); } void OliveGlobal::new_project() { if (can_close_project()) { - // clear graph editor - panel_graph_editor->set_row(nullptr); - - // clear effects panel - panel_effect_controls->Clear(true); - - // clear existing project - olive::Global->set_sequence(nullptr); - panel_footage_viewer->set_media(nullptr); - - // clear project contents (footage, sequences, etc.) - panel_project->clear(); - - // clear undo stack - olive::UndoStack.clear(); - - // empty current project filename - update_project_filename(""); - - // full update of all panels - update_ui(false); - - // set to unmodified - olive::Global->set_modified(false); + ClearProject(); } } @@ -359,8 +358,9 @@ void OliveGlobal::set_sequence(SequencePtr s) } void OliveGlobal::OpenProjectWorker(const QString& fn, bool autorecovery) { + ClearProject(); update_project_filename(fn); - LoadProject(fn, autorecovery, true); + LoadProject(fn, autorecovery); olive::UndoStack.clear(); } diff --git a/global/global.h b/global/global.h index 560295f7c..17c88f535 100644 --- a/global/global.h +++ b/global/global.h @@ -366,7 +366,15 @@ private: * TRUE if the current project should be closed before opening, FALSE if the project should be imported into the * currently open one. */ - void LoadProject(const QString& fn, bool autorecovery, bool clear); + void LoadProject(const QString& fn, bool autorecovery); + + /** + * @brief Indiscriminately clear the project without prompting the user + * + * Will clear the entire project without prompting to save. This is dangerous, use new_project() instead for + * anything initiated by the user. + */ + void ClearProject(); /** * @brief File filter used for any file dialogs relating to Olive project files. diff --git a/project/loadthread.cpp b/project/loadthread.cpp index 578ac11c9..8cd888d81 100644 --- a/project/loadthread.cpp +++ b/project/loadthread.cpp @@ -37,10 +37,9 @@ #include #include -LoadThread::LoadThread(const QString& filename, bool autorecovery, bool clear) : +LoadThread::LoadThread(const QString& filename, bool autorecovery) : filename_(filename), autorecovery_(autorecovery), - clear_(clear), cancelled_(false) { connect(this, SIGNAL(finished()), this, SLOT(deleteLater())); @@ -779,14 +778,12 @@ void LoadThread::success_func() { counter++; } - if (clear_) { - olive::Global->update_project_filename(orig_filename); - } + olive::Global->update_project_filename(orig_filename); } else { panel_project->add_recent_project(filename_); } - olive::Global->set_modified(autorecovery_ || !clear_); + olive::Global->set_modified(autorecovery_); if (open_seq != nullptr) { olive::Global->set_sequence(open_seq); } diff --git a/project/loadthread.h b/project/loadthread.h index cdf63ae69..2a8d1a07b 100644 --- a/project/loadthread.h +++ b/project/loadthread.h @@ -35,7 +35,7 @@ class LoadThread : public QThread { Q_OBJECT public: - LoadThread(const QString& filename, bool autorecovery, bool clear); + LoadThread(const QString& filename, bool autorecovery); void run(); public slots: void cancel(); @@ -50,7 +50,6 @@ private slots: void success_func(); private: bool autorecovery_; - bool clear_; QString filename_; bool load_worker(QFile& f, QXmlStreamReader& stream, int type);