Fix bug closing the app when it's saving (fix #1326)

This commit is contained in:
David Capello 2016-11-14 17:01:41 -03:00
parent c1e3054e3f
commit 617b909e1e
3 changed files with 21 additions and 1 deletions

View File

@ -13,6 +13,7 @@
#include "app/commands/commands.h"
#include "app/context.h"
#include "app/document.h"
#include "app/job.h"
#include "app/ui/main_window.h"
#include "ui/alert.h"
@ -36,6 +37,11 @@ ExitCommand::ExitCommand()
void ExitCommand::onExecute(Context* ctx)
{
// Ignore ExitCommand when we are saving documents or doing a
// background task
if (Job::runningJobs() > 0)
return;
if (ctx->hasModifiedDocuments()) {
Command* closeAll = CommandsModule::instance()->getCommandByName(CommandId::CloseAllFiles);
Params params;

View File

@ -19,10 +19,19 @@
#include "ui/widget.h"
#include "ui/window.h"
#include <atomic>
static const int kMonitoringPeriod = 100;
static std::atomic<int> g_runningJobs(0);
namespace app {
// static
int Job::runningJobs()
{
return g_runningJobs;
}
Job::Job(const char* jobName)
{
m_mutex = NULL;
@ -60,6 +69,7 @@ Job::~Job()
void Job::startJob()
{
m_thread = new base::thread(&Job::thread_proc, this);
++g_runningJobs;
if (m_alert_window) {
m_alert_window->openWindowInForeground();
@ -93,7 +103,9 @@ void Job::waitJob()
if (m_thread) {
m_thread->join();
delete m_thread;
m_thread = NULL;
m_thread = nullptr;
--g_runningJobs;
}
}

View File

@ -24,6 +24,8 @@ namespace app {
class Job {
public:
static int runningJobs();
Job(const char* jobName);
virtual ~Job();