Move OpenFileJob to its own header

This commit is contained in:
Martín Capello 2024-09-10 18:05:08 -03:00
parent b110078a8b
commit f7eed69d7c
2 changed files with 60 additions and 41 deletions

View File

@ -19,12 +19,12 @@
#include "app/file/file.h"
#include "app/file_selector.h"
#include "app/i18n/strings.h"
#include "app/job.h"
#include "app/modules/gui.h"
#include "app/pref/preferences.h"
#include "app/recent_files.h"
#include "app/ui/status_bar.h"
#include "app/ui_context.h"
#include "app/util/open_file_job.h"
#include "base/fs.h"
#include "base/thread.h"
#include "doc/sprite.h"
@ -34,46 +34,6 @@
namespace app {
class OpenFileJob : public Job, public IFileOpProgress {
public:
OpenFileJob(FileOp* fop, const bool showProgress)
: Job(Strings::open_file_loading(), showProgress)
, m_fop(fop)
{
}
void showProgressWindow() {
startJob();
if (isCanceled())
m_fop->stop();
waitJob();
}
private:
// Thread to do the hard work: load the file from the disk.
virtual void onJob() override {
try {
m_fop->operate(this);
}
catch (const std::exception& e) {
m_fop->setError("Error loading file:\n%s", e.what());
}
if (m_fop->isStop() && m_fop->document())
delete m_fop->releaseDocument();
m_fop->done();
}
virtual void ackFileOpProgress(double progress) override {
jobProgress(progress);
}
FileOp* m_fop;
};
OpenFileCommand::OpenFileCommand()
: Command(CommandId::OpenFile(), CmdRecordableFlag)
, m_ui(true)

View File

@ -0,0 +1,59 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_OPEN_FILE_JOB_H_INCLUDED
#define APP_OPEN_FILE_JOB_H_INCLUDED
#pragma once
#include "app/file/file.h"
#include "app/i18n/strings.h"
#include "app/job.h"
namespace app {
class OpenFileJob : public Job, public IFileOpProgress {
public:
OpenFileJob(FileOp* fop, const bool showProgress)
: Job(Strings::open_file_loading(), showProgress)
, m_fop(fop)
{
}
void showProgressWindow() {
startJob();
if (isCanceled())
m_fop->stop();
waitJob();
}
private:
// Thread to do the hard work: load the file from the disk.
virtual void onJob() override {
try {
m_fop->operate(this);
}
catch (const std::exception& e) {
m_fop->setError("Error loading file:\n%s", e.what());
}
if (m_fop->isStop() && m_fop->document())
delete m_fop->releaseDocument();
m_fop->done();
}
virtual void ackFileOpProgress(double progress) override {
jobProgress(progress);
}
FileOp* m_fop;
};
} // namespace app
#endif