]> git.lyx.org Git - features.git/commitdiff
Factor LFUN_REF_APPLY code.
authorAngus Leeming <leeming@lyx.org>
Wed, 26 Feb 2003 11:37:53 +0000 (11:37 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 26 Feb 2003 11:37:53 +0000 (11:37 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6276 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/formulabase.C
src/mathed/ref_inset.C
src/mathed/ref_inset.h

index 15dcfef950c67dfc31db2da721cc0e5ddba99283..d08cf4d442b4d3887070b7a90dfcc8508272d811 100644 (file)
@@ -1,3 +1,12 @@
+003-02-26  Angus Leeming  <leeming@lyx.org>
+
+       * ref_inset.[Ch]: add a localDispatch method to RefInset.
+       add a string2RefInset function to 'translate' the string passed to the
+       LyX core from the Reference dialog.
+
+       * formulabase.C (localDispatch): factor the code for LFUN_REF_APPLY
+       to use these new functions and so avoid a dynamic cast.
+
 2003-02-25  Alfredo Braunstein <abraunst@libero.it>
 
        * formula.C (draw): eliminate BufferView argument in call to 
index c3113c815fa023874c7c38e11db13abc8dda4eac..22c0474580a660a1a1ff2b7a87a3d63f7eb1fd49 100644 (file)
@@ -805,40 +805,22 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        break;
 
        case LFUN_REF_APPLY: {
-               // argument comes with a head "LatexCommand " and a
-               // tail "\nend_inset\n\n". Strip them off.
-               string trimmed;
-               string body = split(argument, trimmed, ' ');
-               split(body, trimmed, '\n');
-               lyxerr << "passing '" << trimmed << "' to the math parser\n";
-
-               MathArray ar;
-               mathed_parse_cell(ar, trimmed);
-               if (ar.size() != 1) {
-                       result = UNDISPATCHED;
-                       break;
-               }
-
-               RefInset * tmp = ar[0].nucleus()->asRefInset();
-               if (!tmp) {
-                       result = UNDISPATCHED;
-                       break;
-               }
-
                InsetBase * base =
                        bv->owner()->getDialogs().getOpenInset("ref");
+
                if (base) {
-                       RefInset * inset = dynamic_cast<RefInset *>(base);
-                       if (!inset) {
+                       result = base->localDispatch(cmd);
+               } else {
+                       // Turn 'argument' into a temporary RefInset.
+                       MathArray ar;
+                       if (string2RefInset(argument, ar)) {
+                               mathcursor->insert(ar);
+                       } else {
                                result = UNDISPATCHED;
-                               break;
                        }
-
-                       *inset = *tmp;
-               } else {
-                       mathcursor->insert(ar);
                }
-               updateLocal(bv, true);
+               if (result == DISPATCHED)
+                       updateLocal(bv, true);
        }
        break;
 
index 3fba790a82d011b44bce3953fa54e6b118f0a846..e140fdff70b264cf8dcc45cd7dc6f429fe0a5d1f 100644 (file)
@@ -14,6 +14,8 @@
 #include "debug.h"
 #include "math_mathmlstream.h"
 #include "Lsstream.h"
+#include "math_parser.h"
+#include "support/lstrings.h"
 
 
 RefInset::RefInset()
@@ -41,7 +43,6 @@ void RefInset::infoize(std::ostream & os) const
 dispatch_result
 RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
 {
-       lyxerr << "RefInset::dispatch " << cmd.argument << std::endl;
        switch (cmd.action) {
                case LFUN_MOUSE_RELEASE:
                        if (cmd.button() == mouse_button::button3) {
@@ -129,6 +130,33 @@ int RefInset::docbook(std::ostream & os, bool) const
 }
 
 
+dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
+{
+       MathArray ar;
+       if (!string2RefInset(cmd.argument, ar))
+               return UNDISPATCHED;
+
+       *this = *ar[0].nucleus()->asRefInset();
+       return DISPATCHED;
+}
+
+
+bool string2RefInset(string const & str, MathArray & ar)
+{
+       // str comes with a head "LatexCommand " and a
+       // tail "\nend_inset\n\n". Strip them off.
+       string trimmed;
+       string body = split(str, trimmed, ' ');
+       split(body, trimmed, '\n');
+
+       mathed_parse_cell(ar, trimmed);
+       if (ar.size() != 1)
+               return false;
+
+       return ar[0].nucleus()->asRefInset();
+}
+
+
 RefInset::ref_type_info RefInset::types[] = {
        { "ref",        N_("Standard"),                 N_("Ref: ")},
        { "pageref",    N_("Page Number"),              N_("Page: ")},
index fe1880b4f6ebd0f075413d812b770477ff5b6009..c689c10cb603b5987211bd8ff68ab0960b1ca492 100644 (file)
@@ -33,6 +33,8 @@ public:
        /// docbook output
        int docbook(std::ostream & os, bool) const;
 
+       /// small wrapper for the time being
+       dispatch_result localDispatch(FuncRequest const & cmd);
 
        struct ref_type_info {
                ///
@@ -49,4 +51,10 @@ public:
        static string const & getName(int type);
 };
 
+/** Fills ar with the contents of str.
+ *  str is created by the reference dialog and returned to the LyX core.
+ *  The function returns true if it succeeds in creating a RefInset.
+ */
+bool string2RefInset(string const & str, MathArray & ar);
+
 #endif