]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetFloat.cpp
Stupid bug fix.
[lyx.git] / src / insets / InsetFloat.cpp
index df970d3de98dea2e3e3437d872e56b20b9592e7f..a595b2e0321f5560530f58b5abef6d6fd352c9b4 100644 (file)
 #include "ParIterator.h"
 #include "TextClass.h"
 
+#include "support/convert.h"
 #include "support/debug.h"
+#include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
-#include "support/docstream.h"
-#include "support/convert.h"
+
+#include "frontends/Application.h"
 
 using namespace std;
 
-namespace lyx {
 
+namespace lyx {
 
 // With this inset it will be possible to support the latex package
 // float.sty, and I am sure that with this and some additional support
@@ -121,7 +123,25 @@ InsetFloat::InsetFloat(Buffer const & buf, string const & type)
 
 InsetFloat::~InsetFloat()
 {
-       InsetFloatMailer(*this).hideDialog();
+       hideDialogs("float", this);
+}
+
+
+docstring InsetFloat::toolTip(BufferView const & bv, int x, int y) const
+{
+       if (InsetCollapsable::toolTip(bv, x, y).empty())
+               return docstring();
+
+       docstring default_tip;
+       if (isOpen())
+               default_tip = _("Left-click to collapse the inset");
+       else
+               default_tip = _("Left-click to open the inset");
+       OutputParams rp(&buffer().params().encoding());
+       docstring caption_tip = getCaptionText(rp);
+       if (!isOpen() && !caption_tip.empty())
+               return caption_tip + '\n' + default_tip;
+       return default_tip;
 }
 
 
@@ -131,29 +151,18 @@ void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                InsetFloatParams params;
-               InsetFloatMailer::string2params(to_utf8(cmd.argument()), params);
+               string2params(to_utf8(cmd.argument()), params);
                params_.placement = params.placement;
                params_.wide      = params.wide;
                params_.sideways  = params.sideways;
                params_.subfloat  = params.subfloat;
-               wide(params_.wide, cur.buffer().params());
-               sideways(params_.sideways, cur.buffer().params());
+               setWide(params_.wide, cur.buffer().params());
+               setSideways(params_.sideways, cur.buffer().params());
                break;
        }
 
        case LFUN_INSET_DIALOG_UPDATE: {
-               InsetFloatMailer(*this).updateDialog(&cur.bv());
-               break;
-       }
-
-       case LFUN_MOUSE_RELEASE: {
-               if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
-                       if (params_.subfloat)
-                               break;
-                       InsetFloatMailer(*this).showDialog(&cur.bv());
-                       break;
-               }
-               InsetCollapsable::doDispatch(cur, cmd);
+               cur.bv().updateDialog("float", params2string(params()));
                break;
        }
 
@@ -171,7 +180,7 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_INSET_MODIFY:
        case LFUN_INSET_DIALOG_UPDATE:
-               flag.enabled(true);
+               flag.setEnabled(true);
                return true;
 
        default:
