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"
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
#include "GuiView.h"
|
2007-12-10 13:05:00 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-11-23 09:44:02 +00:00
|
|
|
|
2007-11-18 00:01:14 +00:00
|
|
|
#include "Buffer.h"
|
2008-06-05 16:03:08 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2005-04-13 09:43:58 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXFunc.h"
|
2005-04-13 09:43:58 +00:00
|
|
|
|
2008-06-05 16:03:08 +00:00
|
|
|
#include "insets/Inset.h"
|
|
|
|
|
2007-12-10 00:11:22 +00:00
|
|
|
#include "support/debug.h"
|
2008-05-07 14:45:49 +00:00
|
|
|
#include "support/lassert.h"
|
2007-12-09 22:35:04 +00:00
|
|
|
|
2007-12-10 13:05:00 +00:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QString>
|
|
|
|
|
2007-11-23 10:45:14 +00:00
|
|
|
#include <string>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-12-09 22:35:04 +00:00
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2007-09-10 22:32:59 +00:00
|
|
|
|
2008-03-05 20:11:47 +00:00
|
|
|
Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
|
2008-02-05 12:43:19 +00:00
|
|
|
: name_(name), title_(title), lyxview_(&lv)
|
2007-11-23 10:45:14 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-09-10 22:32:59 +00:00
|
|
|
Dialog::~Dialog()
|
2003-03-10 03:13:28 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
bool Dialog::canApply() const
|
2007-09-08 21:16:54 +00:00
|
|
|
{
|
2008-03-05 20:11:47 +00:00
|
|
|
FuncRequest const fr(getLfun(), fromqstr(name_));
|
2007-09-10 22:32:59 +00:00
|
|
|
FuncStatus const fs(getStatus(fr));
|
|
|
|
return fs.enabled();
|
2007-09-08 21:16:54 +00:00
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
void Dialog::dispatch(FuncRequest const & fr) const
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2007-11-26 22:45:17 +00:00
|
|
|
theLyXFunc().setLyXView(lyxview_);
|
|
|
|
lyx::dispatch(fr);
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 10:45:14 +00:00
|
|
|
void Dialog::updateDialog() const
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2008-03-05 20:11:47 +00:00
|
|
|
dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_)));
|
2007-09-03 05:59:32 +00:00
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
|
2007-11-23 10:45:14 +00:00
|
|
|
void Dialog::disconnect() const
|
2007-09-03 05:59:32 +00:00
|
|
|
{
|
2008-03-05 20:11:47 +00:00
|
|
|
lyxview_->disconnectDialog(fromqstr(name_));
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
bool Dialog::isBufferAvailable() const
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
return lyxview_->buffer() != 0;
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
bool Dialog::isBufferReadonly() const
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
if (!lyxview_->buffer())
|
|
|
|
return true;
|
|
|
|
return lyxview_->buffer()->isReadonly();
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
QString Dialog::bufferFilepath() const
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
return toqstr(buffer().filePath());
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
KernelDocType Dialog::docType() const
|
2003-02-25 14:51:38 +00:00
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
if (buffer().isLatex())
|
|
|
|
return LATEX;
|
|
|
|
if (buffer().isLiterate())
|
|
|
|
return LITERATE;
|
|
|
|
|
|
|
|
return DOCBOOK;
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
BufferView const * Dialog::bufferview() const
|
2007-09-10 19:02:11 +00:00
|
|
|
{
|
2009-09-05 14:29:11 +00:00
|
|
|
return lyxview_->currentBufferView();
|
2007-09-10 19:02:11 +00:00
|
|
|
}
|
|
|
|
|
2003-07-17 15:35:42 +00:00
|
|
|
|
2007-10-09 21:21:01 +00:00
|
|
|
Buffer const & Dialog::buffer() const
|
2005-04-26 09:37:52 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(lyxview_->buffer(), /**/);
|
2007-09-10 22:32:59 +00:00
|
|
|
return *lyxview_->buffer();
|
2005-04-26 09:37:52 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
|
|
|
|
void Dialog::showData(string const & data)
|
|
|
|
{
|
|
|
|
if (isBufferDependent() && !isBufferAvailable())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!initialiseParams(data)) {
|
2008-05-02 22:07:51 +00:00
|
|
|
LYXERR0("Dialog \"" << name()
|
2007-12-09 22:35:04 +00:00
|
|
|
<< "\" failed to translate the data string passed to show()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
showView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::apply()
|
|
|
|
{
|
|
|
|
if (isBufferDependent()) {
|
|
|
|
if (!isBufferAvailable() ||
|
|
|
|
(isBufferReadonly() && !canApplyToReadOnly()))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyView();
|
|
|
|
dispatchParams();
|
|
|
|
|
|
|
|
if (disconnectOnApply() && !isClosing()) {
|
|
|
|
disconnect();
|
|
|
|
initialiseParams(string());
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-16 17:22:43 +00:00
|
|
|
void Dialog::prepareView()
|
2007-12-09 22:35:04 +00:00
|
|
|
{
|
2008-02-08 17:25:59 +00:00
|
|
|
// Make sure the dialog controls are correctly enabled/disabled with
|
|
|
|
// readonly status.
|
|
|
|
checkStatus();
|
2007-12-09 22:35:04 +00:00
|
|
|
|
|
|
|
QWidget * w = asQWidget();
|
2008-02-05 12:43:19 +00:00
|
|
|
w->setWindowTitle(title_);
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
QSize const hint = w->sizeHint();
|
|
|
|
if (hint.height() >= 0 && hint.width() >= 0)
|
|
|
|
w->setMinimumSize(hint);
|
2009-06-16 17:22:43 +00:00
|
|
|
}
|
2007-12-09 22:35:04 +00:00
|
|
|
|
2009-06-16 17:22:43 +00:00
|
|
|
|
|
|
|
void Dialog::showView()
|
|
|
|
{
|
|
|
|
prepareView();
|
|
|
|
|
|
|
|
QWidget * w = asQWidget();
|
2007-12-09 22:35:04 +00:00
|
|
|
if (w->isVisible()) {
|
|
|
|
w->raise();
|
|
|
|
w->activateWindow();
|
|
|
|
} else
|
|
|
|
w->show();
|
|
|
|
|
2008-06-09 14:52:38 +00:00
|
|
|
if (wantInitialFocus())
|
|
|
|
w->setFocus();
|
2008-06-09 15:33:42 +00:00
|
|
|
else {
|
|
|
|
lyxview_->raise();
|
|
|
|
lyxview_->activateWindow();
|
2008-06-09 14:52:38 +00:00
|
|
|
lyxview_->setFocus();
|
2008-06-09 15:33:42 +00:00
|
|
|
}
|
2007-12-09 22:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::hideView()
|
|
|
|
{
|
|
|
|
QWidget * w = asQWidget();
|
|
|
|
if (!w->isVisible())
|
|
|
|
return;
|
|
|
|
clearParams();
|
|
|
|
disconnect();
|
|
|
|
w->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Dialog::isVisibleView() const
|
|
|
|
{
|
|
|
|
return asQWidget()->isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-06 08:01:59 +00:00
|
|
|
Inset const * Dialog::inset(InsetCode code) const
|
2008-06-05 16:03:08 +00:00
|
|
|
{
|
|
|
|
Inset * ins = bufferview()->cursor().innerInsetOfType(code);
|
|
|
|
if (!ins)
|
|
|
|
ins = bufferview()->cursor().nextInset();
|
|
|
|
if (!ins || ins->lyxCode() != code)
|
|
|
|
return 0;
|
|
|
|
return ins;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
void Dialog::checkStatus()
|
|
|
|
{
|
|
|
|
// buffer independant dialogs are always active.
|
|
|
|
// This check allows us leave canApply unimplemented for some dialogs.
|
2008-05-03 07:56:07 +00:00
|
|
|
if (!isBufferDependent()) {
|
|
|
|
updateView();
|
2007-12-09 22:35:04 +00:00
|
|
|
return;
|
2008-05-03 07:56:07 +00:00
|
|
|
}
|
2007-12-09 22:35:04 +00:00
|
|
|
|
|
|
|
// deactivate the dialog if we have no buffer
|
|
|
|
if (!isBufferAvailable()) {
|
|
|
|
enableView(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether this dialog may be active
|
|
|
|
if (canApply()) {
|
|
|
|
bool const readonly = isBufferReadonly();
|
2009-04-11 18:34:03 +00:00
|
|
|
enableView(!readonly || canApplyToReadOnly());
|
2007-12-09 22:35:04 +00:00
|
|
|
// refreshReadOnly() is too generous in _enabling_ widgets
|
|
|
|
// update dialog to disable disabled widgets again
|
|
|
|
|
|
|
|
if (!readonly || canApplyToReadOnly())
|
|
|
|
updateView();
|
|
|
|
|
|
|
|
} else
|
|
|
|
enableView(false);
|
|
|
|
}
|
|
|
|
|
2007-12-10 13:05:00 +00:00
|
|
|
|
|
|
|
QString Dialog::sessionKey() const
|
|
|
|
{
|
2008-09-21 21:28:37 +00:00
|
|
|
return "views/" + QString::number(lyxview_->id())
|
2008-03-05 20:11:47 +00:00
|
|
|
+ "/" + name();
|
2007-12-10 13:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::saveSession() const
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Dialog::restoreSession()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
asQWidget()->restoreGeometry(
|
|
|
|
settings.value(sessionKey() + "/geometry").toByteArray());
|
|
|
|
}
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|