mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 05:01:49 +00:00
* lyx_main.[Ch]
- merge exec() and priv_exec() - LyX constructor is now public. - there is no global singleton_ object anymore, only a pointer. - IconvProcessor(): new utf8 to ucs4 convertor. * main.C: instantiate a LyX object and exec() it. No more use of static methods. * docstring.C: use utf8ToUcs4() instead of a static variable. * unicode.h: declare extern utf8ToUcs4(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15967 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
eea50a7542
commit
7aa50e8f2b
@ -57,6 +57,7 @@
|
||||
#include "support/package.h"
|
||||
#include "support/path.h"
|
||||
#include "support/systemcall.h"
|
||||
#include "support/unicode.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
@ -114,6 +115,7 @@ namespace {
|
||||
string cl_system_support;
|
||||
string cl_user_support;
|
||||
|
||||
LyX * singleton_ = 0;
|
||||
|
||||
void showFileError(string const & error)
|
||||
{
|
||||
@ -140,6 +142,9 @@ void reconfigureUserLyXDir()
|
||||
/// The main application class private implementation.
|
||||
struct LyX::Singletons
|
||||
{
|
||||
Singletons(): iconv(ucs4_codeset, "UTF-8")
|
||||
{
|
||||
}
|
||||
/// our function handler
|
||||
LyXFunc lyxfunc_;
|
||||
///
|
||||
@ -154,11 +159,12 @@ struct LyX::Singletons
|
||||
boost::scoped_ptr<frontend::Application> application_;
|
||||
/// lyx session, containing lastfiles, lastfilepos, and lastopened
|
||||
boost::scoped_ptr<Session> session_;
|
||||
|
||||
///
|
||||
IconvProcessor iconv;
|
||||
};
|
||||
|
||||
|
||||
boost::scoped_ptr<LyX> LyX::singleton_;
|
||||
|
||||
LyX::~LyX()
|
||||
{
|
||||
// Static data are not treated in the same way at all on the Mac (and
|
||||
@ -171,35 +177,24 @@ LyX::~LyX()
|
||||
}
|
||||
|
||||
|
||||
int LyX::exec(int & argc, char * argv[])
|
||||
{
|
||||
BOOST_ASSERT(!singleton_.get());
|
||||
// We must return from this before launching the gui so that
|
||||
// other parts of the code can access singleton_ through
|
||||
// LyX::ref and LyX::cref.
|
||||
singleton_.reset(new LyX);
|
||||
// Start the real execution loop.
|
||||
return singleton_->priv_exec(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
LyX & LyX::ref()
|
||||
{
|
||||
BOOST_ASSERT(singleton_.get());
|
||||
return *singleton_.get();
|
||||
BOOST_ASSERT(singleton_);
|
||||
return *singleton_;
|
||||
}
|
||||
|
||||
|
||||
LyX const & LyX::cref()
|
||||
{
|
||||
BOOST_ASSERT(singleton_.get());
|
||||
return *singleton_.get();
|
||||
BOOST_ASSERT(singleton_);
|
||||
return *singleton_;
|
||||
}
|
||||
|
||||
|
||||
LyX::LyX()
|
||||
: first_start(false), geometryOption_(false)
|
||||
{
|
||||
singleton_ = this;
|
||||
pimpl_.reset(new Singletons);
|
||||
}
|
||||
|
||||
@ -291,6 +286,12 @@ kb_keymap & LyX::topLevelKeymap()
|
||||
}
|
||||
|
||||
|
||||
IconvProcessor & LyX::iconvProcessor()
|
||||
{
|
||||
return pimpl_->iconv;
|
||||
}
|
||||
|
||||
|
||||
kb_keymap const & LyX::topLevelKeymap() const
|
||||
{
|
||||
BOOST_ASSERT(pimpl_->toplevel_keymap_.get());
|
||||
@ -317,7 +318,7 @@ Buffer const * const LyX::updateInset(InsetBase const * inset) const
|
||||
}
|
||||
|
||||
|
||||
int LyX::priv_exec(int & argc, char * argv[])
|
||||
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"
|
||||
@ -387,12 +388,9 @@ void LyX::prepareExit()
|
||||
lyxerr[Debug::INFO] << "Deleting tmp dir " << package().temp_dir() << endl;
|
||||
|
||||
if (!destroyDir(package().temp_dir())) {
|
||||
// FIXME UNICODE: package().temp_dir() could in theory contain utf8 characters.
|
||||
// We cannot use from_utf8() here because this involves the use of static data
|
||||
// that may have been destroyed already on Mac systems.
|
||||
docstring const msg =
|
||||
bformat(_("Unable to remove the temporary directory %1$s"),
|
||||
from_ascii(package().temp_dir()));
|
||||
from_utf8(package().temp_dir()));
|
||||
Alert::warning(_("Unable to remove temporary directory"), msg);
|
||||
}
|
||||
}
|
||||
@ -1325,4 +1323,10 @@ kb_keymap & theTopLevelKeymap()
|
||||
return LyX::ref().topLevelKeymap();
|
||||
}
|
||||
|
||||
|
||||
IconvProcessor & utf8ToUcs4()
|
||||
{
|
||||
return LyX::ref().iconvProcessor();
|
||||
}
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -25,6 +25,7 @@ namespace lyx {
|
||||
class Buffer;
|
||||
class BufferList;
|
||||
class ErrorItem;
|
||||
class IconvProcessor;
|
||||
class InsetBase;
|
||||
class LyXFunc;
|
||||
class LyXServer;
|
||||
@ -41,6 +42,7 @@ namespace frontend { class Application; }
|
||||
class LyX : boost::noncopyable {
|
||||
public:
|
||||
|
||||
LyX();
|
||||
~LyX();
|
||||
|
||||
/**
|
||||
@ -48,16 +50,14 @@ public:
|
||||
* -# LyX::exec()
|
||||
* -# LyX::priv_exec()
|
||||
* -# lyx::createApplication()
|
||||
* -# LyX::exec2()
|
||||
* Step 3 is omitted if no gui is wanted. We need lyx::createApplication()
|
||||
* only to create the QApplication object in the qt frontend. All
|
||||
* attempts with static and dynamically allocated QApplication
|
||||
* objects lead either to harmless error messages on exit
|
||||
* ("Mutex destroy failure") or crashes (OS X).
|
||||
*/
|
||||
static int exec(int & argc, char * argv[]);
|
||||
/// Execute LyX (inner execution loop, \sa exec)
|
||||
int exec2(int & argc, char * argv[]);
|
||||
int exec(int & argc, char * argv[]);
|
||||
|
||||
static LyX & ref();
|
||||
static LyX const & cref();
|
||||
|
||||
@ -95,6 +95,9 @@ public:
|
||||
kb_keymap & topLevelKeymap();
|
||||
kb_keymap const & topLevelKeymap() const;
|
||||
|
||||
///
|
||||
IconvProcessor & iconvProcessor();
|
||||
|
||||
LyXView * newLyXView();
|
||||
|
||||
/** redraw \c inset in all the BufferViews in which it is currently
|
||||
@ -103,11 +106,6 @@ public:
|
||||
Buffer const * const updateInset(InsetBase const *) const;
|
||||
|
||||
private:
|
||||
static boost::scoped_ptr<LyX> singleton_;
|
||||
|
||||
LyX();
|
||||
int priv_exec(int & argc, char * argv[]);
|
||||
|
||||
/// Do some cleanup in preparation of an exit.
|
||||
void prepareExit();
|
||||
|
||||
|
@ -43,5 +43,7 @@ int main(int argc, char * argv[])
|
||||
// initialize for internationalized version *EK*
|
||||
lyx::locale_init();
|
||||
|
||||
return lyx::LyX::exec(argc, argv);
|
||||
lyx::LyX the_lyx_instance;
|
||||
|
||||
return the_lyx_instance.exec(argc, argv);
|
||||
}
|
||||
|
@ -57,14 +57,6 @@ std::string const to_ascii(docstring const & ucs4)
|
||||
|
||||
void utf8_to_ucs4(std::string const & utf8, docstring & ucs4)
|
||||
{
|
||||
// FIXME (Abdel 17/11/06): static data are evil!
|
||||
// This function cannot be used in the final exit process on Mac because
|
||||
// static data are already destroyed at this stage.
|
||||
// One solution would be to instantiate the utf8 to ucs4 IconvProcessor as a
|
||||
// singleton inside the LyX main class to ensure that it does not get
|
||||
// destroyed too early.
|
||||
static IconvProcessor iconv(ucs4_codeset, "UTF-8");
|
||||
|
||||
size_t n = utf8.size();
|
||||
// as utf8 is a multi-byte encoding, there would be at most
|
||||
// n characters:
|
||||
@ -76,7 +68,7 @@ void utf8_to_ucs4(std::string const & utf8, docstring & ucs4)
|
||||
// basic_string::data() is not recognized by some old gcc version
|
||||
// so we use &(ucs4[0]) instead.
|
||||
char * outbuf = (char *)(&(ucs4[0]));
|
||||
int bytes = iconv.convert(utf8.c_str(), n, outbuf, maxoutsize);
|
||||
int bytes = utf8ToUcs4().convert(utf8.c_str(), n, outbuf, maxoutsize);
|
||||
|
||||
// adjust to the real converted size
|
||||
ucs4.resize(bytes/4);
|
||||
|
@ -56,7 +56,7 @@ private:
|
||||
boost::scoped_ptr<Private> pimpl_;
|
||||
};
|
||||
|
||||
// utf8_to_ucs4
|
||||
extern IconvProcessor & utf8ToUcs4();
|
||||
|
||||
// A single codepoint conversion for utf8_to_ucs4 does not make
|
||||
// sense, so that function is left out.
|
||||
|
Loading…
Reference in New Issue
Block a user