diff --git a/src/frontends/qt/GuiInclude.cpp b/src/frontends/qt/GuiInclude.cpp index c55d71fa7f..5a386547dd 100644 --- a/src/frontends/qt/GuiInclude.cpp +++ b/src/frontends/qt/GuiInclude.cpp @@ -32,6 +32,7 @@ #include "insets/InsetInclude.h" #include +#include #include #include @@ -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");