#include "buffer_funcs.h"
#include "BufferList.h"
#include "Converter.h"
+#include "CutAndPaste.h"
#include "debug.h"
#include "Encoding.h"
#include "ErrorList.h"
#include "Format.h"
#include "gettext.h"
-#include "kb_keymap.h"
+#include "KeyMap.h"
#include "Language.h"
#include "Session.h"
-#include "LColor.h"
-#include "lyx_cb.h"
+#include "Color.h"
#include "LyXAction.h"
#include "LyXFunc.h"
-#include "LyXLex.h"
+#include "Lexer.h"
#include "LyXRC.h"
-#include "LyXServer.h"
-#include "LyXServerSocket.h"
-#include "LyXTextClassList.h"
+#include "ModuleList.h"
+#include "Server.h"
+#include "ServerSocket.h"
+#include "TextClassList.h"
#include "MenuBackend.h"
#include "Messages.h"
#include "Mover.h"
#include "ToolbarBackend.h"
-#include "frontends/Alert.h"
+#include "frontends/alert.h"
#include "frontends/Application.h"
+#include "frontends/Dialogs.h"
#include "frontends/Gui.h"
#include "frontends/LyXView.h"
#include "support/Systemcall.h"
#include <boost/bind.hpp>
-#include <boost/filesystem/operations.hpp>
+#include <algorithm>
#include <iostream>
#include <csignal>
#include <map>
#include <string>
#include <vector>
+using std::endl;
+using std::for_each;
+using std::map;
+using std::make_pair;
+using std::string;
+using std::vector;
+
+#ifndef CXX_GLOBAL_CSTD
+using std::exit;
+using std::signal;
+using std::system;
+#endif
namespace lyx {
using support::prependEnvPath;
using support::rtrim;
using support::Systemcall;
+using frontend::LyXView;
namespace Alert = frontend::Alert;
namespace os = support::os;
-namespace fs = boost::filesystem;
-using std::endl;
-using std::for_each;
-using std::map;
-using std::make_pair;
-using std::string;
-using std::vector;
-
-#ifndef CXX_GLOBAL_CSTD
-using std::exit;
-using std::signal;
-using std::system;
-#endif
/// are we using the GUI at all?
-/**
+/**
* We default to true and this is changed to false when the export feature is used.
*/
bool use_gui = true;
+bool quitting; // flag, that we are quitting the program
namespace {
/// The main application class private implementation.
-struct LyX::Singletons
+struct LyX::Singletons
{
Singletons()
{
///
BufferList buffer_list_;
///
- boost::scoped_ptr<kb_keymap> toplevel_keymap_;
+ boost::scoped_ptr<KeyMap> toplevel_keymap_;
///
- boost::scoped_ptr<LyXServer> lyx_server_;
+ boost::scoped_ptr<Server> lyx_server_;
///
- boost::scoped_ptr<LyXServerSocket> lyx_socket_;
+ boost::scoped_ptr<ServerSocket> lyx_socket_;
///
boost::scoped_ptr<frontend::Application> application_;
/// lyx session, containing lastfiles, lastfilepos, and lastopened
// The system converters copy after reading lyxrc.defaults.
Converters system_converters_;
-
+
///
Movers movers_;
-
+
///
Movers system_movers_;
};
}
-LyXServer & LyX::server()
+Server & LyX::server()
{
BOOST_ASSERT(pimpl_->lyx_server_.get());
- return *pimpl_->lyx_server_.get();
+ return *pimpl_->lyx_server_.get();
}
-LyXServer const & LyX::server() const
+Server const & LyX::server() const
{
BOOST_ASSERT(pimpl_->lyx_server_.get());
- return *pimpl_->lyx_server_.get();
+ return *pimpl_->lyx_server_.get();
}
-LyXServerSocket & LyX::socket()
+ServerSocket & LyX::socket()
{
BOOST_ASSERT(pimpl_->lyx_socket_.get());
return *pimpl_->lyx_socket_.get();
}
-LyXServerSocket const & LyX::socket() const
+ServerSocket const & LyX::socket() const
{
BOOST_ASSERT(pimpl_->lyx_socket_.get());
return *pimpl_->lyx_socket_.get();
}
-kb_keymap & LyX::topLevelKeymap()
+KeyMap & LyX::topLevelKeymap()
{
BOOST_ASSERT(pimpl_->toplevel_keymap_.get());
return *pimpl_->toplevel_keymap_.get();
}
-kb_keymap const & LyX::topLevelKeymap() const
+KeyMap const & LyX::topLevelKeymap() const
{
BOOST_ASSERT(pimpl_->toplevel_keymap_.get());
return *pimpl_->toplevel_keymap_.get();
if (it != pimpl_->messages_.end())
return it->second;
- std::pair<map<string, Messages>::iterator, bool> result =
+ std::pair<map<string, Messages>::iterator, bool> result =
pimpl_->messages_.insert(std::make_pair(language, Messages(language)));
BOOST_ASSERT(result.second);
}
-Buffer const * const LyX::updateInset(InsetBase const * inset) const
+Buffer const * LyX::updateInset(Inset const * inset) const
{
- if (!inset)
+ if (quitting || !inset)
return 0;
Buffer const * buffer_ptr = 0;
}
+void LyX::hideDialogs(std::string const & name, Inset * inset) const
+{
+ if (quitting || !use_gui)
+ return;
+
+ vector<int> const & view_ids = pimpl_->application_->gui().viewIds();
+ vector<int>::const_iterator it = view_ids.begin();
+ vector<int>::const_iterator const end = view_ids.end();
+ for (; it != end; ++it)
+ pimpl_->application_->gui().view(*it).getDialogs().
+ hide(name, inset);
+}
+
+
int LyX::exec(int & argc, char * argv[])
{
// Here we need to parse the command line. At least
// we need to parse for "-dbg" and "-help"
easyParse(argc, argv);
- try { support::init_package(to_utf8(from_local8bit(argv[0])),
- cl_system_support, cl_user_support,
- support::top_build_dir_is_one_level_up);
+ try {
+ support::init_package(to_utf8(from_local8bit(argv[0])),
+ cl_system_support, cl_user_support,
+ support::top_build_dir_is_one_level_up);
} catch (support::ExceptionMessage const & message) {
if (message.type_ == support::ErrorException) {
Alert::error(message.title_, message.details_);
}
}
+ // Reinit the messages machinery in case package() knows
+ // something interesting about the locale directory.
+ Messages::init();
+
if (!use_gui) {
// FIXME: create a ConsoleApplication
int exit_status = init(argc, argv);
}
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) {
+ for (BufferList::iterator I = begin; I != pimpl_->buffer_list_.end(); ++I) {
Buffer * buf = *I;
+ if (buf != buf->masterBuffer())
+ continue;
bool success = false;
buf->dispatch(batch_command, &success);
- final_success |= success;
+ final_success |= success;
}
prepareExit();
return !final_success;
}
- // Force adding of font path _before_ Application is initialized
- support::os::addFontResources();
-
// Let the frontend parse and remove all arguments that it knows
pimpl_->application_.reset(createApplication(argc, argv));
*/
// Note: socket callback must be registered after init(argc, argv)
// such that package().temp_dir() is properly initialized.
- pimpl_->lyx_server_.reset(new LyXServer(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
- pimpl_->lyx_socket_.reset(new LyXServerSocket(&pimpl_->lyxfunc_,
+ pimpl_->lyx_server_.reset(new Server(&pimpl_->lyxfunc_, lyxrc.lyxpipes));
+ pimpl_->lyx_socket_.reset(new ServerSocket(&pimpl_->lyxfunc_,
FileName(package().temp_dir().absFilename() + "/lyxsocket")));
// Start the real execution loop.
exit_status = pimpl_->application_->exec();
-
- prepareExit();
- // Restore original font resources after Application is destroyed.
- support::os::restoreFontResources();
+ prepareExit();
return exit_status;
}
void LyX::prepareExit()
{
+ // Clear the clipboard and selection stack:
+ cap::clearCutStack();
+ cap::clearSelection();
+
// Set a flag that we do quitting from the program,
// so no refreshes are necessary.
quitting = true;
}
+void LyX::addFileToLoad(FileName const & fname)
+{
+ vector<FileName>::const_iterator cit = std::find(
+ pimpl_->files_to_load_.begin(), pimpl_->files_to_load_.end(),
+ fname);
+
+ if (cit == pimpl_->files_to_load_.end())
+ pimpl_->files_to_load_.push_back(fname);
+}
+
+
void LyX::loadFiles()
{
vector<FileName>::const_iterator it = pimpl_->files_to_load_.begin();
// aknowledged.
restoreGuiSession();
+ // if reconfiguration is needed.
+ if (textclasslist.empty()) {
+ switch (Alert::prompt(
+ _("No textclass is found"),
+ _("LyX cannot continue because no textclass is found. "
+ "You can either reconfigure normally, or reconfigure using "
+ "default textclasses, or quit LyX."),
+ 0, 2,
+ _("&Reconfigure"),
+ _("&Use Default"),
+ _("&Exit LyX")))
+ {
+ case 0:
+ // regular reconfigure
+ pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE, ""));
+ break;
+ case 1:
+ // reconfigure --without-latex-config
+ pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_RECONFIGURE,
+ " --without-latex-config"));
+ break;
+ }
+ pimpl_->lyxfunc_.dispatch(FuncRequest(LFUN_LYX_QUIT));
+ return;
+ }
+
// Execute batch commands if available
if (batch_command.empty())
return;
{
LyXView * view = newLyXView();
+ // if there is no valid class list, do not load any file.
+ if (textclasslist.empty())
+ return;
+
// if some files were specified at command-line we assume that the
// user wants to edit *these* files and not to restore the session.
if (!pimpl_->files_to_load_.empty()) {
// clear this list to save a few bytes of RAM
pimpl_->files_to_load_.clear();
pimpl_->session_->lastOpened().clear();
- return;
- }
- if (!lyxrc.load_session)
- return;
+ } else if (lyxrc.load_session) {
+ vector<FileName> const & lastopened = pimpl_->session_->lastOpened().getfiles();
+ // do not add to the lastfile list since these files are restored from
+ // last session, and should be already there (regular files), or should
+ // not be added at all (help files).
+ for_each(lastopened.begin(), lastopened.end(),
+ bind(&LyXView::loadLyXFile, view, _1, false));
+
+ // clear this list to save a few bytes of RAM
+ pimpl_->session_->lastOpened().clear();
+ }
- vector<FileName> const & lastopened = pimpl_->session_->lastOpened().getfiles();
- // do not add to the lastfile list since these files are restored from
- // last session, and should be already there (regular files), or should
- // not be added at all (help files).
- for_each(lastopened.begin(), lastopened.end(),
- bind(&LyXView::loadLyXFile, view, _1, false));
+ BufferList::iterator I = pimpl_->buffer_list_.begin();
+ BufferList::iterator end = pimpl_->buffer_list_.end();
+ for (; I != end; ++I) {
+ Buffer * buf = *I;
+ if (buf != buf->masterBuffer())
+ continue;
+ updateLabels(*buf);
+ }
- // clear this list to save a few bytes of RAM
- pimpl_->session_->lastOpened().clear();
+ // FIXME: Switch to the last loaded Buffer. This must not be the first one
+ // because the Buffer won't be connected in this case. The correct solution
+ // would be to avoid the manual connection of the current Buffer in LyXView.
+ if (!pimpl_->buffer_list_.empty())
+ view->setBuffer(pimpl_->buffer_list_.last());
}
posy = convert<int>(val);
}
- if (!geometryArg.empty())
+ if (!geometryArg.empty())
{
width = 0;
height = 0;
lyxrc.sans_font_name = pimpl_->application_->sansFontName();
if (lyxrc.typewriter_font_name.empty())
- lyxrc.typewriter_font_name
+ lyxrc.typewriter_font_name
= pimpl_->application_->typewriterFontName();
}
LYXERR(Debug::INIT) << "Reading layouts..." << endl;
if (!LyXSetStyle())
return false;
+ //...and the modules
+ moduleList.load();
- if (use_gui) {
- // Set the language defined by the user.
- //setGuiLanguage(lyxrc.gui_language);
+ // read keymap and ui files in batch mode as well
+ // because InsetInfo needs to know these to produce
+ // the correct output
- // Set up bindings
- pimpl_->toplevel_keymap_.reset(new kb_keymap);
- defaultKeyBindings(pimpl_->toplevel_keymap_.get());
- pimpl_->toplevel_keymap_->read(lyxrc.bind_file);
+ // Set the language defined by the user.
+ //setGuiLanguage(lyxrc.gui_language);
- pimpl_->lyxfunc_.initKeySequences(pimpl_->toplevel_keymap_.get());
+ // Set up bindings
+ pimpl_->toplevel_keymap_.reset(new KeyMap);
+ defaultKeyBindings(pimpl_->toplevel_keymap_.get());
+ pimpl_->toplevel_keymap_->read(lyxrc.bind_file);
- // Read menus
- if (!readUIFile(lyxrc.ui_file))
- return false;
- }
+ pimpl_->lyxfunc_.initKeySequences(pimpl_->toplevel_keymap_.get());
+
+ // Read menus
+ if (!readUIFile(lyxrc.ui_file))
+ return false;
if (lyxerr.debugging(Debug::LYXRC))
lyxrc.print();
prependEnvPath("PATH", lyxrc.path_prefix);
FileName const document_path(lyxrc.document_path);
- if (fs::exists(document_path.toFilesystemEncoding()) &&
- fs::is_directory(document_path.toFilesystemEncoding()))
+ if (document_path.exists() && document_path.isDirectory())
package().document_dir() = document_path;
package().temp_dir() = createLyXTmpDir(FileName(lyxrc.tempdir_path));
}
LYXERR(Debug::INIT) << "LyX tmp dir: `"
- << package().temp_dir().absFilename()
- << '\'' << endl;
+ << package().temp_dir().absFilename()
+ << '\'' << endl;
LYXERR(Debug::INIT) << "Reading session information '.lyx/session'..." << endl;
pimpl_->session_.reset(new Session(lyxrc.num_lastfiles));
}
-void LyX::defaultKeyBindings(kb_keymap * kbmap)
+void LyX::defaultKeyBindings(KeyMap * kbmap)
{
kbmap->bind("Right", FuncRequest(LFUN_CHAR_FORWARD));
kbmap->bind("Left", FuncRequest(LFUN_CHAR_BACKWARD));
}
-void LyX::deadKeyBindings(kb_keymap * kbmap)
+void LyX::deadKeyBindings(KeyMap * kbmap)
{
// bindKeyings for transparent handling of deadkeys
// The keysyms are gotten from XFree86 X11R6
}
-namespace {
-
// return true if file does not exist or is older than configure.py.
-bool needsUpdate(string const & file)
+static bool needsUpdate(string const & file)
{
// We cannot initialize configure_script directly because the package
// is not initialized yet when static objects are constructed.
- static string configure_script;
+ static FileName configure_script;
static bool firstrun = true;
if (firstrun) {
- configure_script = FileName(addName(
- package().system_support().absFilename(),
- "configure.py")).toFilesystemEncoding();
+ configure_script =
+ FileName(addName(package().system_support().absFilename(),
+ "configure.py"));
firstrun = false;
}
- string const absfile = FileName(addName(
- package().user_support().absFilename(), file)).toFilesystemEncoding();
- return (! fs::exists(absfile))
- || (fs::last_write_time(configure_script)
- > fs::last_write_time(absfile));
-}
-
+ FileName absfile =
+ FileName(addName(package().user_support().absFilename(), file));
+ return !absfile.exists()
+ || configure_script.lastModified() > absfile.lastModified();
}
bool LyX::queryUserLyXDir(bool explicit_userdir)
{
// Does user directory exist?
- string const user_support =
- package().user_support().toFilesystemEncoding();
- if (fs::exists(user_support) && fs::is_directory(user_support)) {
+ FileName const sup = package().user_support();
+ if (sup.exists() && sup.isDirectory()) {
first_start = false;
return needsUpdate("lyxrc.defaults")
+ || needsUpdate("lyxmodules.lst")
|| needsUpdate("textclass.lst")
|| needsUpdate("packages.lst");
}
}
lyxerr << to_utf8(bformat(_("LyX: Creating directory %1$s"),
- from_utf8(package().user_support().absFilename())))
- << endl;
+ from_utf8(sup.absFilename()))) << endl;
- if (!createDirectory(package().user_support(), 0755)) {
+ if (!createDirectory(sup, 0755)) {
// Failed, so let's exit.
lyxerr << to_utf8(_("Failed to create directory. Exiting."))
<< endl;
LYXERR(Debug::INIT) << "About to read " << name << "..." << endl;
-
+
FileName ui_path;
if (include) {
ui_path = libFileSearch("ui", name, "inc");
}
else
ui_path = libFileSearch("ui", name, "ui");
-
+
if (ui_path.empty()) {
LYXERR(Debug::INIT) << "Could not find " << name << endl;
showFileError(name);
LYXERR(Debug::INIT) << "Found " << name
<< " in " << ui_path << endl;
- LyXLex lex(uitags, ui_last - 1);
+ Lexer lex(uitags, ui_last - 1);
lex.setFile(ui_path);
if (!lex.isOK()) {
lyxerr << "Unable to set LyXLeX for ui file: " << ui_path
// Read the encodings file `name'
bool LyX::readEncodingsFile(string const & enc_name,
- string const & symbols_name)
+ string const & symbols_name)
{
LYXERR(Debug::INIT) << "About to read " << enc_name << " and "
- << symbols_name << "..." << endl;
+ << symbols_name << "..." << endl;
FileName const symbols_path = libFileSearch(string(), symbols_name);
if (symbols_path.empty()) {
}
-LyXServer & theLyXServer()
+Server & theServer()
{
// FIXME: this should not be use_gui dependent
BOOST_ASSERT(use_gui);
}
-LyXServerSocket & theLyXServerSocket()
+ServerSocket & theServerSocket()
{
// FIXME: this should not be use_gui dependent
BOOST_ASSERT(use_gui);
}
-kb_keymap & theTopLevelKeymap()
+KeyMap & theTopLevelKeymap()
{
- BOOST_ASSERT(use_gui);
return LyX::ref().topLevelKeymap();
}