Fix bug 4475.

Add ability to create child from the include dialog.

(cherry picked from commit a385b7dc2b)
This commit is contained in:
Richard Kimberly Heck 2020-08-22 15:15:47 -04:00
parent 1c21beb14c
commit 3a7560dcb0
3 changed files with 216 additions and 150 deletions

View File

@ -32,6 +32,7 @@
#include "insets/InsetInclude.h" #include "insets/InsetInclude.h"
#include <QCheckBox> #include <QCheckBox>
#include <QFile>
#include <QLineEdit> #include <QLineEdit>
#include <QPushButton> #include <QPushButton>
@ -265,6 +266,61 @@ void GuiInclude::applyView()
else else
params_.setCmdName("verbatiminput"); params_.setCmdName("verbatiminput");
} }
// 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;
}
int const item = typeCO->currentIndex();
// Are we inputting or including a LyX file?
if (item != 0 && item != 1) {
okPB->setText("OK");
return true;
}
// Do we have a LyX filename?
if (!support::isLyXFileName(fromqstr(fname))) {
okPB->setText("OK");
return false;
}
string const bpath = buffer().filePath();
QString absfname = makeAbsPath(fname, toqstr(bpath));
bool const fexists = QFile::exists(absfname);
okPB->setText(fexists ? "OK" : "Create");
editPB->setEnabled(fexists);
return true;
} }
@ -288,25 +344,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 GuiInclude::browse(QString const & in_name, Type in_type) const
{ {
QString const title = qt_("Select document to include"); QString const title = qt_("Select document to include");

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>IncludeUi</class> <class>IncludeUi</class>
<widget class="QDialog" name="IncludeUi"> <widget class="QDialog" name="IncludeUi">
@ -5,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>371</width> <width>440</width>
<height>374</height> <height>442</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -16,7 +17,16 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="margin" > <property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="spacing"> <property name="spacing">
@ -25,9 +35,7 @@
<item row="3" column="0" colspan="6"> <item row="3" column="0" colspan="6">
<widget class="QGroupBox" name="listingsGB"> <widget class="QGroupBox" name="listingsGB">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -36,7 +44,16 @@
<string>Listing Parameters</string> <string>Listing Parameters</string>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="margin" > <property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="spacing"> <property name="spacing">
@ -45,9 +62,7 @@
<item row="3" column="1"> <item row="3" column="1">
<widget class="QTextEdit" name="listingsED"> <widget class="QTextEdit" name="listingsED">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<hsizetype>5</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -116,9 +131,7 @@
<item row="3" column="0"> <item row="3" column="0">
<widget class="QTextBrowser" name="listingsTB"> <widget class="QTextBrowser" name="listingsTB">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<hsizetype>0</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -135,8 +148,8 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="cursor" > <property name="cursor" stdset="0">
<cursor>0</cursor> <cursorShape>ArrowCursor</cursorShape>
</property> </property>
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
@ -163,18 +176,25 @@
</item> </item>
<item row="2" column="0" colspan="6"> <item row="2" column="0" colspan="6">
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<property name="margin" >
<number>0</number>
</property>
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<widget class="QCheckBox" name="visiblespaceCB"> <widget class="QCheckBox" name="visiblespaceCB">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -190,9 +210,7 @@
<item> <item>
<widget class="QCheckBox" name="previewCB"> <widget class="QCheckBox" name="previewCB">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -209,12 +227,21 @@
</item> </item>
<item row="4" column="0" colspan="6"> <item row="4" column="0" colspan="6">
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<property name="margin" >
<number>0</number>
</property>
<property name="spacing"> <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item> <item>
<spacer> <spacer>
<property name="orientation"> <property name="orientation">
@ -223,7 +250,7 @@
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Expanding</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>20</height> <height>20</height>
@ -236,10 +263,10 @@
<property name="text"> <property name="text">
<string>&amp;OK</string> <string>&amp;OK</string>
</property> </property>
<property name="default" > <property name="autoDefault">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="autoDefault" > <property name="default">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
@ -272,7 +299,7 @@
<item row="0" column="1" colspan="4"> <item row="0" column="1" colspan="4">
<widget class="QLineEdit" name="filenameED"> <widget class="QLineEdit" name="filenameED">
<property name="toolTip"> <property name="toolTip">
<string>File name to include</string> <string>File name to include. (You can create a new file by entering the name of one that does not yet exist.)</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -318,7 +345,7 @@
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Expanding</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>28</width> <width>28</width>
<height>28</height> <height>28</height>

View File

@ -30,6 +30,8 @@ What's new
- Focus keyword field in Thesaurus dialog. - Focus keyword field in Thesaurus dialog.
- Allow creation of a child file from the include dialog (bug 4475).
* MISCELLANEOUS * MISCELLANEOUS