commit 40e9dea5513c9e941aafc9bc3eee46d569cd6fcf
Author: Enrico Forestieri <for...@lyx.org>
Date:   Thu Aug 10 01:32:23 2017 +0200

    Use the OK/Apply paradigm for all document settings
    
    Due to its peculiarity of not being saved in the document, the
    shell escape setting was applied immediately without the need
    for hitting the Apply or OK buttons. However, for uniformity
    sake, it is better to adhere to the established paragdim of
    confirming any changes before applying them.
---
 src/frontends/qt4/GuiDocument.cpp |   54 ++++++++++++++++++++++++++-----------
 src/frontends/qt4/GuiDocument.h   |    8 +++++
 src/frontends/qt4/ui/OutputUi.ui  |    2 +-
 3 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/src/frontends/qt4/GuiDocument.cpp 
b/src/frontends/qt4/GuiDocument.cpp
index 8889fdf..e980921 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -664,7 +664,8 @@ void LocalLayout::validatePressed() {
 
 GuiDocument::GuiDocument(GuiView & lv)
        : GuiDialog(lv, "document", qt_("Document Settings")),
-         biblioChanged_(false), nonModuleChanged_(false)
+         biblioChanged_(false), nonModuleChanged_(false),
+         modulesChanged_(false), shellescapeChanged_(false)
 {
        setupUi(this);
 
@@ -1542,18 +1543,30 @@ void GuiDocument::change_adaptor()
 
 void GuiDocument::shellescapeChanged()
 {
-       // This is treated specially as the change is automatically applied
-       // and the document isn't marked as dirty. Visual feedback is given
-       // by the appearance/disappearance of a red icon in the status bar.
-       bp_.shell_escape = outputModule->shellescapeCB->isChecked();
-       if (!bp_.shell_escape)
-           theSession().shellescapeFiles().remove(buffer().absFileName());
-       else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
-           theSession().shellescapeFiles().insert(buffer().absFileName());
-       Buffer & buf = const_cast<Buffer &>(buffer());
-       buf.params().shell_escape = bp_.shell_escape;
-       BufferView * bv = const_cast<BufferView *>(bufferview());
-       bv->processUpdateFlags(Update::Force);
+       shellescapeChanged_ = true;
+       changed();
+}
+
+
+void GuiDocument::slotApply()
+{
+       bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
+       bool wasclean = buffer().isClean();
+       GuiDialog::slotApply();
+       if (wasclean && only_shellescape_changed)
+               buffer().markClean();
+       modulesChanged_ = false;
+}
+
+
+void GuiDocument::slotOK()
+{
+       bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
+       bool wasclean = buffer().isClean();
+       GuiDialog::slotOK();
+       if (wasclean && only_shellescape_changed)
+               buffer().markClean();
+       modulesChanged_ = false;
 }
 
 
@@ -2662,7 +2675,7 @@ void GuiDocument::modulesChanged()
 {
        modulesToParams(bp_);
 
-       if (applyPB->isEnabled() && nonModuleChanged_) {
+       if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) 
{
                int const ret = Alert::prompt(_("Unapplied changes"),
                                _("Some changes in the dialog were not yet 
applied.\n"
                                "If you do not apply now, they will be lost 
after this action."),
@@ -2671,6 +2684,7 @@ void GuiDocument::modulesChanged()
                        applyView();
        }
 
+       modulesChanged_ = true;
        bp_.makeDocumentClass();
        paramsToDialog();
        changed();
@@ -3136,6 +3150,12 @@ void GuiDocument::applyView()
        bp_.useNonTeXFonts = nontexfonts;
 
        bp_.shell_escape = outputModule->shellescapeCB->isChecked();
+       if (!bp_.shell_escape)
+           theSession().shellescapeFiles().remove(buffer().absFileName());
+       else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
+           theSession().shellescapeFiles().insert(buffer().absFileName());
+       Buffer & buf = const_cast<Buffer &>(buffer());
+       buf.params().shell_escape = bp_.shell_escape;
 
        bp_.output_sync = outputModule->outputsyncCB->isChecked();
 
@@ -3274,8 +3294,9 @@ void GuiDocument::applyView()
        pdf.quoted_options = pdf.quoted_options_check(
                                fromqstr(pdfSupportModule->optionsLE->text()));
 
-       // reset tracker
+       // reset trackers
        nonModuleChanged_ = false;
+       shellescapeChanged_ = false;
 }
 
 
@@ -3863,8 +3884,9 @@ void GuiDocument::paramsToDialog()
        // clear changed branches cache
        changedBranches_.clear();
 
-       // reset tracker
+       // reset trackers
        nonModuleChanged_ = false;
+       shellescapeChanged_ = false;
 }
 
 
diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h
index 5efde8e..be1b7e4 100644
--- a/src/frontends/qt4/GuiDocument.h
+++ b/src/frontends/qt4/GuiDocument.h
@@ -86,6 +86,10 @@ public:
 
 public Q_SLOTS:
        void onBufferViewChanged();//override
+       // OK button clicked
+       void slotOK();
+       // Apply button clicked
+       void slotApply();
 
 private Q_SLOTS:
        void updateNumbering();
@@ -303,6 +307,10 @@ private:
        bool biblioChanged_;
        /// Track if a non-module document param changed
        bool nonModuleChanged_;
+       /// Track if used modules changed
+       bool modulesChanged_;
+       /// Track if the shellescape param changed
+       bool shellescapeChanged_;
 };
 
 
diff --git a/src/frontends/qt4/ui/OutputUi.ui b/src/frontends/qt4/ui/OutputUi.ui
index e3e36da..b309bbb 100644
--- a/src/frontends/qt4/ui/OutputUi.ui
+++ b/src/frontends/qt4/ui/OutputUi.ui
@@ -108,7 +108,7 @@
    <item row="1" column="0">
     <widget class="QCheckBox" name="shellescapeCB">
      <property name="toolTip">
-      <string>Runs the LaTeX backend with the -shell-escape option (this 
setting is always applied immediately)</string>
+      <string>Runs the LaTeX backend with the -shell-escape option (Warning: 
use only when really necessary)</string>
      </property>
      <property name="text">
       <string>&amp;Allow running external programs</string>

Reply via email to