Here is a patch (and some new files) that generalize the Note inset to serve as a variety of annotation insets: Foot, Margin, ..., as well as Branches.
Currently the LaTeX side is unimplemented, as is the machinery for selecting the branch to be output. But the inset work, including a dialog for changing note type and branch, is done and works. This is against CVS of over a week ago so it may not apply cleanly. Anyway, I submit this for comment in the present unfinished form as I am leaving the domain of tcp/ip (especially fast such) for a longer period for the enjoyments of chopping wood and hauling water :-). Martin -- Martin Vermeer [EMAIL PROTECTED] Helsinki University of Technology Dept. of Surveying, Inst. of Geodesy P.O. Box 1200, FIN-02015 HUT, Finland :wq
Index: factory.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/factory.C,v
retrieving revision 1.33
diff -u -p -r1.33 factory.C
--- factory.C 2003/06/04 09:16:28 1.33
+++ factory.C 2003/06/25 14:21:02
@@ -69,7 +69,7 @@ Inset * createInset(FuncRequest const &
return new InsetMinipage(params);
case LFUN_INSERT_NOTE:
- return new InsetNote(params);
+ return new InsetNote(params, "Note");
case LFUN_INSET_ERT:
return new InsetERT(params);
@@ -347,7 +347,19 @@ Inset * readInset(LyXLex & lex, Buffer c
} else if (tmptok == "Graphics") {
inset = new InsetGraphics;
} else if (tmptok == "Note") {
- inset = new InsetNote(buf.params);
+ inset = new InsetNote(buf.params, tmptok);
+ } else if (tmptok == "blind") {
+ inset = new InsetNote(buf.params, tmptok);
+ } else if (tmptok == "foot") {
+ inset = new InsetNote(buf.params, tmptok);
+ } else if (tmptok == "margin") {
+ inset = new InsetNote(buf.params, tmptok);
+ } else if (tmptok == "petite") {
+ inset = new InsetNote(buf.params, tmptok);
+ } else if (tmptok == "greyedout") {
+ inset = new InsetNote(buf.params, tmptok);
+ } else if (tmptok == "branch") {
+ inset = new InsetNote(buf.params, tmptok);
} else if (tmptok == "Include") {
InsetCommandParams p("Include");
inset = new InsetInclude(p, buf);
Index: frontends/Dialogs.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/Dialogs.C,v
retrieving revision 1.24
diff -u -p -r1.24 Dialogs.C
--- frontends/Dialogs.C 2003/06/06 08:06:23 1.24
+++ frontends/Dialogs.C 2003/06/25 14:21:04
@@ -16,6 +16,7 @@
#include <boost/signals/signal2.hpp>
#include <boost/bind.hpp>
+#include "debug.h"
// Note that static boost signals break some compilers, so this wrapper
// initialises the signal dynamically when it is first invoked.
@@ -91,6 +92,7 @@ Dialog * Dialogs::find(string const & na
void Dialogs::show(string const & name, string const & data)
{
+lyxerr << "dialogs... data=" << data << endl;
Dialog * dialog = find(name);
if (!dialog)
return;
@@ -101,10 +103,10 @@ void Dialogs::show(string const & name,
void Dialogs::show(string const & name, string const & data, InsetBase * inset)
{
+lyxerr << "dialogs... data=" << data << endl;
Dialog * dialog = find(name);
if (!dialog)
return;
-
dialog->show(data);
open_insets_[name] = inset;
}
Index: frontends/controllers/Dialog.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/Dialog.C,v
retrieving revision 1.4
diff -u -p -r1.4 Dialog.C
--- frontends/controllers/Dialog.C 2003/05/22 15:42:49 1.4
+++ frontends/controllers/Dialog.C 2003/06/25 14:21:04
@@ -65,8 +65,10 @@ void Dialog::RestoreButton()
void Dialog::show(string const & data)
{
- if (controller().isBufferDependent() && !kernel().isBufferAvailable())
+lyxerr << "Dialog (in controllers) data=" << data << endl;
+ if (controller().isBufferDependent() && !kernel().isBufferAvailable()) {
return;
+ }
if (!controller().initialiseParams(data)) {
lyxerr << "Dialog \"" << name_
Index: frontends/controllers/Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/controllers/Makefile.am,v
retrieving revision 1.55
diff -u -p -r1.55 Makefile.am
--- frontends/controllers/Makefile.am 2003/05/13 21:15:47 1.55
+++ frontends/controllers/Makefile.am 2003/06/25 14:21:04
@@ -70,6 +70,8 @@ libcontrollers_la_SOURCES= \
ControlMath.h \
ControlMinipage.C \
ControlMinipage.h \
+ ControlNote.C \
+ ControlNote.h \
ControlParagraph.C \
ControlParagraph.h \
ControlPreamble.C \
Index: frontends/xforms/Dialogs.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/Dialogs.C,v
retrieving revision 1.106
diff -u -p -r1.106 Dialogs.C
--- frontends/xforms/Dialogs.C 2003/06/04 09:16:29 1.106
+++ frontends/xforms/Dialogs.C 2003/06/25 14:21:05
@@ -30,6 +30,7 @@
#include "ControlInclude.h"
#include "ControlLog.h"
#include "ControlMinipage.h"
+#include "ControlNote.h"
#include "ControlParagraph.h"
#include "ControlRef.h"
#include "ControlShowFile.h"
@@ -54,6 +55,7 @@
#include "FormInclude.h"
#include "FormLog.h"
#include "FormMinipage.h"
+#include "FormNote.h"
#include "FormParagraph.h"
#include "FormRef.h"
#include "FormTabular.h"
@@ -76,7 +78,7 @@
namespace {
-char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes",
"character", "citation", "error", "errorlist" , "ert", "external", "file", "float",
"graphics", "include", "index", "label", "log", "minipage", "paragraph", "ref",
"tabular", "tabularcreate",
+char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes",
"character", "citation", "error", "errorlist" , "ert", "external", "file", "float",
"graphics", "include", "index", "label", "log", "minipage", "note", "paragraph",
"ref", "tabular", "tabularcreate",
#ifdef HAVE_LIBAIKSAURUS
"thesaurus",
@@ -189,6 +191,10 @@ Dialog * Dialogs::build(string const & n
dialog->setController(new ControlMinipage(*dialog));
dialog->setView(new FormMinipage(*dialog));
dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
+ } else if (name == "note") {
+ dialog->setController(new ControlNote(*dialog));
+ dialog->setView(new FormNote(*dialog));
+ dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
} else if (name == "paragraph") {
dialog->setController(new ControlParagraph(*dialog));
dialog->setView(new FormParagraph(*dialog));
Index: frontends/xforms/Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/Makefile.am,v
retrieving revision 1.98
diff -u -p -r1.98 Makefile.am
--- frontends/xforms/Makefile.am 2003/05/14 09:17:21 1.98
+++ frontends/xforms/Makefile.am 2003/06/25 14:21:16
@@ -111,6 +111,8 @@ libxforms_la_SOURCES = \
FormMathsStyle.h \
FormMinipage.C \
FormMinipage.h \
+ FormNote.C \
+ FormNote.h \
FormParagraph.C \
FormParagraph.h \
FormPreamble.C \
Index: insets/insetnote.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetnote.C,v
retrieving revision 1.25
diff -u -p -r1.25 insetnote.C
--- insets/insetnote.C 2003/06/03 15:10:11 1.25
+++ insets/insetnote.C 2003/06/25 14:21:20
@@ -10,6 +10,7 @@
#include <config.h>
+#include "Lsstream.h"
#include "insetnote.h"
#include "gettext.h"
@@ -17,10 +18,12 @@
#include "language.h"
#include "buffer.h"
#include "BufferView.h"
+#include "lyxlex.h"
#include "lyxtext.h"
#include "insets/insettext.h"
#include "support/LOstream.h"
#include "support/lstrings.h"
+
#include "debug.h"
using std::ostream;
@@ -34,25 +37,181 @@ void InsetNote::init()
font.setColor(LColor::note);
setLabelFont(font);
setBackgroundColor(LColor::notebg);
- setLabel(_("note"));
setInsetName("Note");
}
-InsetNote::InsetNote(BufferParams const & bp)
+InsetNote::InsetNote(BufferParams const & bp, string const & label)
: InsetCollapsable(bp)
{
init();
+ params_.type = label;
+ setLabel(label);
}
-InsetNote::InsetNote(InsetNote const & in)
+InsetNote::InsetNote(InsetNote const & in, string const & label)
: InsetCollapsable(in)
{
init();
}
+InsetNote::~InsetNote() // MV
+{
+ InsetNoteMailer mailer("note", *this);
+ mailer.hideDialog();
+}
+
+void InsetNote::write(Buffer const * buf, ostream & os) const
+{
+ params_.write(os);
+ InsetCollapsable::write(buf, os);
+}
+
+
+void InsetNote::read(Buffer const * buf, LyXLex & lex)
+{
+ //params_.read(lex);
+ if (trim(params_.type) == "branch") {
+ if (lex.isOK()) {
+ lex.next();
+ params_.branch = lex.getString();
+ }
+ }
+ InsetCollapsable::read(buf, lex);
+ setButtonLabel();
+}
+
+
+void InsetNote::setButtonLabel()
+{
+ if (trim(params_.type) == "branch") {
+ setLabel(params_.branch);
+ } else {
+ setLabel(params_.type);
+ }
+ if (trim(params_.type) == "blind") {
+ setBackgroundColor(LColor::notebg);
+ } else {
+ setBackgroundColor(LColor::background);
+ }
+}
+
+dispatch_result InsetNote::localDispatch(FuncRequest const & cmd)
+{
+ BufferView * bv = cmd.view();
+
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY: {
+lyxerr << "MODIFY:" << cmd.argument << endl;
+ InsetNoteParams params;
+ InsetNoteMailer::string2params(cmd.argument, params);
+ params_.type = params.type;
+ params_.branch = params.branch;
+lyxerr << "MODIFY..." << params_.type << params_.branch << endl;
+ setButtonLabel();
+ bv->updateInset(this);
+ return DISPATCHED;
+ }
+
+ case LFUN_INSET_EDIT:
+lyxerr << "EDIT" << endl;
+ if (cmd.button() == mouse_button::button3)
+ break;
+ return InsetCollapsable::localDispatch(cmd);
+
+ case LFUN_INSET_DIALOG_UPDATE:
+lyxerr << "UPDATE" << endl;
+ InsetNoteMailer("note", *this).updateDialog(bv);
+ return DISPATCHED;
+
+ case LFUN_MOUSE_RELEASE:
+ if (cmd.button() == mouse_button::button3) {
+lyxerr << "RELEASE, call InsetNoteMailer:" << params_.type << endl;
+ InsetNoteMailer("note", *this).showDialog(bv);
+ return DISPATCHED;
+ }
+
+ default:
+lyxerr << "default:" << params_.type << endl;
+ return InsetCollapsable::localDispatch(cmd);
+ }
+
+ return UNDISPATCHED; // suppresses warning
+}
+
+
+InsetNoteMailer::InsetNoteMailer(string const & name,
+ InsetNote & inset)
+ : name_(name), inset_(inset)
+{
+}
+
+
+string const InsetNoteMailer::inset2string() const
+{
+ return params2string(name_, inset_.params());
+}
+
+
+string const InsetNoteMailer::params2string(string const & name,
+ InsetNoteParams const & params)
+{
+ ostringstream data;
+ data << name << ' ';
+ params.write(data);
+lyxerr << "params2string:" << STRCONV(data.str()) << endl;
+ return STRCONV(data.str());
+
+}
+
+
+void InsetNoteMailer::string2params(string const & in,
+ InsetNoteParams & params)
+{
+ params = InsetNoteParams();
+
+ if (in.empty())
+ return;
+
+ istringstream data(STRCONV(in));
+ LyXLex lex(0,0);
+ lex.setStream(data);
+ params.read(lex);
+
+}
+
+
+void InsetNoteParams::write(ostream & os) const
+{
+ os << type << " ";
+ if (trim(type) == "branch") {
+ os << branch << "\n";
+ }
+}
+
+
+void InsetNoteParams::read(LyXLex & lex)
+{
+ if (lex.isOK()) {
+ lex.next();
+ string token = lex.getString();
+ }
+
+ if (lex.isOK()) {
+ lex.next();
+ type = lex.getString();
+ }
+ if (trim(type) == "branch") {
+ if (lex.isOK()) {
+ lex.next();
+ branch = lex.getString();
+ }
+ }
+}
+
+
Inset * InsetNote::clone() const
{
return new InsetNote(*this);
@@ -64,9 +223,3 @@ string const InsetNote::editMessage() co
return _("Opened Note Inset");
}
-
-void InsetNote::write(Buffer const * buf, ostream & os) const
-{
- os << getInsetName() << "\n";
- InsetCollapsable::write(buf, os);
-}
Index: insets/insetnote.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetnote.h,v
retrieving revision 1.21
diff -u -p -r1.21 insetnote.h
--- insets/insetnote.h 2003/06/03 15:10:11 1.21
+++ insets/insetnote.h 2003/06/25 14:21:20
@@ -15,16 +15,35 @@
#include "insetcollapsable.h"
+
+struct InsetNoteParams {
+ ///
+ void write(std::ostream & os) const;
+ ///
+ void read(LyXLex & lex);
+ ///
+ string type;
+ ///
+ string branch;
+};
+
+
+
+
/** The PostIt note inset
*/
class InsetNote : public InsetCollapsable {
public:
+ ///
+ InsetNote(BufferParams const &, string const &);
///
- InsetNote(BufferParams const &);
+ InsetNote(InsetNote const &, string const &);
///
- InsetNote(InsetNote const &);
+ ~InsetNote();
///
+ dispatch_result InsetNote::localDispatch(FuncRequest const &);
+ ///
Inset * clone() const;
///
string const editMessage() const;
@@ -33,6 +52,10 @@ public:
///
void write(Buffer const *, std::ostream &) const;
///
+ void read(Buffer const * buf, LyXLex & lex);
+ ///
+ void setButtonLabel();
+ ///
int latex(Buffer const *, std::ostream &,
LatexRunParams const &) const
{ return 0; }
@@ -47,10 +70,41 @@ public:
{ return 0; }
///
void validate(LaTeXFeatures &) const {}
+ ///
+ InsetNoteParams const & params() const { return params_; }
+
private:
+ friend class InsetNoteParams;
+
/// used by the constructors
void init();
+ ///
+ InsetNoteParams params_;
+};
+#include "mailinset.h"
+
+class InsetNoteMailer : public MailInset {
+public:
+ ///
+ InsetNoteMailer(string const & name, InsetNote & inset);
+ ///
+ virtual InsetBase & inset() const { return inset_; }
+ ///
+ virtual string const & name() const { return name_; }
+ ///
+ virtual string const inset2string() const;
+ ///
+ static string const params2string(string const &, InsetNoteParams const &);
+ ///
+ static void string2params(string const &, InsetNoteParams &);
+private:
+ ///
+ string const name_;
+ ///
+ InsetNote & inset_;
};
+
+
#endif
Index: insets/mailinset.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/mailinset.C,v
retrieving revision 1.7
diff -u -p -r1.7 mailinset.C
--- insets/mailinset.C 2003/06/06 08:06:24 1.7
+++ insets/mailinset.C 2003/06/25 14:21:20
@@ -19,7 +19,6 @@
#include "support/LAssert.h"
#include "Lsstream.h"
-
void MailInset::showDialog(BufferView * bv) const
{
lyx::Assert(bv);
/**
* \file ControlNote.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "ControlNote.h"
#include "funcrequest.h"
#include "insets/insetnote.h"
#include "debug.h"
ControlNote::ControlNote(Dialog & parent)
: Dialog::Controller(parent)
{}
bool ControlNote::initialiseParams(string const & data)
{
InsetNoteParams params;
InsetNoteMailer::string2params(data, params);
params_.reset(new InsetNoteParams(params));
lyxerr << "ControlNote::initialiseParams string:" << data << endl;
return true;
}
void ControlNote::clearParams()
{
lyxerr << "ControlNote: clearParams" << endl;
params_.reset();
}
void ControlNote::dispatchParams()
{
string const lfun = InsetNoteMailer::params2string(string("note"), params());
lyxerr << "before kernel-dispatch:" << lfun << endl;
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
}
// -*- C++ -*-
/**
* \file ControlNote.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#ifndef CONTROLNOTE_H
#define CONTROLNOTE_H
#include "Dialog.h"
#include "debug.h"
class InsetNoteParams;
class ControlNote : public Dialog::Controller {
public:
///
ControlNote(Dialog &);
///
virtual bool initialiseParams(string const & data);
///
virtual void clearParams();
///
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
InsetNoteParams & params() { return *params_.get(); }
///
InsetNoteParams const & params() const { return *params_.get(); }
///
private:
///
boost::scoped_ptr<InsetNoteParams> params_;
};
#endif // CONTROLNOTE_H
/**
* \file FormNote.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "xformsBC.h"
#include "ControlNote.h"
#include "FormNote.h"
#include "forms/form_note.h"
#include "xforms_helpers.h" // formatted
#include "lyx_forms.h"
#include "insets/insetnote.h"
typedef FormController<ControlNote, FormView<FD_note> > base_class;
FormNote::FormNote(Dialog & parent)
: base_class(parent, _("Note"))
{}
void FormNote::build()
{
dialog_.reset(build_note(this));
fl_addto_choice(dialog_->choice_type,
_("blind|foot|margin|petite|greyedout|branch").c_str());
bcview().setOK(dialog_->button_ok);
bcview().setApply(dialog_->button_apply);
bcview().setCancel(dialog_->button_cancel);
}
void FormNote::update()
{
string type(controller().params().type);
string branch(controller().params().branch);
lyxerr << "(update) type:" << type << "branch:" << branch << endl;
if (type == "branch") {
setEnabled(dialog_->string_branch, true);
} else {
setEnabled(dialog_->string_branch, false);
}
fl_set_choice_text(dialog_->choice_type, type.c_str());
fl_set_input(dialog_->string_branch, branch.c_str());
}
void FormNote::apply()
{
string const type = fl_get_choice_text(dialog_->choice_type);
string const branch = fl_get_input(dialog_->string_branch);
lyxerr << "(apply) type:" << type << "branch:" << branch << endl;
controller().params().type = type;
controller().params().branch = branch;
}
// -*- C++ -*-
/**
* \file FormNote.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#ifndef FORMNOTE_H
#define FORMNOTE_H
#include "FormDialogView.h"
class ControlNote;
struct FD_note;
/** This class provides an XForms implementation of the Note Dialog.
*/
class FormNote : public FormController<ControlNote, FormView<FD_note> > {
public:
/// Constructor
FormNote(Dialog &);
private:
///
virtual void apply();
/// Build the dialog
virtual void build();
/// Update dialog before showing it
virtual void update();
};
#endif // FORMNOTE_H
Magic: 13000
Internal Form Definition File
(do not change)
Number of forms: 1
Unit of measure: FL_COORD_PIXEL
SnapGrid: 7
=============== FORM ===============
Name: form_note
Width: 451
Height: 162
Number of Objects: 6
--------------------
class: FL_BOX
type: UP_BOX
box: 0 0 451 162
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
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_INPUT
type: NORMAL_INPUT
box: 110 60 210 30
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Branch|#B
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: string_branch
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHOICE
type: NORMAL_CHOICE
box: 110 20 110 30
boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_BLACK
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Type|#T
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: choice_type
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: RETURN_BUTTON
box: 49 112 84 28
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: OK
shortcut: ^M
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: button_ok
callback: C_FormDialogView_OKCB
argument: 0
--------------------
class: FL_BUTTON
type: RETURN_BUTTON
box: 154 112 119 28
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
shortcut: ^M
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: button_apply
callback: C_FormDialogView_ApplyCB
argument: 0
--------------------
class: FL_BUTTON
type: RETURN_BUTTON
box: 287 112 126 28
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: Cancel|^[
shortcut: ^M
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: button_cancel
callback: C_FormDialogView_CancelCB
argument: 0
==============================
create_the_forms
pgp00000.pgp
Description: PGP signature
