+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
#include "command_inset.h"
#include "math_mathmlstream.h"
#include "funcrequest.h"
+#include "Lsstream.h"
CommandInset::CommandInset(string const & data)
{
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();
+}
+
+
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_;
};
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;
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;
}
#include "math_support.h"
#include "Lsstream.h"
#include "support/filetools.h" // LibFileSearch
+#include "support/lstrings.h"
#include "frontends/lyx_gui.h"
#include <map>
//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();
+}
+
#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
#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()
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;
return UNDISPATCHED;
MathArray ar;
- if (!string2RefInset(cmd.argument, ar))
+ if (!createMathInset_fromDialogStr(cmd.argument, ar))
return UNDISPATCHED;
*this = *ar[0].nucleus()->asRefInset();
}
-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: ")},
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