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"
|
2011-05-13 19:39:56 +00:00
|
|
|
#include "BufferParams.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"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.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"
|
2013-04-25 21:27:10 +00:00
|
|
|
#include "support/gettext.h"
|
2008-05-07 14:45:49 +00:00
|
|
|
#include "support/lassert.h"
|
2007-12-09 22:35:04 +00:00
|
|
|
|
2010-02-07 20:25:53 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QList>
|
2007-12-10 13:05:00 +00:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QString>
|
2010-02-07 20:25:53 +00:00
|
|
|
#include <QValidator>
|
2007-12-10 13:05:00 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
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
|
|
|
{
|
2009-09-05 15:09:45 +00:00
|
|
|
return lyxview_->currentBufferView() != 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
|
|
|
{
|
2009-09-05 15:09:45 +00:00
|
|
|
if (!lyxview_->documentBufferView())
|
2007-09-10 22:32:59 +00:00
|
|
|
return true;
|
2009-09-05 15:09:45 +00:00
|
|
|
return lyxview_->documentBufferView()->buffer().isReadonly();
|
2003-02-25 14:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-21 01:19:30 +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
|
|
|
{
|
2011-05-13 19:39:56 +00:00
|
|
|
if (buffer().params().isLatex())
|
2007-09-10 22:32:59 +00:00
|
|
|
return LATEX;
|
2011-05-13 19:39:56 +00:00
|
|
|
if (buffer().params().isLiterate())
|
2007-09-10 22:32:59 +00:00
|
|
|
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
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LAPPERR(lyxview_->currentBufferView());
|
2009-09-05 15:09:45 +00:00
|
|
|
return lyxview_->currentBufferView()->buffer();
|
2005-04-26 09:37:52 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
|
2011-05-27 21:53:23 +00:00
|
|
|
Buffer const & Dialog::documentBuffer() const
|
|
|
|
{
|
2013-04-27 22:12:27 +00:00
|
|
|
LAPPERR(lyxview_->documentBufferView());
|
2011-05-27 21:53:23 +00:00
|
|
|
return lyxview_->documentBufferView()->buffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2015-05-26 17:33:07 +00:00
|
|
|
// ins: the innermost inset of the type we look for
|
|
|
|
// that contains the cursor
|
2008-06-05 16:03:08 +00:00
|
|
|
Inset * ins = bufferview()->cursor().innerInsetOfType(code);
|
2015-05-26 17:33:07 +00:00
|
|
|
// next: a potential inset at cursor position
|
|
|
|
Inset * next = bufferview()->cursor().nextInset();
|
|
|
|
// Check if next is of the type we look for
|
|
|
|
if (next)
|
|
|
|
if (next->lyxCode() != code)
|
|
|
|
next = 0;
|
|
|
|
if (ins) {
|
|
|
|
// prefer next if it is of the requested type (bug 8716)
|
|
|
|
if (next)
|
|
|
|
ins = next;
|
|
|
|
} else
|
|
|
|
// no containing inset of requested type
|
|
|
|
// use next (which might also be 0)
|
|
|
|
ins = next;
|
2008-06-05 16:03:08 +00:00
|
|
|
return ins;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
void Dialog::checkStatus()
|
|
|
|
{
|
2009-12-31 16:43:43 +00:00
|
|
|
// buffer independent dialogs are always active.
|
2007-12-09 22:35:04 +00:00
|
|
|
// 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
|
|
|
|
|
2009-12-31 16:43:43 +00:00
|
|
|
updateView();
|
2007-12-09 22:35:04 +00:00
|
|
|
} 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
|