]> git.lyx.org Git - features.git/commitdiff
Separate caption and label from InsetListingsParams and handle them separately in...
authorBo Peng <bpeng@lyx.org>
Mon, 14 May 2007 20:42:14 +0000 (20:42 +0000)
committerBo Peng <bpeng@lyx.org>
Mon, 14 May 2007 20:42:14 +0000 (20:42 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18324 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
lib/layouts/stdcounters.inc
src/Text.cpp
src/buffer_funcs.cpp
src/frontends/qt4/QInclude.cpp
src/frontends/qt4/QListings.cpp
src/frontends/qt4/ui/IncludeUi.ui
src/frontends/qt4/ui/ListingsUi.ui
src/insets/InsetCaption.cpp
src/insets/InsetCaption.h
src/insets/InsetListings.cpp
src/insets/InsetListings.h
src/insets/InsetListingsParams.cpp

index f5a41ca8a45a03ecd9514a9a47addb4a2918a42c..9c8801f460def849b1c5795610a856b7b0fd93e1 100644 (file)
@@ -76,3 +76,7 @@ End
 Counter
        Name                 equation
 End
+
+Counter
+       Name                 listing
+End
index 0512915623d7a8193e90ffcb28cd14a3b14a0fae..6c810b986907b26e834f50e2a153e1118bef7c21 100644 (file)
@@ -1871,6 +1871,8 @@ docstring Text::getPossibleLabel(Cursor & cur) const
                name = from_ascii("thm");
        else if (name == "Foot")
                name = from_ascii("fn");
+       else if (name == "listing")
+               name = from_ascii("lst");
                
        if (!name.empty())
                text = name.substr(0, 3) + ':' + text;
index f8469d702e51b4fd3175e692889d6751fcee3eec..6527018748ae4f21737c42a8cfdcfd30bb5085b6 100644 (file)
@@ -417,6 +417,8 @@ void setCaptions(Paragraph & par, TextClass const & textclass)
                        // FIXME: are "table" and "Table" the correct type and label?
                        setCaptionLabels(inset, "table", from_ascii("Table"), counters);
                }
+               else if (inset.lyxCode() == Inset::LISTINGS_CODE)
+                       setCaptionLabels(inset, "listing", from_ascii("Listing"), counters);
        }
 }
 
index 007a89ae8e2386cc548a176dc4ab5d0edd664132..1680e7e7b1d18944ab82b8022ab302abcd1c3f24 100644 (file)
@@ -11,6 +11,7 @@
 #include <config.h>
 
 #include "support/os.h"
+#include "support/lstrings.h"
 
 #include "QInclude.h"
 
 #include <QLineEdit>
 
 using std::string;
+using std::vector;
 
 using lyx::support::os::internal_path;
