2007-09-03 05:59:32 +00:00
|
|
|
/**
|
|
|
|
* \file Dialog.cpp
|
|
|
|
* 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 "GuiDialog.h"
|
|
|
|
#include "debug.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-09-10 22:32:59 +00:00
|
|
|
#include "frontends/LyXView.h"
|
|
|
|
|
2007-09-28 09:45:50 +00:00
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QShowEvent>
|
|
|
|
|
2007-09-10 22:32:59 +00:00
|
|
|
using std::string;
|
2007-09-03 05:59:32 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
|
2007-10-09 21:21:01 +00:00
|
|
|
: Dialog(lv), is_closing_(false), name_(name)
|
2007-10-09 19:34:27 +00:00
|
|
|
{}
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
GuiDialog::~GuiDialog()
|
|
|
|
{
|
|
|
|
}
|
2007-09-03 05:59:32 +00:00
|
|
|
|
|
|
|
|
2007-09-10 19:02:11 +00:00
|
|
|
void GuiDialog::setViewTitle(docstring const & title)
|
|
|
|
{
|
|
|
|
setWindowTitle("LyX: " + toqstr(title));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
void GuiDialog::setButtonsValid(bool valid)
|
|
|
|
{
|
|
|
|
bc().setValid(valid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 17:06:15 +00:00
|
|
|
void GuiDialog::slotApply()
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
|
|
|
apply();
|
|
|
|
bc().apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 17:06:15 +00:00
|
|
|
void GuiDialog::slotOK()
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
|
|
|
is_closing_ = true;
|
|
|
|
apply();
|
|
|
|
is_closing_ = false;
|
2007-09-05 20:33:29 +00:00
|
|
|
QDialog::hide();
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 17:06:15 +00:00
|
|
|
void GuiDialog::slotClose()
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
QDialog::hide();
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-11 17:06:15 +00:00
|
|
|
void GuiDialog::slotRestore()
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
// Tell the controller that a request to refresh the dialog's contents
|
|
|
|
// has been received. It's up to the controller to supply the necessary
|
2007-09-03 20:28:26 +00:00
|
|
|
// info by calling GuiDialog::updateView().
|
2007-10-09 19:34:27 +00:00
|
|
|
updateDialog(name_);
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiDialog::checkStatus()
|
|
|
|
{
|
|
|
|
// buffer independant dialogs are always active.
|
|
|
|
// This check allows us leave canApply unimplemented for some dialogs.
|
2007-10-09 19:34:27 +00:00
|
|
|
if (!isBufferDependent())
|
2007-09-03 05:59:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// deactivate the dialog if we have no buffer
|
2007-10-09 19:34:27 +00:00
|
|
|
if (!isBufferAvailable()) {
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().setReadOnly(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether this dialog may be active
|
2007-10-09 19:34:27 +00:00
|
|
|
if (canApply()) {
|
|
|
|
bool const readonly = isBufferReadonly();
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().setReadOnly(readonly);
|
|
|
|
// refreshReadOnly() is too generous in _enabling_ widgets
|
|
|
|
// update dialog to disable disabled widgets again
|
2007-09-26 14:50:35 +00:00
|
|
|
|
2007-10-09 19:34:27 +00:00
|
|
|
if (!readonly || canApplyToReadOnly())
|
2007-09-26 14:50:35 +00:00
|
|
|
updateView();
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
} else {
|
|
|
|
bc().setReadOnly(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bool GuiDialog::isVisibleView() const
|
|
|
|
{
|
|
|
|
return QDialog::isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::showView()
|
|
|
|
{
|
|
|
|
QSize const hint = sizeHint();
|
|
|
|
if (hint.height() >= 0 && hint.width() >= 0)
|
|
|
|
setMinimumSize(hint);
|
|
|
|
|
|
|
|
updateView(); // make sure its up-to-date
|
2007-10-09 19:34:27 +00:00
|
|
|
if (exitEarly())
|
2007-09-05 20:33:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (QWidget::isVisible()) {
|
|
|
|
raise();
|
|
|
|
activateWindow();
|
|
|
|
} else {
|
|
|
|
QWidget::show();
|
|
|
|
}
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::hideView()
|
|
|
|
{
|
|
|
|
QDialog::hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::changed()
|
|
|
|
{
|
|
|
|
if (updating_)
|
|
|
|
return;
|
|
|
|
bc().setValid(isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::updateView()
|
|
|
|
{
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
|
|
|
// protect the BC from unwarranted state transitions
|
|
|
|
updating_ = true;
|
2007-09-11 18:33:42 +00:00
|
|
|
updateContents();
|
2007-09-05 20:33:29 +00:00
|
|
|
updating_ = false;
|
|
|
|
|
|
|
|
setUpdatesEnabled(true);
|
|
|
|
QDialog::update();
|
|
|
|
}
|
|
|
|
|
2007-09-10 22:32:59 +00:00
|
|
|
|
|
|
|
void GuiDialog::showData(string const & data)
|
|
|
|
{
|
2007-10-09 19:34:27 +00:00
|
|
|
if (isBufferDependent() && !isBufferAvailable())
|
2007-09-10 22:32:59 +00:00
|
|
|
return;
|
|
|
|
|
2007-10-09 19:34:27 +00:00
|
|
|
if (!initialiseParams(data)) {
|
2007-09-10 22:32:59 +00:00
|
|
|
lyxerr << "Dialog \"" << name_
|
|
|
|
<< "\" failed to translate the data "
|
|
|
|
"string passed to show()" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-09 19:34:27 +00:00
|
|
|
bc().setReadOnly(isBufferReadonly());
|
2007-09-10 22:32:59 +00:00
|
|
|
showView();
|
|
|
|
// The widgets may not be valid, so refresh the button controller
|
|
|
|
bc().refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::updateData(string const & data)
|
|
|
|
{
|
2007-10-09 19:34:27 +00:00
|
|
|
if (isBufferDependent() && !isBufferAvailable())
|
2007-09-10 22:32:59 +00:00
|
|
|
return;
|
|
|
|
|
2007-10-09 19:34:27 +00:00
|
|
|
if (!initialiseParams(data)) {
|
2007-09-10 22:32:59 +00:00
|
|
|
lyxerr << "Dialog \"" << name_
|
|
|
|
<< "\" could not be initialized" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-09 19:34:27 +00:00
|
|
|
bc().setReadOnly(isBufferReadonly());
|
2007-09-10 22:32:59 +00:00
|
|
|
updateView();
|
|
|
|
// The widgets may not be valid, so refresh the button controller
|
|
|
|
bc().refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::hide()
|
|
|
|
{
|
|
|
|
if (!isVisibleView())
|
|
|
|
return;
|
|
|
|
|
2007-10-09 19:34:27 +00:00
|
|
|
clearParams();
|
2007-09-10 22:32:59 +00:00
|
|
|
hideView();
|
2007-10-09 21:21:01 +00:00
|
|
|
Dialog::disconnect(name_);
|
2007-09-10 22:32:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::apply()
|
|
|
|
{
|
2007-10-09 19:34:27 +00:00
|
|
|
if (isBufferDependent()) {
|
|
|
|
if (!isBufferAvailable() ||
|
|
|
|
(isBufferReadonly() && !canApplyToReadOnly()))
|
2007-09-10 22:32:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyView();
|
2007-10-09 19:34:27 +00:00
|
|
|
dispatchParams();
|
2007-09-10 22:32:59 +00:00
|
|
|
|
2007-10-09 19:34:27 +00:00
|
|
|
if (disconnectOnApply() && !is_closing_) {
|
2007-10-09 21:21:01 +00:00
|
|
|
Dialog::disconnect(name_);
|
2007-10-09 19:34:27 +00:00
|
|
|
initialiseParams(string());
|
2007-09-10 22:32:59 +00:00
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-28 09:45:50 +00:00
|
|
|
void GuiDialog::showEvent(QShowEvent * e)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
string key = name_ + "/geometry";
|
|
|
|
restoreGeometry(settings.value(key.c_str()).toByteArray());
|
|
|
|
QDialog::showEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiDialog::closeEvent(QCloseEvent * e)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
string key = name_ + "/geometry";
|
|
|
|
settings.setValue(key.c_str(), saveGeometry());
|
|
|
|
QDialog::closeEvent(e);
|
|
|
|
}
|
2007-09-27 14:35:12 +00:00
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-10-07 14:41:49 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Command based dialogs
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "insets/InsetCommand.h"
|
|
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
GuiCommand::GuiCommand(LyXView & lv, string const & name)
|
2007-10-19 17:22:55 +00:00
|
|
|
: GuiDialog(lv, name), params_(insetCode(name)), lfun_name_(name)
|
2007-10-07 14:41:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiCommand::initialiseParams(string const & data)
|
|
|
|
{
|
|
|
|
// The name passed with LFUN_INSET_APPLY is also the name
|
|
|
|
// used to identify the mailer.
|
|
|
|
InsetCommandMailer::string2params(lfun_name_, data, params_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiCommand::dispatchParams()
|
|
|
|
{
|
|
|
|
if (lfun_name_.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
string const lfun =
|
|
|
|
InsetCommandMailer::params2string(lfun_name_, params_);
|
|
|
|
dispatch(FuncRequest(getLfun(), lfun));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
#include "GuiDialog_moc.cpp"
|