]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetNewpage.cpp
Context menu for InsetArgument
[lyx.git] / src / insets / InsetNewpage.cpp
index e7b9b0523a2ac251187ef7da76a9a5a23b16de43..85e8d14dd394d02539d1963015f389613f141ddf 100644 (file)
@@ -3,8 +3,8 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
- * \author Jürgen Spitzmüller
+ * \author André Pönitz
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
 
 #include "InsetNewpage.h"
 
+#include "Cursor.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
-#include "Text.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
+#include "output_xhtml.h"
+#include "Text.h"
 #include "TextMetrics.h"
 
 #include "frontends/FontMetrics.h"
@@ -34,12 +36,12 @@ using namespace std;
 
 namespace lyx {
 
-InsetNewpage::InsetNewpage()
+       InsetNewpage::InsetNewpage() : Inset(0)
 {}
 
 
 InsetNewpage::InsetNewpage(InsetNewpageParams const & params)
-       : params_(params)
+       : Inset(0), params_(params)
 {}
 
 
@@ -65,27 +67,20 @@ void InsetNewpageParams::write(ostream & os) const
 
 void InsetNewpageParams::read(Lexer & lex)
 {
-       lex.next();
-       string const command = lex.getString();
+       lex.setContext("InsetNewpageParams::read");
+       string token;
+       lex >> token;
 
-       if (command == "newpage")
+       if (token == "newpage")
                kind = InsetNewpageParams::NEWPAGE;
-       else if (command == "pagebreak")
+       else if (token == "pagebreak")
                kind = InsetNewpageParams::PAGEBREAK;
-       else if (command == "clearpage")
+       else if (token == "clearpage")
                kind = InsetNewpageParams::CLEARPAGE;
-       else if (command == "cleardoublepage")
+       else if (token == "cleardoublepage")
                kind = InsetNewpageParams::CLEARDOUBLEPAGE;
        else
-               lex.printError("InsetNewpage: Unknown kind: `$$Token'");
-
-       string token;
-       lex >> token;
-       if (!lex)
-               return;
-       if (token != "\\end_inset")
-               lex.printError("Missing \\end_inset at this point. "
-                              "Read: `$$Token'");
+               lex.printError("Unknown kind");
 }
 
 
@@ -99,6 +94,7 @@ void InsetNewpage::write(ostream & os) const
 void InsetNewpage::read(Lexer & lex)
 {
        params_.read(lex);
+       lex >> "\\end_inset";
 }
 
 
@@ -142,10 +138,11 @@ void InsetNewpage::draw(PainterInfo & pi, int x, int y) const
 
 void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
 
        case LFUN_INSET_MODIFY: {
                InsetNewpageParams params;
+               cur.recordUndo();
                string2params(to_utf8(cmd.argument()), params);
                params_.kind = params.kind;
                break;
@@ -161,16 +158,15 @@ void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
 bool InsetNewpage::getStatus(Cursor & cur, FuncRequest const & cmd,
        FuncStatus & status) const
 {
-       switch (cmd.action) {
+       switch (cmd.action()) {
        // we handle these
        case LFUN_INSET_MODIFY:
                if (cmd.getArg(0) == "newpage") {
                        InsetNewpageParams params;
                        string2params(to_utf8(cmd.argument()), params);
                        status.setOnOff(params_.kind == params.kind);
-               } else {
-                       status.enabled(true);
-               }
+               } 
+               status.setEnabled(true);
                return true;
        default:
                return Inset::getStatus(cur, cmd, status);
@@ -203,26 +199,21 @@ docstring InsetNewpage::insetLabel() const
 ColorCode InsetNewpage::ColorName() const
 {
        switch (params_.kind) {
-               case InsetNewpageParams::NEWPAGE:
-                       return Color_newpage;
-                       break;
                case InsetNewpageParams::PAGEBREAK:
                        return Color_pagebreak;
                        break;
+               case InsetNewpageParams::NEWPAGE:
                case InsetNewpageParams::CLEARPAGE:
-                       return Color_newpage;
-                       break;
                case InsetNewpageParams::CLEARDOUBLEPAGE:
                        return Color_newpage;
                        break;
-               default:
-                       return Color_newpage;
-                       break;
        }
+       // not really useful, but to avoids gcc complaints
+       return Color_newpage;
 }
 
 
-int InsetNewpage::latex(odocstream & os, OutputParams const &) const
+void InsetNewpage::latex(otexstream & os, OutputParams const &) const
 {
        switch (params_.kind) {
                case InsetNewpageParams::NEWPAGE:
@@ -241,7 +232,6 @@ int InsetNewpage::latex(odocstream & os, OutputParams const &) const
                        os << "\\newpage{}";
                        break;
        }
-       return 0;
 }
 
 
@@ -259,9 +249,16 @@ int InsetNewpage::docbook(odocstream & os, OutputParams const &) const
 }
 
 
-docstring InsetNewpage::contextMenu(BufferView const &, int, int) const
+docstring InsetNewpage::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       xs << html::CompTag("br");
+       return docstring();
+}
+
+
+string InsetNewpage::contextMenuName() const
 {
-       return from_ascii("context-newpage");
+       return "context-newpage";
 }
 
 
@@ -272,7 +269,7 @@ void InsetNewpage::string2params(string const & in, InsetNewpageParams & params)
                return;
 
        istringstream data(in);
-       Lexer lex(0,0);
+       Lexer lex;
        lex.setStream(data);
 
        string name;