Hi,

With this patch an error dialog will be shown to the user if the inset parameters were wrong upon creation. This patch uses exceptions.

NOTE: I didn't re-indent the code in factory on purpose so that the patch remains understandable and minimal. I will do so in the final commit.

Comments?
Abdel.
Index: factory.C
===================================================================
--- factory.C   (revision 17825)
+++ factory.C   (working copy)
@@ -57,7 +57,10 @@
 #include "mathed/MathMacroTemplate.h"
 #include "mathed/InsetMathHull.h"
 
+#include "frontends/Alert.h"
+
 #include "support/lstrings.h"
+#include "support/ExceptionMessage.h"
 
 #include <boost/assert.hpp>
 #include <boost/current_function.hpp>
@@ -67,6 +70,8 @@
 
 namespace lyx {
 
+namespace Alert = frontend::Alert;
+
 using support::compare_ascii_no_case;
 
 using std::auto_ptr;
@@ -78,6 +83,8 @@
 {
        BufferParams const & params = bv->buffer()->params();
 
+       try {
+
        switch (cmd.action) {
        case LFUN_HFILL_INSERT:
                return new InsetHFill;
@@ -349,6 +356,17 @@
                break;
        }
 
+       } catch (support::ExceptionMessage const & message) {
+               if (message.type_ == support::ErrorException) {
+                       Alert::error(message.title_, message.details_);
+                       exit(1);
+               } else if (message.type_ == support::WarningException) {
+                       Alert::warning(message.title_, message.details_);
+                       return 0;
+               }
+       }
+
+
        return 0;
 }
 
Index: insets/insetcommandparams.C
===================================================================
--- insets/insetcommandparams.C (revision 17825)
+++ insets/insetcommandparams.C (working copy)
@@ -14,8 +14,10 @@
 #include "insetcommandparams.h"
 
 #include "debug.h"
+#include "gettext.h"
 #include "lyxlex.h"
 
+#include "support/ExceptionMessage.h"
 #include "support/lstrings.h"
 
 #include <boost/assert.hpp>
@@ -29,6 +31,8 @@
 using std::endl;
 using std::ostream;
 
+using support::ExceptionMessage;
+using support::WarningException;
 
 InsetCommandParams::InsetCommandParams(string const & name)
        : name_(name), preview_(false)
@@ -258,8 +262,12 @@
                lex.next();
                name_ = lex.getString();
                info_ = findInfo(name_);
-               if (!info_)
+               if (!info_) {
                        lex.printError("InsetCommand: Unknown inset name 
`$$Token'");
+                       throw ExceptionMessage(WarningException,
+                               _("Unknown inset name: "),
+                               from_utf8(name_));
+               }
        }
 
        string token;
@@ -278,12 +286,19 @@
                if (i >= 0) {
                        lex.next(true);
                        params_[i] = lex.getDocString();
-               } else
+               } else {
                        lex.printError("Unknown parameter name `$$Token' for 
command " + name_);
+                       throw ExceptionMessage(WarningException,
+                               _("Inset Command :") + from_ascii(name_),
+                               _("Unknown parameter name: ") + 
from_utf8(token));
+               }
        }
        if (token != "\\end_inset") {
                lex.printError("Missing \\end_inset at this point. "
                               "Read: `$$Token'");
+               throw ExceptionMessage(WarningException,
+                       _("Missing \\end_inset at this point."),
+                       from_utf8(token));
        }
 }
 

Reply via email to