From 197ca2420b20d468fb2f4a5bd5b5ec69e15d8c6f Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Sun, 14 Jan 2007 10:37:14 +0000 Subject: [PATCH] * 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 --- src/buffer.C | 8 ++++---- src/gettext.C | 14 +------------- src/lyx_main.C | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- src/lyx_main.h | 8 ++++++++ src/messages.h | 7 +++++++ 5 files changed, 71 insertions(+), 18 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index 6e93b04bbc..1fe5db90ff 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -178,7 +178,7 @@ public: /// name of the file the buffer is associated with. FileName filename; - boost::scoped_ptr 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); diff --git a/src/gettext.C b/src/gettext.C index 55b2ef8082..46053cfc59 100644 --- a/src/gettext.C +++ b/src/gettext.C @@ -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); } diff --git a/src/lyx_main.C b/src/lyx_main.C index 56605bf9b0..edbbbcf511 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -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 #include +#include +#include #include @@ -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 files_to_load_; + + /// + map messages_; }; /// @@ -306,6 +314,33 @@ kb_keymap const & LyX::topLevelKeymap() const } +Messages & LyX::getMessages(std::string const & language) +{ + map::iterator it = pimpl_->messages_.find(language); + + if (it != pimpl_->messages_.end()) + return it->second; + + std::pair::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 diff --git a/src/lyx_main.h b/src/lyx_main.h index 9b228c6639..01357b8853 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -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(); diff --git a/src/messages.h b/src/messages.h index 93fc3d0c9b..166f4601d0 100644 --- a/src/messages.h +++ b/src/messages.h @@ -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