Implemented controller-view split for FormError and FormInclude.

Cleaned up code in controllers in the process; I think that the interface
is stabilising now.
Cleaned up code in InsetInclude a little.

Mental note (to me?!): the Bibitem, Bibtex and Include insets create an
inset when the appropriate menu item is selected. This is incorrect;
the inset should only be created when "Ok" is pressed, as with the
majority of insets. CREATE_XXX flags and associated code are needed.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1817 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2001-03-23 17:09:34 +00:00
parent fb28d5b938
commit 9705be9f1b
41 changed files with 853 additions and 666 deletions

View File

@ -2928,13 +2928,14 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
if (!bv_->insertInset(inset, "Standard", true)) if (!bv_->insertInset(inset, "Standard", true))
delete inset; delete inset;
} }
break; break;
case LFUN_CHILD_INSERT: case LFUN_CHILD_INSERT:
{ {
InsetInclude::InsetIncludeParams p; InsetInclude::Params p;
p.cparams.setFromString(argument); p.cparams.setFromString(argument);
p.buffer = buffer_; p.masterFilename_ = buffer_->fileName();
InsetInclude * inset = new InsetInclude(p); InsetInclude * inset = new InsetInclude(p);
if (!bv_->insertInset(inset)) if (!bv_->insertInset(inset))

View File

@ -2,6 +2,9 @@
* LString.h: removed "using std::getline"! * LString.h: removed "using std::getline"!
* BufferView_pimpl.C (Dispatch): changes due to changes in
InsetInclude::Params.
* buffer.C (tag_name): removed redundant break statements as they were * buffer.C (tag_name): removed redundant break statements as they were
producing lots of warnings with my compiler. producing lots of warnings with my compiler.

View File

@ -1,3 +1,25 @@
2001-03-23 Angus Leeming <a.leeming@ic.ac.uk>
* ControlDialogs.h: moved class ControlInset into its own file.
* ControlInset.h: new file. class ControlInset has been expanded to take
two template parameters, Inset and Params. Believe that all inset
controllers can be derived from this with the minimum of effort.
* ControlBibitem.[Ch]:
* ControlBibtex.[Ch]:
* ControlCitation.[Ch]:
* ControlCommand.[Ch]: moved most code into ControlInset.
* lots of files. Moved protected stuff into private where possible.
* ControlError.[Ch]:
* ControlInclude.[Ch]: new files; controllers for the LaTeX error and
Include popups, respectively.
* GUI.h:
* Makefile.am: associated changes.
2001-03-23 Angus Leeming <a.leeming@ic.ac.uk> 2001-03-23 Angus Leeming <a.leeming@ic.ac.uk>
* ControlCredits.[Ch] (getCredits): returns a stringstream not a * ControlCredits.[Ch] (getCredits): returns a stringstream not a

View File

@ -23,7 +23,7 @@
#include "ControlBibitem.h" #include "ControlBibitem.h"
#include "Dialogs.h" #include "Dialogs.h"
#include "LyXView.h" #include "LyXView.h"
#include "BufferView.h" #include "buffer.h"
using SigC::slot; using SigC::slot;
@ -33,24 +33,19 @@ ControlBibitem::ControlBibitem(LyXView & lv, Dialogs & d)
d_.showBibitem.connect(slot(this, &ControlBibitem::showInset)); d_.showBibitem.connect(slot(this, &ControlBibitem::showInset));
} }
void ControlBibitem::apply() void ControlBibitem::applyParamsToInset()
{ {
view().apply(); // FIXME:
// confirm, is this only necessary for FormBibTeX ???
if (params().getContents() != inset()->params().getContents())
lv_.view()->ChangeCitationsIfUnique(inset()->params().getContents(),
params().getContents());
if (inset_ && params() != inset_->params()) { inset()->setParams(params());
// FIXME: lv_.view()->updateInset(inset(), true);
// confirm, is this only necessary for FormBibTeX ???
if (params().getContents() != inset_->params().getContents())
lv_.view()->ChangeCitationsIfUnique(
inset_->params().getContents(),
params().getContents());
inset_->setParams(params()); // We need to do a redraw because the maximum
lv_.view()->updateInset(inset_, true); // InsetBibKey width could have changed
lv_.view()->redraw();
// We need to do a redraw because the maximum lv_.view()->fitCursor(lv_.view()->getLyXText());
// InsetBibKey width could have changed
lv_.view()->redraw();
lv_.view()->fitCursor(lv_.view()->getLyXText());
}
} }

View File

@ -30,9 +30,13 @@ public:
/// ///
ControlBibitem(LyXView &, Dialogs &); ControlBibitem(LyXView &, Dialogs &);
protected: private:
/// Get changed parameters and Dispatch them to the kernel. /// Dispatch the changed parameters to the kernel.
virtual void apply(); virtual void applyParamsToInset();
/// not needed.
virtual void applyParamsNoInset() {}
/// not needed.
virtual void clearDaughterParams() {}
}; };
#endif // CONTROLBIBITEM_H #endif // CONTROLBIBITEM_H

View File

@ -23,7 +23,7 @@
#include "ControlBibtex.h" #include "ControlBibtex.h"
#include "Dialogs.h" #include "Dialogs.h"
#include "LyXView.h" #include "LyXView.h"
#include "BufferView.h" #include "buffer.h"
using SigC::slot; using SigC::slot;
@ -33,22 +33,21 @@ ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d)
d_.showBibtex.connect(slot(this, &ControlBibtex::showInset)); d_.showBibtex.connect(slot(this, &ControlBibtex::showInset));
} }
void ControlBibtex::apply() void ControlBibtex::applyParamsToInset()
{ {
view().apply(); if (params().getContents() != inset()->params().getContents())
lv_.view()->ChangeCitationsIfUnique(inset()->params().getContents(),
params().getContents());
if (inset_ && params() != inset_->params()) { inset()->setParams(params());
if (params().getContents() != inset_->params().getContents()) lv_.view()->updateInset(inset(), true);
lv_.view()->ChangeCitationsIfUnique(
inset_->params().getContents(),
params().getContents());
inset_->setParams(params()); // We need to do a redraw because the maximum
lv_.view()->updateInset(inset_, true); // InsetBibKey width could have changed
lv_.view()->redraw();
// We need to do a redraw because the maximum lv_.view()->fitCursor(lv_.view()->getLyXText());
// InsetBibKey width could have changed
lv_.view()->redraw();
lv_.view()->fitCursor(lv_.view()->getLyXText());
}
} }
void ControlBibtex::applyParamsNoInset()
{}

View File

@ -30,9 +30,13 @@ public:
/// ///
ControlBibtex(LyXView &, Dialogs &); ControlBibtex(LyXView &, Dialogs &);
protected: private:
/// Get changed parameters and Dispatch them to the kernel. /// Dispatch the changed parameters to the kernel.
virtual void apply(); virtual void applyParamsToInset();
///
virtual void applyParamsNoInset();
/// not needed.
virtual void clearDaughterParams() {}
}; };
#endif // CONTROLBIBTEX_H #endif // CONTROLBIBTEX_H

View File

@ -71,7 +71,7 @@ public:
/// ///
void setToggleAll(bool); void setToggleAll(bool);
protected: private:
/// Get changed parameters and Dispatch them to the kernel. /// Get changed parameters and Dispatch them to the kernel.
virtual void apply(); virtual void apply();
/// set the params before show or update. /// set the params before show or update.
@ -79,8 +79,9 @@ protected:
/// clean-up on hide. /// clean-up on hide.
virtual void clearParams(); virtual void clearParams();
private: ///
LyXFont * font_; LyXFont * font_;
///
bool toggleall_; bool toggleall_;
}; };

View File

@ -45,7 +45,7 @@ ControlCitation::ControlCitation(LyXView & lv, Dialogs & d)
} }
void ControlCitation::clearParams() void ControlCitation::clearDaughterParams()
{ {
bibkeysInfo_.clear(); bibkeysInfo_.clear();
} }

View File

@ -55,8 +55,8 @@ public:
Empty if no info exists. */ Empty if no info exists. */
string const getBibkeyInfo(string const &); string const getBibkeyInfo(string const &);
private: private:
/// Clean up, then hide dialog. /// clean-up any daughter class-particular data on hide.
virtual void clearParams(); virtual void clearDaughterParams();
/// The info associated with each key /// The info associated with each key
InfoMap bibkeysInfo_; InfoMap bibkeysInfo_;
}; };

