]> git.lyx.org Git - features.git/commitdiff
This is the first part of a cleanup of how we handle the InsetCommand hierarchy....
authorRichard Heck <rgheck@comcast.net>
Thu, 27 Sep 2007 18:24:18 +0000 (18:24 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 27 Sep 2007 18:24:18 +0000 (18:24 +0000)
(i) The file format is changed, so that command insets are represented as:
    \begin_inset CommandInset insetype
    LatexCommand command
    ...
    \end_inset
This involves some lyx2lyx and changes to the readInset() routine in factory.cpp
(ii) The InsetCommand and InsetCommandParams classes also have to be changed, as the command name was used in these classes for various purposes for which the inset type ought really to be used.
Further clean-up to come.

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

23 files changed:
development/FORMAT
lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx_1_6.py
src/Buffer.cpp
src/LyXFunc.cpp
src/factory.cpp
src/frontends/controllers/ControlBibtex.cpp
src/frontends/controllers/ControlCitation.cpp
src/frontends/controllers/ControlCommand.cpp
src/frontends/controllers/ControlCommand.h
src/frontends/controllers/ControlRef.cpp
src/frontends/controllers/ControlToc.cpp
src/frontends/qt4/Dialogs.cpp
src/frontends/qt4/GuiBibitem.cpp
src/frontends/qt4/GuiIndex.cpp
src/frontends/qt4/GuiNomencl.cpp
src/frontends/qt4/GuiURL.cpp
src/insets/Inset.cpp
src/insets/InsetCitation.h
src/insets/InsetCommand.cpp
src/insets/InsetCommandParams.cpp
src/insets/InsetCommandParams.h
src/insets/InsetRef.cpp

index eeb235469a09179859560a306b5bc254b72ddbe2..727ee191ed1d5a7f36197adf07c16e4af5eb3626 100644 (file)
@@ -1,6 +1,10 @@
 LyX file-format changes
 -----------------------
 
+2007-09-25 Richard Heck <rgheck@bobjweil.com>
+       * Format incremented to 288: Change how command insets are
+         represented in LyX files.
+
 2007-09-24 Uwe Stöhr <uwestoehr@web.de>
        * Format incremented to 287: Add missing optional parameters
          for wrapped figures.
index 3d35bade6f2fa968440506cfd9810f23786df5c5..1b8cc4bf2a8b1c0b3b568e82f7e960fd368d274a 100644 (file)
@@ -80,7 +80,7 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 4)),
                    ("1_3",     [221], minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), minor_versions("1.4" , 5)),
                    ("1_5", range(246,277), minor_versions("1.5" , 1)),
-                   ("1_6", range(277,288), minor_versions("1.6" , 0))]
+                   ("1_6", range(277,289), minor_versions("1.6" , 0))] #RGH, command insets
 
 
 def formats_list():
index 14d92b93d69bb4cc40e4cbde25585c93d74567bc..6e7b7aa6a1af8684acfcf7d741ba15a11a0e4c83 100644 (file)
@@ -256,6 +256,67 @@ def remove_inzip_options(document):
         i = i + 1
 
 
+def convert_inset_command(document):
+  """
+    Convert:
+      \begin_inset LatexCommand cmd 
+    to 
+      \begin_inset CommandInset InsetType
+      LatexCommand cmd
+  """
+  i = 0
+  while 1:
+    i = find_token(document.body, "\\begin_inset LatexCommand", i)
+    if i == -1:
+      return
+    line = document.body[i]
+    r = re.compile(r'\\begin_inset LatexCommand (.*)$')
+    m = r.match(line)
+    cmdName = m.group(1)
+    insetName = ""
+    #this is adapted from factory.cpp
+    if cmdName[0:4].lower() == "cite":
+      insetName = "citation"
+    elif cmdName == "url" or cmdName == "htmlurl":
+      insetName = "url"
+    elif cmdName[-3:] == "ref":
+      insetName = "ref"
+    elif cmdName == "tableofcontents":
+      insetName = "toc"
+    elif cmdName == "printnomenclature":
+      insetName = "nomencl_print"
+    elif cmdName == "printindex":
+      insetName = "index_print"
+    else:
+      insetName = cmdName
+    insertion = ["\\begin_inset CommandInset " + insetName, "LatexCommand " + cmdName]
+    document.body[i : i+1] = insertion
+
+
+def revert_inset_command(document):
+  """
+    Convert:
+      \begin_inset CommandInset InsetType
+      LatexCommand cmd
+    to 
+      \begin_inset LatexCommand cmd 
+    Some insets may end up being converted to insets earlier versions of LyX
+    will not be able to recognize. Not sure what to do about that.
+  """
+  i = 0
+  while 1:
+    i = find_token(document.body, "\\begin_inset CommandInset", i)
+    nextline = document.body[i+1]
+    r = re.compile(r'LatexCommand\s+(.*)$')
+    m = r.match(nextline)
+    if not m:
+      document.warning("Malformed LyX document: Missing LatexCommand in " + document.body[i] + ".")
+      continue
+    cmdName = m.group(1)
+    insertion = ["\\begin_inset LatexCommand " + cmdName]
+    document.body[i : i+2] = insertion
+
+
 def convert_wrapfig_options(document):
     "Convert optional options for wrap floats (wrapfig)."
     # adds the tokens "lines", "placement", and "overhang"