-
+using lyx::support::prefixIs;
+using lyx::support::getStringFromVector;
+using lyx::support::getVectorFromString;
 
 namespace lyx {
 namespace frontend {
@@ -58,6 +62,8 @@ QIncludeDialog::QIncludeDialog(QInclude * form)
        connect(typeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
        connect(typeCO, SIGNAL(activated(int)), this, SLOT(typeChanged(int)));
        connect(previewCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
+       connect(captionLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
+       connect(labelLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
        connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
        connect(listingsED, SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
 
@@ -85,13 +91,11 @@ void QIncludeDialog::validate_listings_params()
                InsetListingsParams par(fromqstr(listingsED->toPlainText()));
                if (!isOK) {
                        isOK = true;
-                       // listingsTB->setTextColor("black");
-                       listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+                       listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
                        okPB->setEnabled(true);
                }
        } catch (invalidParam & e) {
                isOK = false;
-               // listingsTB->setTextColor("red");
                listingsTB->setPlainText(e.what());
                okPB->setEnabled(false);
        }
@@ -115,7 +119,6 @@ void QIncludeDialog::typeChanged(int v)
                        previewCB->setEnabled(false);
                        previewCB->setChecked(false);
                        listingsGB->setEnabled(false);
-                       listingsED->setEnabled(false);
                        break;
                //case Input
                case 1:
@@ -123,7 +126,6 @@ void QIncludeDialog::typeChanged(int v)
                        visiblespaceCB->setChecked(false);
                        previewCB->setEnabled(true);
                        listingsGB->setEnabled(false);
-                       listingsED->setEnabled(false);
                        break;
                //case listings
                case 3:
@@ -131,7 +133,6 @@ void QIncludeDialog::typeChanged(int v)
                        visiblespaceCB->setChecked(false);
                        previewCB->setEnabled(false);
                        listingsGB->setEnabled(true);
-                       listingsED->setEnabled(true);
                        break;
                //case Verbatim
                default:
@@ -139,7 +140,6 @@ void QIncludeDialog::typeChanged(int v)
                        previewCB->setEnabled(false);
                        previewCB->setChecked(false);
                        listingsGB->setEnabled(false);
-                       listingsED->setEnabled(false);
                        break;
        }
 }
@@ -183,7 +183,7 @@ void QInclude::build_dialog()
        bcview().addReadOnly(dialog_->visiblespaceCB);
        bcview().addReadOnly(dialog_->typeCO);
        bcview().addReadOnly(dialog_->listingsED);
-       dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+       dialog_->listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
 
        addCheckedLineEdit(bcview(), dialog_->filenameED, dialog_->filenameLA);
 }
@@ -235,7 +235,29 @@ void QInclude::update_contents()
                dialog_->listingsGB->setEnabled(true);
                dialog_->listingsED->setEnabled(true);
                InsetListingsParams par(params.getOptions());
-               dialog_->listingsED->setPlainText(toqstr(par.separatedParams()));
+               // extract caption and label and put them into their respective editboxes
+               vector<string> pars = getVectorFromString(par.separatedParams(), "\n");
+               for (vector<string>::iterator it = pars.begin();
+                       it != pars.end(); ++it) {
+                       if (prefixIs(*it, "caption=")) {
+                               string cap = it->substr(8);
+                               if (cap[0] == '{' && cap[cap.size()-1] == '}')
+                                       dialog_->captionLE->setText(toqstr(cap.substr(1, cap.size()-2)));
+                               else
+                                       throw invalidParam("caption parameter is not quoted with braces");
+                               *it = "";
+                       } else if (prefixIs(*it, "label=")) {
+                               string lbl = it->substr(6);
+                               if (lbl[0] == '{' && lbl[lbl.size()-1] == '}')
+                                       dialog_->labelLE->setText(toqstr(lbl.substr(1, lbl.size()-2)));
+                               else
+                                       throw invalidParam("label parameter is not quoted with braces");
+                               *it = "";
+                       }
+               }
+               // the rest is put to the extra edit box.
+               string extra = getStringFromVector(pars);
+               dialog_->listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams()));
        }       
 }
 
