+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
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;
#include "debug.h"
#include "math_mathmlstream.h"
#include "Lsstream.h"
+#include "math_parser.h"
+#include "support/lstrings.h"
RefInset::RefInset()
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) {
}
+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: ")},
/// 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 {
///
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