@@ -182,15 +191,16 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetFloat::updateLabels(ParIterator const & it)
 {
-       Counters & cnts = buffer().params().documentClass().counters();
+       Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
        string const saveflt = cnts.current_float();
        bool const savesubflt = cnts.isSubfloat();
 
-       bool const subflt = it.innerInsetOfType(FLOAT_CODE);
+       bool const subflt = (it.innerInsetOfType(FLOAT_CODE)
+                            || it.innerInsetOfType(WRAP_CODE));
        // floats can only embed subfloats of their own kind
        if (subflt)
                params_.type = saveflt;
-       subfloat(subflt, buffer().params());
+       setSubfloat(subflt, buffer().params());
 
        // Tell to captions what the current float is
        cnts.current_float(params().type);
@@ -225,32 +235,11 @@ void InsetFloatParams::write(ostream & os) const
 
 void InsetFloatParams::read(Lexer & lex)
 {
-       string token;
-       lex >> token;
-       if (token == "placement") {
+       lex.setContext("InsetFloatParams::read");
+       if (lex.checkFor("placement"))
                lex >> placement;
-       } else {
-               // take countermeasures
-               lex.pushToken(token);
-       }
-       lex >> token;
-       if (token == "wide") {
-               lex >> wide;
-       } else {
-               lyxerr << "InsetFloat::Read:: Missing wide!"
-               << endl;
-               // take countermeasures
-               lex.pushToken(token);
-       }
-       lex >> token;
-       if (token == "sideways") {
-               lex >> sideways;
-       } else {
-               lyxerr << "InsetFloat::Read:: Missing sideways!"
-               << endl;
-               // take countermeasures
-               lex.pushToken(token);
-       }
+       lex >> "wide" >> wide;
+       lex >> "sideways" >> sideways;
 }
 
 
@@ -264,9 +253,9 @@ void InsetFloat::write(ostream & os) const
 void InsetFloat::read(Lexer & lex)
 {
        params_.read(lex);
-       wide(params_.wide, buffer().params());
-       sideways(params_.sideways, buffer().params());
-       subfloat(params_.subfloat, buffer().params());
+       setWide(params_.wide, buffer().params());
+       setSideways(params_.sideways, buffer().params());
+       setSubfloat(params_.subfloat, buffer().params());
        InsetCollapsable::read(lex);
 }
 
@@ -392,12 +381,13 @@ bool InsetFloat::insetAllowed(InsetCode code) const
 bool InsetFloat::showInsetDialog(BufferView * bv) const
 {
        if (!InsetText::showInsetDialog(bv))
-               InsetFloatMailer(const_cast<InsetFloat &>(*this)).showDialog(bv);
+               bv->showDialog("float", params2string(params()),
+                       const_cast<InsetFloat *>(this));
        return true;
 }
 
 
-void InsetFloat::wide(bool w, BufferParams const & bp)
+void InsetFloat::setWide(bool w, BufferParams const & bp)
 {
        params_.wide = w;
        docstring lab = _("float: ") + floatName(params_.type, bp);
@@ -407,7 +397,7 @@ void InsetFloat::wide(bool w, BufferParams const & bp)
 }
 
 
-void InsetFloat::sideways(bool s, BufferParams const & bp)
+void InsetFloat::setSideways(bool s, BufferParams const & bp)
 {
        params_.sideways = s;
        docstring lab = _("float: ") + floatName(params_.type, bp);
@@ -417,7 +407,7 @@ void InsetFloat::sideways(bool s, BufferParams const & bp)
 }
 
 
-void InsetFloat::subfloat(bool s, BufferParams const & bp)
+void InsetFloat::setSubfloat(bool s, BufferParams const & bp)
 {
        params_.subfloat = s;
        docstring lab = _("float: ") + floatName(params_.type, bp);
@@ -453,52 +443,49 @@ docstring InsetFloat::getCaption(OutputParams const & runparams) const
 }
 
 
-string const InsetFloatMailer::name_("float");
-
-InsetFloatMailer::InsetFloatMailer(InsetFloat & inset)
-       : inset_(inset)
-{}
-
-
-string const InsetFloatMailer::inset2string(Buffer const &) const
+docstring InsetFloat::getCaptionText(OutputParams const & runparams) const
 {
-       return params2string(inset_.params());
+       if (paragraphs().empty())
+               return docstring();
+
+       ParagraphList::const_iterator pit = paragraphs().begin();
+       for (; pit != paragraphs().end(); ++pit) {
+               InsetList::const_iterator it = pit->insetList().begin();
+               for (; it != pit->insetList().end(); ++it) {
+                       Inset & inset = *it->inset;
+                       if (inset.lyxCode() == CAPTION_CODE) {
+                               odocstringstream ods;
+                               InsetCaption * ins =
+                                       static_cast<InsetCaption *>(it->inset);
+                               ins->getCaptionText(ods, runparams);
+                               return ods.str();
+                       }
+               }
+       }
+       return docstring();
 }
 
 
-void InsetFloatMailer::string2params(string const & in,
-                                    InsetFloatParams & params)
+void InsetFloat::string2params(string const & in, InsetFloatParams & params)
 {
        params = InsetFloatParams();
        if (in.empty())
                return;
 
        istringstream data(in);
-       Lexer lex(0,0);
+       Lexer lex;
        lex.setStream(data);
-
-       string name;
-       lex >> name;
-       if (!lex || name != name_)
-               return print_mailer_error("InsetFloatMailer", in, 1, name_);
-
-       // This is part of the inset proper that is usually swallowed
-       // by Text::readInset
-       string id;
-       lex >> id;
-       if (!lex || id != "Float")
-               return print_mailer_error("InsetBoxMailer", in, 2, "Float");
-
-       // We have to read the type here!
-       lex >> params.type;
+       lex.setContext("InsetFloat::string2params");
+       lex >> "float" >> "Float";
+       lex >> params.type; // We have to read the type here!
        params.read(lex);
 }
 
 
-string const InsetFloatMailer::params2string(InsetFloatParams const & params)
+string InsetFloat::params2string(InsetFloatParams const & params)
 {
        ostringstream data;
-       data << name_ << ' ';
+       data << "float" << ' ';
        params.write(data);
        return data.str();
 }