2003-02-25 14:51:38 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file Dialog.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 "Dialog.h"
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
#include "ButtonController.h"
|
|
|
|
#include "BCView.h"
|
2003-03-14 00:20:42 +00:00
|
|
|
#include "debug.h"
|
2003-02-25 14:51:38 +00:00
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
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)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
Dialog::~Dialog()
|
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_
|
|
|
|
<< "\" failed to translate the data "
|
|
|
|
"string passed to update()" << std::endl;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::apply()
|
|
|
|
{
|
|
|
|
if (kernel().isBufferReadonly())
|
|
|
|
return;
|
|
|
|
|
|
|
|
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-06-30 23:56:22 +00:00
|
|
|
Assert(bc_ptr_.get());
|
2003-02-25 14:51:38 +00:00
|
|
|
return *bc_ptr_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dialog::Controller & Dialog::controller() const
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(controller_ptr_.get());
|
2003-02-25 14:51:38 +00:00
|
|
|
return *controller_ptr_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dialog::View & Dialog::view() const
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(view_ptr_.get());
|
2003-02-25 14:51:38 +00:00
|
|
|
return *view_ptr_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-22 15:42:50 +00:00
|
|
|
void Dialog::View::setTitle(string const & newtitle)
|
|
|
|
{
|
|
|
|
title_ = newtitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const & Dialog::View::getTitle() const
|
|
|
|
{
|
|
|
|
return title_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
void Dialog::setController(Controller * i)
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(i && !controller_ptr_.get());
|
2003-02-25 14:51:38 +00:00
|
|
|
controller_ptr_.reset(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::setView(View * v)
|
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(v && !view_ptr_.get());
|
2003-02-25 14:51:38 +00:00
|
|
|
view_ptr_.reset(v);
|
|
|
|
}
|