#include "lyxfunc.h"
#include "lyxlex.h"
#include "lyxrc.h"
-#include "lyxtextclasslist.h"
#include "lyxserver.h"
+#include "lyxtextclasslist.h"
#include "MenuBackend.h"
#include "mover.h"
#include "ToolbarBackend.h"
#include "frontends/Alert.h"
-#include "frontends/lyx_gui.h"
+#include "frontends/Application.h"
#include "frontends/LyXView.h"
#include "support/environment.h"
#include "support/filetools.h"
+#include "support/fontutils.h"
#include "support/lyxlib.h"
#include "support/convert.h"
#include "support/os.h"
using lyx::docstring;
+namespace Alert = lyx::frontend::Alert;
namespace os = lyx::support::os;
namespace fs = boost::filesystem;
using std::endl;
using std::string;
using std::vector;
+using std::for_each;
#ifndef CXX_GLOBAL_CSTD
using std::exit;
#endif
-extern LyXServer * lyxserver;
+/// convenient to have it here.
+boost::scoped_ptr<kb_keymap> toplevel_keymap;
-// This is the global bufferlist object
-BufferList bufferlist;
+///
+lyx::frontend::Application * theApp;
-// convenient to have it here.
-boost::scoped_ptr<kb_keymap> toplevel_keymap;
+namespace lyx {
+
+/// 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;
+
+}
namespace {
// FIXME: We should not directly call exit(), since it only
// guarantees a return to the system, no application cleanup.
// This may cause troubles with not executed destructors.
- if (lyx_gui::use_gui)
- // lyx_gui::exit may return and only schedule the exit
- lyx_gui::exit(status);
+ if (lyx::use_gui) {
+ theApp->exit(status);
+ // Restore original font resources after Application is destroyed.
+ lyx::support::restoreFontResources();
+ }
+
exit(status);
}
}
+BufferList & theBufferList()
+{
+ return LyX::ref().bufferList();
+}
+
+
LyX::LyX()
: first_start(false), geometryOption_(false)
-{}
+{
+ buffer_list_.reset(new BufferList);
+}
+
+
+BufferList & LyX::bufferList()
+{
+ return *buffer_list_.get();
+}
+
+
+BufferList const & LyX::bufferList() const
+{
+ return *buffer_list_.get();
+}
lyx::Session & LyX::session()
{
// Here we need to parse the command line. At least
// we need to parse for "-dbg" and "-help"
- lyx_gui::use_gui = easyParse(argc, argv);
+ easyParse(argc, argv);
lyx::support::init_package(argv[0], cl_system_support, cl_user_support,
lyx::support::top_build_dir_is_one_level_up);
// Start the real execution loop.
- if (lyx_gui::use_gui)
- return lyx_gui::exec(argc, argv);
- else
- return exec2(argc, argv);
+ if (lyx::use_gui) {
+ // Force adding of font path _before_ Application is initialized
+ lyx::support::addFontResources();
+ application_.reset(lyx::createApplication(argc, argv));
+ theApp = application_.get();
+ }
+ else {
+ // FIXME: create a ConsoleApplication
+ theApp = 0;
+ }
+
+ int exit_status = exec2(argc, argv);
+
+ if (lyx::use_gui)
+ application_.reset();
+
+ return exit_status;
}
if (!success)
return EXIT_FAILURE;
- if (lyx_gui::use_gui)
- lyx_gui::parse_lyxrc();
-
vector<string> files;
for (int argi = argc - 1; argi >= 1; --argi)
if (b)
last_loaded = b;
} else {
- Buffer * buf = bufferlist.newBuffer(s, false);
+ Buffer * buf = theBufferList().newBuffer(s, false);
if (loadLyXFile(buf, s)) {
last_loaded = buf;
ErrorList const & el = buf->errorList("Parse");
boost::bind(&LyX::printError, this, _1));
}
else
- bufferlist.release(buf);
+ theBufferList().release(buf);
}
}
files.clear(); // the files are already loaded
}
- if (lyx_gui::use_gui) {
+ if (lyx::use_gui) {
// determine windows size and position, from lyxrc and/or session
// initial geometry
unsigned int width = 690;
height = 0;
}
// create the main window
- LyXView * view = lyx_gui::create_view(width, height, posx, posy, maximize);
+ LyXView * view = &application_->createView(width, height, posx, posy, maximize);
+ ref().addLyXView(view);
// load files
for_each(files.begin(), files.end(),
// clear this list to save a few bytes of RAM
session_->clearLastOpenedFiles();
- return lyx_gui::start(view, batch_command);
+ return application_->start(batch_command);
} else {
// Something went wrong above
quitLyX(false);
}
if (lyxrc.roman_font_name.empty())
- lyxrc.roman_font_name = lyx_gui::roman_font_name();
+ lyxrc.roman_font_name =
+ lyx::use_gui? application_->romanFontName(): "serif";
+
if (lyxrc.sans_font_name.empty())
- lyxrc.sans_font_name = lyx_gui::sans_font_name();
+ lyxrc.sans_font_name =
+ lyx::use_gui? application_->sansFontName(): "sans";
+
if (lyxrc.typewriter_font_name.empty())
- lyxrc.typewriter_font_name = lyx_gui::typewriter_font_name();
+ lyxrc.typewriter_font_name =
+ lyx::use_gui? application_->typewriterFontName(): "monospace";
//
// Read configuration files
reconfigureUserLyXDir();
// no need for a splash when there is no GUI
- if (!lyx_gui::use_gui) {
+ if (!lyx::use_gui) {
first_start = false;
}
if (!LyXSetStyle())
return false;
- if (lyx_gui::use_gui) {
+ if (lyx::use_gui) {
// Set up bindings
toplevel_keymap.reset(new kb_keymap);
defaultKeyBindings(toplevel_keymap.get());
// contain documents etc. which might be helpful on
// a crash
- bufferlist.emergencyWriteAll();
- if (lyxserver)
- lyxserver->emergencyCleanup();
+ theBufferList().emergencyWriteAll();
+ application_->server().emergencyCleanup();
}
namespace {
-bool is_gui = true;
string batch;
/// return the the number of arguments consumed
exit(1);
}
batch = "buffer-export " + type;
- is_gui = false;
+ lyx::use_gui = true;
return 1;
}
} // namespace anon
-bool LyX::easyParse(int & argc, char * argv[])
+void LyX::easyParse(int & argc, char * argv[])
{
std::map<string, cmd_helper> cmdmap;
}
batch_command = batch;
-
- return is_gui;
}