]> git.lyx.org Git - features.git/commitdiff
Rearrange Dialog communication code to make it easier to handle similar stuff
authorAngus Leeming <leeming@lyx.org>
Tue, 4 Mar 2003 16:39:13 +0000 (16:39 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 4 Mar 2003 16:39:13 +0000 (16:39 +0000)
for other insets.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6338 a592a061-630c-0410-9148-cb99ea01b6c8

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

index 4df2ea1e1fbc8da41f3c972a775b680515410b6d..b9fa3f9598ac18cbe459b6fc7a5add09a87d61c5 100644 (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
index 22e56af1736a242820d2de35ebed88adb711e4c7..f8a03c2e382e4f34962bbbb2434a3bbca9d1aa74 100644 (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();
+}
+
+
index df5981f71ed9311d87555ac355ed2ab3ff0e8fd1..9902afc811db166d943eace60c3888f5a3f2832f 100644 (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_;
 };
index cca0e6f1c4fb964387eae4e1a02adccf851d64f3..8bdb9e11ebcdbe27b1fb727c456be6ff753f0825 100644 (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;
                        }
index 7ad66b051d980d0f933a32bef1537cecd49f8241..68166b7215bf57706eecdb7c2eeac1d2cf280212 100644 (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();
+}
+
index 8ddb4413ec4620324be0c7530de679f1271c80ba..bcecc29d3b2a357ff0702fd6d5d9d73837a2a77d 100644 (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
index ca7d8e67ec39a63b2f78c3e26fa7e32bd436c7f0..7288930658ced09d0712d815cd59ef1860c155ce 100644 (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: ")},
index c689c10cb603b5987211bd8ff68ab0960b1ca492..0132d78ab3a61a777b32fd461408014bafe1f4f7 100644 (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