]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetlabel.C
reformatting and remove using delc
[lyx.git] / src / insets / insetlabel.C
index b056de2acc890c73dbbfb07e5de8f088df048c0b..cf48ce3d4a1d9c7febe98c6314d2ca9ab55248df 100644 (file)
 #endif
 
 #include "insetlabel.h"
+#include "support/LOstream.h"
+#include "lyx_gui_misc.h"     //askForText
+#include "support/lstrings.h" //frontStrip, strip
+#include "lyxtext.h"
+#include "buffer.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)
+       : 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;
+       if (bv->buffer()->isReadonly()) {
+               WarnReadonly(bv->buffer()->fileName());
+               return;
+       }
+
+       pair<bool, string> result = 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(getLyXText(bv));
+                       } else
+                               bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
+               }
+       }
 }
 
 
-string InsetLabel::getLabel(int) const
+int InsetLabel::Latex(Buffer const *, ostream & os,
+                     bool /*fragile*/, bool /*fs*/) const
 {
-       return contents;
+       os << escape(getCommand());
+       return 0;
 }
 
-
-int InsetLabel::Latex(ostream & os,
-                     signed char /*fragile*/, bool /*fs*/) const
+int InsetLabel::Ascii(Buffer const *, ostream & os, int) const
 {
-       os << escape(getCommand());
+       os << "<" << getContents()  << ">";
        return 0;
 }
 
 
-int InsetLabel::Linuxdoc(ostream & os) const
+int InsetLabel::Linuxdoc(Buffer const *, ostream & os) const
 {
        os << "<label id=\"" << getContents() << "\" >";
        return 0;
 }
 
 
-int InsetLabel::DocBook(ostream & os) const
+int InsetLabel::DocBook(Buffer const *, ostream & os) const
 {
-       os << "<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 {
+string const 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;