From: Angus Leeming Date: Mon, 13 Oct 2003 21:50:33 +0000 (+0000) Subject: displayTranslator is now a function. No need to invoke setDisplayTranslator X-Git-Tag: 1.6.10~15951 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e9e4ffb1d1f7d1e8cb61f5a2cebbcc1b672aa197;p=lyx.git displayTranslator is now a function. No need to invoke setDisplayTranslator explicitly. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7915 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index f7f6e49167..84025be0cf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2003-10-13 Angus Leeming + + * lyx_main.C (LyX): remove call to setDisplayTranslator(). + + * lyxrc.C: displayTranslator is now a function, + declared in GraphicsTypes.h. + 2003-10-13 Joao Luis Meloni Assirati * lyxsocket.[Ch]: new files. A simple local socket interface for lyx. diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 271fb6661e..51c3cac5d1 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,8 @@ +2003-10-13 Angus Leeming + + * GraphicsTypes.[Ch] (setDisplayTranslator): removed. + Make displayTranslator a function, + 2003-10-10 Angus Leeming * PreviewedInset.[Ch]: removed. diff --git a/src/graphics/GraphicsTypes.C b/src/graphics/GraphicsTypes.C index 8ad4dab9fe..82ff4cd7f7 100644 --- a/src/graphics/GraphicsTypes.C +++ b/src/graphics/GraphicsTypes.C @@ -11,8 +11,6 @@ #include #include "graphics/GraphicsTypes.h" -#include "support/translator.h" - using std::string; @@ -20,29 +18,29 @@ using std::string; namespace lyx { namespace graphics { +namespace { + /// The translator between the Display enum and corresponding lyx string. -Translator displayTranslator(DefaultDisplay, "default"); +Translator const initTranslator() +{ + Translator translator(DefaultDisplay, "default"); + + // Fill the display translator + translator.addPair(MonochromeDisplay, "monochrome"); + translator.addPair(GrayscaleDisplay, "grayscale"); + translator.addPair(ColorDisplay, "color"); + translator.addPair(NoDisplay, "none"); + + return translator; +} + +} // namespace anon -void setDisplayTranslator() +Translator const & displayTranslator() { - /// This variable keeps a tab on whether the translator is set. - static bool done = false; - - if (!done) { - done = true; - - // Fill the display translator - displayTranslator.addPair(DefaultDisplay, "default"); - displayTranslator.addPair(MonochromeDisplay, "monochrome"); - displayTranslator.addPair(GrayscaleDisplay, "grayscale"); - displayTranslator.addPair(ColorDisplay, "color"); - displayTranslator.addPair(NoDisplay, "none"); - - // backward compatibility for old lyxrc.display_graphics - displayTranslator.addPair(MonochromeDisplay, "mono"); - displayTranslator.addPair(GrayscaleDisplay, "gray"); - displayTranslator.addPair(NoDisplay, "no"); - } + static Translator const translator = + initTranslator(); + return translator; } } // namespace graphics diff --git a/src/graphics/GraphicsTypes.h b/src/graphics/GraphicsTypes.h index 625e1c8555..1b34eabd77 100644 --- a/src/graphics/GraphicsTypes.h +++ b/src/graphics/GraphicsTypes.h @@ -15,6 +15,8 @@ #ifndef GRAPHICSTYPES_H #define GRAPHICSTYPES_H +#include "support/translator.h" + namespace lyx { namespace graphics { @@ -62,8 +64,8 @@ enum DisplayType { }; -/// -void setDisplayTranslator(); +/// The translator between the Display enum and corresponding lyx string. +Translator const & displayTranslator(); } // namespace graphics } // namespace lyx diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 37ffb5a2bb..f283c448a5 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2003-10-13 Angus Leeming + + * insetexternal.C: + * insetgraphicsParams.C: displayTranslator is now a function. + 2003-10-13 Angus Leeming * insetinclude.C: remove #include "PreviewImage.h". diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 2fb0b6b2d4..14b95c7fde 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -51,16 +51,6 @@ using std::ostringstream; using std::vector; -namespace lyx { -namespace graphics { - -/// The translator between the DisplayType and the corresponding lyx string. -extern Translator displayTranslator; - -} // namespace graphics -} // namespace lyx - - namespace { lyx::graphics::DisplayType const defaultDisplayType = lyx::graphics::NoDisplay; @@ -164,7 +154,7 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const if (display != defaultDisplayType) os << "\tdisplay " - << lyx::graphics::displayTranslator.find(display) + << lyx::graphics::displayTranslator().find(display) << '\n'; if (lyxscale != defaultLyxScale) @@ -269,7 +259,7 @@ bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex) case EX_DISPLAY: { lex.next(); string const name = lex.getString(); - display = lyx::graphics::displayTranslator.find(name); + display = lyx::graphics::displayTranslator().find(name); break; } diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index 351d3f0568..a38cca4177 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -35,14 +35,6 @@ using std::string; using std::ostream; -namespace lyx { -namespace graphics { -/// The translator between the DisplayType and the corresponding lyx string. -extern Translator displayTranslator; -} -} - - InsetGraphicsParams::InsetGraphicsParams() { init(); @@ -161,7 +153,7 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const if (lyxscale != 100) os << "\tlyxscale " << lyxscale << '\n'; if (display != lyx::graphics::DefaultDisplay) - os << "\tdisplay " << lyx::graphics::displayTranslator.find(display) << '\n'; + os << "\tdisplay " << lyx::graphics::displayTranslator().find(display) << '\n'; if (!float_equal(scale, 0.0, 0.05)) { if (!float_equal(scale, 100.0, 0.05)) os << "\tscale " << scale << '\n'; @@ -208,7 +200,7 @@ bool InsetGraphicsParams::Read(LyXLex & lex, string const & token, string const } else if (token == "display") { lex.next(); string const type = lex.getString(); - display = lyx::graphics::displayTranslator.find(type); + display = lyx::graphics::displayTranslator().find(type); } else if (token == "scale") { lex.next(); scale = lex.getFloat(); diff --git a/src/lyx_main.C b/src/lyx_main.C index e813c532e5..a96bf63db3 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -113,11 +113,6 @@ LyX::LyX(int & argc, char * argv[]) // we need to parse for "-dbg" and "-help" bool const want_gui = easyParse(argc, argv); - // set the DisplayTranslator only once; should that be done here?? - // if this should not be in this file, please also remove - // #include "graphics/GraphicsTypes.h" at the top -- Rob Lahaye. - lyx::graphics::setDisplayTranslator(); - if (want_gui) lyx_gui::parse_init(argc, argv); diff --git a/src/lyxrc.C b/src/lyxrc.C index 9995916fc4..911c2a80cf 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -29,6 +29,8 @@ #include "lyxlex.h" #include "lyxfont.h" +#include "graphics/GraphicsTypes.h" + #include "support/filetools.h" #include "support/lstrings.h" #include "support/translator.h" @@ -50,13 +52,6 @@ using std::ostream; using std::string; -namespace lyx { -namespace graphics { -/// The translator between the DisplayType and the corresponding lyx string. -extern Translator displayTranslator; -} -} - namespace { // when adding something to this array keep it sorted! @@ -357,7 +352,7 @@ int LyXRC::read(string const & filename) case RC_DISPLAY_GRAPHICS: if (lexrc.next()) { - display_graphics = lyx::graphics::displayTranslator.find(lexrc.getString()); + display_graphics = lyx::graphics::displayTranslator().find(lexrc.getString()); } break; @@ -1134,7 +1129,7 @@ void LyXRC::output(ostream & os) const os << "# Display graphics within LyX\n" << "# monochrome|grayscale|color|none\n" << "\\display_graphics " - << lyx::graphics::displayTranslator.find(display_graphics) + << lyx::graphics::displayTranslator().find(display_graphics) << '\n'; }