]> git.lyx.org Git - lyx.git/commitdiff
displayTranslator is now a function. No need to invoke setDisplayTranslator
authorAngus Leeming <leeming@lyx.org>
Mon, 13 Oct 2003 21:50:33 +0000 (21:50 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 13 Oct 2003 21:50:33 +0000 (21:50 +0000)
explicitly.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7915 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/graphics/ChangeLog
src/graphics/GraphicsTypes.C
src/graphics/GraphicsTypes.h
src/insets/ChangeLog
src/insets/insetexternal.C
src/insets/insetgraphicsParams.C
src/lyx_main.C
src/lyxrc.C

index f7f6e49167ca331e6812f6c5ae09038eebb2b78a..84025be0cf26540f12faffaababead9fe530c0ab 100644 (file)
@@ -1,3 +1,10 @@
+2003-10-13  Angus Leeming  <leeming@lyx.org>
+
+       * 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 <assirati@fma.if.usp.br>
 
        * lyxsocket.[Ch]: new files. A simple local socket interface for lyx.
index 271fb6661e5e9093388d8f622787155ce5e49e74..51c3cac5d1dd0e82c7a47cf4d9c762084e3c3fba 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-13  Angus Leeming  <leeming@lyx.org>
+
+       * GraphicsTypes.[Ch] (setDisplayTranslator): removed.
+       Make displayTranslator a function,
+
 2003-10-10  Angus Leeming  <leeming@lyx.org>
 
        * PreviewedInset.[Ch]: removed.
index 8ad4dab9fef26aa2e3d834d7143e4d65a7a89594..82ff4cd7f7fed103c8bfc87aee7de262bc7b3185 100644 (file)
@@ -11,8 +11,6 @@
 #include <config.h>
 
 #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<DisplayType, string> displayTranslator(DefaultDisplay, "default");
+Translator<DisplayType, string> const initTranslator()
+{
+       Translator<DisplayType, string> 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<DisplayType, string> 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<DisplayType, string> const translator =
+               initTranslator();
+       return translator;
 }
 
 } // namespace graphics
index 625e1c8555e0ed72488303b4c5a6e98568d66f87..1b34eabd77d535603e4aaa1cc4de85f8fe6aea5b 100644 (file)
@@ -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<DisplayType, std::string> const & displayTranslator();
 
 } // namespace graphics
 } // namespace lyx
index 37ffb5a2bb81a762f2ce67b1bb2d82d49a5b1e55..f283c448a5d5347559f097c8757a3b14b4bc7049 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-13  Angus Leeming  <leeming@lyx.org>
+
+       * insetexternal.C:
+       * insetgraphicsParams.C: displayTranslator is now a function.
+
 2003-10-13  Angus Leeming  <leeming@lyx.org>
 
        * insetinclude.C: remove #include "PreviewImage.h".
index 2fb0b6b2d44a482f5267ff06e6656edaa97f2a41..14b95c7fdee304bc7dceffb00d619bdb15cfc9fc 100644 (file)
@@ -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<DisplayType, string> 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;
                }
 
index 351d3f056844de17700f0e69f0dddec8a3cf2f12..a38cca4177e3a2c86812b4f27612c1e4aea4b0dc 100644 (file)
@@ -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<DisplayType, string> 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();
index e813c532e5c8f9a089f16a74fcaf5b674841a647..a96bf63db3efe4b8735fd53e63f777dfc933dc62 100644 (file)
@@ -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);
 
index 9995916fc401415aa52163d9becde132ebc543a0..911c2a80cf878afeab80e24367890281823e57a2 100644 (file)
@@ -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<DisplayType, string> 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';
                }