Rearrange Dialog communication code to make it easier to handle similar stuff

for other insets.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6338 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-03-04 16:39:13 +00:00
parent a719f03d07
commit 3910647ab4
8 changed files with 83 additions and 54 deletions

View File

@ -1,3 +1,18 @@
2003-03-04 Angus Leeming <leeming@lyx.org>
* command_inset.[Ch] (createDialogStr): a new function to generate
something that the frontend Dialogs will understand.
* math_factory.[Ch] (createMathInset_fromDialogStr): new function
parses the string passed from the frontends.
* formulabase.C (localDiapatch):
* ref_inset.C (dispatch): use createDialogStr and
createMathInset_fromDialogStr rather than the current hard-coded
stuff.
* ref_inset.[Ch] (string2RefInset): goes the way of the dodo.
2003-03-04 Angus Leeming <leeming@lyx.org>
* formulabase.C (localDispatch): if an inset is found on

View File

@ -2,6 +2,7 @@
#include "command_inset.h"
#include "math_mathmlstream.h"
#include "funcrequest.h"
#include "Lsstream.h"
CommandInset::CommandInset(string const & data)
@ -51,3 +52,17 @@ string CommandInset::screenLabel() const
{
return name_;
}
string const CommandInset::createDialogStr(string const & name) const
{
ostringstream data;
data << name << " LatexCommand ";
WriteStream wsdata(data);
write(wsdata);
wsdata << "\n\\end_inset\n\n";
return data.str();
}

View File

@ -32,6 +32,8 @@ public:
dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
///
string screenLabel() const;
/// generate something that will be understodd by the Dialogs.
string const createDialogStr(string const & name) const;
public:
string name_;
};

View File

@ -797,7 +797,8 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
case LFUN_DIALOG_SHOW_NEW_INSET: {
string const & name = argument;
if (name == "ref") {
string data = "ref LatexCommand \\ref{}\n\\end_inset\n\n";
RefInset tmp;
string const data = tmp.createDialogStr(name);
bv->owner()->getDialogs().show(name, data, 0);
} else
result = UNDISPATCHED;
@ -806,17 +807,17 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
case LFUN_INSET_APPLY: {
string const name = cmd.getArg(0);
InsetBase * base =
InsetBase * base =
bv->owner()->getDialogs().getOpenInset(name);
if (base) {
FuncRequest fr(bv, LFUN_INSET_MODIFY, cmd.argument);
result = base->localDispatch(fr);
} else {
// Turn 'argument' into a temporary RefInset.
MathArray ar;
if (string2RefInset(cmd.argument, ar)) {
if (createMathInset_fromDialogStr(cmd.argument, ar)) {
mathcursor->insert(ar);
result = DISPATCHED;
} else {
result = UNDISPATCHED;
}

View File

@ -46,6 +46,7 @@
#include "math_support.h"
#include "Lsstream.h"
#include "support/filetools.h" // LibFileSearch
#include "support/lstrings.h"
#include "frontends/lyx_gui.h"
#include <map>
@ -299,3 +300,28 @@ MathAtom createMathInset(string const & s)
//lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << '\'' << endl;
return MathAtom(new MathUnknownInset(s));
}
bool createMathInset_fromDialogStr(string const & str, MathArray & ar)
{
// An example str:
// "ref LatexCommand \\ref{sec:Title}\n\\end_inset\n\n";
string name;
string body = split(str, name, ' ');
if (name != "ref" )
return false;
// body comes with a head "LatexCommand " and a
// tail "\nend_inset\n\n". Strip them off.
string trimmed;
body = split(body, trimmed, ' ');
split(body, trimmed, '\n');
mathed_parse_cell(ar, trimmed);
if (ar.size() != 1)
return false;
return ar[0].nucleus();
}

View File

@ -3,11 +3,16 @@
#include "LString.h"
#include "math_atom.h"
class MathInset;
class latexkeys;
class MathAtom;
class MathArray;
MathAtom createMathInset(string const &);
/** Fills ar with the contents of str.
* str is created by the frontend dialog's and returned to the LyX core.
* The function returns true if successful.
*/
bool createMathInset_fromDialogStr(string const &, MathArray &);
#endif

View File

@ -2,20 +2,18 @@
#include <config.h>
#include "ref_inset.h"
#include "funcrequest.h"
#include "formulabase.h"
#include "math_factory.h"
#include "BufferView.h"
#include "frontends/LyXView.h"
#include "frontends/Painter.h"
#include "frontends/Dialogs.h"
#include "lyxfunc.h"
#include "debug.h"
#include "funcrequest.h"
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "debug.h"
#include "math_mathmlstream.h"
#include "Lsstream.h"
#include "math_parser.h"
#include "support/lstrings.h"
#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
#include "support/LOstream.h"
RefInset::RefInset()
@ -53,14 +51,9 @@ RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
if (cmd.button() == mouse_button::button1) {
// Eventually trigger dialog with button 3
// not 1
ostringstream data;
data << "ref LatexCommand ";
WriteStream wsdata(data);
write(wsdata);
wsdata << "\n\\end_inset\n\n";
string const data = createDialogStr("ref");
cmd.view()->owner()->getDialogs().
show("ref", data.str(), this);
show("ref", data, this);
return DISPATCHED;
}
break;
@ -137,7 +130,7 @@ dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
return UNDISPATCHED;
MathArray ar;
if (!string2RefInset(cmd.argument, ar))
if (!createMathInset_fromDialogStr(cmd.argument, ar))
return UNDISPATCHED;
*this = *ar[0].nucleus()->asRefInset();
@ -149,28 +142,6 @@ dispatch_result RefInset::localDispatch(FuncRequest const & cmd)
}
bool string2RefInset(string const & str, MathArray & ar)
{
string name;
string body = split(str, name, ' ');
if (name != "ref")
return false;
// body comes with a head "LatexCommand " and a
// tail "\nend_inset\n\n". Strip them off.
string trimmed;
body = split(body, 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: ")},

View File

@ -51,10 +51,4 @@ 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