View File

@ -1,4 +1,3 @@
// -*- C++ -*-
/* This file is part of /* This file is part of
* ====================================================== * ======================================================
* *
@ -19,95 +18,39 @@
#include <config.h> #include <config.h>
#include "ControlCommand.h" #include "ControlCommand.h"
#include "BufferView.h" #include "buffer.h"
#include "Dialogs.h" #include "Dialogs.h"
#include "lyxfunc.h" #include "lyxfunc.h"
#include "LyXView.h" #include "LyXView.h"
#include "support/LAssert.h"
ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac) ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac)
: ControlInset<InsetCommand>(lv, d), : ControlInset<InsetCommand, InsetCommandParams>(lv, d),
params_(0), action_(ac) action_(ac)
{} {}
void ControlCommand::showInset(InsetCommand * inset) InsetCommandParams const ControlCommand::getParams(string const & arg)
{ {
if (inset == 0) return; // maybe we should Assert this?
connectInset(inset);
show(inset->params());
}
void ControlCommand::createInset(string const & arg)
{
connectInset();
if ( !arg.empty() )
bc().valid(); // so that the user can press Ok
InsetCommandParams params; InsetCommandParams params;
params.setFromString(arg); params.setFromString(arg);
show(params); return params;
} }
InsetCommandParams const ControlCommand::getParams(InsetCommand const & inset)
void ControlCommand::update()
{ {
if (params_) delete params_; return inset.params();
if (inset_)
params_ = new InsetCommandParams(inset_->params());
else
params_ = new InsetCommandParams;
bc().readOnly(isReadonly());
view().update();
} }
void ControlCommand::applyParamsToInset()
void ControlCommand::show(InsetCommandParams const & params)
{ {
if (params_) delete params_; inset()->setParams(params());
params_ = new InsetCommandParams(params); lv_.view()->updateInset(inset(), true);
bc().readOnly(isReadonly());
view().show();
} }
void ControlCommand::applyParamsNoInset()
void ControlCommand::hide()
{ {
if (params_) { if (action_ == LFUN_NOACTION) return;
delete params_;
params_ = 0;
}
clearParams(); lv_.getLyXFunc()->Dispatch(action_, params().getAsString());
disconnect();
view().hide();
} }
InsetCommandParams & ControlCommand::params() const
{
Assert(params_);
return *params_;
}
void ControlCommand::apply()
{
view().apply();
if (inset_) {
// Only update if contents have changed
if (params() != inset_->params()) {
inset_->setParams(params());
lv_.view()->updateInset(inset_, true);
}
} else if (action_ != LFUN_NOACTION){
lv_.getLyXFunc()->Dispatch(action_, params().getAsString());
}
}

View File

@ -1,4 +1,3 @@
// -*- C++ -*-
/* This file is part of /* This file is part of
* ====================================================== * ======================================================
* *
@ -27,49 +26,29 @@
#pragma interface #pragma interface
#endif #endif
#include "ControlDialogs.h" #include "ControlInset.h"
#include "insets/insetcommand.h" #include "insets/insetcommand.h"
#include "commandtags.h" // kb_action #include "commandtags.h" // kb_action
/** The Inset dialog controller. Connects/disconnects signals, launches /** The Inset dialog controller. Connects/disconnects signals, launches
GUI-dependent View and returns the output from this View to the kernel. GUI-dependent View and returns the output from this View to the kernel.
*/ */
class ControlCommand : public ControlInset<InsetCommand> class ControlCommand : public ControlInset<InsetCommand, InsetCommandParams>
{ {
public: public:
/// ///
ControlCommand(LyXView &, Dialogs &, kb_action=LFUN_NOACTION); ControlCommand(LyXView &, Dialogs &, kb_action=LFUN_NOACTION);
/// Allow the View access to the local copy.
InsetCommandParams & params() const;
protected:
/// Slots connected in the daughter classes c-tor.
/// Slot launching dialog to (possibly) create a new inset.
void createInset(string const &);
/// Slot launching dialog to an existing inset.
void showInset(InsetCommand *);
/// Connect signals and launch View.
void show(InsetCommandParams const &);
/// Instantiation of private ControlBase virtual methods.
/// Get changed parameters and Dispatch them to the kernel.
virtual void apply();
/// Disconnect signals and hide View.
virtual void hide();
/// Update dialog before showing it.
virtual void update();
/// clean-up on hide.
virtual void clearParams() {}
private: private:
/** A local copy of the inset's params. /// Dispatch the changed parameters to the kernel.
Memory is allocated only whilst the dialog is visible. virtual void applyParamsToInset();
*/ ///
InsetCommandParams * params_; virtual void applyParamsNoInset();
/// get the parameters from the string passed to createInset.
virtual InsetCommandParams const getParams(string const &);
/// get the parameters from the inset passed to showInset.
virtual InsetCommandParams const getParams(InsetCommand const &);
/// Controls what is done in LyXFunc::Dispatch() /// Controls what is done in LyXFunc::Dispatch()
kb_action const action_; kb_action const action_;
}; };

View File

@ -108,17 +108,17 @@ public:
protected: protected:
/// ///
virtual bool isBufferDependent() const { return true; } virtual bool isBufferDependent() const { return true; }
/** Slot connected to update signal.
Bool indicates if a buffer switch took place.
Default behaviour is to ignore this and simply update().
*/
virtual void updateSlot(bool) { update(); }
/// Connect signals /// Connect signals
virtual void connect(); virtual void connect();
/// Disconnect signals /// Disconnect signals
virtual void disconnect(); virtual void disconnect();
private: private:
/** Slot connected to update signal.
Bool indicates if a buffer switch took place.
Default behaviour is to ignore this and simply update().
*/
virtual void updateSlot(bool) { update(); }
/// Update connection. /// Update connection.
SigC::Connection u_; SigC::Connection u_;
}; };

View File

@ -10,33 +10,16 @@
* \file ControlDialogs.h * \file ControlDialogs.h
* \author Angus Leeming <a.leeming@ic.ac.uk> * \author Angus Leeming <a.leeming@ic.ac.uk>
* *
* ControlDialogs.h contains the definition of two template controller classes,
* ControlDialog and ControlInset, rather clumsy names for classes that
* control the showing, updating and hiding of popups.
*
* ControlInset is to be used as a parent class for popups that display and
* can perhaps modify the contents of an individual inset. An example being the
* ubiquitous Citation popup.
*
* ControlDialog is to be used as a parent class for popups that are not * ControlDialog is to be used as a parent class for popups that are not
* Inset-popups. (An ugly description I know, but I hope the meaning is clear! * Inset-popups. (An ugly description I know, but I hope the meaning is clear!
* Can anyone do any better?) Examples would be the Document and Paragraph * Can anyone do any better?) Examples would be the Document and Paragraph
* popups. * popups.
*
* At the moment, ControlDialog is reaching a state of maturity as several
* controllers are now derived from it and its required functionality
* becaomes clear.
*
* ControlInset is still in a state of flux as currently only InsetCommand-type
* insets have a controller.
*
*/ */
#ifndef CONTROLCONNECTIONS2_H #ifndef CONTROLDIALOGS_H
#define CONTROLCONNECTIONS2_H #define CONTROLDIALOGS_H
#include "ControlConnections.h" #include "ControlConnections.h"
#include "LyXView.h"
/** Base class to control connection/disconnection of signals with the LyX /** Base class to control connection/disconnection of signals with the LyX
kernel for dialogs NOT used with insets. kernel for dialogs NOT used with insets.
@ -57,46 +40,14 @@ protected:
/// Update the dialog. /// Update the dialog.
virtual void update(); virtual void update();
/// set the params before show or update
virtual void setParams() {}
/// clean-up on hide. /// clean-up on hide.
virtual void clearParams() {} virtual void clearParams() {}
/// set the params before show or update
virtual void setParams() {}
}; };
/** Base class to control connection/disconnection of signals with the LyX #include "LyXView.h"
kernel for Inset dialogs.
*/
class Inset;
template <class Inset>
class ControlInset : public ControlConnectBD
{
public:
///
ControlInset(LyXView &, Dialogs &);
protected:
/// Slot connected to update signal.
virtual void updateSlot(bool);
/// Connect signals
void connectInset(Inset * = 0);
/// Disconnect signals
virtual void disconnect();
///
void disconnectInset();
protected:
/// pointer to the inset passed through connectInset
Inset * inset_;
private:
/// inset::hide connection.
SigC::Connection ih_;
};
template <class Base> template <class Base>
@ -138,56 +89,4 @@ void ControlDialog<Base>::hide()
view().hide(); view().hide();
} }
#endif // CONTROLDIALOGS_H
template <class Inset>
ControlInset<Inset>::ControlInset(LyXView & lv, Dialogs & d)
: ControlConnectBD(lv, d),
inset_(0), ih_(0)
{}
template <class Inset>
void ControlInset<Inset>::updateSlot(bool switched)
{
if (switched)
hide();
else
update();
}
template <class Inset>
void ControlInset<Inset>::disconnect()
{
inset_ = 0;
ih_.disconnect();
ControlConnectBD::disconnect();
}
template <class Inset>
void ControlInset<Inset>::connectInset(Inset * inset)
{
// If connected to another inset, disconnect from it.
if (inset_) {
ih_.disconnect();
inset_ = 0;
}
if (inset) {
inset_ = inset;
ih_ = inset->hideDialog.connect(
SigC::slot(this, &ControlInset::hide));
}
connect();
}
template <class Inset>
void ControlInset<Inset>::disconnectInset()
{
ih_.disconnect();
}
#endif // CONTROLCONNECTIONS2_H

