mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
Factor LFUN_REF_APPLY code.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6276 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
081c629f6f
commit
7058c66b10
@ -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
|
||||
|
@ -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 = UNDISPATCHED;
|
||||
break;
|
||||
}
|
||||
|
||||
*inset = *tmp;
|
||||
if (base) {
|
||||
result = base->localDispatch(cmd);
|
||||
} else {
|
||||
mathcursor->insert(ar);
|
||||
// Turn 'argument' into a temporary RefInset.
|
||||
MathArray ar;
|
||||
if (string2RefInset(argument, ar)) {
|
||||
mathcursor->insert(ar);
|
||||
} else {
|
||||
result = UNDISPATCHED;
|
||||
}
|
||||
}
|
||||
updateLocal(bv, true);
|
||||
if (result == DISPATCHED)
|
||||
updateLocal(bv, true);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -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: ")},
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user