Do not use Application for a 'cancel export' boolean

It is not good for a support function to depend of anything outside of
it, especially Application.

Here the boolean that indicates that export should be canceled is put
in Systemcall. This allows to remove all the dummy theApp() function
that have been added here and there for linking needs.
This commit is contained in:
Jean-Marc Lasgouttes 2018-01-02 00:23:27 +01:00
parent fd6ff2b203
commit 39a8000589
9 changed files with 21 additions and 41 deletions

View File

@ -69,13 +69,6 @@ namespace lyx {
// Dummy verbose support
bool verbose = false;
struct App {
bool cancel_export;
};
App app;
App * theApp() { return &app; }
// Dummy LyXRC support
struct LyXRC {
string icon_set;

View File

@ -166,7 +166,7 @@ class Application
{
public:
///
Application() : cancel_export(false) {}
Application() {}
///
virtual ~Application() {}
@ -253,8 +253,6 @@ public:
// Add a buffer to the current view, do not switch to it.
virtual bool unhide(Buffer * buf) = 0;
///
bool cancel_export;
};
/// Return the list of loadable formats.

View File

@ -3731,7 +3731,7 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
break;
}
case LFUN_EXPORT_CANCEL: {
theApp()->cancel_export = true;
Systemcall::killscript();
break;
}
case LFUN_BUFFER_SWITCH: {

View File

@ -23,10 +23,7 @@
#include "support/os.h"
#include "support/ProgressInterface.h"
#include "frontends/Application.h"
#include "LyX.h"
#include "LyXRC.h"
#include <cstdlib>
#include <iostream>
@ -236,6 +233,12 @@ string const parsecmd(string const & incmd, string & infile, string & outfile,
} // namespace
void Systemcall::killscript()
{
SystemcallPrivate::kill_script = true;
}
int Systemcall::startscript(Starttype how, string const & what,
string const & path, string const & lpath,
bool process_events)
@ -315,6 +318,9 @@ int Systemcall::startscript(Starttype how, string const & what,
}
bool SystemcallPrivate::kill_script = false;
SystemcallPrivate::SystemcallPrivate(std::string const & sf, std::string const & of,
std::string const & ef)
: state(Error), process_(new QProcess), out_index_(0), err_index_(0),
@ -403,11 +409,11 @@ void SystemcallPrivate::startProcess(QString const & cmd, string const & path,
bool SystemcallPrivate::waitAndCheck()
{
Sleep::millisec(100);
if (theApp() && theApp()->cancel_export) {
if (kill_script) {
// is there a better place to reset this?
process_->kill();
state = Killed;
theApp()->cancel_export = false;
kill_script = false;
LYXERR0("Export Canceled!!");
return false;
}

View File

@ -38,7 +38,7 @@ public:
WaitLoop, //< wait, but check occasionally for cancellation
DontWait //< don't wait for completion
};
// enum values chosen hopefully not to conflict with ordinary return values
enum ReturnValue {
OK = 0,
@ -48,6 +48,10 @@ public:
KILLED = 9001
};
// Kill the process which is running at time being
static void killscript();
/** Start child process.
* The string "what" contains a commandline with arguments separated
* by spaces and encoded in the filesystem encoding. "$$s" will be

View File

@ -58,6 +58,9 @@ public:
static void killProcess(QProcess * p);
// when true, kill any running script ASAP
static bool kill_script;
public Q_SLOTS:
void stdOut();

View File

@ -62,11 +62,4 @@ namespace lyx {
return dummy;
}
struct App {
bool cancel_export;
};
App app;
App * theApp() { return &app; }
} // namespace lyx

View File

@ -65,11 +65,4 @@ namespace lyx {
return dummy;
}
struct App {
bool cancel_export;
};
App app;
App * theApp() { return &app; }
} // namespace lyx

View File

@ -129,16 +129,6 @@ frontend::FontMetrics const & theFontMetrics(FontInfo const &) {
return dummy;
}
//
// Dummy theApp() support (needed by support/Systemcall.cpp)
//
struct App {
bool cancel_export;
};
App app;
App * theApp() { return &app; }
//
// Keep the linker happy on Windows
//