[LyX/master] Fix bug 4475. Add ability to create child from the include dialog.
Richard Kimberly Heck
rikiheck at lyx.org
Mon Aug 31 14:54:05 UTC 2020
commit a385b7dc2b585ff259f9a9681e5d68168d1dac66
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Sat Aug 22 15:15:47 2020 -0400
Fix bug 4475.
Add ability to create child from the include dialog.
---
src/frontends/qt/GuiInclude.cpp | 76 +++++++++++++++++++++++++++++----------
1 files changed, 57 insertions(+), 19 deletions(-)
diff --git a/src/frontends/qt/GuiInclude.cpp b/src/frontends/qt/GuiInclude.cpp
index c55d71f..5a38654 100644
--- a/src/frontends/qt/GuiInclude.cpp
+++ b/src/frontends/qt/GuiInclude.cpp
@@ -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");
More information about the lyx-cvs
mailing list