mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 18:24:48 +00:00
0062cd3408
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7003 a592a061-630c-0410-9148-cb99ea01b6c8
189 lines
3.0 KiB
C
189 lines
3.0 KiB
C
// -*- 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"
|
|
|
|
#include "ButtonController.h"
|
|
#include "BCView.h"
|
|
#include "debug.h"
|
|
#include "support/LAssert.h"
|
|
|
|
|
|
Dialog::Dialog(LyXView & lv, string const & name)
|
|
: is_closing_(false), kernel_(lv), name_(name),
|
|
bc_ptr_(new ButtonController)
|
|
{}
|
|
|
|
|
|
Dialog::~Dialog()
|
|
{}
|
|
|
|
|
|
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;
|
|
|
|
if (!controller().initialiseParams(data)) {
|
|
lyxerr << "Dialog \"" << name_
|
|
<< "\" failed to translate the data "
|
|
"string passed to show()" << std::endl;
|
|
return;
|
|
}
|
|
|
|
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;
|
|
|
|
if (!controller().initialiseParams(data)) {
|
|
lyxerr << "Dialog \"" << name_
|
|
<< "\" failed to translate the data "
|
|
"string passed to update()" << std::endl;
|
|
return;
|
|
}
|
|
|
|
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());
|
|
controller().initialiseParams(string());
|
|
view().update();
|
|
}
|
|
}
|
|
|
|
|
|
bool Dialog::isVisible() const
|
|
{
|
|
return view().isVisible();
|
|
}
|
|
|
|
|
|
void Dialog::redraw()
|
|
{
|
|
view().redraw();
|
|
}
|
|
|
|
|
|
ButtonController & Dialog::bc() const
|
|
{
|
|
lyx::Assert(bc_ptr_.get());
|
|
return *bc_ptr_.get();
|
|
}
|
|
|
|
|
|
Dialog::Controller & Dialog::controller() const
|
|
{
|
|
lyx::Assert(controller_ptr_.get());
|
|
return *controller_ptr_.get();
|
|
}
|
|
|
|
|
|
Dialog::View & Dialog::view() const
|
|
{
|
|
lyx::Assert(view_ptr_.get());
|
|
return *view_ptr_.get();
|
|
}
|
|
|
|
|
|
void Dialog::View::setTitle(string const & newtitle)
|
|
{
|
|
title_ = newtitle;
|
|
}
|
|
|
|
|
|
string const & Dialog::View::getTitle() const
|
|
{
|
|
return title_;
|
|
}
|
|
|
|
|
|
void Dialog::setController(Controller * i)
|
|
{
|
|
lyx::Assert(i && !controller_ptr_.get());
|
|
controller_ptr_.reset(i);
|
|
}
|
|
|
|
|
|
void Dialog::setView(View * v)
|
|
{
|
|
lyx::Assert(v && !view_ptr_.get());
|
|
view_ptr_.reset(v);
|
|
}
|