From 73be03161fc07678b65d27450763c1b733a4ae0a Mon Sep 17 00:00:00 2001 From: krzys-h Date: Tue, 27 Sep 2016 18:57:24 +0200 Subject: [PATCH] Fix infinite pause when cloning program with errors, closes #837 --- src/ui/object_interface.cpp | 8 ++++---- src/ui/object_interface.h | 13 ++++++++++++- src/ui/studio.cpp | 4 ++-- src/ui/studio.h | 2 +- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index 44140059..a435c825 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -275,7 +275,7 @@ bool CObjectInterface::EventProcess(const Event &event) } if( action == EVENT_STUDIO_CLONE ) { - StopEditScript(false); + StopEditScript(true); Program* newProgram = m_programStorage->CloneProgram(m_programStorage->GetProgram(m_selScript)); m_selScript = m_programStorage->GetProgramIndex(newProgram); m_main->SaveOneScript(m_object); @@ -738,12 +738,12 @@ void CObjectInterface::StartEditScript(Program* program, std::string name) // End of editing a program. -void CObjectInterface::StopEditScript(bool bCancel) +void CObjectInterface::StopEditScript(bool closeWithErrors) { - if ( !m_studio->StopEditScript(bCancel) ) return; + if ( !m_studio->StopEditScript(closeWithErrors) ) return; m_studio.reset(); - if ( !bCancel ) m_programStorage->SetActiveVirus(false); + if ( !closeWithErrors ) m_programStorage->SetActiveVirus(false); CreateInterface(true); // puts the control buttons } diff --git a/src/ui/object_interface.h b/src/ui/object_interface.h index b7b97105..a35638a4 100644 --- a/src/ui/object_interface.h +++ b/src/ui/object_interface.h @@ -64,8 +64,19 @@ public: protected: bool EventFrame(const Event &event); + /** + * \brief Start the program editor + * \param program Program instance to edit + * \param name Program name, used only if the program is empty to insert main function stub code + * \remarks If the editor is already open, the behaviour is undefined + */ void StartEditScript(Program* program, std::string name); - void StopEditScript(bool bCancel); + /** + * \brief Close the program editor + * \param closeWithErrors If true, the editor will be forced to close even if the program contains errors + * \remarks If the editor isn't open, the behaviour is undefined + */ + void StopEditScript(bool closeWithErrors); void GroundFlat(); void ColorFlag(int color); diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index 4f6fa206..e3545cbb 100644 --- a/src/ui/studio.cpp +++ b/src/ui/studio.cpp @@ -875,7 +875,7 @@ void CStudio::AdjustEditScript() // Ends edition of a program. -bool CStudio::StopEditScript(bool bCancel) +bool CStudio::StopEditScript(bool closeWithErrors) { CWindow* pw; CEdit* edit; @@ -883,7 +883,7 @@ bool CStudio::StopEditScript(bool bCancel) pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3)); if ( pw == nullptr ) return false; - if ( !bCancel && !m_script->IsRunning() ) + if ( !closeWithErrors && !m_script->IsRunning() ) { edit = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT)); if ( edit != nullptr ) diff --git a/src/ui/studio.h b/src/ui/studio.h index 201e58b2..f3369754 100644 --- a/src/ui/studio.h +++ b/src/ui/studio.h @@ -58,7 +58,7 @@ public: bool EventProcess(const Event &event); void StartEditScript(CScript *script, std::string name, Program* program); - bool StopEditScript(bool bCancel); + bool StopEditScript(bool closeWithErrors); void SetInfoText(std::string text, bool bClickable);