@@ -257,7 +279,14 @@ void QInclude::apply()
        } else if (item == 3) {
                params.setCmdName("lstinputlisting");
                // the parameter string should have passed validation
-               params.setOptions(InsetListingsParams(fromqstr(dialog_->listingsED->toPlainText())).params());
+               InsetListingsParams par(fromqstr(dialog_->listingsED->toPlainText()));
+               string caption = fromqstr(dialog_->captionLE->text());
+               string label = fromqstr(dialog_->labelLE->text());
+               if (!caption.empty())
+                       par.addParam("caption", "{" + caption + "}");
+               if (!label.empty())
+                       par.addParam("label", "{" + label + "}");
+               params.setOptions(par.params());
        } else {
                if (dialog_->visiblespaceCB->isChecked())
                        params.setCmdName("verbatiminput*");
index 7398d5417d9552a20417f6aa666935ffefcf41c0..d9e690765626757a1d74321bc2cbf19a310c365b 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Bo Peng
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -78,8 +79,6 @@ QListingsDialog::QListingsDialog(QListings * form)
        connect(breaklinesCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
        connect(spaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
        connect(extendedcharsCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
-       connect(captionLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
-       connect(labelLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
        
        connect(listingsED,  SIGNAL(textChanged()), this, SLOT(change_adaptor()));
        connect(listingsED,  SIGNAL(textChanged()), this, SLOT(validate_listings_params()));
@@ -108,7 +107,7 @@ string QListingsDialog::construct_params()
        
        bool left = numberLeftCB->checkState() == Qt::Checked;
        bool right = numberRightCB->checkState() == Qt::Checked;
-       string step = fromqstr(numberStepLE->text());
+       string stepnumber = fromqstr(numberStepLE->text());
        string numberfontsize = fromqstr(numberFontSizeCO->currentText());
        string firstline = fromqstr(firstlineLE->text());
        string lastline = fromqstr(lastlineLE->text());
@@ -122,11 +121,7 @@ string QListingsDialog::construct_params()
                basicstyle += "\\" + fontstyle;
        bool breakline = breaklinesCB->checkState() == Qt::Checked;
        bool space = spaceCB->checkState() == Qt::Checked;
-       bool extendedchar = extendedcharsCB->checkState() == Qt::Checked;
-       
-       string caption = fromqstr(captionLE->text());
-       string label = fromqstr(labelLE->text());
-       
+       bool extendedchars = extendedcharsCB->checkState() == Qt::Checked;
        string extra = fromqstr(listingsED->toPlainText());
 
        // compose a string
@@ -147,18 +142,16 @@ string QListingsDialog::construct_params()
                par.addParam("firstline", firstline);
        if (!lastline.empty())
                par.addParam("lastline", lastline);
-       if (basicstyle != "")
+       if (!stepnumber.empty())
+               par.addParam("stepnumber", stepnumber);
+       if (!basicstyle.empty())
                par.addParam("basicstyle", basicstyle);
        if (breakline)
                par.addParam("breaklines", "true");
        if (space)
                par.addParam("showspaces", "true");
-       if (extendedchar)
+       if (extendedchars)
                par.addParam("extendedchars", "true");
-       if (!caption.empty())
-               par.addParam("caption", "{" + caption + "}");
-       if (!label.empty())
-               par.addParam("label", "{" + label + "}");
        par.addParams(extra);
        return par.params();
 }
@@ -171,13 +164,11 @@ void QListingsDialog::validate_listings_params()
                InsetListingsParams par(construct_params());
                if (!isOK) {
                        isOK = true;
-                       // listingsTB->setTextColor("black");
-                       listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+                       listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
                        okPB->setEnabled(true);
                }
        } catch (invalidParam & e) {
                isOK = false;
-               // listingsTB->setTextColor("red");
                listingsTB->setPlainText(e.what());
                okPB->setEnabled(false);
        }
@@ -203,7 +194,7 @@ void QListings::build_dialog()
        
        bcview().setOK(dialog_->okPB);
        bcview().setCancel(dialog_->closePB);
-       dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+       dialog_->listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
 
        update_contents();
 }
@@ -257,7 +248,7 @@ void QListings::update_contents()
        dialog_->placementLE->setValidator(new QRegExpValidator(QRegExp("[tbph]*"), this));
 
        //
-       dialog_->listingsTB->setPlainText("Input listings parameters below. Enter ? for a list of parameters.");
+       dialog_->listingsTB->setPlainText("Input listings parameters on the right. Enter ? for a list of parameters.");
 
        // set values from param string
        InsetListingsParams & params = controller().params();
@@ -345,22 +336,6 @@ void QListings::update_contents()
                } else if (prefixIs(*it, "extendedchars=")) {
                        dialog_->extendedcharsCB->setChecked(contains(*it, "true"));
                        *it = "";
-               } else if (prefixIs(*it, "caption=")) {
-                       string cap = it->substr(8);
-                       if ((cap[0] == '{' && cap[cap.size()-1] == '}') ||
-                               (cap[0] == '"' && cap[cap.size()-1] == '"') )
-                               dialog_->captionLE->setText(toqstr(cap.substr(1, cap.size()-2)));
-                       else
-                               dialog_->captionLE->setText(toqstr(cap));               
-                       *it = "";
-               } else if (prefixIs(*it, "label=")) {
-                       string lbl = it->substr(6);
-                       if ((lbl[0] == '{' && lbl[lbl.size()-1] == '}') ||
-                               (lbl[0] == '"' && lbl[lbl.size()-1] == '"') )
-                               dialog_->labelLE->setText(toqstr(lbl.substr(1, lbl.size()-2)));
-                       else
-                               dialog_->labelLE->setText(toqstr(lbl));                 
-                       *it = "";
                }
        }
        // parameters that can be handled by widgets are cleared
index 89be7cf0804a0f44963c717962af958d7cd78840..bbbeaeae09edc3a4b746afb78e7a753a3f237ce8 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>389</width>
-    <height>385</height>
+    <width>315</width>
+    <height>379</height>
    </rect>
   </property>
   <property name="windowTitle" >
          <number>6</number>
         </property>
         <item>
-         <widget class="QTextBrowser" name="listingsTB" >
-          <property name="minimumSize" >
-           <size>
-            <width>0</width>
-            <height>0</height>
-           </size>
-          </property>
-          <property name="maximumSize" >
-           <size>
-            <width>200</width>
-            <height>16777215</height>
-           </size>
-          </property>
-          <property name="cursor" >
-           <cursor>0</cursor>
-          </property>
-          <property name="acceptDrops" >
-           <bool>false</bool>
-          </property>
-          <property name="frameShape" >
-           <enum>QFrame::NoFrame</enum>
-          </property>
-          <property name="frameShadow" >
-           <enum>QFrame::Plain</enum>
-          </property>
-          <property name="lineWidth" >
+         <layout class="QGridLayout" >
+          <property name="margin" >
            <number>0</number>
           </property>
-          <property name="acceptRichText" >
-           <bool>false</bool>
+          <property name="spacing" >
+           <number>6</number>
           </property>
-         </widget>
+          <item row="1" column="0" >
+           <widget class="QLabel" name="labelLabel" >
+            <property name="text" >
+             <string>Label</string>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="1" >
+           <widget class="QLineEdit" name="captionLE" >
+            <property name="minimumSize" >
+             <size>
+              <width>150</width>
+              <height>0</height>
+             </size>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="0" >
+           <widget class="QLabel" name="captionLabel" >
+            <property name="text" >
+             <string>Caption</string>
+            </property>
+           </widget>
+          </item>
+          <item row="1" column="1" >
+           <widget class="QLineEdit" name="labelLE" />
+          </item>
+         </layout>
         </item>
         <item>
-         <widget class="QTextEdit" name="listingsED" >
-          <property name="minimumSize" >
+         <spacer>
+          <property name="orientation" >
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" >
            <size>
-            <width>0</width>
-            <height>0</height>
+            <width>20</width>
+            <height>20</height>
            </size>
           </property>
-         </widget>
+         </spacer>
         </item>
        </layout>
       </item>
+      <item>
+       <widget class="QLabel" name="label_3" >
+        <property name="text" >
+         <string>More parameters</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QSplitter" name="splitter" >
+        <property name="orientation" >
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <widget class="QTextBrowser" name="listingsTB" >
+         <property name="minimumSize" >
+          <size>
+           <width>0</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="maximumSize" >
+          <size>
+           <width>200</width>
+           <height>16777215</height>
+          </size>
+         </property>
+         <property name="cursor" >
+          <cursor>0</cursor>
+         </property>
+         <property name="acceptDrops" >
+          <bool>false</bool>
+         </property>
+         <property name="frameShape" >
+          <enum>QFrame::NoFrame</enum>
+         </property>
+         <property name="frameShadow" >
+          <enum>QFrame::Plain</enum>
+         </property>
+         <property name="lineWidth" >
+          <number>0</number>
+         </property>
+         <property name="acceptRichText" >
+          <bool>false</bool>
+         </property>
+        </widget>
+        <widget class="QTextEdit" name="listingsED" >
+         <property name="minimumSize" >
+          <size>
+           <width>0</width>
+           <height>0</height>
+          </size>
+         </property>
+        </widget>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
   <tabstop>loadPB</tabstop>
   <tabstop>visiblespaceCB</tabstop>
   <tabstop>previewCB</tabstop>
+  <tabstop>captionLE</tabstop>
+  <tabstop>labelLE</tabstop>
   <tabstop>listingsTB</tabstop>
   <tabstop>listingsED</tabstop>
  </tabstops>
index bcdc72a23cdf1ee23888052608986698f8c5cc30..39cb60b48a9508350665592df26f9088dc8ea87f 100644 (file)
@@ -8,8 +8,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>499</width>
-    <height>355</height>
+    <width>511</width>
+    <height>325</height>
    </rect>
   </property>
   <property name="windowTitle" >
             <property name="wordWrap" >
              <bool>false</bool>
             </property>
-            <property name="buddy" >
-             <cstring>captionLE</cstring>
-            </property>
            </widget>
           </item>
           <item row="1" column="0" colspan="2" >
          </layout>
         </widget>
        </item>
-       <item row="2" column="0" colspan="3" >
-        <widget class="QGroupBox" name="captionGB_3" >
-         <property name="title" >
-          <string>Display</string>
-         </property>
-         <layout class="QGridLayout" >
-          <property name="margin" >
-           <number>9</number>
-          </property>
-          <property name="spacing" >
-           <number>6</number>
-          </property>
-          <item row="1" column="0" >
-           <widget class="QLabel" name="labelL_4" >
-            <property name="text" >
-             <string>&amp;Label:</string>
-            </property>
-            <property name="wordWrap" >
-             <bool>false</bool>
-            </property>
-            <property name="buddy" >
-             <cstring>labelLE</cstring>
-            </property>
-           </widget>
-          </item>
-          <item row="0" column="0" >
-           <widget class="QLabel" name="captionL_4" >
-            <property name="text" >
-             <string>&amp;Caption:</string>
-            </property>
-            <property name="wordWrap" >
-             <bool>false</bool>
-            </property>
-            <property name="buddy" >
-             <cstring>captionLE</cstring>
-            </property>
-           </widget>
-          </item>
-          <item row="0" column="1" >
-           <widget class="QLineEdit" name="captionLE" >
-            <property name="minimumSize" >
-             <size>
-              <width>150</width>
-              <height>0</height>
-             </size>
-            </property>
-            <property name="toolTip" >
-             <string>A caption for the List of Listings</string>
-            </property>
-            <property name="text" >
-             <string/>
-            </property>
-           </widget>
-          </item>
-          <item row="1" column="1" >
-           <widget class="QLineEdit" name="labelLE" >
-            <property name="minimumSize" >
-             <size>
-              <width>150</width>
-              <height>0</height>
-             </size>
-            </property>
-            <property name="toolTip" >
-             <string>A Label for the caption</string>
-            </property>
-            <property name="text" >
-             <string/>
-            </property>
-           </widget>
-          </item>
-         </layout>
-        </widget>
-       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tab_2" >
  <tabstops>
   <tabstop>okPB</tabstop>
   <tabstop>closePB</tabstop>
-  <tabstop>languageCO</tabstop>
+  <tabstop>listingsTW</tabstop>
   <tabstop>inlineCB</tabstop>
   <tabstop>floatCB</tabstop>
   <tabstop>placementLE</tabstop>
+  <tabstop>languageCO</tabstop>
   <tabstop>numberLeftCB</tabstop>
   <tabstop>numberRightCB</tabstop>
   <tabstop>numberStepLE</tabstop>
   <tabstop>breaklinesCB</tabstop>
   <tabstop>spaceCB</tabstop>
   <tabstop>extendedcharsCB</tabstop>
-  <tabstop>captionLE</tabstop>
-  <tabstop>labelLE</tabstop>
   <tabstop>listingsTB</tabstop>
   <tabstop>listingsED</tabstop>
  </tabstops>
index 19bcc3859c00e52d2467ce0f2b0135004ba04c86..56d85432804399c85d5aab97a7e4654e3fa908a9 100644 (file)
@@ -278,6 +278,20 @@ int InsetCaption::docbook(Buffer const & buf, odocstream & os,
 }
 
 
+int InsetCaption::getArgument(Buffer const & buf, odocstream & os,
+                        OutputParams const & runparams) const
+{
+       return InsetText::latex(buf, os, runparams);
+}
+
+
+int InsetCaption::getOptArg(Buffer const & buf, odocstream & os,
+                        OutputParams const & runparams) const
+{
+       return latexOptArgInsets(buf, paragraphs()[0], os, runparams, 1);
+}
+
+
 void InsetCaption::computeFullLabel(Buffer const & buf) const
 {
        if (type_.empty())
index 296ca8a802d2f2841ccae524f7fed7664519cdc3..dabfa39e995616b63cb2a9de9bd3ea2f1882c0e7 100644 (file)
@@ -69,6 +69,12 @@ public:
        ///
        int docbook(Buffer const & buf, odocstream & os,
                    OutputParams const & runparams) const;
+       /// return the mandatory argument (LaTeX format) only
+       int getArgument(Buffer const & buf, odocstream & os,
+                 OutputParams const &) const;
+       /// return the optional argument(s) only
+       int getOptArg(Buffer const & buf, odocstream & os,
+                 OutputParams const &) const;
        ///
        void setCount(int c) { counter_ = c; }
        ///
index 30ba1a2a4ef6e2d05b8ce089a699e315f3f0d9e9..baf9ff9860953411156a0c023c05b2aee104c33a 100644 (file)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Bo Peng
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -11,6 +12,7 @@
 #include <config.h>
 
 #include "InsetListings.h"
+#include "InsetCaption.h"
 
 #include "Language.h"
 #include "gettext.h"
@@ -127,8 +129,8 @@ docstring const InsetListings::editMessage() const
 }
 
 
-int InsetListings::latex(Buffer const &, odocstream & os,
-                   OutputParams const &) const
+int InsetListings::latex(Buffer const & buf, odocstream & os,
+                   OutputParams const & runparams) const
 {
        string param_string = params().encodedString();
        // NOTE: I use {} to quote text, which is an experimental feature
@@ -141,10 +143,18 @@ int InsetListings::latex(Buffer const &, odocstream & os,
                else
                        os << "\\lstinline[" << from_ascii(param_string) << "]{";
        } else {
-               if (param_string.empty())
+               docstring const caption = getCaption(buf, runparams);
+               if (param_string.empty() && caption.empty())
                        os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}\n";
-               else
-                       os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}[" << from_ascii(param_string) << "]\n";
+               else {
+                       os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}[";
+                       if (!caption.empty()) {
+                               os << "caption={" << caption << '}';
+                               if (!param_string.empty())
+                                       os << ',';
+                       }
+                       os << from_ascii(param_string) << "]\n";
+               }
                lines += 4;
        }
        ParagraphList::const_iterator par = paragraphs().begin();
