2003-02-25 14:51:38 +00:00
|
|
|
/**
|
2007-04-25 18:04:04 +00:00
|
|
|
* \file Dialog.cpp
|
2003-02-25 14:51:38 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-25 14:51:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "Dialog.h"
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
#include "ButtonController.h"
|
|
|
|
#include "BCView.h"
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2005-04-13 09:43:58 +00:00
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
Dialog::Dialog(LyXView & lv, string const & name)
|
2003-03-10 03:13:28 +00:00
|
|
|
: is_closing_(false), kernel_(lv), name_(name),
|
|
|
|
bc_ptr_(new ButtonController)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
void Dialog::ApplyButton()
|
|
|
|
{
|
|
|
|
apply();
|
|
|
|
bc().apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::OKButton()
|
|
|
|
{
|
|
|
|
is_closing_ = true;
|
|
|
|
apply();
|
|
|
|
is_closing_ = false;
|
|
|
|
hide();
|
|
|
|
bc().ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::CancelButton()
|
|
|
|
{
|
|
|
|
hide();
|
|
|
|
bc().cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::RestoreButton()
|
|
|
|
{
|
|
|
|
// Tell the kernel that a request to refresh the dialog's contents
|
|
|
|
// has been received. It's up to the kernel to supply the necessary
|
|
|
|
// info by calling Dialog::update().
|
|
|
|
kernel().updateDialog(name_);
|
|
|
|
bc().restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::show(string const & data)
|
|
|
|
{
|
|
|
|
if (controller().isBufferDependent() && !kernel().isBufferAvailable())
|
|
|
|
return;
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
if (!controller().initialiseParams(data)) {
|
|
|
|
lyxerr << "Dialog \"" << name_
|
|
|
|
<< "\" failed to translate the data "
|
|
|
|
"string passed to show()" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
bc().readOnly(kernel().isBufferReadonly());
|
|
|
|
view().show();
|
|
|
|
|
|
|
|
// The widgets may not be valid, so refresh the button controller
|
|
|
|
bc().refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::update(string const & data)
|
|
|
|
{
|
|
|
|
if (controller().isBufferDependent() && !kernel().isBufferAvailable())
|
|
|
|
return;
|
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
if (!controller().initialiseParams(data)) {
|
|
|
|
lyxerr << "Dialog \"" << name_
|
2004-03-31 19:51:55 +00:00
|
|
|
<< "\" could not be initialized" << std::endl;
|
2003-03-14 00:20:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
bc().readOnly(kernel().isBufferReadonly());
|
|
|
|
view().update();
|
|
|
|
|
|
|
|
// The widgets may not be valid, so refresh the button controller
|
|
|
|
bc().refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::hide()
|
|
|
|
{
|
|
|
|
if (!view().isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
controller().clearParams();
|
|
|
|
view().hide();
|
2004-01-09 08:52:53 +00:00
|
|
|
kernel().disconnect(name());
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::apply()
|
|
|
|
{
|
2004-03-31 18:51:11 +00:00
|
|
|
if (controller().isBufferDependent()) {
|
|
|
|
if (!kernel().isBufferAvailable() ||
|
|
|
|
kernel().isBufferReadonly())
|
|
|
|
return;
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
view().apply();
|
|
|
|
controller().dispatchParams();
|
|
|
|
|
|
|
|
if (controller().disconnectOnApply() && !is_closing_) {
|
|
|
|
kernel().disconnect(name());
|
2003-06-30 23:56:22 +00:00
|
|
|
controller().initialiseParams(string());
|
2003-02-25 14:51:38 +00:00
|
|
|
view().update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Dialog::isVisible() const
|
|
|
|
{
|
|
|
|
return view().isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::redraw()
|
|
|
|
{
|
|
|
|
view().redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
ButtonController & Dialog::bc() const
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(bc_ptr_.get());
|
2003-02-25 14:51:38 +00:00
|
|
|
return *bc_ptr_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-17 15:35:42 +00:00
|
|
|
void Dialog::setController(Controller * i)
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(i && !controller_ptr_.get());
|
2003-07-17 15:35:42 +00:00
|
|
|
controller_ptr_.reset(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::setView(View * v)
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(v && !view_ptr_.get());
|
2003-07-17 15:35:42 +00:00
|
|
|
view_ptr_.reset(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-13 09:43:58 +00:00
|
|
|
void Dialog::checkStatus()
|
|
|
|
{
|
2005-04-26 09:37:52 +00:00
|
|
|
// 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
|
2005-10-03 10:37:28 +00:00
|
|
|
if (controller().canApply()) {
|
|
|
|
bool const readonly = kernel().isBufferReadonly();
|
|
|
|
bc().readOnly(readonly);
|
|
|
|
// refreshReadOnly() is too generous in _enabling_ widgets
|
|
|
|
// update dialog to disable disabled widgets again
|
|
|
|
if (!readonly)
|
|
|
|
view().update();
|
|
|
|
} else
|
2005-04-13 09:43:58 +00:00
|
|
|
bc().readOnly(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-16 20:10:59 +00:00
|
|
|
Dialog::Controller::Controller(Dialog & parent)
|
|
|
|
: parent_(parent)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2005-04-26 09:37:52 +00:00
|
|
|
bool Dialog::Controller::canApply() const
|
|
|
|
{
|
|
|
|
FuncRequest const fr(getLfun(), dialog().name());
|
2007-04-25 23:06:48 +00:00
|
|
|
FuncStatus const fs(getStatus(fr));
|
2005-04-26 09:37:52 +00:00
|
|
|
return fs.enabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
Dialog::Controller & Dialog::controller() const
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(controller_ptr_.get());
|
2003-02-25 14:51:38 +00:00
|
|
|
return *controller_ptr_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-09 10:35:14 +00:00
|
|
|
Dialog::View::View(Dialog & parent, docstring title) :
|
2003-07-16 20:10:59 +00:00
|
|
|
p_(parent), title_(title)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
Dialog::View & Dialog::view() const
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(view_ptr_.get());
|
2003-02-25 14:51:38 +00:00
|
|
|
return *view_ptr_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-09 10:35:14 +00:00
|
|
|
void Dialog::View::setTitle(docstring const & newtitle)
|
2003-05-22 15:42:50 +00:00
|
|
|
{
|
|
|
|
title_ = newtitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-09 10:35:14 +00:00
|
|
|
docstring const & Dialog::View::getTitle() const
|
2003-05-22 15:42:50 +00:00
|
|
|
{
|
|
|
|
return title_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-17 15:35:42 +00:00
|
|
|
void Dialog::View::partialUpdate(int)
|
|
|
|
{}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|