View File

@ -0,0 +1,38 @@
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 2001 The LyX Team.
*
* ======================================================
*
* \file ControlError.C
* \author Angus Leeming <a.leeming@ic.ac.uk>
*/
#ifdef __GNUG__
#pragma implementation
#endif
#include <config.h>
#include "ControlError.h"
#include "Dialogs.h"
#include "LyXView.h"
#include "buffer.h"
#include "insets/inseterror.h"
using SigC::slot;
ControlError::ControlError(LyXView & lv, Dialogs & d)
: ControlInset<InsetError, string>(lv, d)
{
d_.showError.connect(slot(this, &ControlError::showInset));
}
string const ControlError::getParams(InsetError const & inset)
{
return inset.getContents();
}

View File

@ -0,0 +1,47 @@
/*
* \file ControlError.h
* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 2000-2001 The LyX Team.
*
* ======================================================
*
* \author Angus Leeming, a.leeming@.ac.uk
*/
#ifndef CONTROLERROR_H
#define CONTROLERROR_H
#ifdef __GNUG__
#pragma interface
#endif
#include "ControlInset.h"
class InsetError;
/** A controller for LaTeX Error dialogs.
*/
class ControlError : public ControlInset<InsetError, string>
{
public:
///
ControlError(LyXView &, Dialogs &);
private:
/// not needed.
virtual void applyParamsToInset() {}
///
virtual void applyParamsNoInset() {}
///
virtual void clearDaughterParams() {}
/// get the parameters from the string passed to createInset.
virtual string const getParams(string const &) { return string(); }
/// get the parameters from the inset passed to showInset.
virtual string const getParams(InsetError const &);
};
#endif // CONTROLERROR_H

View File

@ -0,0 +1,40 @@
/**
* \file ControlInclude.C
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author Alejandro Aguilar Sierra
* \author John Levon, moz@compsoc.man.ac.uk
* \author Angus Leeming, a.leeming@.ac.uk
*/
#ifdef __GNUG__
#pragma implementation
#endif
#include <config.h>
#include "ControlInclude.h"
#include "buffer.h"
#include "Dialogs.h"
#include "lyxfunc.h"
#include "LyXView.h"
using SigC::slot;
ControlInclude::ControlInclude(LyXView & lv, Dialogs & d)
: ControlInset<InsetInclude, InsetInclude::Params>(lv, d)
{
d_.showInclude.connect(slot(this, &ControlInclude::showInset));
}
LyXView * ControlInclude::lv() const
{
return &lv_;
}
void ControlInclude::applyParamsToInset()
{
inset()->set(params());
lv_.view()->updateInset(inset(), true);
}

View File

@ -0,0 +1,47 @@
/**
* \file ControlInclude.h
* Copyright 2001 the LyX Team
* See the file COPYING
*
* \author Alejandro Aguilar Sierra
* \author John Levon, moz@compsoc.man.ac.uk
* \author Angus Leeming, a.leeming@.ac.uk
*/
#ifndef CONTROLINCLUDE_H
#define CONTROLINCLUDE_H
#ifdef __GNUG__
#pragma interface
#endif
#include "ControlInset.h"
#include "insets/insetinclude.h" // InsetIncludeParams
/** A controller for the Include file dialog.
*/
class ControlInclude
: public ControlInset<InsetInclude, InsetInclude::Params>
{
public:
///
ControlInclude(LyXView &, Dialogs &);
/// The file dialog popup requires a LyXView * ???
LyXView * lv() const;
private:
/// Dispatch the changed parameters to the kernel.
virtual void applyParamsToInset();
/// Should be used but currently isn't
virtual void applyParamsNoInset() {}
/// not needed.
virtual void clearDaughterParams() {}
/// get the parameters from the string passed to createInset.
virtual InsetInclude::Params const getParams(string const &)
{ return InsetInclude::Params(); }
/// get the parameters from the inset passed to showInset.
virtual InsetInclude::Params const getParams(InsetInclude const & inset)
{ return inset.params(); }
};
#endif // CONTROLINCLUDE_H

View File

