]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetlabel.C
Rename ascii to plaintext and LatexRunParams to OutputParams.
[lyx.git] / src / insets / insetlabel.C
index 2ebb685295e86b4ca01490d5b20c2308b010f4aa..16978b739845e99c8e579be621d4c868f9a107e7 100644 (file)
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-1999 The LyX Team.
+/**
+ * \file insetlabel.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * ======================================================*/
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "insetlabel.h"
 
-/* Label. Used to insert a label automatically */
+#include "BufferView.h"
+#include "dispatchresult.h"
+#include "funcrequest.h"
 
+#include "frontends/LyXView.h"
 
-InsetLabel::InsetLabel(string const & cmd)
-{
-       scanCommand(cmd);
-}
+#include "support/lstrings.h"
+
+#include "support/std_ostream.h"
+
+using lyx::support::escape;
+
+using std::string;
+using std::ostream;
+
+
+InsetLabel::InsetLabel(InsetCommandParams const & p)
+       : InsetCommand(p)
+{}
 
 
 InsetLabel::~InsetLabel()
 {
+       InsetCommandMailer("label", *this).hideDialog();
 }
 
 
-Inset* InsetLabel::Clone()
+std::auto_ptr<InsetBase> InsetLabel::clone() const
 {
-       InsetLabel *result = new InsetLabel(getCommand());
-       return result;
+       return std::auto_ptr<InsetBase>(new InsetLabel(params()));
 }
 
 
-int InsetLabel::GetNumberOfLabels() const
+void InsetLabel::getLabelList(Buffer const &, std::vector<string> & list) const
 {
-       return 1;
+       list.push_back(getContents());
 }
 
 
-string InsetLabel::getLabel(int) const
+string const InsetLabel::getScreenLabel(Buffer const &) const
 {
-       return contents;
+       return getContents();
 }
 
-int InsetLabel::Latex(FILE *file, signed char /*fragile*/)
+
+DispatchResult
+InsetLabel::priv_dispatch(FuncRequest const & cmd,
+                         idx_type & idx, pos_type & pos)
 {
-       fprintf(file, "%s", escape(getCommand()).c_str());
-       return 0;
+       BOOST_ASSERT(cmd.view());
+       BufferView * const bv = cmd.view();
+
+       switch (cmd.action) {
+
+       case LFUN_MOUSE_RELEASE:
+               InsetCommandMailer("label", *this).showDialog(bv);
+               return DispatchResult(true, true);
+
+       case LFUN_INSET_MODIFY: {
+               InsetCommandParams p;
+               InsetCommandMailer::string2params(cmd.argument, p);
+               if (p.getCmdName().empty())
+                       return DispatchResult(false);
+
+               bool clean = true;
+               if (bv && p.getContents() != params().getContents()) {
+                       clean = bv->ChangeRefsIfUnique(params().getContents(),
+                                                      p.getContents());
+               }
+
+               setParams(p);
+               bv->updateInset(this);
+               return DispatchResult(true, true);
+       }
+
+       default:
+               return InsetCommand::priv_dispatch(cmd, idx, pos);
+       }
 }
 
 
-int InsetLabel::Latex(string &file, signed char /*fragile*/)
+int InsetLabel::latex(Buffer const &, ostream & os,
+                     OutputParams const &) const
 {
-       file += escape(getCommand());
+       os << escape(getCommand());
        return 0;
 }
 
 
-int InsetLabel::Linuxdoc(string &file)
+int InsetLabel::plaintext(Buffer const &, ostream & os,
+                     OutputParams const &) const
 {
-       file += "<label id=\"" + getContents() +"\" >";
+       os << '<' << getContents()  << '>';
        return 0;
 }
 
 
-int InsetLabel::DocBook(string &file)
+int InsetLabel::linuxdoc(Buffer const &, ostream & os,
+                        OutputParams const &) const
 {
-       file += "<anchor id=\"" + getContents() +"\" >";
+       os << "<label id=\"" << getContents() << "\" >";
        return 0;
 }
 
 
-// This function escapes 8-bit characters and other problematic characters
-// It's exactly the same code as in insetref.C.
-string InsetLabel::escape(string const & lab) const {
-       char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
-                             '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-       string enc;
-       for (string::size_type i=0; i<lab.length(); i++) {
-               unsigned char c=lab[i];
-               if (c >= 128 || c=='=' || c=='%') {
-                       enc += '=';
-                       enc += hexdigit[c>>4];
-                       enc += hexdigit[c & 15];
-               } else {
-                       enc += (char) c;
-               }
-       }
-       return enc;
+int InsetLabel::docbook(Buffer const &, ostream & os,
+                       OutputParams const &) const
+{
+       os << "<anchor id=\"" << getContents() << "\">";
+       return 0;
 }