mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
Fix bug 4475.
Add ability to create child from the include dialog.
This commit is contained in:
parent
46fca4dc1d
commit
a385b7dc2b
@ -32,6 +32,7 @@
|
||||
#include "insets/InsetInclude.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QFile>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
@ -265,6 +266,62 @@ void GuiInclude::applyView()
|
||||
}
|
||||
params_["literal"] = literalCB->isChecked()
|
||||
? from_ascii("true") : from_ascii("false");
|
||||
|
||||
// Do we need to create a LyX file?
|
||||
if (item == 0 || item == 1) {
|
||||
QString fname = filenameED->text();
|
||||
string const mypath = buffer().absFileName();
|
||||
string const bpath = buffer().filePath();
|
||||
QString absfname = makeAbsPath(fname, toqstr(bpath));
|
||||
if (!QFile::exists(absfname)) {
|
||||
dispatch(FuncRequest(LFUN_BUFFER_NEW, fromqstr(absfname)));
|
||||
dispatch(FuncRequest(LFUN_BUFFER_WRITE));
|
||||
dispatch(FuncRequest(LFUN_BUFFER_SWITCH, mypath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiInclude::edit()
|
||||
{
|
||||
if (!isValid())
|
||||
return;
|
||||
if (bc().policy().buttonStatus(ButtonPolicy::OKAY)) {
|
||||
slotOK();
|
||||
applyView();
|
||||
} else
|
||||
hideView();
|
||||
dispatch(FuncRequest(LFUN_INSET_EDIT));
|
||||
}
|
||||
|
||||
|
||||
bool GuiInclude::isValid()
|
||||
{
|
||||
QString fname = filenameED->text();
|
||||
bool fempty = fname.isEmpty();
|
||||
if (fempty || !validate_listings_params().empty()) {
|
||||
editPB->setEnabled(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
QPushButton * okbutton = buttonBox->button(QDialogButtonBox::Ok);
|
||||
int const item = typeCO->currentIndex();
|
||||
// Are we inputting or including a LyX file?
|
||||
if (item != 0 && item != 1) {
|
||||
okbutton->setText("OK");
|
||||
return true;
|
||||
}
|
||||
// Do we have a LyX filename?
|
||||
if (!support::isLyXFileName(fromqstr(fname))) {
|
||||
okbutton->setText("OK");
|
||||
return false;
|
||||
}
|
||||
string const bpath = buffer().filePath();
|
||||
QString absfname = makeAbsPath(fname, toqstr(bpath));
|
||||
bool const fexists = QFile::exists(absfname);
|
||||
okbutton->setText(fexists ? "OK" : "Create");
|
||||
editPB->setEnabled(fexists);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -288,25 +345,6 @@ void GuiInclude::browse()
|
||||
}
|
||||
|
||||
|
||||
void GuiInclude::edit()
|
||||
{
|
||||
if (!isValid())
|
||||
return;
|
||||
if (bc().policy().buttonStatus(ButtonPolicy::OKAY)) {
|
||||
slotOK();
|
||||
applyView();
|
||||
} else
|
||||
hideView();
|
||||
dispatch(FuncRequest(LFUN_INSET_EDIT));
|
||||
}
|
||||
|
||||
|
||||
bool GuiInclude::isValid()
|
||||
{
|
||||
return !filenameED->text().isEmpty() && validate_listings_params().empty();
|
||||
}
|
||||
|
||||
|
||||
QString GuiInclude::browse(QString const & in_name, Type in_type) const
|
||||
{
|
||||
QString const title = qt_("Select document to include");
|
||||
|
Loading…
Reference in New Issue
Block a user