]> git.lyx.org Git - features.git/commitdiff
InsetNote clean-up.
authorAngus Leeming <leeming@lyx.org>
Wed, 10 Dec 2003 17:28:14 +0000 (17:28 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 10 Dec 2003 17:28:14 +0000 (17:28 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8226 a592a061-630c-0410-9148-cb99ea01b6c8

21 files changed:
development/ChangeLog
development/FORMAT
lib/ChangeLog
lib/lyx2lyx/lyx2lyx
lib/lyx2lyx/lyxconvert_225.py [new file with mode: 0644]
lib/lyx2lyx/lyxrevert_226.py [new file with mode: 0644]
src/ChangeLog
src/buffer.C
src/factory.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlNote.C
src/frontends/controllers/ControlNote.h
src/frontends/qt2/ChangeLog
src/frontends/qt2/QNote.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormNote.C
src/frontends/xforms/FormNote.h
src/frontends/xforms/forms/form_note.fd
src/insets/ChangeLog
src/insets/insetnote.C
src/insets/insetnote.h

index 1346a9e9db3ad40ef3f1e8d7db3a187316a8f446..e38452a716a8cb1f5828eb70866b1df5c9bdf69e 100644 (file)
@@ -1,55 +1,11 @@
+2003-12-10  Angus Leeming  <leeming@lyx.org>
+
+       * FORMAT: document format 226.
 
 2003-12-01  André Pönitz  <poenitz@gmx.net>
 
        * 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  <assirati@fma.if.usp.br>
 
index ca6f7246b8d5581b3e53e1b435f2202afeef88a4..1ad361c6bec76f716e2283ba3d2a564cac03a01f 100644 (file)
@@ -1,5 +1,13 @@
 LyX file-format changes
 -----------------------
+
+2003-12-10  Angus Leeming  <leeming@lyx.org>
+
+       * 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. 
index 9d78f9a86a42f191d4dd8c8e0d72d9f02a2e0c7e..29a3a2598c2a91ef69e7dd5b9488cb8861738c48 100644 (file)
@@ -1,3 +1,10 @@
+2003-12-10  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <lasgouttes@lyx.org>
 
        * CREDITS: add Felix Kurth
index 449c1eda65f2cfde8f91d82e8cbdb8ae85b4417a..1fb1593497328d0b5bba92389b0ebcd125a2aa58 100755 (executable)
@@ -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 (file)
index 0000000..8363d7a
--- /dev/null
@@ -0,0 +1,36 @@
+# This file is part of lyx2lyx
+# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
+#
+# 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 (file)
index 0000000..f0d04e5
--- /dev/null
@@ -0,0 +1,35 @@
+# This file is part of lyx2lyx
+# Copyright (C) 2003 Jos\81é Matos <jamatos@fep.up.pt>
+#
+# 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
index 21034c64ace1b8c55220a8bee396403b62364573..8529d4a9c63ee4fc8586bd86200fbe94f9839155 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-10  Angus Leeming  <leeming@lyx.org>
+
+       * buffer.C: up the format to 226.
+
+       * factory.C: the note inset is now identified simply by 'Note'.
+
 2003-12-08  Alfredo Braunstein  <abraunst@libero.it>
 
        * lyxtext.h, text2.C (setLayout): don't use cursor to iterate,
index e5bd4431fcbf88f35a83b77d481ecd49350e3564..e28f687035a8fdbf22b150f7f330bc80f2fd8df8 100644 (file)
@@ -132,7 +132,7 @@ extern BufferList bufferlist;
 
 namespace {
 
-const int LYX_FORMAT = 225;
+const int LYX_FORMAT = 226;
 
 } // namespace anon
 
index f497598942656b6865a11deedb1d833bdee34b76..747fc7a5897ba2b85ac26b88280c94690b4dbe66 100644 (file)
@@ -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"
index edda46b6fd051705dd0e96adae9badbede6f7632..aa7c8684320a964d078387398be634234f7af030 100644 (file)
@@ -1,3 +1,7 @@
+2003-12-10  Angus Leeming  <leeming@lyx.org>
+
+       * ControlNote.[Ch] (note_gui_tokens): removed; no longer needed.
+
 2003-12-10  Angus Leeming  <leeming@lyx.org>
 
        * ControlBranch.C (dispatchParams): change to invocation of
index 6f22c819bc5672f1b506b7ed166985c585f774cb..b7f66a038b593d5fb9891195d1c2788ed1700470 100644 (file)
@@ -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<string> & ids, vector<string> & gui_names)
-{
-       char const * const ids_[] = {"Note", "Comment", "Greyedout"};
-       size_t const ids_size = sizeof(ids_) / sizeof(char *);
-       ids = vector<string>(ids_, ids_ + ids_size);
-       gui_names.clear();
-       gui_names.push_back(_("LyX Note"));
-       gui_names.push_back(_("Comment"));
-       gui_names.push_back(_("Greyed Out"));
-}
index 486a08640bd54ba0085fd442573be4c3cc513c83..ad504e9e183c0f0d55ad2aa7990026d2cc5141e8 100644 (file)
@@ -40,7 +40,4 @@ private:
        boost::scoped_ptr<InsetNoteParams> params_;
 };
 