@ -0,0 +1,241 @@
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 2001 The LyX Team.
*
* ======================================================
*
* \file ControlInsets.h
* \author Angus Leeming <a.leeming@ic.ac.uk>
*
* ControlInset is to be used as a parent class for popups that display and
* can perhaps modify the contents of an individual inset. An example being the
* ubiquitous Citation popup.
*/
#ifndef CONTROLINSET_H
#define CONTROLINSET_H
#include "ControlConnections.h"
class Inset;
template <class Inset, class Params>
class ControlInset : public ControlConnectBD
{
public:
///
ControlInset(LyXView &, Dialogs &);
/// Allow the View access to the local copy.
Params & params() const;
protected:
/// Slots connected in the daughter classes c-tor.
/// Slot launching dialog to (possibly) create a new inset.
void createInset(string const &);
/// Slot launching dialog to an existing inset.
void showInset(Inset * inset);
/// Allow the daughter methods to access the inset.
Inset * inset() const;
private:
/** These 5 methods are all that the individual daughter classes
should need to instantiate. */
/// if the inset exists then do this...
virtual void applyParamsToInset() = 0;
/// else this...
virtual void applyParamsNoInset() = 0;
/// clean-up any daughter class-particular data on hide.
virtual void clearDaughterParams() = 0;
/// get the parameters from the string passed to createInset.
virtual Params const getParams(string const &) = 0;
/// get the parameters from the inset passed to showInset.
virtual Params const getParams(Inset const &) = 0;
/// Instantiation of ControlBase virtual methods.
/// Get changed parameters and Dispatch them to the kernel.
virtual void apply();
/// Disconnect signals and hide View.
virtual void hide();
/// Update the dialog.
virtual void update();
/** Instantiation of ControlConnectBD private virtual method.
Slot connected to update signal. */
virtual void updateSlot(bool);
/// Show the dialog.
void show(Params const &);
/// Connect signals
void connectInset(Inset * = 0);
/// Disconnect signals
virtual void disconnect();
///
void disconnectInset();
/// pointer to the inset passed through connectInset
Inset * inset_;
/// inset::hide connection.
SigC::Connection ih_;
/** A local copy of the inset's params.
Memory is allocated only whilst the dialog is visible.
*/
Params * params_;
};
#include "LyXView.h"
#include "support/LAssert.h"
template <class Inset, class Params>
ControlInset<Inset, Params>::ControlInset(LyXView & lv, Dialogs & d)
: ControlConnectBD(lv, d),
inset_(0), ih_(0), params_(0)
{}
template <class Inset, class Params>
void ControlInset<Inset, Params>::showInset(Inset * inset)
{
if (inset == 0) return; // maybe we should Assert this?
connectInset(inset);
show(getParams(*inset));
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::createInset(string const & arg)
{
connectInset();
if ( !arg.empty() )
bc().valid(); // so that the user can press Ok
show(getParams(arg));
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::show(Params const & params)
{
if (params_) delete params_;
params_ = new Params(params);
bc().readOnly(isReadonly());
view().show();
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::hide()
{
if (params_) {
delete params_;
params_ = 0;
}
clearDaughterParams();
disconnect();
view().hide();
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::update()
{
if (params_) delete params_;
if (inset_)
params_ = new Params(getParams(*inset_));
else
params_ = new Params();
bc().readOnly(isReadonly());
view().update();
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::apply()
{
if (lv_.buffer()->isReadonly() || !inset_)
return;
view().apply();
if (inset_ && params() != getParams(*inset_))
applyParamsToInset();
else if (!inset_)
applyParamsNoInset();
}
template <class Inset, class Params>
Params & ControlInset<Inset, Params>::params() const
{
Assert(params_);
return *params_;
}
template <class Inset, class Params>
Inset * ControlInset<Inset, Params>::inset() const
{
Assert(inset_);
return inset_;
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::updateSlot(bool switched)
{
if (switched)
hide();
else
update();
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::disconnect()
{
inset_ = 0;
ih_.disconnect();
ControlConnectBD::disconnect();
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::connectInset(Inset * inset)
{
// If connected to another inset, disconnect from it.
if (inset_) {
ih_.disconnect();
inset_ = 0;
}
if (inset) {
inset_ = inset;
ih_ = inset->hideDialog.connect(
SigC::slot(this, &ControlInset::hide));
}
connect();
}
template <class Inset, class Params>
void ControlInset<Inset, Params>::disconnectInset()
{
ih_.disconnect();
}
#endif // CONTROLINSET_H

View File

@ -36,7 +36,7 @@ public:
std::pair<Buffer::LogType, string> const & logfile() std::pair<Buffer::LogType, string> const & logfile()
{ return logfile_; } { return logfile_; }
protected: private:
/// ///
virtual void apply() {} virtual void apply() {}
/// set the params before show or update /// set the params before show or update
@ -44,7 +44,6 @@ protected:
/// clean-up on hide. /// clean-up on hide.
virtual void clearParams(); virtual void clearParams();
private:
std::pair<Buffer::LogType, string> logfile_; std::pair<Buffer::LogType, string> logfile_;
}; };

View File

@ -34,7 +34,7 @@ public:
/// ///
string const & logfile() { return logfile_; } string const & logfile() { return logfile_; }
protected: private:
/// ///
virtual void apply() {} virtual void apply() {}
/// set the params before show or update /// set the params before show or update
@ -42,7 +42,6 @@ protected:
/// clean-up on hide. /// clean-up on hide.
virtual void clearParams(); virtual void clearParams();
private:
string logfile_; string logfile_;
}; };

View File

@ -109,6 +109,34 @@ public:
}; };
/** Specialization for Error dialog
*/
class ControlError;
template <class GUIview, class GUIbc>
class GUIError :
public GUI<ControlError, GUIview, OkCancelPolicy, GUIbc> {
public:
///
GUIError(LyXView & lv, Dialogs & d)
: GUI<ControlError, GUIview, OkCancelPolicy, GUIbc>(lv, d) {}
};
/** Specialization for Include dialog
*/
class ControlInclude;
template <class GUIview, class GUIbc>
class GUIInclude :
public GUI<ControlInclude, GUIview, OkCancelReadOnlyPolicy, GUIbc> {
public:
///
GUIInclude(LyXView & lv, Dialogs & d)
: GUI<ControlInclude, GUIview, OkCancelReadOnlyPolicy, GUIbc>(lv, d) {}
};
/** Specialization for Log dialog /** Specialization for Log dialog
*/ */
class ControlLog; class ControlLog;

View File

@ -29,9 +29,14 @@ libcontrollers_la_SOURCES=\
ControlConnections.C \ ControlConnections.C \
ControlConnections.h \ ControlConnections.h \
ControlCopyright.C \ ControlCopyright.C \
ControlCopyright.h \
ControlCredits.h \ ControlCredits.h \
ControlCredits.C \ ControlCredits.C \
ControlCopyright.h \ ControlError.h \
ControlError.C \
ControlInclude.C \
ControlInclude.h \
ControlInset.h \
ControlLog.C \ ControlLog.C \
ControlLog.h \ ControlLog.h \
ControlVCLog.C \ ControlVCLog.C \

View File

@ -1,3 +1,21 @@
2001-03-23 Angus Leeming <a.leeming@ic.ac.uk>
* FormError.[Ch]:
* form_error.fd:
* FormInclude.[Ch]:
* form_include.fd: implemented controller-view split.
* Dialogs.C: associated changes.
* FormBibitem.h:
* FormBibtex.h:
* FormCitation.h: moved methods from protected to private.
2001-03-23 Angus Leeming <a.leeming@ic.ac.uk>
* FormCredits.C (build): changes associated with
ControlCredits::getCredits returning a stringstream not a vector<string>
2001-03-22 Angus Leeming <a.leeming@ic.ac.uk> 2001-03-22 Angus Leeming <a.leeming@ic.ac.uk>
* FormCopyright.[Ch]: * FormCopyright.[Ch]:

View File

@ -25,6 +25,8 @@
#include "ControlCitation.h" #include "ControlCitation.h"
#include "ControlCopyright.h" #include "ControlCopyright.h"
#include "ControlCredits.h" #include "ControlCredits.h"
#include "ControlError.h"
#include "ControlInclude.h"
#include "ControlLog.h" #include "ControlLog.h"
#include "ControlVCLog.h" #include "ControlVCLog.h"
@ -38,6 +40,8 @@
#include "form_citation.h" #include "form_citation.h"
#include "form_copyright.h" #include "form_copyright.h"
#include "form_credits.h" #include "form_credits.h"
#include "form_error.h"
#include "form_include.h"
#include "FormBibitem.h" #include "FormBibitem.h"
#include "FormBibtex.h" #include "FormBibtex.h"
@ -45,14 +49,14 @@
#include "FormCitation.h" #include "FormCitation.h"
#include "FormCopyright.h" #include "FormCopyright.h"
#include "FormCredits.h" #include "FormCredits.h"
#include "FormError.h"
#include "FormInclude.h"
#include "FormLog.h" #include "FormLog.h"
#include "FormVCLog.h" #include "FormVCLog.h"
#include "FormDocument.h" #include "FormDocument.h"
#include "FormError.h"
#include "FormExternal.h" #include "FormExternal.h"
#include "FormGraphics.h" #include "FormGraphics.h"
#include "FormInclude.h"
#include "FormIndex.h" #include "FormIndex.h"
#include "FormMathsPanel.h" #include "FormMathsPanel.h"
#include "FormParagraph.h" #include "FormParagraph.h"
@ -82,14 +86,14 @@ Dialogs::Dialogs(LyXView * lv)
add(new GUICitation<FormCitation, xformsBC>(*lv, *this)); add(new GUICitation<FormCitation, xformsBC>(*lv, *this));
add(new GUICopyright<FormCopyright, xformsBC>(*lv, *this)); add(new GUICopyright<FormCopyright, xformsBC>(*lv, *this));
add(new GUICredits<FormCredits, xformsBC>(*lv, *this)); add(new GUICredits<FormCredits, xformsBC>(*lv, *this));
add(new GUIError<FormError, xformsBC>(*lv, *this));
add(new GUIInclude<FormInclude, xformsBC>(*lv, *this));
add(new GUILog<FormLog, xformsBC>(*lv, *this)); add(new GUILog<FormLog, xformsBC>(*lv, *this));
add(new GUIVCLog<FormVCLog, xformsBC>(*lv, *this)); add(new GUIVCLog<FormVCLog, xformsBC>(*lv, *this));
add(new FormDocument(lv, this)); add(new FormDocument(lv, this));
add(new FormError(lv, this));
add(new FormExternal(lv, this)); add(new FormExternal(lv, this));
add(new FormGraphics(lv, this)); add(new FormGraphics(lv, this));
add(new FormInclude(lv, this));
add(new FormIndex(lv, this)); add(new FormIndex(lv, this));
add(new FormMathsPanel(lv, this)); add(new FormMathsPanel(lv, this));
add(new FormParagraph(lv, this)); add(new FormParagraph(lv, this));

View File

@ -28,16 +28,13 @@ public:
/// ///
FormBibitem(ControlBibitem &); FormBibitem(ControlBibitem &);
// Functions accessible to the Controller. private:
/// Set the Params variable for the Controller. /// Set the Params variable for the Controller.
virtual void apply(); virtual void apply();
/// Build the dialog. /// Build the dialog.
virtual void build(); virtual void build();
/// Update dialog before/whilst showing it. /// Update dialog before/whilst showing it.
virtual void update(); virtual void update();
private:
/// Filter the inputs on callback from xforms /// Filter the inputs on callback from xforms
virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);

View File

@ -28,16 +28,13 @@ public:
/// ///
FormBibtex(ControlBibtex &); FormBibtex(ControlBibtex &);
// Functions accessible to the Controller. private:
/// Set the Params variable for the Controller. /// Set the Params variable for the Controller.
virtual void apply(); virtual void apply();
/// Build the dialog. /// Build the dialog.
virtual void build(); virtual void build();
/// Update dialog before/whilst showing it. /// Update dialog before/whilst showing it.
virtual void update(); virtual void update();
private:
/// Filter the inputs on callback from xforms /// Filter the inputs on callback from xforms
virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
/// ///

View File

@ -30,17 +30,6 @@ public:
/// ///
FormCitation(ControlCitation &); FormCitation(ControlCitation &);
// Functions accessible to the Controller.
/// Set the Params variable for the Controller.
virtual void apply();
/// Build the dialog.
virtual void build();
/// Hide the dialog.
virtual void hide();
/// Update dialog before/whilst showing it.
virtual void update();
private: private:
/// ///
enum State { enum State {
@ -50,6 +39,14 @@ private:
OFF OFF
}; };
/// Set the Params variable for the Controller.
virtual void apply();
/// Build the dialog.
virtual void build();
/// Hide the dialog.
virtual void hide();
/// Update dialog before/whilst showing it.
virtual void update();
/// Filter the inputs on callback from xforms /// Filter the inputs on callback from xforms
virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);

