2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-04-26 03:53:02 +00:00
|
|
|
* \file QInclude.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-01-12 03:19:58 +00:00
|
|
|
#include "support/os.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "QInclude.h"
|
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "CheckedLineEdit.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "Qt2BC.h"
|
|
|
|
#include "qt_helpers.h"
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "Validator.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include "controllers/ControlInclude.h"
|
|
|
|
|
2007-04-25 10:57:54 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QLineEdit>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
2007-01-12 03:19:58 +00:00
|
|
|
using lyx::support::os::internal_path;
|
|
|
|
|
2007-04-25 10:57:54 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-04-25 10:57:54 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// QIncludeDialog
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QIncludeDialog::QIncludeDialog(QInclude * form)
|
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
|
|
|
|
|
|
|
|
connect(visiblespaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
connect(filenameED, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(loadPB, SIGNAL(clicked()), this, SLOT(loadClicked()));
|
|
|
|
connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked()));
|
|
|
|
connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
|
|
|
|
connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
|
|
|
|
connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
|
|
|
|
|
|
|
filenameED->setValidator(new PathValidator(true, filenameED));
|
|
|
|
setFocusProxy(filenameED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QIncludeDialog::show()
|
|
|
|
{
|
|
|
|
QDialog::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QIncludeDialog::change_adaptor()
|
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QIncludeDialog::closeEvent(QCloseEvent * e)
|
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QIncludeDialog::typeChanged(int v)
|
|
|
|
{
|
|
|
|
switch (v) {
|
|
|
|
//case Include
|
|
|
|
case 0:
|
|
|
|
visiblespaceCB->setEnabled(false);
|
|
|
|
visiblespaceCB->setChecked(false);
|
|
|
|
previewCB->setEnabled(false);
|
|
|
|
previewCB->setChecked(false);
|
|
|
|
break;
|
|
|
|
//case Input
|
|
|
|
case 1:
|
|
|
|
visiblespaceCB->setEnabled(false);
|
|
|
|
visiblespaceCB->setChecked(false);
|
|
|
|
previewCB->setEnabled(true);
|
|
|
|
break;
|
|
|
|
//case Verbatim
|
|
|
|
default:
|
|
|
|
visiblespaceCB->setEnabled(true);
|
|
|
|
previewCB->setEnabled(false);
|
|
|
|
previewCB->setChecked(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QIncludeDialog::loadClicked()
|
|
|
|
{
|
|
|
|
form_->load();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QIncludeDialog::browseClicked()
|
|
|
|
{
|
|
|
|
form_->browse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// QInclude
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
typedef QController<ControlInclude, QView<QIncludeDialog> > IncludeBase;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
QInclude::QInclude(Dialog & parent)
|
2007-04-25 10:57:54 +00:00
|
|
|
: IncludeBase(parent, _("Child Document"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void QInclude::build_dialog()
|
|
|
|
{
|
|
|
|
dialog_.reset(new QIncludeDialog(this));
|
|
|
|
|
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
bcview().addReadOnly(dialog_->filenameED);
|
|
|
|
bcview().addReadOnly(dialog_->browsePB);
|
|
|
|
bcview().addReadOnly(dialog_->visiblespaceCB);
|
|
|
|
bcview().addReadOnly(dialog_->typeCO);
|
|
|
|
|
|
|
|
addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QInclude::update_contents()
|
|
|
|
{
|
|
|
|
PathValidator * path_validator = getPathValidator(dialog_->filenameED);
|
|
|
|
if (path_validator)
|
|
|
|
path_validator->setChecker(kernel().docType(), lyxrc);
|
|
|
|
|
|
|
|
InsetCommandParams const & params = controller().params();
|
|
|
|
|
2006-10-20 13:53:43 +00:00
|
|
|
dialog_->filenameED->setText(toqstr(params["filename"]));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
dialog_->visiblespaceCB->setChecked(false);
|
|
|
|
dialog_->visiblespaceCB->setEnabled(false);
|
|
|
|
dialog_->previewCB->setChecked(false);
|
|
|
|
dialog_->previewCB->setEnabled(false);
|
|
|
|
|
|
|
|
string cmdname = controller().params().getCmdName();
|
|
|
|
if (cmdname != "include" &&
|
|
|
|
cmdname != "verbatiminput" &&
|
|
|
|
cmdname != "verbatiminput*")
|
|
|
|
cmdname = "input";
|
|
|
|
|
2007-03-18 03:42:40 +00:00
|
|
|
if (cmdname == "include") {
|
2006-08-17 08:55:41 +00:00
|
|
|
dialog_->typeCO->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-03-18 03:42:40 +00:00
|
|
|
} else if (cmdname == "input") {
|
2006-08-17 08:55:41 +00:00
|
|
|
dialog_->typeCO->setCurrentIndex(1);
|
2007-03-18 03:42:40 +00:00
|
|
|
dialog_->previewCB->setEnabled(true);
|
|
|
|
dialog_->previewCB->setChecked(params.preview());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
} else if (cmdname == "verbatiminput*") {
|
2006-08-17 08:55:41 +00:00
|
|
|
dialog_->typeCO->setCurrentIndex(2);
|
2006-03-05 17:24:44 +00:00
|
|
|
dialog_->visiblespaceCB->setEnabled(true);
|
|
|
|
dialog_->visiblespaceCB->setChecked(true);
|
|
|
|
|
|
|
|
} else if (cmdname == "verbatiminput") {
|
2006-08-17 08:55:41 +00:00
|
|
|
dialog_->typeCO->setCurrentIndex(2);
|
2006-03-05 17:24:44 +00:00
|
|
|
dialog_->visiblespaceCB->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QInclude::apply()
|
|
|
|
{
|
|
|
|
InsetCommandParams params = controller().params();
|
|
|
|
|
2007-01-18 20:47:27 +00:00
|
|
|
params["filename"] = from_utf8(internal_path(fromqstr(dialog_->filenameED->text())));
|
2006-03-05 17:24:44 +00:00
|
|
|
params.preview(dialog_->previewCB->isChecked());
|
|
|
|
|
2006-08-17 08:55:41 +00:00
|
|
|
int const item = dialog_->typeCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
if (item == 0)
|
|
|
|
params.setCmdName("include");
|
2007-03-18 03:42:40 +00:00
|
|
|
else if (item == 1)
|
|
|
|
params.setCmdName("input");
|
2006-03-05 17:24:44 +00:00
|
|
|
else {
|
|
|
|
if (dialog_->visiblespaceCB->isChecked())
|
|
|
|
params.setCmdName("verbatiminput*");
|
|
|
|
else
|
|
|
|
params.setCmdName("verbatiminput");
|
|
|
|
}
|
|
|
|
controller().setParams(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QInclude::browse()
|
|
|
|
{
|
|
|
|
ControlInclude::Type type;
|
|
|
|
|
2006-08-17 08:55:41 +00:00
|
|
|
int const item = dialog_->typeCO->currentIndex();
|
2006-03-05 17:24:44 +00:00
|
|
|
if (item == 0)
|
|
|
|
type = ControlInclude::INCLUDE;
|
2007-03-18 03:42:40 +00:00
|
|
|
else if (item == 1)
|
|
|
|
type = ControlInclude::INPUT;
|
2006-03-05 17:24:44 +00:00
|
|
|
else
|
|
|
|
type = ControlInclude::VERBATIM;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
docstring const & name =
|
|
|
|
controller().browse(qstring_to_ucs4(dialog_->filenameED->text()), type);
|
2006-03-05 17:24:44 +00:00
|
|
|
if (!name.empty())
|
|
|
|
dialog_->filenameED->setText(toqstr(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QInclude::load()
|
|
|
|
{
|
|
|
|
if (isValid()) {
|
2007-04-25 10:57:54 +00:00
|
|
|
string const file = fromqstr(dialog_->filenameED->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
slotOK();
|
|
|
|
controller().load(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QInclude::isValid()
|
|
|
|
{
|
|
|
|
return !dialog_->filenameED->text().isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-25 10:57:54 +00:00
|
|
|
|
|
|
|
#include "QInclude_moc.cpp"
|