-///
-void note_gui_tokens(std::vector<std::string> &, std::vector<std::string> &);
-
 #endif // CONTROLNOTE_H
index 2751ddb8dbdaeaac9caf6147e656c137d95b4420..26025ef87b40ae90bc11d9bf945552535defc055 100644 (file)
@@ -1,3 +1,8 @@
+2003-12-10  Angus Leeming  <leeming@lyx.org>
+
+       * QNote.C: changes due to the change of type of InsetNoteParams::type
+       from string to an enum.
+
 2003-12-10  Angus Leeming  <leeming@lyx.org>
 
        * lengthvalidator.[Ch]: make <qwidget.h> visible to the class.
index 26823d20b4641b56e471e611440acdfb98e2ab01..a6cfd48e69479b09d475a8e26308fc298da6494e 100644 (file)
@@ -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;
 }
index 9b1f3a49226be82f0541ec6287d3b52173828007..8103a77717e13814b0c5430c78e135bbf267a326 100644 (file)
@@ -1,3 +1,12 @@
+2003-12-10  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * FormVCLog.[Ch]: removed.
index 3db5352fc54f1fc1c2810f82ee893b2b9fc510ee..1160d69e76d4482d6b56decb64500a84e61afd84 100644 (file)
@@ -28,7 +28,7 @@ using std::string;
 typedef FormController<ControlNote, FormView<FD_note> > 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;
 }
index fa6e07600f7d6b970088ac8d6a687703e8eea992..d444734a2e262831e409911648b0c5c366830da0 100644 (file)
@@ -32,10 +32,6 @@ private:
        virtual void build();
        /// Update dialog before showing it
        virtual void update();
-       ///
-       std::vector<std::string> ids_;
-       ///
-       std::vector<std::string> gui_names_;
 };
 
 #endif // FORMNOTE_H
index b7e6e09990f0beb9d7565b1b13262aaf496a3829..e62230aaf2294fe18a70286934aa4e7c76a4b7d4 100644 (file)
@@ -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
index dba5e2eb633abb7ea1dbef15c92d8ffc50616d73..ada3f05a673d55934cce3962f34f0157877b8349 100644 (file)
@@ -1,3 +1,10 @@
+2003-12-10  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * insetbranch.[Ch]: changes to the InsetBranchMailer interface.
index 14f2ec49c605ec375561a00b9b8b452a1d553b4f..83888887c7afc3cf369d2bb3d34e568c73aae0f3 100644 (file)
@@ -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<std::string, InsetNoteParams::Type> 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 << "<comment>\n";
+       ostringstream ss;
+       if (params_.type == InsetNoteParams::Comment)
+               ss << "<comment>\n";
 
-       if (pt != "Note")
-               i = inset.linuxdoc(buf, os, runparams);
+       inset.linuxdoc(buf, ss, runparams);
 
-       if (pt == "Comment") {
-               os << "\n</comment>\n";
-               i += 3;
-       }
-       return i;
+       if (params_.type == InsetNoteParams::Comment)
+               ss << "\n</comment>\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 << "<remark>\n";
+       ostringstream ss;
+       if (params_.type == InsetNoteParams::Comment)
+               ss << "<remark>\n";
 
-       if (pt != "Note")
-               i = inset.docbook(buf, os, runparams);
+       inset.docbook(buf, ss, runparams);
 
-       if (pt == "Comment") {
-               os << "\n</remark>\n";
-               i += 3;
-       }
-       return i;
+       if (params_.type == InsetNoteParams::Comment)
+               ss << "\n</remark>\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);
 }
index f2bd70d7ae4308ca6177c4e6ff572e09b9193031..c2d660f5188276847c45600d5414182a51379a4c 100644 (file)
 
 
 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;
 };