refine the logic for checking whether a dialog may apply its data or not

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9874 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2005-04-26 09:37:52 +00:00
parent a4315ed9de
commit a70b4ef051
26 changed files with 81 additions and 19 deletions

View File

@ -1,3 +1,12 @@
2005-04-25 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* Dialog.h, ControlCharacter.h, ControlPrint.h, ControlSendto.h,
ControlTabular.h, ControlTabularCreate.h (getLfun): new, return the
lfun for applying the data
* Control*.C (dispatchParams): use getLfun where appropriate
* Dialog.[Ch], ControlChanges.h, ControlDocument.h (canApply): new,
check whether the dialog data may be applied
2005-04-11 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* ControlDocument.C (dispatchParams): update the counters if

View File

@ -47,7 +47,7 @@ void ControlBox::clearParams()
void ControlBox::dispatchParams()
{
string const lfun = InsetBoxMailer::params2string(params());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -49,7 +49,7 @@ void ControlBranch::clearParams()
void ControlBranch::dispatchParams()
{
string const lfun = InsetBranchMailer::params2string(params());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -32,6 +32,8 @@ public:
virtual void dispatchParams() {}
///
virtual bool isBufferDependent() const { return true; }
/// always true since dispatchParams() is empty
virtual bool canApply() const { return true; }
/// find the next merge chunk and highlight it
bool find();

View File

@ -65,7 +65,7 @@ void ControlCharacter::dispatchParams()
string data;
if (font2string(*font_.get(), toggleall_, data)) {
kernel().dispatch(FuncRequest(LFUN_FREEFONT_UPDATE, data));
kernel().dispatch(FuncRequest(getLfun(), data));
}
}

View File

@ -34,6 +34,8 @@ public:
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
virtual kb_action getLfun() const { return LFUN_TABULAR_INSERT; }
///
void setFamily(LyXFont::FONT_FAMILY);

View File

@ -49,7 +49,7 @@ void ControlCommand::dispatchParams()
string const lfun = InsetCommandMailer::params2string(lfun_name_,
params_);
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend

View File

@ -38,6 +38,8 @@ public:
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
/// always true since we don't manipulate document contents
virtual bool canApply() const { return true; }
///
LyXTextClass const & textClass() const;
///

View File

@ -41,7 +41,7 @@ void ControlERT::clearParams()
void ControlERT::dispatchParams()
{
string const lfun = InsetERTMailer::params2string(status_);
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend

View File

@ -69,7 +69,7 @@ void ControlExternal::dispatchParams()
string const lfun = InsetExternalMailer::params2string(params(),
kernel().buffer());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -43,7 +43,7 @@ void ControlFloat::clearParams()
void ControlFloat::dispatchParams()
{
string const lfun = InsetFloatMailer::params2string(params());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend

View File

@ -77,7 +77,7 @@ void ControlGraphics::dispatchParams()
InsetGraphicsParams tmp_params(params());
string const lfun =
InsetGraphicsMailer::params2string(tmp_params, kernel().buffer());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -62,7 +62,7 @@ void ControlInclude::clearParams()
void ControlInclude::dispatchParams()
{
string const lfun = InsetIncludeMailer::params2string(params_);
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -44,7 +44,7 @@ void ControlNote::clearParams()
void ControlNote::dispatchParams()
{
string const lfun = InsetNoteMailer::params2string(params());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend

View File

@ -139,7 +139,7 @@ void ControlPrint::dispatchParams()
pp.file_name;
string const data = target + " " + target_name + " " + command;
kernel().dispatch(FuncRequest(LFUN_PRINT, data));
kernel().dispatch(FuncRequest(getLfun(), data));
}
} // namespace frontend

View File

@ -35,6 +35,8 @@ public:
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
virtual kb_action getLfun() const { return LFUN_PRINT; }
/// Browse for a file
std::string const browse(std::string const &) const;

View File

@ -11,6 +11,7 @@
#include <config.h>
#include "ControlSendto.h"
#include "buffer.h"
#include "converter.h"
#include "format.h"
@ -50,7 +51,7 @@ void ControlSendto::dispatchParams()
return;
string const data = format_->name() + " " + command_;
kernel().dispatch(FuncRequest(LFUN_EXPORT_CUSTOM, data));
kernel().dispatch(FuncRequest(getLfun(), data));
}

View File

@ -34,6 +34,8 @@ public:
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
virtual kb_action getLfun() const { return LFUN_EXPORT_CUSTOM; }
/// Return a vector of those formats that can be exported from "lyx".
std::vector<Format const *> const allFormats() const;

View File

@ -73,7 +73,7 @@ LyXTabular const & ControlTabular::tabular() const
void ControlTabular::set(LyXTabular::Feature f, string const & arg)
{
string const data = featureAsString(f) + ' ' + arg;
kernel().dispatch(FuncRequest(LFUN_TABULAR_FEATURE, data));
kernel().dispatch(FuncRequest(getLfun(), data));
}

View File

@ -34,6 +34,8 @@ public:
virtual void dispatchParams() {};
///
virtual bool isBufferDependent() const { return true; }
///
virtual kb_action getLfun() const { return LFUN_TABULAR_FEATURE; }
///
LyXTabular::idx_type getActiveCell() const;

View File

@ -44,7 +44,7 @@ void ControlTabularCreate::clearParams()
void ControlTabularCreate::dispatchParams()
{
string const data = convert<string>(params().first) + ' ' + convert<string>(params().second);
kernel().dispatch(FuncRequest(LFUN_TABULAR_INSERT, data));
kernel().dispatch(FuncRequest(getLfun(), data));
}
} // namespace frontend

View File

@ -32,6 +32,8 @@ public:
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
///
virtual kb_action getLfun() const { return LFUN_TABULAR_INSERT; }
///
typedef std::pair<size_t, size_t> rowsCols;

View File

@ -49,7 +49,7 @@ void ControlVSpace::clearParams()
void ControlVSpace::dispatchParams()
{
string const str = InsetVSpaceMailer::params2string(params_);
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, str));
kernel().dispatch(FuncRequest(getLfun(), str));
}