View File

@ -1,74 +1,34 @@
// -*- C++ -*- /*
/* This file is part of * \file FormError.C
* This file is part of
* ====================================================== * ======================================================
* *
* LyX, The Document Processor * LyX, The Document Processor
* *
* Copyright 2000 The LyX Team. * Copyright 2000-2001 The LyX Team.
* *
* ====================================================== * ======================================================
*
* \author Angus Leeming, a.leeming@.ac.uk
*/ */
#include <config.h>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation #pragma implementation
#endif #endif
#include "Dialogs.h" #include <config.h>
#include "xformsBC.h"
#include "ControlError.h"
#include "FormError.h" #include "FormError.h"
#include "form_error.h" #include "form_error.h"
#include "insets/inseterror.h" #include "xforms_helpers.h" // formatted
#include "support/LAssert.h"
using SigC::slot; typedef FormCB<ControlError, FormDB<FD_form_error> > base_class;
FormError::FormError(LyXView * lv, Dialogs * d) FormError::FormError(ControlError & c)
: FormInset( lv, d, _("LaTeX Error")), : base_class(c, _("LaTeX Error"))
inset_(0) {}
{
Assert(lv && d);
// let the dialog be shown
// This is a permanent connection so we won't bother
// storing a copy because we won't be disconnecting.
d->showError.connect(slot(this, &FormError::showInset));
}
FL_FORM * FormError::form() const
{
if (dialog_.get()) return dialog_->form;
return 0;
}
void FormError::disconnect()
{
inset_ = 0;
message_.erase();
FormInset::disconnect();
}
void FormError::showInset(InsetError * inset)
{
if (inset == 0) return; // Is this _really_ allowed? (Lgb)
// If connected to another inset, disconnect from it.
if (inset_)
ih_.disconnect();
inset_ = inset;
message_ = inset->getContents();
ih_ = inset->hideDialog.connect(slot(this, &FormError::hide));
show();
}
void FormError::update()
{
fl_set_object_label(dialog_->message, message_.c_str());
}
void FormError::build() void FormError::build()
@ -79,3 +39,11 @@ void FormError::build()
bc().setCancel(dialog_->button_cancel); bc().setCancel(dialog_->button_cancel);
bc().refresh(); bc().refresh();
} }
void FormError::update()
{
string const txt = formatted(controller().params(),
dialog_->message->w-10);
fl_set_object_label(dialog_->message, txt.c_str());
}

View File

@ -1,65 +1,46 @@
// -*- C++ -*- /*
/* This file is part of * \file FormError.h
* This file is part of
* ====================================================== * ======================================================
* *
* LyX, The Document Processor * LyX, The Document Processor
* *
* Copyright 2000 The LyX Team. * Copyright 2000-2001 The LyX Team.
* *
* ====================================================== * ======================================================
*
* \author Angus Leeming, a.leeming@.ac.uk
*/ */
#ifndef FORMERROR_H #ifndef FORMERROR_H
#define FORMERROR_H #define FORMERROR_H
#include <boost/smart_ptr.hpp>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface #pragma interface
#endif #endif
#include "FormInset.h" #include "FormBase.h"
class InsetError; class ControlError;
struct FD_form_error; struct FD_form_error;
/** This class provides an XForms implementation of the FormError Dialog. /** This class provides an XForms implementation of the Error Dialog.
*/ */
class FormError : public FormInset { class FormError : public FormCB<ControlError, FormDB<FD_form_error> > {
public: public:
/// Constructor /// Constructor
FormError(LyXView *, Dialogs *); FormError(ControlError &);
private:
/// Pointer to the actual instantiation of the ButtonController.
virtual xformsBC & bc();
/// Disconnect signals. Also perform any necessary housekeeping.
virtual void disconnect();
/// Slot launching dialog to an existing inset private:
void showInset(InsetError *); /// not needed.
/// Update dialog before showing it virtual void apply() {}
virtual void update();
/// Build the dialog /// Build the dialog
virtual void build(); virtual void build();
/// Pointer to the actual instantiation of the xforms form /// Update dialog before showing it
virtual FL_FORM * form() const; virtual void update();
/// Fdesign generated method /// Fdesign generated method
FD_form_error * build_error(); FD_form_error * build_error();
/// Real GUI implementation.
boost::scoped_ptr<FD_form_error> dialog_;
/// pointer to the inset passed through showInset
InsetError * inset_;
/// the error message
string message_;
/// The ButtonController
ButtonController<OkCancelPolicy, xformsBC> bc_;
}; };
#endif // FORMERROR_H
inline
xformsBC & FormError::bc()
{
return bc_;
}
#endif

View File

