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,58 +1,73 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>IncludeUi</class> <class>IncludeUi</class>
<widget class="QDialog" name="IncludeUi" > <widget class="QDialog" name="IncludeUi">
<property name="geometry" > <property name="geometry">
<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">
<string/> <string/>
</property> </property>
<property name="sizeGripEnabled" > <property name="sizeGripEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout">
<property name="margin" > <property name="leftMargin">
<number>9</number> <number>9</number>
</property> </property>
<property name="spacing" > <property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<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>
</property> </property>
<property name="title" > <property name="title">
<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> <number>9</number>
</property> </property>
<property name="spacing" > <property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<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>
</property> </property>
<property name="minimumSize" > <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
@ -60,19 +75,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="2" > <item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="bypassCB" > <widget class="QCheckBox" name="bypassCB">
<property name="toolTip" > <property name="toolTip">
<string>Check it to enter parameters that are not recognizable by LyX</string> <string>Check it to enter parameters that are not recognizable by LyX</string>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Bypass validation</string> <string>&amp;Bypass validation</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" > <item row="0" column="1">
<widget class="QLineEdit" name="captionLE" > <widget class="QLineEdit" name="captionLE">
<property name="minimumSize" > <property name="minimumSize">
<size> <size>
<width>150</width> <width>150</width>
<height>0</height> <height>0</height>
@ -80,80 +95,78 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" > <item row="0" column="0">
<widget class="QLabel" name="captionLabel" > <widget class="QLabel" name="captionLabel">
<property name="text" > <property name="text">
<string>C&amp;aption:</string> <string>C&amp;aption:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>captionLE</cstring> <cstring>captionLE</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" > <item row="1" column="1">
<widget class="QLineEdit" name="labelLE" /> <widget class="QLineEdit" name="labelLE"/>
</item> </item>
<item row="1" column="0" > <item row="1" column="0">
<widget class="QLabel" name="labelLabel" > <widget class="QLabel" name="labelLabel">
<property name="text" > <property name="text">
<string>La&amp;bel:</string> <string>La&amp;bel:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>labelLE</cstring> <cstring>labelLE</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2" > <item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_3" > <widget class="QLabel" name="label_3">
<property name="text" > <property name="text">
<string>Mo&amp;re parameters</string> <string>Mo&amp;re parameters</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>listingsED</cstring> <cstring>listingsED</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<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>
</property> </property>
<property name="minimumSize" > <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize" > <property name="maximumSize">
<size> <size>
<width>120</width> <width>120</width>
<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>
</property> </property>
<property name="acceptDrops" > <property name="acceptDrops">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="frameShape" > <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow" > <property name="frameShadow">
<enum>QFrame::Plain</enum> <enum>QFrame::Plain</enum>
</property> </property>
<property name="lineWidth" > <property name="lineWidth">
<number>0</number> <number>0</number>
</property> </property>
<property name="acceptRichText" > <property name="acceptRichText">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
@ -161,69 +174,83 @@
</layout> </layout>
</widget> </widget>
</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" > <property name="spacing">
<number>0</number>
</property>
<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>
</property> </property>
<property name="toolTip" > <property name="toolTip">
<string>Underline spaces in generated output</string> <string>Underline spaces in generated output</string>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Mark spaces in output</string> <string>&amp;Mark spaces in output</string>
</property> </property>
</widget> </widget>
</item> </item>
<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>
</property> </property>
<property name="toolTip" > <property name="toolTip">
<string>Show LaTeX preview</string> <string>Show LaTeX preview</string>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Show preview</string> <string>&amp;Show preview</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</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" > <property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="spacing" > <property name="topMargin">
<number>6</number> <number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property> </property>
<item> <item>
<spacer> <spacer>
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<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>
@ -232,93 +259,93 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="okPB" > <widget class="QPushButton" name="okPB">
<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>
</item> </item>
<item> <item>
<widget class="QPushButton" name="closePB" > <widget class="QPushButton" name="closePB">
<property name="text" > <property name="text">
<string>&amp;Close</string> <string>&amp;Close</string>
</property> </property>
<property name="autoDefault" > <property name="autoDefault">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item row="0" column="0" > <item row="0" column="0">
<widget class="QLabel" name="filenameLA" > <widget class="QLabel" name="filenameLA">
<property name="toolTip" > <property name="toolTip">
<string/> <string/>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;File:</string> <string>&amp;File:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>filenameED</cstring> <cstring>filenameED</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<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>
<item row="1" column="0" colspan="2" > <item row="1" column="0" colspan="2">
<widget class="QLabel" name="TextLabel1" > <widget class="QLabel" name="TextLabel1">
<property name="text" > <property name="text">
<string>&amp;Include Type:</string> <string>&amp;Include Type:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>typeCO</cstring> <cstring>typeCO</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2" > <item row="1" column="2">
<widget class="QComboBox" name="typeCO" > <widget class="QComboBox" name="typeCO">
<item> <item>
<property name="text" > <property name="text">
<string>Include</string> <string>Include</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Input</string> <string>Input</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Verbatim</string> <string>Verbatim</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text" > <property name="text">
<string>Program Listing</string> <string>Program Listing</string>
</property> </property>
</item> </item>
</widget> </widget>
</item> </item>
<item row="1" column="3" > <item row="1" column="3">
<spacer> <spacer>
<property name="orientation" > <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<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>
@ -326,22 +353,22 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="5" > <item row="0" column="5">
<widget class="QPushButton" name="browsePB" > <widget class="QPushButton" name="browsePB">
<property name="toolTip" > <property name="toolTip">
<string>Select a file</string> <string>Select a file</string>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Browse...</string> <string>&amp;Browse...</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="5" > <item row="1" column="5">
<widget class="QPushButton" name="editPB" > <widget class="QPushButton" name="editPB">
<property name="toolTip" > <property name="toolTip">
<string>Edit the file</string> <string>Edit the file</string>
</property> </property>
<property name="text" > <property name="text">
<string>&amp;Edit</string> <string>&amp;Edit</string>
</property> </property>
</widget> </widget>
@ -363,7 +390,7 @@
<tabstop>closePB</tabstop> <tabstop>closePB</tabstop>
</tabstops> </tabstops>
<includes> <includes>
<include location="local" >qt_i18n.h</include> <include location="local">qt_i18n.h</include>
</includes> </includes>
<resources/> <resources/>
<connections/> <connections/>

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