]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetlabel.C
Hopefully fixed the redo problems with insets!
[lyx.git] / src / insets / insetlabel.C
index 9e5143df54f8e7d4046b4f3cafe507a7a008eef7..590b50a65dd85f6a5218a630da96d86c7524a6c1 100644 (file)
@@ -4,7 +4,7 @@
  *           LyX, The Document Processor
  *      
  *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-1999 The LyX Team.
+ *          Copyright 1995-2001 The LyX Team.
  *
  * ====================================================== */
 
 #endif
 
 #include "insetlabel.h"
+#include "support/LOstream.h"
+#include "frontends/Alert.h"
+#include "support/lstrings.h" //frontStrip, strip
+#include "lyxtext.h"
+#include "buffer.h"
+#include "gettext.h"
+#include "BufferView.h"
+#include "support/lstrings.h"
+
+using std::ostream;
+using std::vector;
+using std::pair;
 
 /* Label. Used to insert a label automatically */
 
 
-InsetLabel::InsetLabel(string const & cmd)
-{
-       scanCommand(cmd);
-}
+InsetLabel::InsetLabel(InsetCommandParams const & p, bool)
+       : InsetCommand(p)
+{}
 
 
-Inset * 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, unsigned int)
 {
-       return 1;
+       pair<bool, string> result = Alert::askForText(_("Enter label:"), getContents());
+       if (result.first) {
+               string new_contents = frontStrip(strip(result.second));
+               if (!new_contents.empty() &&
+                   getContents() != new_contents) {
+                       bv->buffer()->markDirty();
+                       bool flag = bv->ChangeRefsIfUnique(getContents(),
+                                                          new_contents);
+                       setContents(new_contents);
+                       bv->text->redoParagraph(bv);
+                       if (flag) {
+                               bv->redraw();
+                               bv->fitCursor();
+                       } else
+                               bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+               }
+       }
 }
 
 
-string InsetLabel::getLabel(int) const
+void InsetLabel::edit(BufferView * bv, bool)
 {
-       return contents;
+       edit(bv, 0, 0, 0);
 }
 
 
-int InsetLabel::Latex(ostream & os, signed char /*fragile*/) const
+int InsetLabel::latex(Buffer const *, ostream & os,
+                     bool /*fragile*/, bool /*fs*/) const
 {
        os << escape(getCommand());
        return 0;
 }
 
-
-int InsetLabel::Latex(string & file, signed char /*fragile*/) const
+int InsetLabel::ascii(Buffer const *, ostream & os, int) const
 {
-       file += escape(getCommand());
+       os << "<" << getContents()  << ">";
        return 0;
 }
 
 
-int InsetLabel::Linuxdoc(string & file) const
+int InsetLabel::linuxdoc(Buffer const *, ostream & os) const
 {
-       file += "<label id=\"" + getContents() +"\" >";
+       os << "<label id=\"" << getContents() << "\" >";
        return 0;
 }
 
 
-int InsetLabel::DocBook(string & file) const
+int InsetLabel::docbook(Buffer const *, ostream & os) const
 {
-       file += "<anchor id=\"" + getContents() +"\" >";
+       os << "<anchor id=\"" << getContents() << "\" ></anchor>";
        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;
-}