* lyx_main.[Ch]

- execBatchCommands(): split in loadFiles() and execBatchCommands().
  - exec(): enable batch command to be processed from GUI.

* Application:
  - start(): deleted.

* GuiApplication:
  - execBatchCommands(): new method

* GuiWorkArea::update(): call viewport()->repaint() instead of viewport()->update(), this enable to update the screen immediately when asked by a batch command.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16051 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-11-26 02:18:32 +00:00
parent 7913b8c652
commit e6a6548712
7 changed files with 69 additions and 64 deletions

View File

@ -86,13 +86,6 @@ void Application::setCurrentView(LyXView & current_view)
current_view_ = &current_view;
}
int Application::start(std::string const & /*batch*/)
{
return exec();
}
} // namespace frontend

View File

@ -105,12 +105,12 @@ public:
///
virtual ~Application() {}
/// Start the main event loop, after executing the given batch
/// commands.
int start(std::string const & batch);
///
virtual Gui & gui() = 0;
///
/// Start the main event loop.
/// The batch command is programmed to be execute once
/// the event loop is started.
virtual int const exec() = 0;
/// Quit running LyX.

View File

@ -169,6 +169,7 @@ Selection& GuiApplication::selection()
int const GuiApplication::exec()
{
QTimer::singleShot(1, this, SLOT(execBatchCommands()));
return QApplication::exec();
}
@ -179,6 +180,12 @@ void GuiApplication::exit(int status)
}
void GuiApplication::execBatchCommands()
{
LyX::ref().execBatchCommands();
}
string const GuiApplication::romanFontName()
{
QFont font;

View File

@ -83,6 +83,10 @@ public:
///
GuiFontLoader & guiFontLoader() { return font_loader_; }
private Q_SLOTS:
///
void execBatchCommands();
private:
///
GuiImplementation gui_;

View File

@ -454,7 +454,7 @@ void GuiWorkArea::resizeEvent(QResizeEvent * ev)
void GuiWorkArea::update(int x, int y, int w, int h)
{
viewport()->update(x, y, w, h);
viewport()->repaint(x, y, w, h);
}

View File

@ -331,7 +331,11 @@ int LyX::exec(int & argc, char * argv[])
if (!use_gui) {
// FIXME: create a ConsoleApplication
return execBatchCommands(argc, argv, files);
int exit_status = loadFiles(argc, argv, files);
if (exit_status)
return exit_status;
execBatchCommands();
return EXIT_SUCCESS;
}
// Force adding of font path _before_ Application is initialized
@ -339,10 +343,14 @@ int LyX::exec(int & argc, char * argv[])
// Let the frontend parse and remove all arguments that it knows
pimpl_->application_.reset(createApplication(argc, argv));
// FIXME: this global pointer should probably go.
theApp = pimpl_->application_.get();
initGuiFont();
// Parse and remove all known arguments in the LyX singleton
// Give an error for all remaining ones.
int exit_status = execBatchCommands(argc, argv, files);
int exit_status = loadFiles(argc, argv, files);
if (exit_status) {
// Kill the application object before exiting.
pimpl_->application_.reset();
@ -351,9 +359,6 @@ int LyX::exec(int & argc, char * argv[])
return exit_status;
}
initGuiFont();
// FIXME: this global pointer should probably go.
theApp = pimpl_->application_.get();
restoreGuiSession(files);
// Start the real execution loop.
@ -368,12 +373,7 @@ int LyX::exec(int & argc, char * argv[])
pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_,
support::os::internal_path(package().temp_dir() + "/lyxsocket")));
// handle the batch commands the user asked for
if (!batch_command.empty()) {
pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(batch_command));
}
exit_status = pimpl_->application_->start(batch_command);
exit_status = pimpl_->application_->exec();
// Kill the application object before exiting. This avoid crash
// on exit on Linux.
pimpl_->application_.reset();
@ -431,7 +431,7 @@ void LyX::quit()
}
int LyX::execBatchCommands(int & argc, char * argv[],
int LyX::loadFiles(int & argc, char * argv[],
vector<string> & files)
{
// check for any spurious extra arguments
@ -464,54 +464,52 @@ int LyX::execBatchCommands(int & argc, char * argv[],
if (first_start)
files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
// Execute batch commands if available
if (!batch_command.empty()) {
Buffer * last_loaded = 0;
lyxerr[Debug::INIT] << "About to handle -x '"
<< batch_command << '\'' << endl;
vector<string>::const_iterator it = files.begin();
vector<string>::const_iterator end = files.end();
Buffer * last_loaded = 0;
vector<string>::const_iterator it = files.begin();
vector<string>::const_iterator end = files.end();
for (; it != end; ++it) {
// get absolute path of file and add ".lyx" to
// the filename if necessary
string s = fileSearch(string(), *it, "lyx");
if (s.empty()) {
Buffer * const b = newFile(*it, string(), true);
if (b)
last_loaded = b;
} else {
Buffer * buf = pimpl_->buffer_list_.newBuffer(s, false);
if (loadLyXFile(buf, s)) {
last_loaded = buf;
ErrorList const & el = buf->errorList("Parse");
if (!el.empty())
for_each(el.begin(), el.end(),
boost::bind(&LyX::printError, this, _1));
}
else
pimpl_->buffer_list_.release(buf);
for (; it != end; ++it) {
// get absolute path of file and add ".lyx" to
// the filename if necessary
string s = fileSearch(string(), *it, "lyx");
if (s.empty()) {
Buffer * const b = newFile(*it, string(), true);
if (b)
last_loaded = b;
} else {
Buffer * buf = pimpl_->buffer_list_.newBuffer(s, false);
if (loadLyXFile(buf, s)) {
last_loaded = buf;
ErrorList const & el = buf->errorList("Parse");
if (!el.empty())
for_each(el.begin(), el.end(),
boost::bind(&LyX::printError, this, _1));
}
else
pimpl_->buffer_list_.release(buf);
}
// try to dispatch to last loaded buffer first
if (last_loaded) {
success = false;
if (last_loaded->dispatch(batch_command, &success)) {
prepareExit();
return !success;
}
}
files.clear(); // the files are already loaded
}
files.clear(); // the files are already loaded
return EXIT_SUCCESS;
}
void LyX::execBatchCommands()
{
// Execute batch commands if available
if (batch_command.empty())
return;
lyxerr[Debug::INIT] << "About to handle -x '"
<< batch_command << '\'' << endl;
pimpl_->lyxfunc_.dispatch(lyxaction.lookupFunc(batch_command));
}
void LyX::restoreGuiSession(vector<string> const & files)
{
LyXView * view = newLyXView();

View File

@ -105,6 +105,9 @@ public:
*/
Buffer const * const updateInset(InsetBase const *) const;
/// Execute batch commands if available.
void execBatchCommands();
private:
/// Do some cleanup in preparation of an exit.
void prepareExit();
@ -112,12 +115,12 @@ private:
/// Early exit during the initialisation process.
void earlyExit(int status);
/// Initialise LyX and execute batch commands if available.
/// Initialise LyX and load files if asked.
/**
\param files is filled in with the command-line file names.
\return exit code failure if any.
*/
int execBatchCommands(int & argc, char * argv[],
int loadFiles(int & argc, char * argv[],
std::vector<std::string> & files);
/// Create a View and restore GUI Session.