using support::createDirectory;
using support::createLyXTmpDir;
using support::destroyDir;
+using support::FileName;
using support::fileSearch;
using support::getEnv;
using support::i18nLibFileSearch;
support::top_build_dir_is_one_level_up);
vector<string> files;
- int exit_status = execBatchCommands(argc, argv, files);
-
- if (exit_status)
- return exit_status;
- if (use_gui) {
- // Force adding of font path _before_ Application is initialized
- support::addFontResources();
- pimpl_->application_.reset(createApplication(argc, argv));
- initGuiFont();
- // FIXME: this global pointer should probably go.
- theApp = pimpl_->application_.get();
- restoreGuiSession(files);
- // Start the real execution loop.
-
- // FIXME
- /* Create a CoreApplication class that will provide the main event loop
- * and the socket callback registering. With Qt4, only QtCore
- * library would be needed.
- * When this is done, a server_mode could be created and the following two
- * line would be moved out from here.
- */
- pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
- 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));
+ if (!use_gui) {
+ // FIXME: create a ConsoleApplication
+ int exit_status = loadFiles(argc, argv, files);
+ if (exit_status) {
+ prepareExit();
+ return exit_status;
}
- exit_status = pimpl_->application_->start(batch_command);
- // Kill the application object before exiting. This avoid crash
- // on exit on Linux.
- pimpl_->application_.reset();
- // Restore original font resources after Application is destroyed.
- support::restoreFontResources();
+ if (batch_command.empty() || pimpl_->buffer_list_.empty()) {
+ prepareExit();
+ return EXIT_SUCCESS;
+ }
+
+ BufferList::iterator begin = pimpl_->buffer_list_.begin();
+ BufferList::iterator end = pimpl_->buffer_list_.end();
+
+ bool final_success = false;
+ for (BufferList::iterator I = begin; I != end; ++I) {
+ Buffer * buf = *I;
+ bool success = false;
+ buf->dispatch(batch_command, &success);
+ final_success |= success;
+ }
+ prepareExit();
+ return !final_success;
}
- else {
- // FIXME: create a ConsoleApplication
- theApp = 0;
+
+ // Force adding of font path _before_ Application is initialized
+ support::addFontResources();
+
+ // 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 = loadFiles(argc, argv, files);
+ if (exit_status) {
+ // Kill the application object before exiting.
+ pimpl_->application_.reset();
+ use_gui = false;
+ prepareExit();
+ return exit_status;
}
+ restoreGuiSession(files);
+ // Start the real execution loop.
+
+ // FIXME
+ /* Create a CoreApplication class that will provide the main event loop
+ * and the socket callback registering. With Qt4, only QtCore
+ * library would be needed.
+ * When this is done, a server_mode could be created and the following two
+ * line would be moved out from here.
+ */
+ pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
+ pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_,
+ support::os::internal_path(package().temp_dir() + "/lyxsocket")));
+
+ exit_status = pimpl_->application_->exec();
+ // Kill the application object before exiting. This avoid crash
+ // on exit on Linux.
+ pimpl_->application_.reset();
+ // Restore original font resources after Application is destroyed.
+ support::restoreFontResources();
+
return exit_status;
}
}
-int LyX::execBatchCommands(int & argc, char * argv[],
+int LyX::loadFiles(int & argc, char * argv[],
vector<string> & files)
{
// check for any spurious extra arguments
if (!success)
return EXIT_FAILURE;
- for (int argi = argc - 1; argi >= 1; --argi)
+ for (int argi = argc - 1; argi >= 1; --argi) {
+ // check for any remaining extra arguments other than
+ // document file names. These will be passed out to the
+ // frontend.
+ if (argv[argi][0] == '-')
+ continue;
files.push_back(os::internal_path(argv[argi]));
+ }
if (first_start)
- files.push_back(i18nLibFileSearch("examples", "splash.lyx"));
+ files.push_back(i18nLibFileSearch("examples", "splash.lyx").absFilename());
- // Execute batch commands if available
- if (!batch_command.empty()) {
-
- lyxerr[Debug::INIT] << "About to handle -x '"
- << batch_command << '\'' << endl;
-
- 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);
- }
- }
+ Buffer * last_loaded = 0;
+
+ vector<string>::const_iterator it = files.begin();
+ vector<string>::const_iterator end = files.end();
- // try to dispatch to last loaded buffer first
- if (last_loaded) {
- success = false;
- if (last_loaded->dispatch(batch_command, &success)) {
- prepareExit();
- return !success;
+ for (; it != end; ++it) {
+ // get absolute path of file and add ".lyx" to
+ // the filename if necessary
+ string s = fileSearch(string(), *it, "lyx").absFilename();
+ 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);
}
- 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();
// initial geometry
unsigned int width = 690;
unsigned int height = 510;
+ // default icon size, will be overwritten by stored session value
+ unsigned int iconSizeXY = 26;
bool maximize = false;
// first try lyxrc
if (lyxrc.geometry_width != 0 && lyxrc.geometry_height != 0 ) {
height = convert<unsigned int>(val);
if (session().sessionInfo().load("WindowIsMaximized") == "yes")
maximize = true;
+ val = session().sessionInfo().load("IconSizeXY");
+ if (!val.empty())
+ iconSizeXY = convert<unsigned int>(val);
}
// if user wants to restore window position
height = 0;
}
// create the main window
- LyXView * view = &pimpl_->application_->createView(width, height, posx, posy, maximize);
+ LyXView * view = &pimpl_->application_->createView(width, height, posx, posy, maximize, iconSizeXY);
return view;
}
fs::is_directory(lyxrc.document_path))
package().document_dir() = lyxrc.document_path;
- package().temp_dir() = createLyXTmpDir(lyxrc.tempdir_path);
+ package().temp_dir() = createLyXTmpDir(FileName(lyxrc.tempdir_path)).absFilename();
if (package().temp_dir().empty()) {
Alert::error(_("Could not create temporary directory"),
bformat(_("Could not create a temporary directory in\n"
{
lyxerr[Debug::INIT] << "About to read " << name << "... ";
- string const lyxrc_path = libFileSearch(string(), name);
+ FileName const lyxrc_path = libFileSearch(string(), name);
if (!lyxrc_path.empty()) {
lyxerr[Debug::INIT] << "Found in " << lyxrc_path << endl;
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
- string const ui_path = libFileSearch("ui", name, "ui");
+ FileName const ui_path = libFileSearch("ui", name, "ui");
if (ui_path.empty()) {
lyxerr[Debug::INIT] << "Could not find " << name << endl;
{
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
- string const lang_path = libFileSearch(string(), name);
+ FileName const lang_path = libFileSearch(string(), name);
if (lang_path.empty()) {
showFileError(name);
return false;
{
lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
- string const enc_path = libFileSearch(string(), name);
+ FileName const enc_path = libFileSearch(string(), name);
if (enc_path.empty()) {
showFileError(name);
return false;