@@ -152,16 +162,19 @@ int InsetListings::latex(Buffer const &, odocstream & os,
 
        while (par != end) {
                pos_type siz = par->size();
+               bool captionline = false;
                for (pos_type i = 0; i < siz; ++i) {
-                       // ignore all struck out text
-                       if (par->isDeleted(i))
+                       if (i == 0 && par->isInset(i) && i + 1 == siz)
+                               captionline = true;
+                       // ignore all struck out text and (caption) insets
+                       if (par->isDeleted(i) || par->isInset(i))
                                continue;
                        os.put(par->getChar(i));
                }
                ++par;
                // for the inline case, if there are multiple paragraphs
-               // they are simply joined. Otherwise, expect latex errors. 
-               if (par != end && !lstinline) {
+               // they are simply joined. Otherwise, expect latex errors.
+               if (par != end && !lstinline && !captionline) {
                        os << "\n";
                        ++lines;
                }
@@ -210,6 +223,9 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd,
                case LFUN_INSET_DIALOG_UPDATE:
                        status.enabled(true);
                        return true;
+               case LFUN_CAPTION_INSERT:
+                       status.enabled(!params().isInline());
+                       return true;
                default:
                        return InsetERT::getStatus(cur, cmd, status);
        }
@@ -245,6 +261,31 @@ void InsetListings::getDrawFont(Font & font) const
 }
 
 
+docstring InsetListings::getCaption(Buffer const & buf,
+                   OutputParams const & runparams) const
+{
+       if (paragraphs().empty())
+               return docstring();
+
+       ParagraphList::const_iterator pit = paragraphs().begin();
+       for (; pit != paragraphs().end(); ++pit) {
+               InsetList::const_iterator it = pit->insetlist.begin();
+               for (; it != pit->insetlist.end(); ++it) {
+                       Inset & inset = *it->inset;
+                       if (inset.lyxCode() == Inset::CAPTION_CODE) {
+                               odocstringstream ods;
+                               InsetCaption * ins =
+                                       static_cast<InsetCaption *>(it->inset);
+                               ins->getOptArg(buf, ods, runparams);
+                               ins->getArgument(buf, ods, runparams);
+                               return ods.str();
+                       }
+               }
+       }
+       return docstring();
+}
+
+
 string const InsetListingsMailer::name_("listings");
 
 InsetListingsMailer::InsetListingsMailer(InsetListings & inset)
index 1d02c7cd4fe6136421c6a78ec28c904f0620d0ae..6bbca9d5fd86e040603ffbe89dbefcf60a426f0d 100644 (file)
@@ -67,6 +67,8 @@ private:
        ///
        void setButtonLabel();
        ///
+       docstring getCaption(Buffer const &, OutputParams const &) const;
+       ///
        InsetListingsParams params_;
 };
 
