]> git.lyx.org Git - features.git/commitdiff
Change how InsetBibTeX does this check.
authorRichard Heck <rgheck@comcast.net>
Tue, 16 Oct 2007 18:53:10 +0000 (18:53 +0000)
committerRichard Heck <rgheck@comcast.net>
Tue, 16 Oct 2007 18:53:10 +0000 (18:53 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20996 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetBibtex.cpp
src/insets/InsetCommand.cpp
src/insets/InsetCommand.h
src/insets/InsetCommandParams.h

index 2d3e05f37379911430b9f4bac92ebf83970e25fd..7443cfc3d752372cd2ab9571b04dcc29066e6ddc 100644 (file)
@@ -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;
        }
 
index 542d99e28937451485dd8a13aa9462c5c214c074..477ebfcd4238a4dcce1f0dcb66415553c41c15c5 100644 (file)
@@ -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;
 }
 
 
index e9db7a1a3ee8e79f1a80b449b95aa1d0b35dc686..84eb0d87d82ef2ad4ef2e9fe0b2146ce43e12d2c 100644 (file)
@@ -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,
index f02d2a6ebd195a17bc8e9529e5c55da5b32910f0..00ff8965706d61cfe585faed23ff15f64d6a70f6 100644 (file)
@@ -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