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
This commit is contained in:
Angus Leeming 2003-10-13 21:50:33 +00:00
parent 9a01e253a1
commit e9e4ffb1d1
9 changed files with 47 additions and 58 deletions

View 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> 2003-10-13 Joao Luis Meloni Assirati <assirati@fma.if.usp.br>
* lyxsocket.[Ch]: new files. A simple local socket interface for lyx. * lyxsocket.[Ch]: new files. A simple local socket interface for lyx.

View 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> 2003-10-10 Angus Leeming <leeming@lyx.org>
* PreviewedInset.[Ch]: removed. * PreviewedInset.[Ch]: removed.

View File

@ -11,8 +11,6 @@
#include <config.h> #include <config.h>
#include "graphics/GraphicsTypes.h" #include "graphics/GraphicsTypes.h"
#include "support/translator.h"
using std::string; using std::string;
@ -20,29 +18,29 @@ using std::string;
namespace lyx { namespace lyx {
namespace graphics { namespace graphics {
namespace {
/// The translator between the Display enum and corresponding lyx string. /// The translator between the Display enum and corresponding lyx string.
Translator<DisplayType, string> displayTranslator(DefaultDisplay, "default"); Translator<DisplayType, string> const initTranslator()
void setDisplayTranslator()
{ {
/// This variable keeps a tab on whether the translator is set. Translator<DisplayType, string> translator(DefaultDisplay, "default");
static bool done = false;
if (!done) {
done = true;
// Fill the display translator // Fill the display translator
displayTranslator.addPair(DefaultDisplay, "default"); translator.addPair(MonochromeDisplay, "monochrome");
displayTranslator.addPair(MonochromeDisplay, "monochrome"); translator.addPair(GrayscaleDisplay, "grayscale");
displayTranslator.addPair(GrayscaleDisplay, "grayscale"); translator.addPair(ColorDisplay, "color");
displayTranslator.addPair(ColorDisplay, "color"); translator.addPair(NoDisplay, "none");
displayTranslator.addPair(NoDisplay, "none");
// backward compatibility for old lyxrc.display_graphics return translator;
displayTranslator.addPair(MonochromeDisplay, "mono");
displayTranslator.addPair(GrayscaleDisplay, "gray");
displayTranslator.addPair(NoDisplay, "no");
} }
} // namespace anon
Translator<DisplayType, string> const & displayTranslator()
{
static Translator<DisplayType, string> const translator =
initTranslator();
return translator;
} }
} // namespace graphics } // namespace graphics

View File

@ -15,6 +15,8 @@
#ifndef GRAPHICSTYPES_H #ifndef GRAPHICSTYPES_H
#define GRAPHICSTYPES_H #define GRAPHICSTYPES_H
#include "support/translator.h"
namespace lyx { namespace lyx {
namespace graphics { namespace graphics {
@ -62,8 +64,8 @@ enum DisplayType {
}; };
/// /// The translator between the Display enum and corresponding lyx string.
void setDisplayTranslator(); Translator<DisplayType, std::string> const & displayTranslator();
} // namespace graphics } // namespace graphics
} // namespace lyx } // namespace lyx

View 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> 2003-10-13 Angus Leeming <leeming@lyx.org>
* insetinclude.C: remove #include "PreviewImage.h". * insetinclude.C: remove #include "PreviewImage.h".

View File

@ -51,16 +51,6 @@ using std::ostringstream;
using std::vector; 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 { namespace {
lyx::graphics::DisplayType const defaultDisplayType = lyx::graphics::NoDisplay; lyx::graphics::DisplayType const defaultDisplayType = lyx::graphics::NoDisplay;
@ -164,7 +154,7 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
if (display != defaultDisplayType) if (display != defaultDisplayType)
os << "\tdisplay " os << "\tdisplay "
<< lyx::graphics::displayTranslator.find(display) << lyx::graphics::displayTranslator().find(display)
<< '\n'; << '\n';
if (lyxscale != defaultLyxScale) if (lyxscale != defaultLyxScale)
@ -269,7 +259,7 @@ bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
case EX_DISPLAY: { case EX_DISPLAY: {
lex.next(); lex.next();
string const name = lex.getString(); string const name = lex.getString();
display = lyx::graphics::displayTranslator.find(name); display = lyx::graphics::displayTranslator().find(name);
break; break;
} }

View File

@ -35,14 +35,6 @@ using std::string;
using std::ostream; using std::ostream;
namespace lyx {
namespace graphics {
/// The translator between the DisplayType and the corresponding lyx string.
extern Translator<DisplayType, string> displayTranslator;
}
}
InsetGraphicsParams::InsetGraphicsParams() InsetGraphicsParams::InsetGraphicsParams()
{ {
init(); init();
@ -161,7 +153,7 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
if (lyxscale != 100) if (lyxscale != 100)
os << "\tlyxscale " << lyxscale << '\n'; os << "\tlyxscale " << lyxscale << '\n';
if (display != lyx::graphics::DefaultDisplay) 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, 0.0, 0.05)) {
if (!float_equal(scale, 100.0, 0.05)) if (!float_equal(scale, 100.0, 0.05))
os << "\tscale " << scale << '\n'; os << "\tscale " << scale << '\n';
@ -208,7 +200,7 @@ bool InsetGraphicsParams::Read(LyXLex & lex, string const & token, string const
} else if (token == "display") { } else if (token == "display") {
lex.next(); lex.next();
string const type = lex.getString(); string const type = lex.getString();
display = lyx::graphics::displayTranslator.find(type); display = lyx::graphics::displayTranslator().find(type);
} else if (token == "scale") { } else if (token == "scale") {
lex.next(); lex.next();
scale = lex.getFloat(); scale = lex.getFloat();

View File

@ -113,11 +113,6 @@ LyX::LyX(int & argc, char * argv[])
// we need to parse for "-dbg" and "-help" // we need to parse for "-dbg" and "-help"
bool const want_gui = easyParse(argc, argv); 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) if (want_gui)
lyx_gui::parse_init(argc, argv); lyx_gui::parse_init(argc, argv);

View File

@ -29,6 +29,8 @@
#include "lyxlex.h" #include "lyxlex.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "graphics/GraphicsTypes.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/translator.h" #include "support/translator.h"
@ -50,13 +52,6 @@ using std::ostream;
using std::string; using std::string;
namespace lyx {
namespace graphics {
/// The translator between the DisplayType and the corresponding lyx string.
extern Translator<DisplayType, string> displayTranslator;
}
}
namespace { namespace {
// when adding something to this array keep it sorted! // when adding something to this array keep it sorted!
@ -357,7 +352,7 @@ int LyXRC::read(string const & filename)
case RC_DISPLAY_GRAPHICS: case RC_DISPLAY_GRAPHICS:
if (lexrc.next()) { if (lexrc.next()) {
display_graphics = lyx::graphics::displayTranslator.find(lexrc.getString()); display_graphics = lyx::graphics::displayTranslator().find(lexrc.getString());
} }
break; break;
@ -1134,7 +1129,7 @@ void LyXRC::output(ostream & os) const
os << "# Display graphics within LyX\n" os << "# Display graphics within LyX\n"
<< "# monochrome|grayscale|color|none\n" << "# monochrome|grayscale|color|none\n"
<< "\\display_graphics " << "\\display_graphics "
<< lyx::graphics::displayTranslator.find(display_graphics) << lyx::graphics::displayTranslator().find(display_graphics)
<< '\n'; << '\n';
} }