]> git.lyx.org Git - features.git/commitdiff
Fix bug 4475.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Sat, 22 Aug 2020 19:15:47 +0000 (15:15 -0400)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Mon, 31 Aug 2020 15:48:13 +0000 (11:48 -0400)
Add ability to create child from the include dialog.

(cherry picked from commit a385b7dc2b585ff259f9a9681e5d68168d1dac66)

src/frontends/qt4/GuiInclude.cpp
src/frontends/qt4/ui/IncludeUi.ui
status.23x

index edbf7a19c42f96617fb991253ba3df1137368ce2..d87f78c40939105030579d57c17a8bb152d30b00 100644 (file)
@@ -32,6 +32,7 @@
 #include "insets/InsetInclude.h"
 
 #include <QCheckBox>
+#include <QFile>
 #include <QLineEdit>
 #include <QPushButton>
 
@@ -265,6 +266,61 @@ void GuiInclude::applyView()
                else
                        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 const title = qt_("Select document to include");
index 0522d3d0af90044f78a7522baa9350f8f2c07d73..bbd2c5b0aa69bbc6439143ab7c3cf5b75b3d8e8f 100644 (file)
@@ -1,58 +1,73 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>IncludeUi</class>
- <widget class="QDialog" name="IncludeUi" >
-  <property name="geometry" >
+ <widget class="QDialog" name="IncludeUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>371</width>
-    <height>374</height>
+    <width>440</width>
+    <height>442</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <property name="sizeGripEnabled" >
+  <property name="sizeGripEnabled">
    <bool>true</bool>
   </property>
-  <layout class="QGridLayout" >
-   <property name="margin" >
+  <layout class="QGridLayout">
+   <property name="leftMargin">
     <number>9</number>
    </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>
    </property>
-   <item row="3" column="0" colspan="6" >
-    <widget class="QGroupBox" name="listingsGB" >
-     <property name="sizePolicy" >
-      <sizepolicy>
-       <hsizetype>7</hsizetype>
-       <vsizetype>7</vsizetype>
+   <item row="3" column="0" colspan="6">
+    <widget class="QGroupBox" name="listingsGB">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <property name="title" >
+     <property name="title">
       <string>Listing Parameters</string>
      </property>
-     <layout class="QGridLayout" >
-      <property name="margin" >
+     <layout class="QGridLayout">
+      <property name="leftMargin">
+       <number>9</number>
+      </property>
+      <property name="topMargin">
+       <number>9</number>
+      </property>
+      <property name="rightMargin">
        <number>9</number>
       </property>
-      <property name="spacing" >
+      <property name="bottomMargin">
+       <number>9</number>
+      </property>
+      <property name="spacing">
        <number>6</number>
       </property>
-      <item row="3" column="1" >
-       <widget class="QTextEdit" name="listingsED" >
-        <property name="sizePolicy" >
-         <sizepolicy>
-          <hsizetype>5</hsizetype>
-          <vsizetype>7</vsizetype>
+      <item row="3" column="1">
+       <widget class="QTextEdit" name="listingsED">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
-        <property name="minimumSize" >
+        <property name="minimumSize">
          <size>
           <width>0</width>
           <height>0</height>
         </property>
        </widget>
       </item>
-      <item row="4" column="0" colspan="2" >
-       <widget class="QCheckBox" name="bypassCB" >
-        <property name="toolTip" >
+      <item row="4" column="0" colspan="2">
+       <widget class="QCheckBox" name="bypassCB">
+        <property name="toolTip">
          <string>Check it to enter parameters that are not recognizable by LyX</string>
         </property>
-        <property name="text" >
+        <property name="text">
          <string>&amp;Bypass validation</string>
         </property>
        </widget>
       </item>
-      <item row="0" column="1" >
-       <widget class="QLineEdit" name="captionLE" >
-        <property name="minimumSize" >
+      <item row="0" column="1">
+       <widget class="QLineEdit" name="captionLE">
+        <property name="minimumSize">
          <size>
           <width>150</width>
           <height>0</height>
         </property>
        </widget>
       </item>
-      <item row="0" column="0" >
-       <widget class="QLabel" name="captionLabel" >
-        <property name="text" >
+      <item row="0" column="0">
+       <widget class="QLabel" name="captionLabel">
+        <property name="text">
          <string>C&amp;aption:</string>
         </property>
-        <property name="buddy" >
+        <property name="buddy">
          <cstring>captionLE</cstring>
         </property>
        </widget>
       </item>
-      <item row="1" column="1" >
-       <widget class="QLineEdit" name="labelLE" />
+      <item row="1" column="1">
+       <widget class="QLineEdit" name="labelLE"/>
       </item>