@ -4,9 +4,10 @@
* Read the file COPYING * Read the file COPYING
* *
* \author Alejandro Aguilar Sierra * \author Alejandro Aguilar Sierra
* \author John Levon * \author John Levon, moz@compsoc.man.ac.uk
* \author Angus Leeming, a.leeming@.ac.uk
*/ */
#include <config.h>
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
@ -14,65 +15,30 @@
#pragma implementation #pragma implementation
#endif #endif
#include "Dialogs.h" #include <config.h>
#include "xformsBC.h"
#include "ControlInclude.h"
#include "FormInclude.h" #include "FormInclude.h"
#include "form_include.h"
#include "insets/insetinclude.h" #include "insets/insetinclude.h"
#include "frontends/FileDialog.h" #include "frontends/FileDialog.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "LyXView.h" #include "LyXView.h"
#include "buffer.h" #include "buffer.h"
#include "lyxrc.h"
#include "lyxfunc.h"
#include "xforms_helpers.h"
#include "form_include.h" #include "xforms_helpers.h" // setEnabled
#include "support/filetools.h"
#include "support/lstrings.h"
#include "lyxrc.h"
using std::make_pair; using std::make_pair;
using std::pair; using std::pair;
using SigC::slot;
FormInclude::FormInclude(LyXView * lv, Dialogs * d) typedef FormCB<ControlInclude, FormDB<FD_form_include> > base_class;
: FormBaseBD(lv, d, _("Include file")),
ih_(0), inset_(0)
{
d->showInclude.connect(slot(this, &FormInclude::showInclude));
}
FormInclude::FormInclude(ControlInclude & c)
FL_FORM * FormInclude::form() const : base_class(c, _("Include file"))
{ {}
if (dialog_.get())
return dialog_->form;
return 0;
}
void FormInclude::connect()
{
u_ = d_->updateBufferDependent.
connect(slot(this, &FormInclude::updateSlot));
h_ = d_->hideBufferDependent.
connect(slot(this, &FormInclude::hide));
FormBaseDeprecated::connect();
}
void FormInclude::disconnect()
{
ih_.disconnect();
FormBaseBD::disconnect();
inset_ = 0;
}
void FormInclude::updateSlot(bool switched)
{
if (switched)
hide();
else
update();
}
void FormInclude::build() void FormInclude::build()
@ -80,36 +46,21 @@ void FormInclude::build()
dialog_.reset(build_include()); dialog_.reset(build_include());
// Manage the ok and cancel buttons // Manage the ok and cancel buttons
bc_.setOK(dialog_->button_ok); bc().setOK(dialog_->button_ok);
bc_.setCancel(dialog_->button_cancel); bc().setCancel(dialog_->button_cancel);
bc_.refresh(); bc().refresh();
bc_.addReadOnly(dialog_->button_browse); bc().addReadOnly(dialog_->button_browse);
bc_.addReadOnly(dialog_->check_verbatim); bc().addReadOnly(dialog_->check_verbatim);
bc_.addReadOnly(dialog_->check_typeset); bc().addReadOnly(dialog_->check_typeset);
bc_.addReadOnly(dialog_->check_useinput); bc().addReadOnly(dialog_->check_useinput);
bc_.addReadOnly(dialog_->check_useinclude); bc().addReadOnly(dialog_->check_useinclude);
}
void FormInclude::showInclude(InsetInclude * inset)
{
// If connected to another inset, disconnect from it.
if (inset_)
ih_.disconnect();
inset_ = inset;
params = inset->params();
ih_ = inset->hideDialog.connect(slot(this, &FormInclude::hide));
show();
} }
void FormInclude::update() void FormInclude::update()
{ {
bc().readOnly(lv_->buffer()->isReadonly()); if (controller().params().noload) {
if (!inset_) {
fl_set_input(dialog_->input_filename, ""); fl_set_input(dialog_->input_filename, "");
fl_set_button(dialog_->check_typeset, 0); fl_set_button(dialog_->check_typeset, 0);
fl_set_button(dialog_->check_useinput, 0); fl_set_button(dialog_->check_useinput, 0);
@ -121,11 +72,13 @@ void FormInclude::update()
return; return;
} }
fl_set_input(dialog_->input_filename, params.cparams.getContents().c_str()); fl_set_input(dialog_->input_filename,
controller().params().cparams.getContents().c_str());
string const cmdname = params.cparams.getCmdName(); string const cmdname = controller().params().cparams.getCmdName();
fl_set_button(dialog_->check_typeset, int(params.noload)); fl_set_button(dialog_->check_typeset,
int(controller().params().noload));
fl_set_button(dialog_->check_useinput, cmdname == "input"); fl_set_button(dialog_->check_useinput, cmdname == "input");
fl_set_button(dialog_->check_useinclude, cmdname == "include"); fl_set_button(dialog_->check_useinclude, cmdname == "include");
@ -145,86 +98,85 @@ void FormInclude::update()
void FormInclude::apply() void FormInclude::apply()
{ {
if (lv_->buffer()->isReadonly()) controller().params().noload = fl_get_button(dialog_->check_typeset);
return;
params.noload = fl_get_button(dialog_->check_typeset); controller().params().cparams.
setContents(fl_get_input(dialog_->input_filename));
params.cparams.setContents(fl_get_input(dialog_->input_filename));
if (fl_get_button(dialog_->check_useinput)) if (fl_get_button(dialog_->check_useinput))
params.flag = InsetInclude::INPUT; controller().params().flag = InsetInclude::INPUT;
else if (fl_get_button(dialog_->check_useinclude)) else if (fl_get_button(dialog_->check_useinclude))
params.flag = InsetInclude::INCLUDE; controller().params().flag = InsetInclude::INCLUDE;
else if (fl_get_button(dialog_->check_verbatim)) { else if (fl_get_button(dialog_->check_verbatim)) {
if (fl_get_button(dialog_->check_visiblespace)) if (fl_get_button(dialog_->check_visiblespace))
params.flag = InsetInclude::VERBAST; controller().params().flag = InsetInclude::VERBAST;
else else
params.flag = InsetInclude::VERB; controller().params().flag = InsetInclude::VERB;
} }
inset_->setFromParams(params);
lv_->view()->updateInset(inset_, true);
} }
#ifdef WITH_WARNINGS
#warning convert this to use the buttoncontroller ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
#endif
bool FormInclude::input(FL_OBJECT *, long data)
{ {
State state = static_cast<State>(data); if (ob == dialog_->button_browse)
return inputBrowse();
switch (state) { if (ob == dialog_->button_load) {
case BROWSE: { if (compare(fl_get_input(dialog_->input_filename),"")) {
// Should browsing too be disabled in RO-mode? ApplyButton();
FileDialog fileDlg(lv_, _("Select document to include"), return ButtonPolicy::SMI_NOOP;
LFUN_SELECT_FILE_SYNC, }
make_pair(string(_("Documents")), string(lyxrc.document_path)));
string ext;
/* input TeX, verbatim, or LyX file ? */
if (fl_get_button(dialog_->check_useinput))
ext = _("*.tex| LaTeX Documents (*.tex)");
else if (fl_get_button(dialog_->check_verbatim))
ext = _("*| All files ");
else
ext = _("*.lyx| LyX Documents (*.lyx)");
string mpath;
mpath = OnlyPath(params.buffer->fileName());
FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->input_filename));
// check selected filename
if (result.second.empty())
break;
string const filename2 = MakeRelPath(result.second, mpath);
if (prefixIs(filename2, ".."))
fl_set_input(dialog_->input_filename, result.second.c_str());
else
fl_set_input(dialog_->input_filename, filename2.c_str());
} break;
case LOAD:
if (compare(fl_get_input(dialog_->input_filename),"")) {
apply();
lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.cparams.getContents());
}
break;
case VERBATIM:
setEnabled(dialog_->check_visiblespace, true);
break;
case INPUTINCLUDE:
fl_set_button(dialog_->check_visiblespace, 0);
setEnabled(dialog_->check_visiblespace, false);
break;
} }
return true;
if (ob == dialog_->check_verbatim) {
setEnabled(dialog_->check_visiblespace, true);
} else if (ob == dialog_->check_useinclude ||
ob == dialog_->check_useinput) {
fl_set_button(dialog_->check_visiblespace, 0);
setEnabled(dialog_->check_visiblespace, false);
}
return ButtonPolicy::SMI_VALID;
}
ButtonPolicy::SMInput FormInclude::inputBrowse()
{
// Should browsing too be disabled in RO-mode?
FileDialog fileDlg(controller().lv(),
_("Select document to include"),
LFUN_SELECT_FILE_SYNC,
make_pair(string(_("Documents")),
string(lyxrc.document_path)));
string ext;
// input TeX, verbatim, or LyX file ?
if (fl_get_button(dialog_->check_useinput))
ext = _("*.tex| LaTeX Documents (*.tex)");
else if (fl_get_button(dialog_->check_verbatim))
ext = _("*| All files ");
else
ext = _("*.lyx| LyX Documents (*.lyx)");
string const mpath =
OnlyPath(controller().params().masterFilename_);
FileDialog::Result const result =
fileDlg.Select(mpath, ext,
fl_get_input(dialog_->input_filename));
// check selected filename
if (result.second.empty())
return ButtonPolicy::SMI_NOOP;
string const filename2 = MakeRelPath(result.second, mpath);
if (prefixIs(filename2, ".."))
fl_set_input(dialog_->input_filename, result.second.c_str());
else
fl_set_input(dialog_->input_filename, filename2.c_str());
return ButtonPolicy::SMI_VALID;
} }

View File