@@ -308,10 +369,12 @@ convert = [
            [284, []],
            [285, []], # an empty manifest is automatically added
            [286, []],
-           [287, [convert_wrapfig_options]]
+           [287, [convert_wrapfig_options]],
+           [288, [convert_inset_command]]
           ]
 
 revert =  [
+           [287, [revert_inset_command]],
            [286, [revert_wrapfig_options]],
            [285, [revert_pdf_options]],
            [284, [remove_manifest, remove_inzip_options]],
index 186bdb03c9d495cac3346d92d8c04a6ea9bd76d0..c2ba639fcbb3b6b8990090121c9378d746fa81ae 100644 (file)
@@ -143,7 +143,7 @@ namespace fs = boost::filesystem;
 
 namespace {
 
-int const LYX_FORMAT = 287;
+int const LYX_FORMAT = 288; //RGH, command insets
 
 } // namespace anon
 
index 96cbc25e0c6d691203ac9627172831ca62ba58bc..a2541330df48aedc2fac11bc9beb9297fda5d26d 100644 (file)
@@ -1430,7 +1430,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                InsetBranchParams p;
                                data = InsetBranchMailer::params2string(p);
                        } else if (name == "citation") {
-                               InsetCommandParams p("cite");
+                               InsetCommandParams p("citation");
                                data = InsetCommandMailer::params2string(name, p);
                        } else if (name == "ert") {
                                data = InsetERTMailer::params2string(InsetCollapsable::Open);
@@ -1510,7 +1510,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        arg = token(argument, '|', 0);
                                        opt1 = token(argument, '|', 1);
                                }
-                               InsetCommandParams icp("cite");
+                               InsetCommandParams icp("citation");
                                icp["key"] = from_utf8(arg);
                                if (!opt1.empty())
                                        icp["before"] = from_utf8(opt1);
index cb5c15d36d60e7eab98351841824f548e6ae9d9b..dcecdd0a12c1ec076d4b3e677f99d51ddad01ca3 100644 (file)
@@ -216,13 +216,13 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                }
 
                case LFUN_INDEX_PRINT:
-                       return new InsetPrintIndex(InsetCommandParams("printindex"));
+                       return new InsetPrintIndex(InsetCommandParams("index_print"));
 
                case LFUN_NOMENCL_PRINT:
-                       return new InsetPrintNomencl(InsetCommandParams("printnomenclature"));
+                       return new InsetPrintNomencl(InsetCommandParams("nomencl_print"));
 
                case LFUN_TOC_INSERT:
-                       return new InsetTOC(InsetCommandParams("tableofcontents"));
+                       return new InsetTOC(InsetCommandParams("toc"));
 
                case LFUN_ENVIRONMENT_INSERT:
                        return new InsetEnvironment(params, cmd.argument());
@@ -251,7 +251,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                                return new InsetBibtex(icp);
 
                        } else if (name == "citation") {
-                               InsetCommandParams icp("cite");
+                               InsetCommandParams icp("citation");
                                InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
                                        icp);
                                return new InsetCitation(icp);
@@ -314,7 +314,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                                return new InsetRef(icp, bv->buffer());
 
                        } else if (name == "toc") {
-                               InsetCommandParams icp("tableofcontents");
+                               InsetCommandParams icp("toc");
                                InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
                                        icp);
                                return new InsetTOC(icp);
@@ -393,62 +393,47 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
        string tmptok = lex.getString();
 
        // test the different insets