-      <item row="1" column="0" >
-       <widget class="QLabel" name="labelLabel" >
-        <property name="text" >
+      <item row="1" column="0">
+       <widget class="QLabel" name="labelLabel">
+        <property name="text">
          <string>La&amp;bel:</string>
         </property>
-        <property name="buddy" >
+        <property name="buddy">
          <cstring>labelLE</cstring>
         </property>
        </widget>
       </item>
-      <item row="2" column="0" colspan="2" >
-       <widget class="QLabel" name="label_3" >
-        <property name="text" >
+      <item row="2" column="0" colspan="2">
+       <widget class="QLabel" name="label_3">
+        <property name="text">
          <string>Mo&amp;re parameters</string>
         </property>
-        <property name="buddy" >
+        <property name="buddy">
          <cstring>listingsED</cstring>
         </property>
        </widget>
       </item>
-      <item row="3" column="0" >
-       <widget class="QTextBrowser" name="listingsTB" >
-        <property name="sizePolicy" >
-         <sizepolicy>
-          <hsizetype>0</hsizetype>
-          <vsizetype>7</vsizetype>
+      <item row="3" column="0">
+       <widget class="QTextBrowser" name="listingsTB">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Fixed" vsizetype="Expanding">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
-        <property name="minimumSize" >
+        <property name="minimumSize">
          <size>
           <width>0</width>
           <height>0</height>
          </size>
         </property>
-        <property name="maximumSize" >
+        <property name="maximumSize">
          <size>
           <width>120</width>
           <height>16777215</height>
          </size>
         </property>
-        <property name="cursor" >
-         <cursor>0</cursor>
+        <property name="cursor" stdset="0">
+         <cursorShape>ArrowCursor</cursorShape>
         </property>
-        <property name="focusPolicy" >
+        <property name="focusPolicy">
          <enum>Qt::NoFocus</enum>
         </property>
-        <property name="acceptDrops" >
+        <property name="acceptDrops">
          <bool>true</bool>
         </property>
-        <property name="frameShape" >
+        <property name="frameShape">
          <enum>QFrame::NoFrame</enum>
         </property>
-        <property name="frameShadow" >
+        <property name="frameShadow">
          <enum>QFrame::Plain</enum>
         </property>
-        <property name="lineWidth" >
+        <property name="lineWidth">
          <number>0</number>
         </property>
-        <property name="acceptRichText" >
+        <property name="acceptRichText">
          <bool>false</bool>
         </property>
        </widget>
      </layout>
     </widget>
    </item>
-   <item row="2" column="0" colspan="6" >
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
+   <item row="2" column="0" colspan="6">
+    <layout class="QHBoxLayout">
+     <property name="spacing">
+      <number>6</number>
+     </property>
+     <property name="leftMargin">
       <number>0</number>
      </property>
-     <property name="spacing" >
-      <number>6</number>
+     <property name="topMargin">
+      <number>0</number>
+     </property>
+     <property name="rightMargin">
+      <number>0</number>
+     </property>
+     <property name="bottomMargin">
+      <number>0</number>
      </property>
      <item>
-      <widget class="QCheckBox" name="visiblespaceCB" >
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>3</hsizetype>
-         <vsizetype>0</vsizetype>
+      <widget class="QCheckBox" name="visiblespaceCB">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="toolTip" >
+       <property name="toolTip">
         <string>Underline spaces in generated output</string>
        </property>
-       <property name="text" >
+       <property name="text">
         <string>&amp;Mark spaces in output</string>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QCheckBox" name="previewCB" >
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>3</hsizetype>
-         <vsizetype>0</vsizetype>
+      <widget class="QCheckBox" name="previewCB">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="toolTip" >
+       <property name="toolTip">
         <string>Show LaTeX preview</string>
        </property>
-       <property name="text" >
+       <property name="text">
         <string>&amp;Show preview</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
-   <item row="4" column="0" colspan="6" >
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
+   <item row="4" column="0" colspan="6">
+    <layout class="QHBoxLayout">
+     <property name="spacing">
+      <number>6</number>
+     </property>
+     <property name="leftMargin">
       <number>0</number>
      </property>
-     <property name="spacing" >
-      <number>6</number>
+     <property name="topMargin">
+      <number>0</number>
+     </property>
+     <property name="rightMargin">
+      <number>0</number>
+     </property>
+     <property name="bottomMargin">
+      <number>0</number>
      </property>
      <item>
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
+       <property name="sizeType">
         <enum>QSizePolicy::Expanding</enum>
        </property>