@ -5,86 +5,42 @@
* See the file COPYING * See the file COPYING
* *
* \author Alejandro Aguilar Sierra * \author Alejandro Aguilar Sierra
* \author John Levon * \author John Levon, moz@compsoc.man.ac.uk
* \author Angus Leeming <a.leeming@ic.ac.uk>
*/ */
#ifndef FORMINCLUDE_H #ifndef FORMINCLUDE_H
#define FORMINCLUDE_H #define FORMINCLUDE_H
#include <boost/smart_ptr.hpp>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface #pragma interface
#endif #endif
#include "FormBaseDeprecated.h" #include "FormBase.h"
#include "insets/insetinclude.h"
class ControlInclude;
struct FD_form_include; struct FD_form_include;
/** This class provides an XForms implementation of the FormInclude Dialog. /** This class provides an XForms implementation of the Include Dialog.
*/ */
class FormInclude : public FormBaseBD { class FormInclude : public FormCB<ControlInclude, FormDB<FD_form_include> > {
public: public:
/// ///
FormInclude(LyXView *, Dialogs *); FormInclude(ControlInclude &);
private: private:
/// /// Set the Params variable for the Controller.
enum State { virtual void apply();
/// the browse button
BROWSE = 0,
/// the load file button
LOAD = 5,
/// the verbatim radio choice
VERBATIM = 10,
/// the input and include radio choices
INPUTINCLUDE = 11
};
/// Pointer to the actual instantiation of the ButtonController.
virtual xformsBC & bc();
/// Slot launching dialog to an existing inset
void showInclude(InsetInclude *);
/// Connect signals. Also perform any necessary initialisation.
virtual void connect();
/// Disconnect signals. Also perform any necessary housekeeping.
virtual void disconnect();
/// Build the dialog /// Build the dialog
virtual void build(); virtual void build();
/// Filter the inputs
virtual bool input( FL_OBJECT *, long );
/// Update dialog before showing it /// Update dialog before showing it
virtual void update(); virtual void update();
/// Apply from dialog (modify or create inset) /// Filter the inputs on callback from xforms
virtual void apply(); virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
/// Pointer to the actual instantiation of the xforms form
virtual FL_FORM * form() const;
/// bool indicates if a buffer switch took place
virtual void updateSlot(bool);
///
ButtonPolicy::SMInput inputBrowse();
/// Type definition from the fdesign produced header file. /// Type definition from the fdesign produced header file.
FD_form_include * build_include(); FD_form_include * build_include();
/// Real GUI implementation.
boost::scoped_ptr<FD_form_include> dialog_;
/// The ButtonController
ButtonController<OkCancelReadOnlyPolicy, xformsBC> bc_;
/// inset::hide connection.
SigC::Connection ih_;
/// pointer to the inset passed through showInset
InsetInclude * inset_;
/// the nitty-gritty. What is modified and passed back
InsetInclude::InsetIncludeParams params;
}; };
inline
xformsBC & FormInclude::bc()
{
return bc_;
}
#endif #endif

View File

@ -34,7 +34,7 @@ FD_form_error * FormError::build_error()
} }
fl_set_object_gravity(obj, FL_South, FL_South); fl_set_object_gravity(obj, FL_South, FL_South);
fl_set_object_resize(obj, FL_RESIZE_NONE); fl_set_object_resize(obj, FL_RESIZE_NONE);
fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0); fl_set_object_callback(obj, C_FormBaseCancelCB, 0);
fl_end_form(); fl_end_form();
fdui->form->fdui = fdui; fdui->form->fdui = fdui;

View File

@ -5,7 +5,7 @@
#define FD_form_error_h_ #define FD_form_error_h_
/** Callbacks, globals and object handlers **/ /** Callbacks, globals and object handlers **/
extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long); extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long);
/**** Forms and Objects ****/ /**** Forms and Objects ****/

View File

