]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiViewSource.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiViewSource.cpp
index 9c0ea1d707c3e4262a7205035152ecce81ae6acd..04c6bf5c349796661315388d72b26d91c9febab9 100644 (file)
@@ -197,20 +197,21 @@ void ViewSourceWidget::updateView(BufferView const * bv)
                   masterPerspectiveCB->isChecked());
        QString old = document_->toPlainText();
        QString qcontent = toqstr(content);
-#ifdef DEVEL_VERSION
-       // output tex<->row correspondences in the source panel if the "-dbg latex"
-       // option is given.
-       if (texrow_ && lyx::lyxerr.debugging(Debug::LATEX)) {
-               QStringList list = qcontent.split(QChar('\n'));
-               docstring_list dlist;
-               for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
-                       dlist.push_back(from_utf8(fromqstr(*it)));
-               texrow_->prepend(dlist);
-               qcontent.clear();
-               for (docstring_list::iterator it = dlist.begin(); it != dlist.end(); ++it)
-                       qcontent += toqstr(*it) + '\n';
+       if (guiApp->currentView()->develMode()) {
+               // output tex<->row correspondences in the source panel if the "-dbg latex"
+               // option is given.
+               if (texrow_ && lyx::lyxerr.debugging(Debug::LATEX)) {
+                       QStringList list = qcontent.split(QChar('\n'));
+                       docstring_list dlist;
+                       for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
+                               dlist.push_back(from_utf8(fromqstr(*it)));
+                       texrow_->prepend(dlist);
+                       qcontent.clear();
+                       for (docstring_list::iterator it = dlist.begin(); it != dlist.end(); ++it)
+                               qcontent += toqstr(*it) + '\n';
+               }
        }
-#endif
+
        // prevent gotoCursor()
        QSignalBlocker blocker(viewSourceTV);
        bool const changed = setText(qcontent);
@@ -218,14 +219,9 @@ void ViewSourceWidget::updateView(BufferView const * bv)
        if (changed && !texrow_) {
                // position-to-row is unavailable
                // we jump to the first modification
-               const QChar * oc = old.constData();
-               const QChar * nc = qcontent.constData();
+               int length = min(old.length(), qcontent.length());
                int pos = 0;
-               while (*oc != '\0' && *nc != '\0' && *oc == *nc) {
-                       ++oc;
-                       ++nc;
-                       ++pos;
-               }
+               for (; pos < length && old.at(pos) == qcontent.at(pos); ++pos) {}
                QTextCursor c = QTextCursor(viewSourceTV->document());
                //get some space below the cursor
                c.setPosition(pos);
@@ -308,7 +304,7 @@ docstring ViewSourceWidget::currentFormatName(BufferView const * bv) const
        // Compute the actual format used
        string const format = !bv ? ""
                : flavor2format(bv->buffer().params().getOutputFlavor(view_format_));
-       Format const * f = formats.getFormat(format.empty() ? view_format_ : format);
+       Format const * f = theFormats().getFormat(format.empty() ? view_format_ : format);
        return f ? f->prettyname() : from_utf8(view_format_);
 }
 
@@ -340,24 +336,19 @@ void ViewSourceWidget::updateDefaultFormat(BufferView const & bv)
        QSignalBlocker blocker(outputFormatCO);
        outputFormatCO->clear();
        outputFormatCO->addItem(qt_("Default"),
-                               QVariant(QString("default")));
+                               QVariant(QString("default")));
 
        int index = 0;
-       vector<string> tmp = bv.buffer().params().backends();
-       vector<string>::const_iterator it = tmp.begin();
-       vector<string>::const_iterator en = tmp.end();
-       for (; it != en; ++it) {
-               string const format = *it;
-               Format const * fmt = formats.getFormat(format);
+       for (string const & fmt_name : bv.buffer().params().backends()) {
+               Format const * fmt = theFormats().getFormat(fmt_name);
                if (!fmt) {
-                       LYXERR0("Can't find format for backend " << format << "!");
+                       LYXERR0("Can't find format for backend " << fmt_name << "!");
                        continue;
-               } 
-
+               }
                QString const pretty = toqstr(translateIfPossible(fmt->prettyname()));
-               outputFormatCO->addItem(pretty, QVariant(toqstr(format)));
-               if (format == view_format_)
-                  index = outputFormatCO->count() -1;
+               outputFormatCO->addItem(pretty, QVariant(toqstr(fmt_name)));
+               if (fmt_name == view_format_)
+                       index = outputFormatCO->count() - 1;
        }
        setViewFormat(index);
 }
@@ -375,9 +366,9 @@ void ViewSourceWidget::resizeEvent (QResizeEvent * event)
        QWidget::resizeEvent(event);
 }
 
-void ViewSourceWidget::saveSession(QString const & session_key) const
+
+void ViewSourceWidget::saveSession(QSettings & settings, QString const & session_key) const
 {
-       QSettings settings;
        settings.setValue(session_key + "/output", toqstr(view_format_));
        settings.setValue(session_key + "/contents", contentsCO->currentIndex());
        settings.setValue(session_key + "/autoupdate", autoUpdateCB->isChecked());
@@ -470,10 +461,10 @@ void GuiViewSource::updateTitle()
 }
 
 
-void GuiViewSource::saveSession() const
+void GuiViewSource::saveSession(QSettings & settings) const
 {
-       Dialog::saveSession();
-       widget_->saveSession(sessionKey());
+       Dialog::saveSession(settings);
+       widget_->saveSession(settings, sessionKey());
 }