index 90a79dc8c12596b2ceeecf9417871508690c212c..6c41db8b0fb0e54ffb1b51b5900c49ffc4f87b72 100644 (file)
@@ -33,12 +33,12 @@ namespace lyx
 {
 
 enum param_type {
-       ALL,
-       TRUEFALSE,
-       INTEGER,
-       LENGTH,
-       ONEOF,
-       SUBSETOF,
+       ALL,  // accept all
+       TRUEFALSE, // accept 'true' or 'false'
+       INTEGER, // accept an integer
+       LENGTH,  // accept an latex length
+       ONEOF,  // accept one of a few values
+       SUBSETOF, // accept a string composed of given characters
 };
 
 
@@ -148,8 +148,12 @@ listings_param_info const listings_param_table[] = {
        { "name", "", false, ALL, "", "" },
        { "thelstnumber", "", false, ALL, "", "" },
        { "title", "", false, ALL, "", "" },
-       { "caption", "", false, ALL, "", "" },
-       { "label", "", false, ALL, "", "" },
+       // this option is not handled in the parameter box
+       { "caption", "", false, ALL, "", "This parameter should not be entered here. "
+               "Please use caption editbox (Include dialog) or insert->caption (listings inset)" },
+       // this option is not handled in the parameter box
+       { "label", "", false, ALL, "", "This parameter should not be entered here."
+               "Please use label editbox (Include dialog) or insert->caption (listings inset)"},
        { "nolol", "", false, TRUEFALSE, "", "" },
        { "captionpos", "", false, SUBSETOF, "tb", "" },
        { "abovecaptionskip", "", false, LENGTH, "", "" },