]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetref.C
Some more changes for updating text-insets.
[lyx.git] / src / insets / insetref.C
index 0a13720d03237c5e0dbd1968c9b4a2c24ab77e57..b211db9ff5447af221be689ac36f79fb9990b639 100644 (file)
 #include "lyxfunc.h"
 #include "commandtags.h"
 #include "gettext.h"
+#include "LaTeXFeatures.h"
+
+using std::ostream;
+using std::endl;
 
 extern BufferView * current_view;
 
@@ -23,10 +27,7 @@ InsetRef::InsetRef(string const & cmd, Buffer * bf)
        : master(bf)
 {
        scanCommand(cmd);
-       if (getCmdName() == "ref")
-               flag = InsetRef::REF;
-       else
-               flag = InsetRef::PAGE_REF;
+       GenerateFlag();
 }
 
 
@@ -36,10 +37,39 @@ InsetRef::InsetRef(InsetCommand const & inscmd, Buffer * bf)
        setCmdName(inscmd.getCmdName());
        setContents(inscmd.getContents());
        setOptions(inscmd.getOptions());
+       GenerateFlag();
+}
+
+
+void InsetRef::GenerateFlag()
+{
        if (getCmdName() == "ref")
-               flag = InsetRef::REF;
+               flag = REF;
+       else if (getCmdName() == "pageref")
+               flag = PAGE_REF;
+       else if (getCmdName() == "vref")
+               flag = VREF;
+       else if (getCmdName() == "vpageref")
+               flag = VPAGE_REF;
+       else if (getCmdName() == "prettyref")
+               flag = PRETTY_REF;
+       else {
+               lyxerr << "ERROR (InsetRef::GenerateFlag): Unknown command name "
+                      << getCmdName() << endl;
+               flag = REF;
+       }
+}
+
+
+void InsetRef::Toggle() {
+       static string const cmd_names[REF_LAST+1] 
+               = {"ref", "pageref", "vref", "vpageref", "prettyref"};
+       
+       if (flag == REF_LAST)
+               flag = REF_FIRST;
        else
-               flag = InsetRef::PAGE_REF;
+               flag = static_cast<Ref_Flags>(flag + 1);
+       setCmdName(cmd_names[flag]);
 }
 
 
@@ -52,12 +82,10 @@ void InsetRef::Edit(BufferView * bv, int, int, unsigned int)
 
 string InsetRef::getScreenLabel() const
 {
-       string temp;
-       if (flag == InsetRef::PAGE_REF)
-               temp += _("Page: ");
-       else 
-               temp += _("Ref: ");
-       temp += getContents();
+       static char const * labels[REF_LAST+1]
+               = { N_("Ref: "), N_("Page: "), N_("TextRef: "), N_("TextPage: "),
+                   N_("PrettyRef: ")};
+       string temp = _(labels[flag]) + getContents();
        if(!current_view->buffer()->isLatex()
           && !getOptions().empty()) {
                temp += "||";
@@ -67,7 +95,8 @@ string InsetRef::getScreenLabel() const
 }
 
 
-int InsetRef::Latex(ostream & os, signed char /*fragile*/) const
+int InsetRef::Latex(Buffer const *, ostream & os,
+                   bool /*fragile*/, bool /*fs*/) const
 {
        if(getOptions().empty())
                os << escape(getCommand());
@@ -81,41 +110,14 @@ int InsetRef::Latex(ostream & os, signed char /*fragile*/) const
 }
 
 
-#ifndef USE_OSTREAM_ONLY
-int InsetRef::Latex(string & file, signed char /*fragile*/) const
+int InsetRef::Ascii(Buffer const *, ostream & os) const
 {
-       if(getOptions().empty())
-               file += escape(getCommand());
-       else {
-               string ns;
-               InsetCommand clone = InsetCommand(getCmdName(),
-                                                 getContents(), ns);
-               file += escape(clone.getCommand());
-       }
+       os << "[" << getContents() << "]";
        return 0;
 }
 
 
-int InsetRef::Linuxdoc(string & file) const
-{
-       file += "<ref id=\"" + getContents()
-               + "\" name=\""+ getOptions() +"\" >" ;
-
-       return 0;
-}
-
-
-int InsetRef::DocBook(string & file) const
-{
-       file += "<link linkend=\"" + getContents()
-               + "\">"+ getOptions() +"</link>" ;
-
-       return 0;
-}
-
-#else
-
-int InsetRef::Linuxdoc(ostream & os) const
+int InsetRef::Linuxdoc(Buffer const *, ostream & os) const
 {
        os << "<ref id=\"" << getContents()
           << "\" name=\"" << getOptions() << "\" >";
@@ -123,13 +125,12 @@ int InsetRef::Linuxdoc(ostream & os) const
 }
 
 
-int InsetRef::DocBook(ostream & os) const
+int InsetRef::DocBook(Buffer const *, ostream & os) const
 {
        os << "<link linkend=\"" << getContents()
           << "\">" << getOptions() << "</link>";
        return 0;
 }
-#endif
 
 
 // This function escapes 8-bit characters and other problematic characters
@@ -151,3 +152,19 @@ string InsetRef::escape(string const & lab) const
        }
        return enc;
 }
+
+void InsetRef::Validate(LaTeXFeatures & features) const
+{
+       switch (flag) {
+       case VREF:
+       case VPAGE_REF: 
+               features.varioref = true;
+               break;
+       case PRETTY_REF:
+               features.prettyref = true;
+               break;
+       case REF:
+       case PAGE_REF:
+               break;
+       }
+}