X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2Fxforms_helpers.C;h=50fb6409d4fb85485fd65cbb49a8008bd56552fa;hb=37e82a546392d43f787826b85481a11f2a27af15;hp=bfb9043cf338300e2e8c5e5014040c83a6dffcf6;hpb=4c16922aad0477028c3725e115f369cbe9f7718f;p=lyx.git diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index bfb9043cf3..50fb6409d4 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -5,33 +5,58 @@ * * \author Angus Leeming * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include #include "xforms_helpers.h" -#include "lyxlex.h" +#include "debug.h" #include "gettext.h" -#include "lyxlength.h" +#include "lengthcommon.h" #include "lyxgluelength.h" -#include "Lsstream.h" +#include "lyxlex.h" -#include "support/LAssert.h" #include "support/FileInfo.h" #include "support/filetools.h" #include "support/lstrings.h" // frontStrip, strip +#include "support/tostr.h" #include "lyx_forms.h" #include "combox.h" +#include + #include +using std::make_pair; + using std::ofstream; -using std::pair; using std::vector; -using std::make_pair; +using std::string; + +namespace lyx { + +using support::AbsolutePath; +using support::FileInfo; +using support::isStrDbl; +using support::OnlyPath; +using support::subst; +using support::trim; + +namespace frontend { + +std::string const buildChoiceLengthString() +{ + string data; + for (int i = 0; i != num_units; ++i) { + if (i != 0) + data += "|"; + data += subst(unit_name_gui[i], "%", "%%"); + } + return data; +} bool isActive(FL_OBJECT * ob) @@ -99,7 +124,7 @@ vector const getVector(FL_OBJECT * ob) } break; default: - lyx::Assert(0); + BOOST_ASSERT(false); } return vec; @@ -110,7 +135,7 @@ vector const getVector(FL_OBJECT * ob) string const getString(FL_OBJECT * ob, int line) { // Negative line value does not make sense. - lyx::Assert(line >= 0); + BOOST_ASSERT(line >= 0); char const * tmp = 0; switch (ob->objclass) { @@ -139,7 +164,7 @@ string const getString(FL_OBJECT * ob, int line) break; default: - lyx::Assert(0); + BOOST_ASSERT(false); } return tmp ? trim(tmp) : string(); @@ -148,7 +173,7 @@ string const getString(FL_OBJECT * ob, int line) string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice) { // Paranoia check - lyx::Assert(input && input->objclass == FL_INPUT && + BOOST_ASSERT(input && input->objclass == FL_INPUT && choice && choice->objclass == FL_CHOICE); string const length = trim(fl_get_input(input)); @@ -170,6 +195,10 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice, string const & str, string const & default_unit) { + // Paranoia check + BOOST_ASSERT(input && input->objclass == FL_INPUT && + choice && choice->objclass == FL_CHOICE); + // use input field only for gluelengths if (!isValidLength(str) && !isStrDbl(str)) { fl_set_input(input, str.c_str()); @@ -189,16 +218,14 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice, string const & default_unit) { // Paranoia check - lyx::Assert(input && input->objclass == FL_INPUT && - choice && choice->objclass == FL_CHOICE); + BOOST_ASSERT(input && input->objclass == FL_INPUT && + choice && choice->objclass == FL_CHOICE); if (len.empty()) { fl_set_input(input, ""); fl_set_choice_text(choice, default_unit.c_str()); } else { - ostringstream buffer; - buffer << len.value(); - fl_set_input(input, buffer.str().c_str()); + fl_set_input(input, tostr(len.value()).c_str()); // Set the choice to the desired unit, if present in the choice. // Else set the choice to the default unit. @@ -220,7 +247,8 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice, string formatted(string const & sin, int w, int size, int style) { string sout; - if (sin.empty()) return sout; + if (sin.empty()) + return sout; string::size_type curpos = 0; string line; @@ -308,9 +336,13 @@ const int xformCount = sizeof(xformTags) / sizeof(keyword_item); bool XformsColor::read(string const & filename) { + FileInfo const f(filename); LyXLex lexrc(xformTags, xformCount); - if (!lexrc.setFile(filename)) + if (f.readable() && !lexrc.setFile(filename)) { + lyxerr << "XformsColor::read(" << filename << ")\n" + << _("Failed to open file.") << std::endl; return false; + } while (lexrc.isOK()) { int const le = lexrc.lex(); @@ -351,8 +383,11 @@ bool XformsColor::read(string const & filename) bool XformsColor::write(string const & filename) { ofstream os(filename.c_str()); - if (!os) + if (!os) { + lyxerr << "XformsColor::write(" << filename << ")\n" + << _("Failed to open file.") << std::endl; return false; + } os << "###" << "### file " << filename << "\n\n" @@ -525,3 +560,6 @@ bool RWInfo::ReadableFile(string const & name) return true; } + +} // namespace frontend +} // namespace lyx