]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetlabel.C
parlist-a-1.diff
[lyx.git] / src / insets / insetlabel.C
index fc2b54719f090a253f2dc3aa006d64ba3dbf230a..66963db35005b0d03398cbd7e78de312fdfb6f78 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"
+#include "buffer.h"
+#include "BufferView.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "lyxtext.h"
+
+#include "support/lstrings.h"
+#include "support/LOstream.h"
+#include "support/lstrings.h" //frontStrip, strip
+
+using std::ostream;
+using std::vector;
+using std::pair;
+
 
-/* Label. Used to insert a label automatically */
+InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
+       : InsetCommand(p)
+{}
 
 
-InsetLabel::InsetLabel(string const & cmd)
+InsetLabel::~InsetLabel()
 {
-       scanCommand(cmd);
+       InsetCommandMailer mailer("label", *this);
+       mailer.hideDialog();
 }
 
 
-InsetLabel * InsetLabel::Clone() const
+vector<string> const InsetLabel::getLabelList() const
 {
-       return new InsetLabel(getCommand());
+       return vector<string>(1, getContents());
 }
 
 
-int InsetLabel::GetNumberOfLabels() const
+void InsetLabel::edit(BufferView * bv, int, int, mouse_button::state)
 {
-       return 1;
+       InsetCommandMailer mailer("label", *this);
+       mailer.showDialog(bv);
 }
 
 
-string InsetLabel::getLabel(int) const
+dispatch_result InsetLabel::localDispatch(FuncRequest const & cmd)
 {
-       return contents;
+       Inset::RESULT result = UNDISPATCHED;
+
+       switch (cmd.action) {
+       case LFUN_INSET_MODIFY: {
+               InsetCommandParams p;
+               InsetCommandMailer::string2params(cmd.argument, p);
+               if (p.getCmdName().empty())
+                       return UNDISPATCHED;
+
+               bool clean = true;
+               if (view() && p.getContents() != params().getContents()) {
+                       clean = view()->ChangeRefsIfUnique(params().getContents(),
+                                                          p.getContents());
+               }
+
+               setParams(p);
+               cmd.view()->updateInset(this);
+               result = DISPATCHED;
+       }
+       break;
+
+       default:
+               result = InsetCommand::localDispatch(cmd);
+       }
+
+       return result;
 }
 
-int InsetLabel::Latex(FILE * file, signed char /*fragile*/)
+
+void InsetLabel::edit(BufferView * bv, bool)
 {
-       fprintf(file, "%s", escape(getCommand()).c_str());
-       return 0;
+       edit(bv, 0, 0, mouse_button::none);
 }
 
 
-int InsetLabel::Latex(string & file, signed char /*fragile*/)
+int InsetLabel::latex(Buffer const *, ostream & os,
+                     bool /*fragile*/, bool /*fs*/) const
 {
-       file += escape(getCommand());
+       os << escape(getCommand());
        return 0;
 }
 
 
-int InsetLabel::Linuxdoc(string & file)
+int InsetLabel::ascii(Buffer const *, ostream & os, int) const
 {
-       file += "<label id=\"" + getContents() +"\" >";
+       os << '<' << getContents()  << '>';
        return 0;
 }
 
 
-int InsetLabel::DocBook(string & file)
+int InsetLabel::linuxdoc(Buffer const *, ostream & os) 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 += c;
-               }
-       }
-       return enc;
+int InsetLabel::docbook(Buffer const *, ostream & os, bool) const
+{
+       os << "<anchor id=\"" << getContents() << "\">";
+       return 0;
 }