-       <property name="sizeHint" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>20</width>
          <height>20</height>
       </spacer>
      </item>
      <item>
-      <widget class="QPushButton" name="okPB" >
-       <property name="text" >
+      <widget class="QPushButton" name="okPB">
+       <property name="text">
         <string>&amp;OK</string>
        </property>
-       <property name="default" >
+       <property name="autoDefault">
         <bool>true</bool>
        </property>
-       <property name="autoDefault" >
+       <property name="default">
         <bool>true</bool>
        </property>
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="closePB" >
-       <property name="text" >
+      <widget class="QPushButton" name="closePB">
+       <property name="text">
         <string>&amp;Close</string>
        </property>
-       <property name="autoDefault" >
+       <property name="autoDefault">
         <bool>false</bool>
        </property>
       </widget>
      </item>
     </layout>
    </item>
-   <item row="0" column="0" >
-    <widget class="QLabel" name="filenameLA" >
-     <property name="toolTip" >
+   <item row="0" column="0">
+    <widget class="QLabel" name="filenameLA">
+     <property name="toolTip">
       <string/>
      </property>
-     <property name="text" >
+     <property name="text">
       <string>&amp;File:</string>
      </property>
-     <property name="buddy" >
+     <property name="buddy">
       <cstring>filenameED</cstring>
      </property>
     </widget>
    </item>
-   <item row="0" column="1" colspan="4" >
-    <widget class="QLineEdit" name="filenameED" >
-     <property name="toolTip" >
-      <string>File name to include</string>
+   <item row="0" column="1" colspan="4">
+    <widget class="QLineEdit" name="filenameED">
+     <property name="toolTip">
+      <string>File name to include. (You can create a new file by entering the name of one that does not yet exist.)</string>
      </property>
     </widget>
    </item>
-   <item row="1" column="0" colspan="2" >
-    <widget class="QLabel" name="TextLabel1" >
-     <property name="text" >
+   <item row="1" column="0" colspan="2">
+    <widget class="QLabel" name="TextLabel1">
+     <property name="text">
       <string>&amp;Include Type:</string>
      </property>
-     <property name="buddy" >
+     <property name="buddy">
       <cstring>typeCO</cstring>
      </property>
     </widget>
    </item>
-   <item row="1" column="2" >
-    <widget class="QComboBox" name="typeCO" >
+   <item row="1" column="2">
+    <widget class="QComboBox" name="typeCO">
      <item>
-      <property name="text" >
+      <property name="text">
        <string>Include</string>
       </property>
      </item>
      <item>
-      <property name="text" >
+      <property name="text">
        <string>Input</string>
       </property>
      </item>
      <item>
-      <property name="text" >
+      <property name="text">
        <string>Verbatim</string>
       </property>
      </item>
      <item>
-      <property name="text" >
+      <property name="text">
        <string>Program Listing</string>
       </property>
      </item>
     </widget>
    </item>
-   <item row="1" column="3" >
+   <item row="1" column="3">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
-     <property name="sizeType" >
+     <property name="sizeType">
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
        <width>28</width>
        <height>28</height>
      </property>
     </spacer>
    </item>
-   <item row="0" column="5" >
-    <widget class="QPushButton" name="browsePB" >
-     <property name="toolTip" >
+   <item row="0" column="5">
+    <widget class="QPushButton" name="browsePB">
+     <property name="toolTip">
       <string>Select a file</string>
      </property>
-     <property name="text" >
+     <property name="text">
       <string>&amp;Browse...</string>
      </property>
     </widget>
    </item>
-   <item row="1" column="5" >
-    <widget class="QPushButton" name="editPB" >
-     <property name="toolTip" >
+   <item row="1" column="5">
+    <widget class="QPushButton" name="editPB">
+     <property name="toolTip">
       <string>Edit the file</string>
      </property>
-     <property name="text" >
+     <property name="text">
       <string>&amp;Edit</string>
      </property>
     </widget>
   <tabstop>closePB</tabstop>
  </tabstops>
  <includes>
-  <include location="local" >qt_i18n.h</include>
+  <include location="local">qt_i18n.h</include>
  </includes>
  <resources/>
  <connections/>
index aef6ca68ad41cce7fd396dd842155d327ba6e12b..b5e54b41c6a0a008d076fe92cc68b4cd51a57ac7 100644 (file)
@@ -30,6 +30,8 @@ What's new
 
 - Focus keyword field in Thesaurus dialog.
 
+- Allow creation of a child file from the include dialog (bug 4475).
+
 
 * MISCELLANEOUS