From: Richard Heck Date: Tue, 16 Oct 2007 18:53:10 +0000 (+0000) Subject: Change how InsetBibTeX does this check. X-Git-Tag: 1.6.10~7820 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=26fd6a1420f28cc9b46283f4a08fb91caa628eb4;p=features.git Change how InsetBibTeX does this check. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20996 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 2d3e05f373..7443cfc3d7 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -26,6 +26,7 @@ #include "frontends/alert.h" +#include "support/ExceptionMessage.h" #include "support/filetools.h" #include "support/lstrings.h" #include "support/lyxlib.h" @@ -90,12 +91,22 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_MODIFY: { InsetCommandParams p("bibtex"); - InsetCommandMailer::string2params("bibtex", to_utf8(cmd.argument()), p); - if (!p.getCmdName().empty()) { - setParams(p); - cur.buffer().updateBibfilesCache(); - } else - cur.noUpdate(); + try { + if (!InsetCommandMailer::string2params("bibtex", + to_utf8(cmd.argument()), p)) { + cur.noUpdate(); + break; + } + } catch (support::ExceptionMessage const & message) { + if (message.type_ == support::WarningException) { + Alert::warning(message.title_, message.details_); + cur.noUpdate(); + } else + throw message; + break; + } + setParams(p); + cur.buffer().updateBibfilesCache(); break; } diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index 542d99e289..477ebfcd42 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -187,12 +187,12 @@ string const InsetCommandMailer::inset2string(Buffer const &) const } -void InsetCommandMailer::string2params( +bool InsetCommandMailer::string2params( string const & name, string const & in, InsetCommandParams & params) { params.clear(); if (in.empty()) - return; + return false; istringstream data(in); Lexer lex(0,0); @@ -200,17 +200,22 @@ void InsetCommandMailer::string2params( string n; lex >> n; - if (!lex || n != name) - return print_mailer_error("InsetCommandMailer", in, 1, name); + if (!lex || n != name) { + print_mailer_error("InsetCommandMailer", in, 1, name); + return false; + } // This is part of the inset proper that is usually swallowed // by Text::readInset string id; lex >> id; - if (!lex || id != "CommandInset") - return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand"); + if (!lex || id != "CommandInset") { + print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand"); + return false; + } params.read(lex); + return true; } diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index e9db7a1a3e..84eb0d87d8 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -136,8 +136,8 @@ public: virtual std::string const & name() const { return name_; } /// virtual std::string const inset2string(Buffer const &) const; - /// - static void string2params(std::string const &, std::string const & name, + /// returns true if params are successfully read + static bool string2params(std::string const &, std::string const & name, InsetCommandParams &); /// static std::string const params2string(std::string const & name, diff --git a/src/insets/InsetCommandParams.h b/src/insets/InsetCommandParams.h index f02d2a6ebd..00ff896570 100644 --- a/src/insets/InsetCommandParams.h +++ b/src/insets/InsetCommandParams.h @@ -33,7 +33,7 @@ public: explicit InsetCommandParams(std::string const & insetType, std::string const & cmdName); /// - std::string insetType() { return insetType_; } + std::string insetType() const { return insetType_; } /// void read(Lexer &); /// Parse the command