-       if (tmptok == "LatexCommand") {
+       if (tmptok == "CommandInset") {
                lex.next();
-               string const cmdName = lex.getString();
-               lex.pushToken(cmdName);
-
-               InsetCommandParams inscmd(cmdName);
+               string const insetType = lex.getString();
+               lex.pushToken(insetType);
+
+               //FIXME 
+               //Inset::Code const code = Inset::translate(insetType);
+               //if (code == Inset::NO_CODE) { choke as below; }
+               //InsetCommandParams inscmd();
+               InsetCommandParams inscmd(insetType);
                inscmd.read(lex);
 
-               // This strange command allows LyX to recognize "natbib" style
-               // citations: citet, citep, Citet etc.
-               // FIXME: We already have partial support for \\fullcite and
-               // the various \\footcite commands. We should increase the
-               // file format number and read these commands here, too.
-               // Then we should use is_possible_cite_command() in
-               // InsetCitation to test for valid cite commands.
-               if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
+               if (insetType == "citation") {
                        inset.reset(new InsetCitation(inscmd));
-               } else if (cmdName == "bibitem") {
+               } else if (insetType == "bibitem") {
                        inset.reset(new InsetBibitem(inscmd));
-               } else if (cmdName == "bibtex") {
+               } else if (insetType == "bibtex") {
                        inset.reset(new InsetBibtex(inscmd));
-               } else if (cmdName == "index") {
+               } else if (insetType == "index") {
                        inset.reset(new InsetIndex(inscmd));
-               } else if (cmdName == "nomenclature") {
+               } else if (insetType == "nomenclature") {
                        inset.reset(new InsetNomencl(inscmd));
-               } else if (cmdName == "include") {
+               } else if (insetType == "include") {
                        inset.reset(new InsetInclude(inscmd));
-               } else if (cmdName == "label") {
+               } else if (insetType == "label") {
                        inset.reset(new InsetLabel(inscmd));
-               } else if (cmdName == "url"
-                          || cmdName == "htmlurl") {
+               } else if (insetType == "url") {
                        inset.reset(new InsetUrl(inscmd));
-               } else if (cmdName == "ref"
-                          || cmdName == "eqref"
-                          || cmdName == "pageref"
-                          || cmdName == "vref"
-                          || cmdName == "vpageref"
-                          || cmdName == "prettyref") {
+               } else if (insetType == "ref") {
                        if (!inscmd["name"].empty()
                            || !inscmd["reference"].empty()) {
                                inset.reset(new InsetRef(inscmd, buf));
                        }
-               } else if (cmdName == "tableofcontents") {
+               } else if (insetType == "toc") {
                        inset.reset(new InsetTOC(inscmd));
-               } else if (cmdName == "listofalgorithms") {
-                       inset.reset(new InsetFloatList("algorithm"));
-               } else if (cmdName == "listoffigures") {
-                       inset.reset(new InsetFloatList("figure"));
-               } else if (cmdName == "listoftables") {
-                       inset.reset(new InsetFloatList("table"));
-               } else if (cmdName == "printindex") {
+               } else if (insetType == "index_print") {
                        inset.reset(new InsetPrintIndex(inscmd));
-               } else if (cmdName == "printnomenclature") {
+               } else if (insetType == "nomencl_print") {
                        inset.reset(new InsetPrintNomencl(inscmd));
                } else {
-                       lyxerr << "unknown CommandInset '" << cmdName
+                       lyxerr << "unknown CommandInset '" << insetType
                               << "'" << std::endl;
                        while (lex.isOK() && lex.getString() != "\\end_inset")
                                lex.next();
index 4e7f226f5826c5710fd4881baacff3785df5cad3..fe14ec9c3797c23fcc808b70b73435c33e841c25 100644 (file)
@@ -42,7 +42,7 @@ namespace frontend {
 
 
 ControlBibtex::ControlBibtex(Dialog & d)
-       : ControlCommand(d, "bibtex", "bibtex")
+       : ControlCommand(d, "bibtex")
 {}
 
 
index 4b8ab880d348d59ab8c9a1adf9a44029f12f0d41..9f09abe1bee28f5df490fe5fbad2e5a70e028fd1 100644 (file)
@@ -34,7 +34,7 @@ vector<biblio::CiteStyle> ControlCitation::citeStyles_;
 
 
 ControlCitation::ControlCitation(Dialog & d)
-       : ControlCommand(d, "cite", "citation")
+       : ControlCommand(d, "citation")
 {}
 
 
index 02913155bb501432239c12986efe5ef6cc9c360b..8bf8cc0aabd0a552eb04568219aed0754f88dc0f 100644 (file)
@@ -21,10 +21,8 @@ using std::string;
 namespace lyx {
 namespace frontend {
 
-ControlCommand::ControlCommand(Dialog & dialog, string const & command_name,
-                              string const & lfun_name)
-       : Controller(dialog), params_(command_name),
-         lfun_name_(lfun_name)
+ControlCommand::ControlCommand(Dialog & dialog, string const & insetType)
+       : Controller(dialog), params_(insetType), lfun_name_(insetType)
 {}
 
 
@@ -48,8 +46,8 @@ void ControlCommand::dispatchParams()
        if (lfun_name_.empty())
                return;
 
-       string const lfun = InsetCommandMailer::params2string(lfun_name_,
-                                                             params_);
+       string const lfun = 
+               InsetCommandMailer::params2string(lfun_name_, params_);
        dispatch(FuncRequest(getLfun(), lfun));
 }
 
index 0bd7ebb33acd98cf1fc564f6f6f287bcec632181..ac07ea6f593855651b350af22821eeb72bdb6896 100644 (file)
@@ -24,13 +24,8 @@ namespace frontend {
 
 class ControlCommand : public Controller {
 public:
-       /** LFUN_INSET_APPLY requires a name, "citation", "ref" etc so that
-           it knows what to do with the rest of the contents.
-           An empty \p lfun_name indicates that no action will occur on
-           'Apply'.
-        */
-       ControlCommand(Dialog &, std::string const & command_name,
-                      std::string const & lfun_name);
+       /// We need to know with what sort of inset we're associated.
+       ControlCommand(Dialog &, std::string const & insetType);
        ///
        virtual ~ControlCommand() {}
        ///
@@ -49,6 +44,9 @@ public:
 private:
        ///
        InsetCommandParams params_;
+       //FIXME It should be possible to eliminate lfun_name_
+       //now and recover that information from params().insetType().
+       //But let's not do that quite yet.
        /// Flags what action is taken by Kernel::dispatch()
        std::string const lfun_name_;
 };
index 0a5d9c4b4d88cd0ab186fd8f81a1a789666ed3f5..f34d197cfa4d81a6407563021e1f390895d98b8b 100644 (file)
@@ -33,7 +33,7 @@ using support::makeDisplayPath;
 namespace frontend {
 
 ControlRef::ControlRef(Dialog & d)
-       : ControlCommand(d, "ref", "ref")
+       : ControlCommand(d, "ref")
 {}
 
 
index de6ca9bf690c83db0f0fb35efb6670a273957e05..a04386578f300d784653bee3627b399f8eb52eba 100644 (file)
@@ -32,7 +32,7 @@ namespace lyx {
 namespace frontend {
 
 ControlToc::ControlToc(Dialog & d)
-       : ControlCommand(d, "tableofcontents", "toc")
+       : ControlCommand(d, "toc")
 {
 }
 
index 2fdd7c6857515f3bbd1c29c2b4604ade19cb80b9..dcdb194ee30ef4ee5f10833111a4cac9bead2698 100644 (file)
@@ -77,6 +77,9 @@ namespace frontend {
 
 namespace {
 
+//This list should be kept in sync with the list of insets in src/insets/Inset.cpp.
+//I.e., if a dialog goes with an inset, the dialog should have the same name as the
+//inset.
 char const * const dialognames[] = {
 "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character",
 "citation", "document", "embedding", "errorlist", "ert", "external", "file",
index 1ee6a8168124b6571a04e12695152a56f7e903b0..2a9294d19fa8e97ce432a1c76a15eeb0806aab2d 100644 (file)
@@ -28,7 +28,7 @@ GuiBibitemDialog::GuiBibitemDialog(LyXView & lv)
 {
        setupUi(this);
        setViewTitle(_("Bibliography Entry Settings"));
-       setController(new ControlCommand(*this, "bibitem", "bibitem"));
+       setController(new ControlCommand(*this, "bibitem"));
 
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
        connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
index 4982b693dcd0ab07bd26bf5c1c233dffd2bc9161..21583078a5b459813867fc7b694681b94c32ecff 100644 (file)
@@ -41,7 +41,7 @@ GuiIndexDialogBase::GuiIndexDialogBase(LyXView & lv,
        label_ = label;
        setupUi(this);
        setViewTitle(title);
-       setController(new ControlCommand(*this, name, name));
+       setController(new ControlCommand(*this, name));
 
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
        connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
index 61f57ef161225642d3feb07468cc3c179c9f72e8..1208faeb89e076e045d6b8bed90852031120b49a 100644 (file)
@@ -33,7 +33,7 @@ GuiNomenclDialog::GuiNomenclDialog(LyXView & lv)
        : GuiDialog(lv, "nomenclature")
 {
        setupUi(this);
-       setController(new ControlCommand(*this, "nomenclature", "nomenclature"));
+       setController(new ControlCommand(*this, "nomenclature"));
 
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
        connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
index 2662ecaf09beccfc25038c0cc257c2bb853c0f87..7e4d41e04a32e07c03040b67a41e3ad2cfd89de2 100644 (file)
@@ -29,7 +29,7 @@ GuiURLDialog::GuiURLDialog(LyXView & lv)
 {
        setupUi(this);
        setViewTitle( _("URL"));
-       setController(new ControlCommand(*this, "url", "url"));
+       setController(new ControlCommand(*this, "url"));
 
        connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
        connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
index 01e039f4616ce76f803103140e3629560db66eac..0814a5042305557114a8d06bd40ef7b960544b3f 100644 (file)
@@ -88,8 +88,8 @@ static TranslatorMap const build_translator()
                InsetName("external", Inset::EXTERNAL_CODE),
                InsetName("caption", Inset::CAPTION_CODE),
                InsetName("mathmacro", Inset::MATHMACRO_CODE),
-               InsetName("cite", Inset::CITE_CODE),
-               InsetName("float_list", Inset::FLOAT_LIST_CODE),
+               InsetName("citation", Inset::CITE_CODE),
+               InsetName("floatlist", Inset::FLOAT_LIST_CODE),
                InsetName("index_print", Inset::INDEX_PRINT_CODE),
                InsetName("nomencl_print", Inset::NOMENCL_PRINT_CODE),
                InsetName("optarg", Inset::OPTARG_CODE),
index 873c71c72de7ed8223a539ef20ad9ade21e6e067..d51fe6649b8ddb524e61895377f524e04764b976 100644 (file)
@@ -63,7 +63,7 @@ private:
        class Cache {
        public:
                ///
-               Cache() : engine(biblio::ENGINE_BASIC), params("cite") {}
+               Cache() : engine(biblio::ENGINE_BASIC), params("citation") {}
                ///
                biblio::CiteEngine engine;
                ///
index 6b84b6b73e724698794491364d0fe506a9029539..f50d33c124e6d1ed806fb36482a58fc782c5fbec 100644 (file)
@@ -208,7 +208,7 @@ void InsetCommandMailer::string2params(string const & name,
        // by Text::readInset
        string id;
        lex >> id;
-       if (!lex || id != "LatexCommand")
+       if (!lex || id != "CommandInset")
                return print_mailer_error("InsetCommandMailer", in, 2, "LatexCommand");
 
        params.read(lex);
index 19a557077fdc3d6cb8224e208f5e410a50fa4ea5..8d9f345b70062a15e312b9d4af93428ec83abdb8 100644 (file)
@@ -34,23 +34,43 @@ using std::ostream;
 using support::ExceptionMessage;
 using support::WarningException;
 
-InsetCommandParams::InsetCommandParams(string const & name)
-       : name_(name), preview_(false)
+
+//FIXME There is no reason now for this to take a string argument.
+//It'd be much more robust if it took an Inset::Code, since then
+//the compiler would do some checking for us.
+InsetCommandParams::InsetCommandParams(string const & insetType)
+       : insetType_(insetType), preview_(false)
+{
+       cmdName_ = getDefaultCmd(insetType);
+       info_ = findInfo(insetType, cmdName_);
+       BOOST_ASSERT(info_);
+       params_.resize(info_->n);
+}
+
+
+InsetCommandParams::InsetCommandParams(string const & insetType,
+       string const & cmdName)
+       : insetType_(insetType), cmdName_(cmdName), preview_(false)
 {
-       info_ = findInfo(name);
+       info_ = findInfo(insetType, cmdName);
        BOOST_ASSERT(info_);
        params_.resize(info_->n);
 }
 
 
+//FIXME This should go into the Insets themselves...so they will tell
+//us what parameters they want.
+//Should this just vanish in favor of the two arg version, or is there
+//a reason to use it in some cases? What should happen in the single
+//arg case, then? Maybe use the default? or leave that up to the inset?
 InsetCommandParams::CommandInfo const *
-InsetCommandParams::findInfo(std::string const & name)
+InsetCommandParams::findInfo(std::string const & insetType)
 {
        // No parameter may be named "preview", because that is a required
        // flag for all commands.
 
        // InsetBibitem
-       if (name == "bibitem") {
+       if (insetType == "bibitem") {
                static const char * const paramnames[] = {"label", "key", ""};
                static const bool isoptional[] = {true, false};
                static const CommandInfo info = {2, paramnames, isoptional};
@@ -58,7 +78,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetBibtex
-       if (name == "bibtex") {
+       if (insetType == "bibtex") {
                static const char * const paramnames[] =
                                {"options", "btprint", "bibfiles", ""};
                static const bool isoptional[] = {true, true, false};
@@ -67,17 +87,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetCitation
-       // FIXME: Use is_possible_cite_command() in
-       // InsetCitation, see comment in src/factory.cpp.
-       if (name == "cite" || name == "citet" || name == "citep" || name == "citealt" ||
-           name == "citealp" || name == "citeauthor" || name == "citeyear" ||
-           name == "citeyearpar" || name == "citet*" || name == "citep*" ||
-           name == "citealt*" || name == "citealp*" ||
-           name == "citeauthor*" || name == "Citet" || name == "Citep" ||
-           name == "Citealt" || name == "Citealp" || name == "Citeauthor" ||
-           name == "Citet*" || name == "Citep*" || name == "Citealt*" ||
-           name == "Citealp*" || name == "Citeauthor*" ||
-           name == "citefield" || name == "citetitle" || name == "cite*") {
+       if (insetType == "citation") {
                // standard cite does only take one argument if jurabib is
                // not used, but jurabib extends this to two arguments, so
                // we have to allow both here. InsetCitation takes care that
@@ -90,7 +100,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetFloatlist
-       if (name == "floatlist") {
+       if (insetType == "floatlist") {
                static const char * const paramnames[] = {"type", ""};
                static const bool isoptional[] = {false};
                static const CommandInfo info = {1, paramnames, isoptional};
@@ -98,22 +108,17 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetHfill
-       if (name == "hfill") {
+       if (insetType == "hfill") {
                static const char * const paramnames[] = {""};
                static const CommandInfo info = {0, paramnames, 0};
                return &info;
        }
 
        // InsetInclude
-       if (name == "include" || name == "input" || name == "verbatiminput" ||
-           name == "verbatiminput*") {
-               static const char * const paramnames[] = {"filename", ""};
-               static const bool isoptional[] = {false};
-               static const CommandInfo info = {1, paramnames, isoptional};
-               return &info;
-       }
-
-       if (name == "lstinputlisting") {
+       //FIXME This is really correct only for lstinputlistings, but it shouldn't
+       //cause a problem before we get things sorted out. Eventually, this calls
+       //InsetInclude::getParams(cmdName_), or something of the sort.
+       if (insetType == "include") {
                static const char * const paramnames[] = {"filename", "lstparams", ""};
                static const bool isoptional[] = {false, true};
                static const CommandInfo info = {2, paramnames, isoptional};
@@ -121,7 +126,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetIndex, InsetPrintIndex, InsetLabel
-       if (name == "index" || name == "printindex" || name == "label") {
+       if (insetType == "index" || insetType == "index_print" || insetType == "label") {
                static const char * const paramnames[] = {"name", ""};
                static const bool isoptional[] = {false};
                static const CommandInfo info = {1, paramnames, isoptional};
@@ -129,7 +134,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetNomencl
-       if (name == "nomenclature") {
+       if (insetType == "nomenclature") {
                static const char * const paramnames[] = {"prefix", "symbol", "description", ""};
                static const bool isoptional[] = {true, false, false};
                static const CommandInfo info = {3, paramnames, isoptional};
@@ -137,7 +142,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetPrintNomencl
-       if (name == "printnomenclature") {
+       if (insetType == "nomencl_print") {
                static const char * const paramnames[] = {"labelwidth", ""};
                static const bool isoptional[] = {true};
                static const CommandInfo info = {1, paramnames, isoptional};
@@ -145,8 +150,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetRef
-       if (name == "eqref" || name == "pageref" || name == "vpageref" ||
-           name == "vref" || name == "prettyref" || name == "ref") {
+       if (insetType == "ref") {
                static const char * const paramnames[] =
                                {"name", "reference", ""};
                static const bool isoptional[] = {true, false};
@@ -155,7 +159,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetTOC
-       if (name == "tableofcontents") {
+       if (insetType == "toc") {
                static const char * const paramnames[] = {"type", ""};
                static const bool isoptional[] = {false};
                static const CommandInfo info = {1, paramnames, isoptional};
@@ -163,7 +167,7 @@ InsetCommandParams::findInfo(std::string const & name)
        }
 
        // InsetUrl
-       if (name == "htmlurl" || name == "url") {
+       if (insetType == "url") {
                static const char * const paramnames[] =
                                {"name", "target", ""};
                static const bool isoptional[] = {true, false};
@@ -175,10 +179,55 @@ InsetCommandParams::findInfo(std::string const & name)
 }
 
 
+//FIXME Will eventually call a static method, etc.
+InsetCommandParams::CommandInfo const *
+               InsetCommandParams::findInfo(std::string const & insetType,
+                                            std::string const & cmdName)
+{
+       return findInfo(insetType);
+}
+
+
+//FIXME Should call InsetBibitem::getDefaultCmd(), eg
+std::string InsetCommandParams::getDefaultCmd(std::string insetType) {
+       if (insetType == "bibitem")
+               return "bibitem";
+       if (insetType == "bibtex") 
+               return "";
+       if (insetType == "citation")
+               return "cite";
+       if (insetType == "floatlist")
+               return "";
+       if (insetType == "hfill")
+               return "hfill";
+       if (insetType == "include")
+               return "include";
+       if (insetType == "index")
+                return "index";
+       if (insetType == "index_print")
+               return "print_index";
+       if (insetType == "label")
+               return "label";
+       if (insetType == "nomenclature")
+               return "nomenclature";
+       if (insetType == "nomencl_print")
+               return "printnomenclature";
+       if (insetType == "ref")
+               return "ref";
+       if (insetType == "toc")
+               return "tableofcontents";
+       if (insetType == "url")
+               return "url";
+       return "";      
+}
+
+
 void InsetCommandParams::setCmdName(string const & name)
 {
-       name_ = name;
-       CommandInfo const * const info = findInfo(name);
+       //FIXME Check command compatibility
+       cmdName_ = name;
+       BOOST_ASSERT(!insetType_.empty());
+       CommandInfo const * const info = findInfo(insetType_, cmdName_);
        BOOST_ASSERT(info);
        ParamVector params(info->n);
        // Overtake parameters with the same name
@@ -265,18 +314,43 @@ void InsetCommandParams::scanCommand(string const & cmd)
 
 void InsetCommandParams::read(Lexer & lex)
 {
+       //FIXME
        if (lex.isOK()) {
                lex.next();
-               name_ = lex.getString();
-               info_ = findInfo(name_);
-               if (!info_) {
-                       lex.printError("InsetCommand: Unknown inset name `$$Token'");
-                       throw ExceptionMessage(WarningException,
-                               _("Unknown inset name: "),
-                               from_utf8(name_));
+               string insetType = lex.getString();
+               if (!insetType_.empty() && insetType != insetType_) {
+                       lex.printError("InsetCommand: Attempt to change type of parameters.");
+                       throw ExceptionMessage(WarningException, _("InsetCommand Error: "),
+                               from_utf8("Attempt to change type of parameters."));
                }
+               // OK, we survived...
+               insetType_ = insetType;
        }
 
+       if (lex.isOK()) {
+               lex.next();
+               string test = lex.getString();
+               if (test != "LatexCommand") {
+                       lex.printError("InsetCommand: no LatexCommand line found.");
+                       throw ExceptionMessage(WarningException, _("InsetCommand error:"),
+                               from_utf8("Can't find LatexCommand line."));
+               }
+       }
+       lex.next();
+       cmdName_ = lex.getString();
+       //FIXME
+       //check that this command is ok with the inset...
+       //so that'll be some kind of static call, depending 
+       //upon what insetType_ is.
+       //it's possible that should go into InsetCommand.cpp,
+       //or maybe it's a standalone function.
+       info_ = findInfo(insetType_, cmdName_);
+       if (!info_) {
+               lex.printError("InsetCommand: Unknown inset name `$$Token'");
+               throw ExceptionMessage(WarningException,
+                       _("Unknown inset name: "), from_utf8(insetType_));
+       }
+       
        string token;
        while (lex.isOK()) {
                lex.next();
@@ -294,9 +368,9 @@ void InsetCommandParams::read(Lexer & lex)
                        lex.next(true);
                        params_[i] = lex.getDocString();
                } else {
-                       lex.printError("Unknown parameter name `$$Token' for command " + name_);
+                       lex.printError("Unknown parameter name `$$Token' for command " + cmdName_);
                        throw ExceptionMessage(WarningException,
-                               _("Inset Command: ") + from_ascii(name_),
+                               _("Inset Command: ") + from_ascii(cmdName_),
                                _("Unknown parameter name: ") + from_utf8(token));
                }
        }
@@ -312,7 +386,8 @@ void InsetCommandParams::read(Lexer & lex)
 
 void InsetCommandParams::write(ostream & os) const
 {
-       os << "LatexCommand " << name_ << '\n';
+       os << "CommandInset " << insetType_ << '\n';
+       os << "LatexCommand " << cmdName_ << '\n';
        for (size_t i = 0; i < info_->n; ++i)
                if (!params_[i].empty())
                        // FIXME UNICODE
@@ -324,7 +399,7 @@ void InsetCommandParams::write(ostream & os) const
 
 docstring const InsetCommandParams::getCommand() const
 {
-       docstring s = '\\' + from_ascii(name_);
+       docstring s = '\\' + from_ascii(cmdName_);
        bool noparam = true;
        for (size_t i = 0; i < info_->n; ++i) {
                if (info_->optional[i]) {
@@ -364,7 +439,7 @@ std::string const InsetCommandParams::getOptions() const
                if (info_->optional[i])
                        return to_utf8(params_[i]);
        lyxerr << "Programming error: get nonexisting option in "
-              << name_ << " inset." << endl;;
+              << insetType_ << " inset." << endl;
        return string();
 }
 
@@ -381,7 +456,7 @@ std::string const InsetCommandParams::getSecOptions() const
                }
        // Happens in InsetCitation
        lyxerr << "Programming error: get nonexisting second option in "
-              << name_ << " inset." << endl;;
+              << insetType_ << " inset." << endl;
        return string();
 }
 
@@ -404,7 +479,7 @@ void InsetCommandParams::setOptions(std::string const & o)
                        return;
                }
        lyxerr << "Programming error: set nonexisting option in "
-              << name_ << " inset." << endl;;
+              << insetType_ << " inset." << endl;
 }
 
 
@@ -422,7 +497,7 @@ void InsetCommandParams::setSecOptions(std::string const & s)
                }
        // Happens in InsetCitation
        lyxerr << "Programming error: set nonexisting second option in "
-              << name_ << " inset." << endl;;
+              << insetType_ << " inset." << endl;
 }
 
 
@@ -463,7 +538,8 @@ void InsetCommandParams::clear()
 bool operator==(InsetCommandParams const & o1,
                InsetCommandParams const & o2)
 {
-       return o1.name_ == o2.name_ &&
+       return o1.insetType_ == o2.insetType_ &&
+              o1.cmdName_ == o2.cmdName_ &&
               o1.info_ == o2.info_ &&
               o1.params_ == o2.params_ &&
               o1.preview_ == o2.preview_;
index 3e6b20eca8f689b1be11eeceaa5fa04105509a32..f02d2a6ebd195a17bc8e9529e5c55da5b32910f0 100644 (file)
@@ -25,8 +25,15 @@ class Lexer;
 
 class InsetCommandParams {
 public:
-       /// Construct parameters for command \p name. \p name must be known.
-       explicit InsetCommandParams(std::string const & name);
+       /// Construct parameters for inset \p insetType, using
+       /// \p insetType as default for \p cmdName_.
+       explicit InsetCommandParams(std::string const & insetType);
+       /// Construct parameters for inset \p insetType with
+       /// command name \p cmdName.
+       explicit InsetCommandParams(std::string const & insetType,
+                       std::string const & cmdName);
+       ///
+       std::string insetType() { return insetType_; }
        ///
        void read(Lexer &);
        /// Parse the command
@@ -37,13 +44,9 @@ public:
        /// Build the complete LaTeX command
        docstring const getCommand() const;
        /// Return the command name
-       std::string const & getCmdName() const { return name_; }
+       std::string const & getCmdName() const { return cmdName_; }
        /// this is used by listings package.
        std::string const getOptions() const;
-private:
-       /// FIXME remove
-       std::string const getSecOptions() const;
-public:
        /// FIXME remove
        std::string const getContents() const;
        /// Set the name to \p n. This must be a known name. All parameters
@@ -52,10 +55,6 @@ public:
        void setCmdName(std::string const & n);
        /// this is used by the listings package
        void setOptions(std::string const &);
-private:
-       /// FIXME remove
-       void setSecOptions(std::string const &);
-public:
        /// FIXME remove
        void setContents(std::string const &);
        /// get parameter \p name
@@ -70,6 +69,10 @@ public:
        void clear();
 
 private:
+       /// FIXME remove
+       std::string const getSecOptions() const;
+       /// FIXME remove
+       void setSecOptions(std::string const &);
        ///
        struct CommandInfo {
                /// Number of parameters
@@ -79,13 +82,23 @@ private:
                /// Tells whether a parameter is optional
                bool const * optional;
        };
-       /// Get information for command \p name.
-       /// Returns 0 if the command is not known.
-       static CommandInfo const * findInfo(std::string const & name);
+       /// Get information for inset type \p insetType.
+       /// Returns 0 if the inset is not known.
+       static CommandInfo const * findInfo(std::string const & insetType);
+       /// Get information for \p insetType and command \p cmdName.
+       /// Returns 0 if the combination is not known.
+       /// Don't call this without first making sure the command name is
+       /// acceptable to the inset.
+       static CommandInfo const * findInfo(std::string const & insetType,
+                                           std::string const & cmdName);
+       ///
+       std::string getDefaultCmd(std::string insetType);
        /// Description of all command properties
        CommandInfo const * info_;
+       /// what kind of inset we're the parameters for
+       std::string insetType_;
        /// The name of this command as it appears in .lyx and .tex files
-       std::string name_;
+       std::string cmdName_;
        ///
        typedef std::vector<docstring> ParamVector;
        /// The parameters (both optional and required ones). The order is
index a1c9f55e41d4a6dd97bc59bebf7f3e7e42cd7c04..49606c425bf1abbf69746ef66a395719b3ace74e 100644 (file)
@@ -82,8 +82,9 @@ docstring const InsetRef::getScreenLabel(Buffer const &) const
 int InsetRef::latex(Buffer const &, odocstream & os,
                    OutputParams const &) const
 {
-       // Don't output p_["name"], this is only used in docbook
-       InsetCommandParams p(getCmdName());
+       // We don't want to output p_["name"], since that is only used 
+       // in docbook. So we construct new params, without it, and use that.
+       InsetCommandParams p("ref", getCmdName());
        p["reference"] = getParam("reference");
        os << escape(p.getCommand());
        return 0;