]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiInclude.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiInclude.cpp
index c0d7f81726895e6bbe04fe4a5ed30ff71c32d8db..c55d71fa7f21ddb116bef58f36c13e3cac16f3d8 100644 (file)
@@ -15,6 +15,7 @@
 #include "GuiInclude.h"
 
 #include "Buffer.h"
+#include "BufferParams.h"
 #include "FuncRequest.h"
 #include "LyXRC.h"
 
@@ -30,9 +31,9 @@
 #include "insets/InsetListingsParams.h"
 #include "insets/InsetInclude.h"
 
-#include <QPushButton>
 #include <QCheckBox>
 #include <QLineEdit>
+#include <QPushButton>
 
 #include <utility>
 
@@ -50,8 +51,8 @@ GuiInclude::GuiInclude(GuiView & lv)
 {
        setupUi(this);
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
 
        connect(visiblespaceCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
        connect(filenameED, SIGNAL(textChanged(const QString &)),
@@ -63,6 +64,7 @@ GuiInclude::GuiInclude(GuiView & lv)
        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(literalCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
        connect(listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
        connect(listingsED, SIGNAL(textChanged()), this, SLOT(setListingsMsg()));
        connect(bypassCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
@@ -71,8 +73,8 @@ GuiInclude::GuiInclude(GuiView & lv)
        setFocusProxy(filenameED);
 
        bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setCancel(closePB);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
        bc().addReadOnly(filenameED);
        bc().addReadOnly(browsePB);
        bc().addReadOnly(visiblespaceCB);
@@ -91,25 +93,18 @@ void GuiInclude::change_adaptor()
 
 docstring GuiInclude::validate_listings_params()
 {
-       // use a cache here to avoid repeated validation
-       // of the same parameters
-       static string param_cache = string();
-       static docstring msg_cache = docstring();
-       
        if (typeCO->currentIndex() != 3 || bypassCB->isChecked())
                return docstring();
-
        string params = fromqstr(listingsED->toPlainText());
-       if (params != param_cache) {
-               param_cache = params;
-               msg_cache = InsetListingsParams(params).validate();
-       }
-       return msg_cache;
+       InsetListingsParams lstparams(params);
+       lstparams.setMinted(buffer().params().use_minted);
+       return lstparams.validate();
 }
 
 
 void GuiInclude::setListingsMsg()
 {
+       // FIXME THREAD
        static bool isOK = true;
        docstring msg = validate_listings_params();
        if (msg.empty()) {
@@ -159,16 +154,12 @@ void GuiInclude::typeChanged(int v)
                        listingsGB->setEnabled(false);
                        break;
        }
-       //see this thread 
-       //  http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg118471.html
-       //for the reason this is here.
-       okPB->setDefault(true);
 }
 
 
-void GuiInclude::paramsToDialog(InsetCommandParams const & params_)
+void GuiInclude::paramsToDialog(InsetCommandParams const & icp)
 {
-       filenameED->setText(toqstr(params_["filename"]));
+       filenameED->setText(toqstr(icp["filename"]));
 
        visiblespaceCB->setChecked(false);
        visiblespaceCB->setEnabled(false);
@@ -181,11 +172,12 @@ void GuiInclude::paramsToDialog(InsetCommandParams const & params_)
        listingsTB->setPlainText(
                qt_("Input listing parameters on the right. Enter ? for a list of parameters."));
 
-       string cmdname = params_.getCmdName();
+       string cmdname = icp.getCmdName();
        if (cmdname != "include" &&
            cmdname != "verbatiminput" &&
            cmdname != "verbatiminput*" &&
-               cmdname != "lstinputlisting")
+           cmdname != "lstinputlisting" &&
+           cmdname != "inputminted")
                cmdname = "input";
 
        if (cmdname == "include") {
@@ -194,7 +186,7 @@ void GuiInclude::paramsToDialog(InsetCommandParams const & params_)
        } else if (cmdname == "input") {
                typeCO->setCurrentIndex(1);
                previewCB->setEnabled(true);
-               previewCB->setChecked(params_.preview());
+               previewCB->setChecked(icp.preview());
 
        } else if (cmdname == "verbatiminput*") {
                typeCO->setCurrentIndex(2);
@@ -205,11 +197,11 @@ void GuiInclude::paramsToDialog(InsetCommandParams const & params_)
                typeCO->setCurrentIndex(2);
                visiblespaceCB->setEnabled(true);
 
-       } else if (cmdname == "lstinputlisting") {
+       } else if (cmdname == "lstinputlisting" || cmdname == "inputminted") {
                typeCO->setCurrentIndex(3);
                listingsGB->setEnabled(true);
                listingsED->setEnabled(true);
-               InsetListingsParams par(to_utf8(params_["lstparams"]));
+               InsetListingsParams par(to_utf8(icp["lstparams"]));
                // 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();
@@ -219,7 +211,7 @@ void GuiInclude::paramsToDialog(InsetCommandParams const & params_)
                                if (cap[0] == '{' && cap[cap.size() - 1] == '}') {
                                        captionLE->setText(toqstr(cap.substr(1, cap.size() - 2)));
                                        *it = "";
-                               } 
+                               }
                        } else if (prefixIs(*it, "label=")) {
                                string lbl = it->substr(6);
                                if (lbl[0] == '{' && lbl[lbl.size()-1] == '}') {
@@ -232,6 +224,7 @@ void GuiInclude::paramsToDialog(InsetCommandParams const & params_)
                string extra = getStringFromVector(pars);
                listingsED->setPlainText(toqstr(InsetListingsParams(extra).separatedParams()));
        }
+       literalCB->setChecked(icp["literal"] == "true");
 
        // Make sure that the bc is in the INITIAL state
        if (bc().policy().buttonStatus(ButtonPolicy::OKAY))
@@ -250,7 +243,10 @@ void GuiInclude::applyView()
        } else if (item == 1) {
                params_.setCmdName("input");
        } else if (item == 3) {
-               params_.setCmdName("lstinputlisting");
+               if (buffer().params().use_minted)
+                       params_.setCmdName("inputminted");
+               else
+                       params_.setCmdName("lstinputlisting");
                // the parameter string should have passed validation
                InsetListingsParams par(fromqstr(listingsED->toPlainText()));
                string caption = fromqstr(captionLE->text());
@@ -267,6 +263,8 @@ void GuiInclude::applyView()
                else
                        params_.setCmdName("verbatiminput");
        }
+       params_["literal"] = literalCB->isChecked()
+                       ? from_ascii("true") : from_ascii("false");
 }
 
 
@@ -294,7 +292,6 @@ void GuiInclude::edit()
 {
        if (!isValid())
                return;
-       string const file = fromqstr(filenameED->text());
        if (bc().policy().buttonStatus(ButtonPolicy::OKAY)) {
                slotOK();
                applyView();
@@ -330,13 +327,13 @@ QString GuiInclude::browse(QString const & in_name, Type in_type) const
        QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
 
        return browseRelToParent(in_name, docpath, title, filters, false,
-               qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+               qt_("D&ocuments"), toqstr(lyxrc.document_path));
 }
 
 
-bool GuiInclude::initialiseParams(std::string const & data)
+bool GuiInclude::initialiseParams(std::string const & sdata)
 {
-       InsetCommand::string2params(data, params_);
+       InsetCommand::string2params(sdata, params_);
        paramsToDialog(params_);
        return true;
 }