@ -32,7 +32,7 @@ FD_form_include * FormInclude::build_include()
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 0); fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{ {
char const * const dummy = N_("Don't typeset|#D"); char const * const dummy = N_("Don't typeset|#D");
fdui->check_typeset = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 180, 70, 150, 30, idex(_(dummy))); fdui->check_typeset = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 180, 70, 150, 30, idex(_(dummy)));
@ -41,21 +41,21 @@ FD_form_include * FormInclude::build_include()
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 120, 170, 100, 30, _("OK")); fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 120, 170, 100, 30, _("OK"));
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseDeprecatedOKCB, 1); fl_set_object_callback(obj, C_FormBaseOKCB, 0);
{ {
char const * const dummy = N_("Cancel|^["); char const * const dummy = N_("Cancel|^[");
fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 230, 170, 100, 30, idex(_(dummy))); fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 230, 170, 100, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 2); fl_set_object_callback(obj, C_FormBaseCancelCB, 0);
{ {
char const * const dummy = N_("Load|#L"); char const * const dummy = N_("Load|#L");
fdui->button_load = obj = fl_add_button(FL_NORMAL_BUTTON, 230, 130, 100, 30, idex(_(dummy))); fdui->button_load = obj = fl_add_button(FL_NORMAL_BUTTON, 230, 130, 100, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 5); fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{ {
char const * const dummy = N_("File name:|#F"); char const * const dummy = N_("File name:|#F");
fdui->input_filename = obj = fl_add_input(FL_NORMAL_INPUT, 10, 30, 210, 30, idex(_(dummy))); fdui->input_filename = obj = fl_add_input(FL_NORMAL_INPUT, 10, 30, 210, 30, idex(_(dummy)));
@ -77,21 +77,21 @@ FD_form_include * FormInclude::build_include()
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 10); fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{ {
char const * const dummy = N_("Use input|#i"); char const * const dummy = N_("Use input|#i");
fdui->check_useinput = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 10, 100, 160, 30, idex(_(dummy))); fdui->check_useinput = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 10, 100, 160, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 11); fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{ {
char const * const dummy = N_("Use include|#U"); char const * const dummy = N_("Use include|#U");
fdui->check_useinclude = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 10, 70, 160, 30, idex(_(dummy))); fdui->check_useinclude = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 10, 70, 160, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseDeprecatedInputCB, 11); fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_end_group(); fl_end_group();
fl_end_form(); fl_end_form();

View File

@ -5,9 +5,9 @@
#define FD_form_include_h_ #define FD_form_include_h_
/** Callbacks, globals and object handlers **/ /** Callbacks, globals and object handlers **/
extern "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT *, long); extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
extern "C" void C_FormBaseDeprecatedOKCB(FL_OBJECT *, long); extern "C" void C_FormBaseOKCB(FL_OBJECT *, long);
extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long); extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long);
/**** Forms and Objects ****/ /**** Forms and Objects ****/

View File

@ -63,7 +63,7 @@ shortcut:
resize: FL_RESIZE_NONE resize: FL_RESIZE_NONE
gravity: FL_South FL_South gravity: FL_South FL_South
name: button_cancel name: button_cancel
callback: C_FormBaseDeprecatedCancelCB callback: C_FormBaseCancelCB
argument: 0 argument: 0
============================== ==============================

View File

@ -63,8 +63,8 @@ shortcut:
resize: FL_RESIZE_ALL resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity gravity: FL_NoGravity FL_NoGravity
name: button_browse name: button_browse
callback: C_FormBaseDeprecatedInputCB callback: C_FormBaseInputCB
argument: 0 argument:
-------------------- --------------------
class: FL_CHECKBUTTON class: FL_CHECKBUTTON
@ -99,8 +99,8 @@ shortcut: ^M
resize: FL_RESIZE_ALL resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity gravity: FL_NoGravity FL_NoGravity
name: button_ok name: button_ok
callback: C_FormBaseDeprecatedOKCB callback: C_FormBaseOKCB
argument: 1 argument:
-------------------- --------------------
class: FL_BUTTON class: FL_BUTTON
@ -117,8 +117,8 @@ shortcut:
resize: FL_RESIZE_ALL resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity gravity: FL_NoGravity FL_NoGravity
name: button_cancel name: button_cancel
callback: C_FormBaseDeprecatedCancelCB callback: C_FormBaseCancelCB
argument: 2 argument:
-------------------- --------------------
class: FL_BUTTON class: FL_BUTTON
@ -135,8 +135,8 @@ shortcut:
resize: FL_RESIZE_ALL resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity gravity: FL_NoGravity FL_NoGravity
name: button_load name: button_load
callback: C_FormBaseDeprecatedInputCB callback: C_FormBaseInputCB
argument: 5 argument:
-------------------- --------------------
class: FL_INPUT class: FL_INPUT
@ -207,8 +207,8 @@ shortcut:
resize: FL_RESIZE_ALL resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity gravity: FL_NoGravity FL_NoGravity
name: check_verbatim name: check_verbatim
callback: C_FormBaseDeprecatedInputCB callback: C_FormBaseInputCB
argument: 10 argument:
-------------------- --------------------
class: FL_CHECKBUTTON class: FL_CHECKBUTTON
@ -225,8 +225,8 @@ shortcut:
resize: FL_RESIZE_ALL resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity gravity: FL_NoGravity FL_NoGravity
name: check_useinput name: check_useinput
callback: C_FormBaseDeprecatedInputCB callback: C_FormBaseInputCB
argument: 11 argument:
-------------------- --------------------
class: FL_CHECKBUTTON class: FL_CHECKBUTTON
@ -243,8 +243,8 @@ shortcut:
resize: FL_RESIZE_ALL resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity gravity: FL_NoGravity FL_NoGravity
name: check_useinclude name: check_useinclude
callback: C_FormBaseDeprecatedInputCB callback: C_FormBaseInputCB
argument: 11 argument:
-------------------- --------------------
class: FL_END_GROUP class: FL_END_GROUP

View File

@ -1,3 +1,9 @@
2001-03-23 Angus Leeming <a.leeming@ic.ac.uk>
* insetinclude.[Ch]: rename InsetInclude::InsetIncludeParams as
InsetInclude::Params. Don't store a buffer * in Params. Store the
master file name instead.
2001-03-23 Juergen Vigna <jug@sad.it> 2001-03-23 Juergen Vigna <jug@sad.it>
* insetcollapsable.C (InsetMotionNotify): * insetcollapsable.C (InsetMotionNotify):

View File

@ -31,8 +31,8 @@ extern BufferList bufferlist;
namespace { namespace {
inline string const unique_id()
string const unique_id() { {
static unsigned int seed = 1000; static unsigned int seed = 1000;
std::ostringstream ost; std::ostringstream ost;
@ -45,19 +45,16 @@ string const unique_id() {
} // namespace anon } // namespace anon
InsetInclude::InsetInclude(InsetIncludeParams const & p) InsetInclude::InsetInclude(Params const & p)
{ : params_(p), include_label(unique_id())
include_label = unique_id(); {}
setFromParams(p);
params_.buffer = p.buffer;
}
InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b) InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b)
{ {
params_.cparams = p;
params_.masterFilename_ = b.fileName();
include_label = unique_id(); include_label = unique_id();
params_.buffer = &b;
setFromParams(p);
} }
@ -67,36 +64,48 @@ InsetInclude::~InsetInclude()
} }
InsetInclude::InsetIncludeParams const & InsetInclude::params() const InsetInclude::Params const & InsetInclude::params() const
{ {
return params_; return params_;
} }
void InsetInclude::setFromParams(InsetIncludeParams const & p) bool InsetInclude::Params::operator==(Params const & o) const
{ {
params_.cparams.setContents(p.cparams.getContents()); if (cparams == o.cparams && flag == o.flag &&
params_.noload = p.noload; noload == o.noload && masterFilename_ == o.masterFilename_)
if (params_.flag == p.flag) return true;
return;
params_.flag = p.flag; return false;
}
bool InsetInclude::Params::operator!=(Params const & o) const
{
return !(*this == o);
}
void InsetInclude::set(Params const & p)
{
params_ = p;
// Just to be safe...
string command; string command;
switch (params_.flag) { switch (params_.flag) {
case INCLUDE: case INCLUDE:
command="include"; command="include";
break; break;
case VERB: case VERB:
command="verbatiminput"; command="verbatiminput";
break; break;
case INPUT: case INPUT:
command="input"; command="input";
break; break;
case VERBAST: case VERBAST:
command="verbatiminput*"; command="verbatiminput*";
break; break;
} }
params_.cparams.setCmdName(command); params_.cparams.setCmdName(command);
@ -105,10 +114,10 @@ void InsetInclude::setFromParams(InsetIncludeParams const & p)
Inset * InsetInclude::Clone(Buffer const & buffer) const Inset * InsetInclude::Clone(Buffer const & buffer) const
{ {
InsetIncludeParams p(params_); Params p(params_);
p.buffer = &buffer; p.masterFilename_ = buffer.fileName();
return new InsetInclude (p); return new InsetInclude(p);
} }
@ -184,7 +193,7 @@ string const InsetInclude::getFileName() const
string const InsetInclude::getMasterFilename() const string const InsetInclude::getMasterFilename() const
{ {
return params_.buffer->fileName(); return params_.masterFilename_;
} }
@ -367,11 +376,11 @@ void InsetInclude::Validate(LaTeXFeatures & features) const
string incfile(params_.cparams.getContents()); string incfile(params_.cparams.getContents());
string writefile; string writefile;
Buffer const & b = *params_.buffer; Buffer const * const b = bufferlist.getBuffer(getMasterFilename());
if (!b.tmppath.empty() && b.niceFile) { if (b && !b->tmppath.empty() && b->niceFile) {
incfile = subst(incfile, '/','@'); incfile = subst(incfile, '/','@');
writefile = AddName(b.tmppath, incfile); writefile = AddName(b->tmppath, incfile);
} else } else
writefile = getFileName(); writefile = getFileName();
@ -388,8 +397,9 @@ void InsetInclude::Validate(LaTeXFeatures & features) const
// to be loaded: // to be loaded:
if (loadIfNeeded()) { if (loadIfNeeded()) {
// a file got loaded // a file got loaded
Buffer * tmp = bufferlist.getBuffer(getFileName()); Buffer const * const tmp = bufferlist.getBuffer(getFileName());
tmp->validate(features); if (tmp)
tmp->validate(features);
} }
} }

View File

@ -27,9 +27,9 @@ struct LaTeXFeatures;
class InsetInclude: public InsetButton, public boost::noncopyable { class InsetInclude: public InsetButton, public boost::noncopyable {
public: public:
/// the type of inclusion /// the type of inclusion
enum IncludeFlags { enum Flags {
/// ///
INCLUDE= 0, INCLUDE = 0,
/// ///
VERB = 1, VERB = 1,
/// ///
@ -38,30 +38,37 @@ public:
VERBAST = 3 VERBAST = 3
}; };
struct InsetIncludeParams { struct Params {
InsetIncludeParams(InsetCommandParams const & cp = InsetCommandParams(), Params(InsetCommandParams const & cp = InsetCommandParams(),
IncludeFlags f = INCLUDE, bool nl = false, Buffer const * b = 0) Flags f = INCLUDE,
: cparams(cp), flag(f), noload(nl), buffer(b) {} bool nl = false,
string const & name = string())
: cparams(cp), flag(f), noload(nl),
masterFilename_(name) {}
InsetCommandParams cparams; InsetCommandParams cparams;
IncludeFlags flag; Flags flag;
bool noload; bool noload;
Buffer const * buffer; string masterFilename_;
///
bool operator==(Params const &) const;
///
bool operator!=(Params const &) const;
}; };
/// ///
InsetInclude(InsetIncludeParams const &); InsetInclude(Params const &);
/// ///
InsetInclude(InsetCommandParams const &, Buffer const &); InsetInclude(InsetCommandParams const &, Buffer const &);
/// ///
~InsetInclude(); ~InsetInclude();
/// get the parameters /// get the parameters
InsetIncludeParams const & params(void) const; Params const & params(void) const;
/// set the parameters /// set the parameters
void setFromParams(InsetIncludeParams const & params); void set(Params const & params);
/// ///
Inset * Clone(Buffer const &) const; Inset * Clone(Buffer const &) const;
/// ///
Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; } Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; }
@ -118,7 +125,7 @@ private:
string const getFileName() const; string const getFileName() const;
/// the parameters /// the parameters
InsetIncludeParams params_; Params params_;
/// ///
string include_label; string include_label;
}; };