]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 84a8ccf8fec3f842b90148d076888cf35ea215ba..732c8430c85e2732b7d980f6de8343830e6219f1 100644 (file)
@@ -50,6 +50,7 @@
 #include "qt_helpers.h"
 #include "Spacing.h"
 #include "TextClass.h"
+#include "Undo.h"
 
 #include "insets/InsetListingsParams.h"
 
@@ -149,6 +150,7 @@ RGBColor set_fontcolor;
 bool is_fontcolor;
 RGBColor set_notefontcolor;
 RGBColor set_boxbgcolor;
+bool forced_fontspec_activation;
 
 namespace {
 // used when sorting the textclass list.
@@ -517,7 +519,7 @@ LocalLayout::LocalLayout() : current_id_(0), validated_(false)
 
 void LocalLayout::update(BufferParams const & params, BufferId id)
 {
-       QString layout = toqstr(params.local_layout);
+       QString layout = toqstr(params.getLocalLayout(false));
        // Nothing to do if the params and preamble are unchanged.
        if (id == current_id_
                && layout == locallayoutTE->document()->toPlainText())
@@ -533,7 +535,7 @@ void LocalLayout::update(BufferParams const & params, BufferId id)
 void LocalLayout::apply(BufferParams & params)
 {
        string const layout = fromqstr(locallayoutTE->document()->toPlainText());
-       params.local_layout = layout;
+       params.setLocalLayout(layout, false);
 }
 
 
@@ -1154,7 +1156,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        headers << qt_("Package") << qt_("Load automatically")
                << qt_("Load always") << qt_("Do not load");
        mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
-       mathsModule->packagesTW->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+       setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);        
        map<string, string> const & packages = BufferParams::auto_packages();
        mathsModule->packagesTW->setRowCount(packages.size());
        int i = 0;
@@ -1208,6 +1210,12 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(allPackagesAlways()));
        connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
                this, SLOT(allPackagesNot()));
+       connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
 
 
        // latex class
@@ -1391,28 +1399,28 @@ GuiDocument::GuiDocument(GuiView & lv)
 
 
        // add the panels
-       docPS->addPanel(latexModule, qt_("Document Class"));
-       docPS->addPanel(masterChildModule, qt_("Child Documents"));
-       docPS->addPanel(modulesModule, qt_("Modules"));
-       docPS->addPanel(localLayout, qt_("Local Layout"));
-       docPS->addPanel(fontModule, qt_("Fonts"));
-       docPS->addPanel(textLayoutModule, qt_("Text Layout"));
-       docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
-       docPS->addPanel(marginsModule, qt_("Page Margins"));
-       docPS->addPanel(langModule, qt_("Language"));
-       docPS->addPanel(colorModule, qt_("Colors"));
-       docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
-       docPS->addPanel(biblioModule, qt_("Bibliography"));
-       docPS->addPanel(indicesModule, qt_("Indexes"));
-       docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
-       docPS->addPanel(mathsModule, qt_("Math Options"));
-       docPS->addPanel(floatModule, qt_("Float Placement"));
-       docPS->addPanel(listingsModule, qt_("Listings[[inset]]"));
-       docPS->addPanel(bulletsModule, qt_("Bullets"));
-       docPS->addPanel(branchesModule, qt_("Branches"));
-       docPS->addPanel(outputModule, qt_("Output"));
-       docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
-       docPS->setCurrentPanel(qt_("Document Class"));
+       docPS->addPanel(latexModule, N_("Document Class"));
+       docPS->addPanel(masterChildModule, N_("Child Documents"));
+       docPS->addPanel(modulesModule, N_("Modules"));
+       docPS->addPanel(localLayout, N_("Local Layout"));
+       docPS->addPanel(fontModule, N_("Fonts"));
+       docPS->addPanel(textLayoutModule, N_("Text Layout"));
+       docPS->addPanel(pageLayoutModule, N_("Page Layout"));
+       docPS->addPanel(marginsModule, N_("Page Margins"));
+       docPS->addPanel(langModule, N_("Language"));
+       docPS->addPanel(colorModule, N_("Colors"));
+       docPS->addPanel(numberingModule, N_("Numbering & TOC"));
+       docPS->addPanel(biblioModule, N_("Bibliography"));
+       docPS->addPanel(indicesModule, N_("Indexes"));
+       docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
+       docPS->addPanel(mathsModule, N_("Math Options"));
+       docPS->addPanel(floatModule, N_("Float Placement"));
+       docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
+       docPS->addPanel(bulletsModule, N_("Bullets"));
+       docPS->addPanel(branchesModule, N_("Branches"));
+       docPS->addPanel(outputModule, N_("Output"));
+       docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
+       docPS->setCurrentPanel("Document Class");
 // FIXME: hack to work around resizing bug in Qt >= 4.2
 // bug verified with Qt 4.2.{0-3} (JSpitzm)
 #if QT_VERSION >= 0x040200
