* messages.h:

- getMessages(), getGuiMessages(): new global function definitions

* lyx_main.C: implementation of getMessages() and getGuiMessages().

* LyX class:
  - getMessages(), getGuiMessages(), setGuiLanguage(): new interface for Messages access.

* LyX::Singletons class:
  - messages_: new container for Messages objects.

* Buffer::Impl::messages is now a pointer to the singleton defined in lyx_main.C.

* gettext.C: _() uses the global getGuiMessages() instead of the local static Messages object.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16673 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-01-14 10:37:14 +00:00
parent f55103109e
commit 197ca2420b
5 changed files with 71 additions and 18 deletions

View File

@ -178,7 +178,7 @@ public:
/// name of the file the buffer is associated with.
FileName filename;
boost::scoped_ptr<Messages> messages;
Messages * messages;
/** Set to true only when the file is fully loaded.
* Used to prevent the premature generation of previews
@ -200,7 +200,7 @@ public:
Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
: lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
filename(file), file_fully_loaded(false), inset(params),
toc_backend(&parent)
toc_backend(&parent), messages(0)
{
inset.setAutoBreakRows(true);
lyxvc.buffer(&parent);
@ -1393,7 +1393,7 @@ void Buffer::updateDocLang(Language const * nlang)
{
BOOST_ASSERT(nlang);
pimpl_->messages.reset(new Messages(nlang->code()));
pimpl_->messages = &getMessages(nlang->code());
}
@ -1466,7 +1466,7 @@ Language const * Buffer::getLanguage() const
docstring const Buffer::B_(string const & l10n) const
{
if (pimpl_->messages.get())
if (pimpl_->messages)
return pimpl_->messages->get(l10n);
return _(l10n);

View File

@ -29,21 +29,9 @@ using support::setEnv;
using std::string;
namespace {
static Messages & getLyXMessages()
{
static Messages lyx_messages;
return lyx_messages;
}
} // anon namespace
docstring const _(string const & str)
{
return getLyXMessages().get(str);
return getGuiMessages().get(str);
}

View File

@ -40,6 +40,7 @@
#include "lyxsocket.h"
#include "lyxtextclasslist.h"
#include "MenuBackend.h"
#include "messages.h"
#include "mover.h"
#include "ToolbarBackend.h"
@ -63,6 +64,8 @@
#include <iostream>
#include <csignal>
#include <map>
#include <string>
#include <vector>
@ -89,9 +92,11 @@ 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;
using std::for_each;
#ifndef CXX_GLOBAL_CSTD
using std::exit;
@ -166,6 +171,9 @@ struct LyX::Singletons
/// Files to load at start.
vector<FileName> files_to_load_;
///
map<string, Messages> messages_;
};
///
@ -306,6 +314,33 @@ kb_keymap const & LyX::topLevelKeymap() const
}
Messages & LyX::getMessages(std::string const & language)
{
map<string, Messages>::iterator it = pimpl_->messages_.find(language);
if (it != pimpl_->messages_.end())
return it->second;
std::pair<map<string, Messages>::iterator, bool> result =
pimpl_->messages_.insert(std::make_pair(language, Messages(language)));
BOOST_ASSERT(result.second);
return result.first->second;
}
Messages & LyX::getGuiMessages()
{
return pimpl_->messages_["GUI"];
}
void LyX::setGuiLanguage(std::string const & language)
{
pimpl_->messages_["GUI"] = Messages(language);
}
Buffer const * const LyX::updateInset(InsetBase const * inset) const
{
if (!inset)
@ -815,6 +850,9 @@ bool LyX::init()
return false;
if (use_gui) {
// Set the User Interface language.
pimpl_->messages_["GUI"] = Messages();
// Set up bindings
pimpl_->toplevel_keymap_.reset(new kb_keymap);
defaultKeyBindings(pimpl_->toplevel_keymap_.get());
@ -1402,4 +1440,16 @@ IconvProcessor & utf8ToUcs4()
return LyX::ref().iconvProcessor();
}
Messages & getMessages(std::string const & language)
{
return LyX::ref().getMessages(language);
}
Messages & getGuiMessages()
{
return LyX::ref().getGuiMessages();
}
} // namespace lyx

View File

@ -30,6 +30,7 @@ class LyXFunc;
class LyXServer;
class LyXServerSocket;
class LyXView;
class Messages;
class Session;
class kb_keymap;
@ -77,6 +78,13 @@ public:
kb_keymap & topLevelKeymap();
kb_keymap const & topLevelKeymap() const;
///
Messages & getMessages(std::string const & language);
///
Messages & getGuiMessages();
///
void setGuiLanguage(std::string const & language);
///
IconvProcessor & iconvProcessor();

View File

@ -37,6 +37,13 @@ private:
mutable TranslationCache cache_;
};
/// Access to the unique Messages object for the passed \p language.
/// Implementation is in lyx_main.C.
extern Messages & getMessages(std::string const & language);
/// Access to the unique Messages object used for GUI element.
/// Implementation is in lyx_main.C.
extern Messages & getGuiMessages();
} // namespace lyx
#endif