View File

@ -43,7 +43,7 @@ void ControlWrap::clearParams()
void ControlWrap::dispatchParams()
{
string const lfun = InsetWrapMailer::params2string(params());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
kernel().dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend

View File

@ -175,9 +175,19 @@ void Dialog::setView(View * v)
void Dialog::checkStatus()
{
FuncRequest const fr(LFUN_INSET_APPLY, name());
FuncStatus const fs(kernel().lyxview().getLyXFunc().getStatus(fr));
if (fs.enabled())
// buffer independant dialogs are always active.
// This check allows us leave canApply unimplemented for some dialogs.
if (!controller().isBufferDependent())
return;
// deactivate the dialog if we have no buffer
if (!kernel().isBufferAvailable()) {
bc().readOnly(true);
return;
}
// check whether this dialog may be active
if (controller().canApply())
bc().readOnly(kernel().isBufferReadonly());
else
bc().readOnly(true);
@ -189,6 +199,14 @@ Dialog::Controller::Controller(Dialog & parent)
{}
bool Dialog::Controller::canApply() const
{
FuncRequest const fr(getLfun(), dialog().name());
FuncStatus const fs(kernel().lyxview().getLyXFunc().getStatus(fr));
return fs.enabled();
}
Dialog::Controller & Dialog::controller() const
{
BOOST_ASSERT(controller_ptr_.get());

View File

@ -13,6 +13,7 @@
#define DIALOG_H
#include "Kernel.h"
#include "lfuns.h"
#include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp>
@ -158,6 +159,25 @@ public:
*/
virtual bool isBufferDependent() const = 0;
/** The lfun that is sent for applying the data.
*
* This method is used by the default implementation of canApply()
* for buffer dependant dialogs that send one lfun when applying the
* data.
* It should be used in dispatchParams(), too for consistency reasons.
* \returns the lfun that is sent for applying the data.
*/
virtual kb_action getLfun() const { return LFUN_INSET_APPLY; }
/** Check whether we may apply our data.
*
* The default implementation works for all dialogs that send one
* lfun when applying the data. Dialogs that send none or more than
* one lfun need to reimplement it.
* \returns whether the data can be applied or not.
*/
virtual bool canApply() const;
/** \return true if the kernel should disconnect the dialog from
* a particular inset after the data has been applied to it.
* Clearly this makes sense only for dialogs modifying the contents