@@ -1463,6 +1471,7 @@ QString GuiDocument::validateListingsParameters()
 {
        // use a cache here to avoid repeated validation
        // of the same parameters
+       // FIXME THREAD
        static string param_cache;
        static QString msg_cache;
 
@@ -1480,6 +1489,7 @@ QString GuiDocument::validateListingsParameters()
 
 void GuiDocument::setListingsMessage()
 {
+       // FIXME THREAD
        static bool isOK = true;
        QString msg = validateListingsParameters();
        if (msg.isEmpty()) {
@@ -1735,11 +1745,22 @@ void GuiDocument::languageChanged(int i)
        Language const * lang = lyx::languages.getLanguage(
                fromqstr(langModule->languageCO->itemData(i).toString()));
        if (lang->babel().empty() && !lang->polyglossia().empty()) {
+                       // If we force to switch fontspec on, store
+                       // current state (#8717)
+                       if (fontModule->osFontsCB->isEnabled())
+                               forced_fontspec_activation =
+                                       !fontModule->osFontsCB->isChecked();
                        fontModule->osFontsCB->setChecked(true);
                        fontModule->osFontsCB->setEnabled(false);
        }
-       else
+       else {
                fontModule->osFontsCB->setEnabled(true);
+               // If we have forced to switch fontspec on,
+               // restore previous state (#8717)
+               if (forced_fontspec_activation)
+                       fontModule->osFontsCB->setChecked(false);
+               forced_fontspec_activation = false;
+       }
 
        // set appropriate quotation mark style
        if (!lang->quoteStyle().empty()) {
@@ -1916,7 +1937,7 @@ void GuiDocument::updateFontlist()
        fontModule->fontsTypewriterCO->clear();
        fontModule->fontsMathCO->clear();
 
-       // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
+       // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
        if (fontModule->osFontsCB->isChecked()) {
                fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
                fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
@@ -2251,6 +2272,7 @@ void GuiDocument::updateEngineType(string const & items, CiteEngineType const &
                        biblioModule->citeStyleCO->setCurrentIndex(0);
                        break;
                case ENGINE_TYPE_NUMERICAL:
+               case ENGINE_TYPE_DEFAULT:
                        biblioModule->citeStyleCO->setCurrentIndex(1);
                        break;
        }
@@ -2472,7 +2494,7 @@ void GuiDocument::updateDefaultFormat()
        if (idx >= 0) {
                string const classname = fromqstr(latexModule->classCO->getData(idx));
                param_copy.setBaseClass(classname);
-               param_copy.makeDocumentClass();
+               param_copy.makeDocumentClass(true);
        }
        outputModule->defaultFormatCO->blockSignals(true);
        outputModule->defaultFormatCO->clear();
@@ -2514,9 +2536,11 @@ void GuiDocument::applyView()
                bp_.setCiteEngine("natbib");
        else if (biblioModule->citeJurabibRB->isChecked())
                bp_.setCiteEngine("jurabib");
-       else
+       if (biblioModule->citeDefaultRB->isChecked()) {
                bp_.setCiteEngine("basic");
-
+               bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
+       }
+       else
        if (biblioModule->citeStyleCO->currentIndex())
                bp_.setCiteEngineType(ENGINE_TYPE_NUMERICAL);
        else
@@ -2923,7 +2947,7 @@ void GuiDocument::paramsToDialog()
                cite_engine == "natbib");
 
        biblioModule->citeStyleCO->setCurrentIndex(
-               bp_.citeEngineType() == ENGINE_TYPE_NUMERICAL);
+               bp_.citeEngineType() & ENGINE_TYPE_NUMERICAL);
 
        updateEngineType(documentClass().opt_enginetype(),
                bp_.citeEngineType());
@@ -3192,11 +3216,11 @@ void GuiDocument::paramsToDialog()
        if (!bufferview() || !buffer().hasChildren()) {
                masterChildModule->childrenTW->clear();
                includeonlys_.clear();
-               docPS->showPanel(qt_("Child Documents"), false);
-               if (docPS->isCurrentPanel(qt_("Child Documents")))
-                       docPS->setCurrentPanel(qt_("Document Class"));
+               docPS->showPanel("Child Documents", false);
+               if (docPS->isCurrentPanel("Child Documents"))
+                       docPS->setCurrentPanel("Document Class");
        } else {
-               docPS->showPanel(qt_("Child Documents"), true);
+               docPS->showPanel("Child Documents", true);
                masterChildModule->setEnabled(true);
                includeonlys_ = bp_.getIncludedChildren();
                updateIncludeonlys();
@@ -3214,12 +3238,18 @@ void GuiDocument::paramsToDialog()
        listingsModule->listingsED->setPlainText(toqstr(lstparams));
 
        // Fonts
+       // some languages only work with polyglossia/XeTeX
+       Language const * lang = lyx::languages.getLanguage(
+               fromqstr(langModule->languageCO->itemData(
+                       langModule->languageCO->currentIndex()).toString()));
+       bool const need_fontspec =
+               lang->babel().empty() && !lang->polyglossia().empty();
        bool const os_fonts_available =
                bp_.baseClass()->outputType() == lyx::LATEX
                && LaTeXFeatures::isAvailable("fontspec");
-       fontModule->osFontsCB->setEnabled(os_fonts_available);
+       fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
        fontModule->osFontsCB->setChecked(
-               os_fonts_available && bp_.useNonTeXFonts);
+               (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
        updateFontsize(documentClass().opt_fontsize(),
                        bp_.fontsize);
 
@@ -3652,6 +3682,11 @@ static void dispatch_bufferparams(Dialog const & dialog,
 
 void GuiDocument::dispatchParams()
 {
+       // We need a non-const buffer object.
+       Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
+       // There may be several undo records; group them (bug #8998)
+       buf.undo().beginUndoGroup();
+
        // This must come first so that a language change is correctly noticed
        setLanguage();
 
@@ -3721,6 +3756,10 @@ void GuiDocument::dispatchParams()
        // If we used an LFUN, we would not need these two lines:
        BufferView * bv = const_cast<BufferView *>(bufferview());
        bv->processUpdateFlags(Update::Force | Update::FitCursor);
+
+       // Don't forget to close the group. Note that it is important
+       // to check that there is no early return in the method.
+       buf.undo().endUndoGroup();
 }