]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetPhantom.cpp
Better TOC output for XHTML, per Rob and Pavel.
[lyx.git] / src / insets / InsetPhantom.cpp
index 3ba99b11332a3f6a1a48d258a74f159785217e0c..9e3808f0e7ca38d1d9bc4f333fc5411ac3360145 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "support/docstream.h"
 #include "support/gettext.h"
+#include "support/lstrings.h"
 #include "support/Translator.h"
 
 #include "frontends/Application.h"
@@ -111,7 +112,7 @@ void InsetPhantomParams::read(Lexer & lex)
 //
 /////////////////////////////////////////////////////////////////////
 
-InsetPhantom::InsetPhantom(Buffer const & buf, string const & label)
+InsetPhantom::InsetPhantom(Buffer * buf, string const & label)
        : InsetCollapsable(buf)
 {
        setDrawFrame(false);
@@ -125,13 +126,7 @@ InsetPhantom::~InsetPhantom()
 }
 
 
-docstring InsetPhantom::editMessage() const
-{
-       return _("Opened Phantom Inset");
-}
-
-
-docstring InsetPhantom::name() const 
+docstring InsetPhantom::layoutName() const
 {
        return from_ascii("Phantom:" + phantomtranslator().find(params_.type));
 }
@@ -159,7 +154,7 @@ void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
        ColorCode const origcol = pi.base.font.color();
        pi.base.font.setColor(Color_special);
        pi.base.font.setColor(origcol);
-       Dimension const dim = dimension(*pi.base.bv);
+       Dimension const dim = Inset::dimension(*pi.base.bv);
 
        if (params_.type == InsetPhantomParams::Phantom ||
                params_.type == InsetPhantomParams::VPhantom) {
@@ -261,11 +256,13 @@ bool InsetPhantom::showInsetDialog(BufferView * bv) const
 
 void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
+               cur.recordUndoInset(ATOMIC_UNDO, this);
                string2params(to_utf8(cmd.argument()), params_);
-               setLayout(buffer().params());
+               setButtonLabel();
+               cur.forceBufferUpdate();
                break;
 
        case LFUN_INSET_DIALOG_UPDATE:
@@ -282,10 +279,14 @@ void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & flag) const
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY:
-       case LFUN_INSET_SETTINGS:
+               if (cmd.getArg(0) == "phantom") {
+                       InsetPhantomParams params;
+                       string2params(to_utf8(cmd.argument()), params);
+                       flag.setOnOff(params_.type == params.type);
+               }
                flag.setEnabled(true);
                return true;
 
@@ -301,21 +302,12 @@ bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 docstring InsetPhantom::toolTip(BufferView const &, int, int) const
 {
-       OutputParams rp(&buffer().params().encoding());
-       odocstringstream ods;
-       InsetCollapsable::plaintext(ods, rp);
-       docstring content_tip = ods.str();
-       // shorten it if necessary
-       if (content_tip.size() > 200)
-               content_tip = content_tip.substr(0, 200) + "...";
-       docstring res = phantomtranslator_loc().find(params_.type);
-       if (!content_tip.empty())
-               res += from_ascii(": ") + content_tip;
-       return res;
+       docstring const res = phantomtranslator_loc().find(params_.type);
+       return toolTipText(res + from_ascii(": "));
 }
 
 
-int InsetPhantom::latex(odocstream & os, OutputParams const & runparams) const
+void InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const
 {
        if (params_.type == InsetPhantomParams::Phantom)
                os << "\\phantom{";
@@ -323,10 +315,8 @@ int InsetPhantom::latex(odocstream & os, OutputParams const & runparams) const
                os << "\\hphantom{";
        else if (params_.type == InsetPhantomParams::VPhantom)
                os << "\\vphantom{";
-       int const i = InsetCollapsable::latex(os, runparams);
+       InsetCollapsable::latex(os, runparams);
        os << "}";
-
-       return i;
 }
 
 
@@ -363,7 +353,12 @@ int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams) const
 }
 
 
-docstring InsetPhantom::contextMenu(BufferView const &, int, int) const
+docstring InsetPhantom::xhtml(XHTMLStream &, OutputParams const &) const
+{
+       return docstring();
+}
+
+docstring InsetPhantom::contextMenuName() const
 {
        return from_ascii("context-phantom");
 }