From: Angus Leeming Date: Wed, 10 Dec 2003 17:28:14 +0000 (+0000) Subject: InsetNote clean-up. X-Git-Tag: 1.6.10~15668 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c2d77773419b02a704ca99a1a52dbe7bbb6c71f8;p=features.git InsetNote clean-up. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8226 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/ChangeLog b/development/ChangeLog index 1346a9e9db..e38452a716 100644 --- a/development/ChangeLog +++ b/development/ChangeLog @@ -1,55 +1,11 @@ +2003-12-10 Angus Leeming + + * FORMAT: document format 226. 2003-12-01 André Pönitz * Code_rules/Recommendations: - * Code_rules/Rules: - + try to implement your class in a way that the automatically generated - + copy constructor and copy assignment work out-of-the box. - -Index: Rules -=================================================================== -RCS file: /usr/local/lyx/cvsroot/lyx-devel/development/Code_rules/Rules,v -retrieving revision 1.14 -diff -u -p -r1.14 Rules ---- Rules 25 Sep 2002 14:26:09 -0000 1.14 -+++ Rules 1 Dec 2003 13:48:53 -0000 -@@ -247,20 +247,6 @@ Formatting - -NOT- - void mangle () // wrong - --* Use of braces -- -- We use braces a lot, even if this lowers the density of the code in -- some cases. In particular we use braces for one-liners in relation -- to if, while, etc. -- -- if (true) { -- do_that(); -- } -- -NOT- -- if (true) -- do_that(); -- -- - * Enumerators - enum { - one = 1, -@@ -293,12 +279,9 @@ Formatting - - * Formatting - -- - Please adapt the formatting of your code to the setting in LyX in that -- particular file. Lars and Asger are slowly, but surely moving the source -- towards Linux kernel style formatting, aka K&R style. We suggest that you -- also do this, but this is NOT something that has been decided generally. -- (a pity - jbl) -- -+ - Adapt the formatting of your code to the one used in the -+ other parts of LyX. In case there is different formatting for -+ the same construct, use the one used more often. - - * Use existing structures - + * Code_rules/Rules: updated 2003-11-05 João Luis M. Assirati diff --git a/development/FORMAT b/development/FORMAT index ca6f7246b8..1ad361c6be 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,5 +1,13 @@ LyX file-format changes ----------------------- + +2003-12-10 Angus Leeming + + * Change the output of InsetNote: + \begin_inset Note -> \begin_inset Note Note + \begin_inset Comment -> \begin_inset Note Comment + \begin_inset Greyedout -> \begin_inset Note Greyedout + 2003-11-28 André Pönitz * Remove space_above/space_below from Paragraph. diff --git a/lib/ChangeLog b/lib/ChangeLog index 9d78f9a86a..29a3a2598c 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,10 @@ +2003-12-10 Angus Leeming + + * lyx2lyx: up the format to 226. + + * lyxconvert_225.py: + * lyxrevert_226.py: convert the Note inset between formats 225 and 226. + 2003-12-10 Jean-Marc Lasgouttes * CREDITS: add Felix Kurth diff --git a/lib/lyx2lyx/lyx2lyx b/lib/lyx2lyx/lyx2lyx index 449c1eda65..1fb1593497 100755 --- a/lib/lyx2lyx/lyx2lyx +++ b/lib/lyx2lyx/lyx2lyx @@ -40,7 +40,7 @@ opt.quiet = 0 format = re.compile(r"(\d)[\.,]?(\d\d)") fileformat = re.compile(r"\\lyxformat\s*(\S*)") -lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225] +lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225, 226] def usage(): print """Usage: lyx2lyx [options] [file] diff --git a/lib/lyx2lyx/lyxconvert_225.py b/lib/lyx2lyx/lyxconvert_225.py new file mode 100644 index 0000000000..8363d7ac49 --- /dev/null +++ b/lib/lyx2lyx/lyxconvert_225.py @@ -0,0 +1,36 @@ +# This file is part of lyx2lyx +# Copyright (C) 2003 José Matos +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +from parser_tools import find_tokens + +def convert_note(lines): + i = 0 + while 1: + i = find_tokens(lines, ["\\begin_inset Note", + "\\begin_inset Comment", + "\\begin_inset Greyedout"], i) + if i == -1: + break + + lines[i] = lines[i][0:13] + 'Note ' + lines[i][13:] + i = i + 1 + +def convert(header, body): + convert_note(body) + +if __name__ == "__main__": + pass diff --git a/lib/lyx2lyx/lyxrevert_226.py b/lib/lyx2lyx/lyxrevert_226.py new file mode 100644 index 0000000000..f0d04e5fba --- /dev/null +++ b/lib/lyx2lyx/lyxrevert_226.py @@ -0,0 +1,35 @@ +# This file is part of lyx2lyx +# Copyright (C) 2003 José Matos +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +from parser_tools import find_token + +def convert_note(lines): + note_header = "\\begin_inset Note " + i = 0 + while 1: + i = find_token(lines, note_header, i) + if i == -1: + break + + lines[i] = "\\begin_inset " + lines[i][len(note_header):] + i = i + 1 + +def convert(header, body): + convert_note(body) + +if __name__ == "__main__": + pass diff --git a/src/ChangeLog b/src/ChangeLog index 21034c64ac..8529d4a9c6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-12-10 Angus Leeming + + * buffer.C: up the format to 226. + + * factory.C: the note inset is now identified simply by 'Note'. + 2003-12-08 Alfredo Braunstein * lyxtext.h, text2.C (setLayout): don't use cursor to iterate, diff --git a/src/buffer.C b/src/buffer.C index e5bd4431fc..e28f687035 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -132,7 +132,7 @@ extern BufferList bufferlist; namespace { -const int LYX_FORMAT = 225; +const int LYX_FORMAT = 226; } // namespace anon diff --git a/src/factory.C b/src/factory.C index f497598942..747fc7a589 100644 --- a/src/factory.C +++ b/src/factory.C @@ -402,8 +402,7 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf) inset.reset(new InsetFormula); } else if (tmptok == "Graphics") { inset.reset(new InsetGraphics); - } else if (tmptok == "Note" || tmptok == "Comment" - || tmptok == "Greyedout") { + } else if (tmptok == "Note") { inset.reset(new InsetNote(buf.params(), tmptok)); } else if (tmptok == "Boxed" || tmptok == "ovalbox" || tmptok == "Shadowbox" || tmptok == "Doublebox" diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index edda46b6fd..aa7c868432 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2003-12-10 Angus Leeming + + * ControlNote.[Ch] (note_gui_tokens): removed; no longer needed. + 2003-12-10 Angus Leeming * ControlBranch.C (dispatchParams): change to invocation of diff --git a/src/frontends/controllers/ControlNote.C b/src/frontends/controllers/ControlNote.C index 6f22c819bc..b7f66a038b 100644 --- a/src/frontends/controllers/ControlNote.C +++ b/src/frontends/controllers/ControlNote.C @@ -16,7 +16,6 @@ #include "gettext.h" -using std::vector; using std::string; @@ -45,15 +44,3 @@ void ControlNote::dispatchParams() string const lfun = InsetNoteMailer::params2string(params()); kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); } - - -void note_gui_tokens(vector & ids, vector & gui_names) -{ - char const * const ids_[] = {"Note", "Comment", "Greyedout"}; - size_t const ids_size = sizeof(ids_) / sizeof(char *); - ids = vector(ids_, ids_ + ids_size); - gui_names.clear(); - gui_names.push_back(_("LyX Note")); - gui_names.push_back(_("Comment")); - gui_names.push_back(_("Greyed Out")); -} diff --git a/src/frontends/controllers/ControlNote.h b/src/frontends/controllers/ControlNote.h index 486a08640b..ad504e9e18 100644 --- a/src/frontends/controllers/ControlNote.h +++ b/src/frontends/controllers/ControlNote.h @@ -40,7 +40,4 @@ private: boost::scoped_ptr params_; }; -/// -void note_gui_tokens(std::vector &, std::vector &); - #endif // CONTROLNOTE_H diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 2751ddb8db..26025ef87b 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2003-12-10 Angus Leeming + + * QNote.C: changes due to the change of type of InsetNoteParams::type + from string to an enum. + 2003-12-10 Angus Leeming * lengthvalidator.[Ch]: make visible to the class. diff --git a/src/frontends/qt2/QNote.C b/src/frontends/qt2/QNote.C index 26823d20b4..a6cfd48e69 100644 --- a/src/frontends/qt2/QNote.C +++ b/src/frontends/qt2/QNote.C @@ -44,14 +44,18 @@ void QNote::build_dialog() void QNote::update_contents() { QRadioButton * rb = 0; - string type(controller().params().type); - if (type == "Note") + switch (controller().params().type) { + case InsetNoteParams::Note: rb = dialog_->noteRB; - else if (type == "Comment") + break; + case InsetNoteParams::Comment: rb = dialog_->commentRB; - else if (type == "Greyedout") + break; + case InsetNoteParams::Greyedout: rb = dialog_->greyedoutRB; + break; + } rb->setChecked(true); } @@ -59,14 +63,14 @@ void QNote::update_contents() void QNote::apply() { - string type; + InsetNoteParams::Type type; if (dialog_->greyedoutRB->isChecked()) - type = "Greyedout"; + type = InsetNoteParams::Greyedout; else if (dialog_->commentRB->isChecked()) - type = "Comment"; + type = InsetNoteParams::Comment; else - type = "Note"; + type = InsetNoteParams::Note; controller().params().type = type; } diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 9b1f3a4922..8103a77717 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,12 @@ +2003-12-10 Angus Leeming + + * FormNote.C: changes due to the change of type of InsetNoteParams::type + from string to an enum. + + * FormNote.[Ch]: + * forms/form_note.fd: re-work so that it has a similar appearance to + that of the Qt frontend. + 2003-12-05 Angus Leeming * FormVCLog.[Ch]: removed. diff --git a/src/frontends/xforms/FormNote.C b/src/frontends/xforms/FormNote.C index 3db5352fc5..1160d69e76 100644 --- a/src/frontends/xforms/FormNote.C +++ b/src/frontends/xforms/FormNote.C @@ -28,7 +28,7 @@ using std::string; typedef FormController > base_class; FormNote::FormNote(Dialog & parent) - : base_class(parent, _("Note")) + : base_class(parent, _("LyX: Note Settings")) {} @@ -36,35 +36,49 @@ void FormNote::build() { dialog_.reset(build_note(this)); - note_gui_tokens(ids_, gui_names_); - for (string::size_type i = 0; i < gui_names_.size(); ++i) { - fl_addto_choice(dialog_->choice_type, gui_names_[i].c_str()); - } - - string str = _("Lyx Note: LyX internal only\n" - "Comment: Export to LaTeX but don't print\n" - "Greyed Out: Print as grey text"); - tooltips().init(dialog_->choice_type, str); + tooltips().init(dialog_->radio_note, + _("LyX internal only")); + tooltips().init(dialog_->radio_comment, + _("Export to LaTeX/Docbook but don't print")); + tooltips().init(dialog_->radio_greyedout, + _("Print as grey text")); bcview().setOK(dialog_->button_ok); - bcview().setApply(dialog_->button_apply); bcview().setCancel(dialog_->button_cancel); } void FormNote::update() { - string type(controller().params().type); - for (string::size_type i = 0; i < gui_names_.size(); ++i) { - if (type == ids_[i]) - fl_set_choice_text(dialog_->choice_type, gui_names_[i].c_str()); - } + FL_OBJECT * rb = 0; + + switch (controller().params().type) { + case InsetNoteParams::Note: + rb = dialog_->radio_note; + break; + case InsetNoteParams::Comment: + rb = dialog_->radio_comment; + break; + case InsetNoteParams::Greyedout: + rb = dialog_->radio_greyedout; + break; + } + + fl_set_button(rb, 1); } void FormNote::apply() { - int i = fl_get_choice(dialog_->choice_type); - controller().params().type = ids_[i - 1]; + InsetNoteParams::Type type; + + if (fl_get_button(dialog_->radio_greyedout)) + type = InsetNoteParams::Greyedout; + else if (fl_get_button(dialog_->radio_comment)) + type = InsetNoteParams::Comment; + else + type = InsetNoteParams::Note; + + controller().params().type = type; } diff --git a/src/frontends/xforms/FormNote.h b/src/frontends/xforms/FormNote.h index fa6e07600f..d444734a2e 100644 --- a/src/frontends/xforms/FormNote.h +++ b/src/frontends/xforms/FormNote.h @@ -32,10 +32,6 @@ private: virtual void build(); /// Update dialog before showing it virtual void update(); - /// - std::vector ids_; - /// - std::vector gui_names_; }; #endif // FORMNOTE_H diff --git a/src/frontends/xforms/forms/form_note.fd b/src/frontends/xforms/forms/form_note.fd index b7e6e09990..e62230aaf2 100644 --- a/src/frontends/xforms/forms/form_note.fd +++ b/src/frontends/xforms/forms/form_note.fd @@ -9,14 +9,14 @@ SnapGrid: 7 =============== FORM =============== Name: form_note -Width: 407 -Height: 113 -Number of Objects: 5 +Width: 225 +Height: 155 +Number of Objects: 9 -------------------- class: FL_BOX type: UP_BOX -box: 0 0 407 113 +box: 0 0 225 155 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -32,63 +32,135 @@ callback: argument: -------------------- -class: FL_CHOICE -type: NORMAL_CHOICE -box: 154 21 217 28 -boxtype: FL_FRAME_BOX -colors: FL_COL1 FL_BLACK -alignment: FL_ALIGN_LEFT +class: FL_LABELFRAME +type: ENGRAVED_FRAME +box: 10 10 205 105 +boxtype: FL_NO_BOX +colors: FL_BLACK FL_COL1 +alignment: FL_ALIGN_TOP_LEFT style: FL_NORMAL_STYLE size: FL_NORMAL_SIZE lcol: FL_BLACK -label: Note Type|#T +label: Type shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: choice_type +name: +callback: +argument: + +-------------------- +class: FL_BEGIN_GROUP +type: 0 +box: 0 10 10 0 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: group_types +callback: +argument: + +-------------------- +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 25 25 185 25 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: LyX Note|#N +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_note callback: C_FormDialogView_InputCB argument: 0 -------------------- -class: FL_BUTTON -type: RETURN_BUTTON -box: 49 70 84 28 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 25 50 185 25 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW alignment: FL_ALIGN_CENTER style: FL_NORMAL_STYLE size: FL_NORMAL_SIZE lcol: FL_BLACK -label: OK -shortcut: ^M +label: Comment|#o +shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: button_ok -callback: C_FormDialogView_OKCB +name: radio_comment +callback: C_FormDialogView_InputCB argument: 0 +-------------------- +class: FL_ROUND3DBUTTON +type: RADIO_BUTTON +box: 25 75 185 25 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Greyed out|#G +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_greyedout +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_END_GROUP +type: 0 +box: 0 0 0 0 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + -------------------- class: FL_BUTTON type: RETURN_BUTTON -box: 154 70 98 28 +box: 10 120 90 25 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER style: FL_NORMAL_STYLE size: FL_NORMAL_SIZE lcol: FL_BLACK -label: Apply|#A +label: OK shortcut: ^M resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: button_apply -callback: C_FormDialogView_ApplyCB +name: button_ok +callback: C_FormDialogView_OKCB argument: 0 -------------------- class: FL_BUTTON type: RETURN_BUTTON -box: 266 70 105 28 +box: 125 120 90 25 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index dba5e2eb63..ada3f05a67 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ +2003-12-10 Angus Leeming + + * insetnote.[Ch]: change the storage type of InsetNoteParams::type + to an enum. Ensuing clean-ups through out the class. + (read, write): now prepend the inset contents with 'Note' to identify + the inset as a note inset. + 2003-12-10 Angus Leeming * insetbranch.[Ch]: changes to the InsetBranchMailer interface. diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index 14f2ec49c6..83888887c7 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -15,6 +15,7 @@ #include "insetnote.h" #include "BufferView.h" +#include "debug.h" #include "dispatchresult.h" #include "funcrequest.h" #include "gettext.h" @@ -24,7 +25,9 @@ #include "metricsinfo.h" #include "paragraph.h" +#include "support/lyxalgo.h" #include "support/std_sstream.h" +#include "support/translator.h" using std::string; @@ -34,6 +37,64 @@ using std::ostream; using std::ostringstream; +namespace { + +typedef Translator NoteTranslator; + +NoteTranslator const init_notetranslator() { + NoteTranslator translator("Note", InsetNoteParams::Note); + translator.addPair("Comment", InsetNoteParams::Comment); + translator.addPair("Greyedout", InsetNoteParams::Greyedout); + return translator; +} + + +NoteTranslator const init_notetranslator_loc() { + NoteTranslator translator(_("Note"), InsetNoteParams::Note); + translator.addPair(_("Comment"), InsetNoteParams::Comment); + translator.addPair(_("Greyed out"), InsetNoteParams::Greyedout); + return translator; +} + + +NoteTranslator const & notetranslator() { + static NoteTranslator translator = init_notetranslator(); + return translator; +} + + +NoteTranslator const & notetranslator_loc() { + static NoteTranslator translator = init_notetranslator_loc(); + return translator; +} + +} // anon + + + + +InsetNoteParams::InsetNoteParams() + : type(Note) +{} + + +void InsetNoteParams::write(ostream & os) const +{ + string const label = notetranslator().find(type); + os << "Note " << label << "\n"; + os << label << "\n"; +} + + +void InsetNoteParams::read(LyXLex & lex) +{ + string label; + lex >> label; + if (lex) + type = notetranslator().find(label); +} + + void InsetNote::init() { setInsetName("Note"); @@ -44,7 +105,7 @@ void InsetNote::init() InsetNote::InsetNote(BufferParams const & bp, string const & label) : InsetCollapsable(bp) { - params_.type = label; + params_.type = notetranslator().find(label); init(); } @@ -83,6 +144,7 @@ void InsetNote::write(Buffer const & buf, ostream & os) const void InsetNote::read(Buffer const & buf, LyXLex & lex) { + params_.read(lex); InsetCollapsable::read(buf, lex); setButtonLabel(); } @@ -90,22 +152,26 @@ void InsetNote::read(Buffer const & buf, LyXLex & lex) void InsetNote::setButtonLabel() { + string const label = notetranslator_loc().find(params_.type); + setLabel(label); + LyXFont font(LyXFont::ALL_SANE); font.decSize(); font.decSize(); - if (params_.type == "Note") { - setLabel(_("LyX Note")); + switch (params_.type) { + case InsetNoteParams::Note: font.setColor(LColor::note); setBackgroundColor(LColor::notebg); - } else if (params_.type == "Comment") { - setLabel(_("Comment")); + break; + case InsetNoteParams::Comment: font.setColor(LColor::comment); setBackgroundColor(LColor::commentbg); - } else { - setLabel(_("Greyed Out")); + break; + case InsetNoteParams::Greyedout: font.setColor(LColor::greyedout); setBackgroundColor(LColor::greyedoutbg); + break; } setLabelFont(font); } @@ -153,89 +219,94 @@ InsetNote::priv_dispatch(FuncRequest const & cmd, int InsetNote::latex(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - string const pt = params_.type; - - int i = 0; - if (pt == "Comment") - // verbatim - os << "%\n\\begin{comment}\n"; - else if (pt == "Greyedout") - // we roll our own macro - os << "%\n\\begin{lyxgreyedout}\n"; - - if (pt != "Note") - i = inset.latex(buf, os, runparams); - - if (pt == "Comment") { - os << "%\n\\end{comment}\n"; - i += 4; - } else if (pt == "Greyedout") { - os << "%\n\\end{lyxgreyedout}\n"; - i += 4; - } - return i; + if (params_.type == InsetNoteParams::Note) + return 0; + + string type; + if (params_.type == InsetNoteParams::Comment) + type = "comment"; + else if (params_.type == InsetNoteParams::Greyedout) + type = "lyxgreyedout"; + + ostringstream ss; + ss << "%\n\\begin{" << type << "}\n"; + inset.latex(buf, ss, runparams); + ss << "%\n\\end{" << type << "}\n"; + + string const str = ss.str(); + os << str; + // Return how many newlines we issued. + return int(lyx::count(str.begin(), str.end(),'\n') + 1); } int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const { - string const pt = params_.type; + if (params_.type == InsetNoteParams::Note) + return 0; - int i = 0; - if (pt == "Comment") - os << "\n"; + ostringstream ss; + if (params_.type == InsetNoteParams::Comment) + ss << "\n"; - if (pt != "Note") - i = inset.linuxdoc(buf, os, runparams); + inset.linuxdoc(buf, ss, runparams); - if (pt == "Comment") { - os << "\n\n"; - i += 3; - } - return i; + if (params_.type == InsetNoteParams::Comment) + ss << "\n\n"; + + string const str = ss.str(); + os << str; + // Return how many newlines we issued. + return int(lyx::count(str.begin(), str.end(),'\n') + 1); } int InsetNote::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const { - string const pt = params_.type; + if (params_.type == InsetNoteParams::Note) + return 0; - int i = 0; - if (pt == "Comment") - os << "\n"; + ostringstream ss; + if (params_.type == InsetNoteParams::Comment) + ss << "\n"; - if (pt != "Note") - i = inset.docbook(buf, os, runparams); + inset.docbook(buf, ss, runparams); - if (pt == "Comment") { - os << "\n\n"; - i += 3; - } - return i; + if (params_.type == InsetNoteParams::Comment) + ss << "\n\n"; + + string const str = ss.str(); + os << str; + // Return how many newlines we issued. + return int(lyx::count(str.begin(), str.end(),'\n') + 1); } int InsetNote::plaintext(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const { - int i = 0; - string const pt = params_.type; - if (pt != "Note") { - os << "["; - i = inset.plaintext(buf, os, runparams); - os << "]"; - } - return i; + if (params_.type == InsetNoteParams::Note) + return 0; + + ostringstream ss; + ss << "["; + inset.plaintext(buf, ss, runparams); + ss << "]"; + + string const str = ss.str(); + os << str; + // Return how many newlines we issued. + return int(lyx::count(str.begin(), str.end(),'\n') + 1); } void InsetNote::validate(LaTeXFeatures & features) const { - if (params_.type == "Comment") + if (params_.type == InsetNoteParams::Comment) features.require("verbatim"); - if (params_.type == "Greyedout") { + if (params_.type == InsetNoteParams::Greyedout) { features.require("color"); features.require("lyxgreyedout"); } @@ -277,25 +348,21 @@ void InsetNoteMailer::string2params(string const & in, istringstream data(in); LyXLex lex(0,0); lex.setStream(data); - params.read(lex); -} - -void InsetNoteParams::write(ostream & os) const -{ - os << type << "\n"; -} - - -void InsetNoteParams::read(LyXLex & lex) -{ - if (lex.isOK()) { - lex.next(); - string token = lex.getString(); + string name; + lex >> name; + if (!lex || name != name_) { + lyxerr << "InsetNoteMailer::string2params(" << in << ")\n" + << "Missing identifier \"" << name_ << '"' << std::endl; + return; } - if (lex.isOK()) { - lex.next(); - type = lex.getString(); - } + // This is part of the inset proper that is usually swallowed + // by LyXText::readInset + string inset_id; + lex >> inset_id; + if (!lex || inset_id != "Note") + return; + + params.read(lex); } diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index f2bd70d7ae..c2d660f518 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -16,12 +16,19 @@ struct InsetNoteParams { + enum Type { + Note, + Comment, + Greyedout + }; + /// \c type defaults to Note + InsetNoteParams(); /// void write(std::ostream & os) const; /// void read(LyXLex & lex); /// - std::string type; + Type type; };