commit ca58674267b2c050b3b53402c9414b6bd697dc0a
Author: Guillaume Munch <g...@lyx.org>
Date:   Sun Aug 28 21:57:17 2016 +0100

    Better title for ViewSource
    
    The title is changed to "LaTeX (pdflatex) Preview", etc. depending on the
    format. The actual default format is computed.
    
    The menu name "Source Pane" is replaced by "Code Preview Pane" to better 
reflect
    its purpose.
---
 lib/ui/stdmenus.inc                 |    2 +-
 src/Format.cpp                      |    1 +
 src/frontends/qt4/GuiViewSource.cpp |   57 +++++++++++++++++++++--------------
 src/frontends/qt4/GuiViewSource.h   |   10 +++++-
 4 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc
index 62ed8e2..87c78ed 100644
--- a/lib/ui/stdmenus.inc
+++ b/lib/ui/stdmenus.inc
@@ -336,7 +336,7 @@ Menuset
                Item "Fold Math Macro|d" "math-macro-fold"
                Separator
                Item "Outline Pane|u" "dialog-toggle toc"
-               Item "Source Pane|S" "dialog-toggle view-source"
+               Item "Code Preview Pane|P" "dialog-toggle view-source"
                Item "Messages Pane|g" "dialog-toggle progress"
                Submenu "Toolbars|b" "toolbars"
                Separator
diff --git a/src/Format.cpp b/src/Format.cpp
index 09fb33b..b605c4e 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -846,6 +846,7 @@ FlavorTranslator initFlavorTranslator()
        f.addPair(OutputParams::XML, "docbook-xml");
        f.addPair(OutputParams::HTML, "xhtml");
        f.addPair(OutputParams::TEXT, "text");
+       f.addPair(OutputParams::LYX, "lyx");
        return f;
 }
 
diff --git a/src/frontends/qt4/GuiViewSource.cpp 
b/src/frontends/qt4/GuiViewSource.cpp
index d347e1a..db50b47 100644
--- a/src/frontends/qt4/GuiViewSource.cpp
+++ b/src/frontends/qt4/GuiViewSource.cpp
@@ -149,7 +149,12 @@ void ViewSourceWidget::contentsChanged()
 void ViewSourceWidget::setViewFormat(int const index)
 {
        outputFormatCO->setCurrentIndex(index);
-       view_format_ = outputFormatCO->itemData(index).toString();
+       string format = fromqstr(outputFormatCO->itemData(index).toString());
+       if (view_format_ != format) {
+               view_format_ = format;
+               // emit signal
+               formatChanged();
+       }
 }
 
 
@@ -185,8 +190,6 @@ void ViewSourceWidget::realUpdateView()
        // we will try to preserve this
        int const h_scroll = viewSourceTV->horizontalScrollBar()->value();
 
-       string const format = fromqstr(view_format_);
-
        Buffer::OutputWhat output = Buffer::CurrentParagraph;
        if (contentsCO->currentIndex() == 1)
                output = Buffer::FullSource;
@@ -196,7 +199,8 @@ void ViewSourceWidget::realUpdateView()
                output = Buffer::OnlyBody;
 
        docstring content;
-       getContent(bv_, output, content, format, 
masterPerspectiveCB->isChecked());
+       getContent(bv_, output, content, view_format_,
+                  masterPerspectiveCB->isChecked());
        QString old = document_->toPlainText();
        QString qcontent = toqstr(content);
 #ifdef DEVEL_VERSION
@@ -306,6 +310,16 @@ void ViewSourceWidget::realUpdateView()
 }
 
 
+docstring ViewSourceWidget::currentFormatName() 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);
+       return f ? f->prettyname() : from_utf8(view_format_);
+}
+
+
 // only used in DEVEL_MODE for debugging
 // need a proper LFUN if we want to implement it in release mode
 void ViewSourceWidget::gotoCursor()
@@ -341,9 +355,8 @@ void ViewSourceWidget::updateDefaultFormat()
                } 
 
                QString const pretty = 
toqstr(translateIfPossible(fmt->prettyname()));
-               QString const qformat = toqstr(format);
-               outputFormatCO->addItem(pretty, QVariant(qformat));
-               if (qformat == view_format_)
+               outputFormatCO->addItem(pretty, QVariant(toqstr(format)));
+               if (format == view_format_)
                   index = outputFormatCO->count() -1;
        }
        setViewFormat(index);
@@ -367,7 +380,7 @@ void ViewSourceWidget::resizeEvent (QResizeEvent * event)
 void ViewSourceWidget::saveSession(QString const & session_key) const
 {
        QSettings settings;
-       settings.setValue(session_key + "/output", view_format_);
+       settings.setValue(session_key + "/output", toqstr(view_format_));
        settings.setValue(session_key + "/contents", 
contentsCO->currentIndex());
        settings.setValue(session_key + "/autoupdate", 
autoUpdateCB->isChecked());
        settings.setValue(session_key + "/masterview",
@@ -378,7 +391,8 @@ void ViewSourceWidget::saveSession(QString const & 
session_key) const
 void ViewSourceWidget::restoreSession(QString const & session_key)
 {
        QSettings settings;
-    view_format_ = settings.value(session_key + "/output", 0).toString();
+       view_format_ = fromqstr(settings.value(session_key + "/output", 0)
+                               .toString());
        contentsCO->setCurrentIndex(settings
                                                                
.value(session_key + "/contents", 0)
                                                                .toInt());
@@ -396,10 +410,11 @@ void ViewSourceWidget::restoreSession(QString const & 
session_key)
 
 GuiViewSource::GuiViewSource(GuiView & parent,
                Qt::DockWidgetArea area, Qt::WindowFlags flags)
-       : DockView(parent, "view-source", qt_("LaTeX Source"), area, flags)
+       : DockView(parent, "view-source", qt_("Code Preview"), area, flags)
 {
        widget_ = new ViewSourceWidget;
        setWidget(widget_);
+       connect(widget_, SIGNAL(formatChanged()), this, SLOT(updateTitle()));
 }
 
 
@@ -416,6 +431,7 @@ void GuiViewSource::updateView()
                widget_->updateView();
        }
        widget_->masterPerspectiveCB->setEnabled(buffer().parent());
+       updateTitle();
 }
 
 
@@ -431,24 +447,19 @@ void GuiViewSource::enableView(bool enable)
 
 bool GuiViewSource::initialiseParams(string const & /*source*/)
 {
-       setWindowTitle(title());
+       updateTitle();
        return true;
 }
 
 
-QString GuiViewSource::title() const
+void GuiViewSource::updateTitle()
 {
-       switch (docType()) {
-               case LATEX:
-                       //FIXME: this is shown for LyXHTML source, LyX source, 
etc.
-                       return qt_("LaTeX Source");
-               case DOCBOOK:
-                       return qt_("DocBook Source");
-               case LITERATE:
-                       return qt_("Literate Source");
-       }
-       LATTEST(false);
-       return QString();
+       docstring const format = widget_->currentFormatName();
+       QString const title = format.empty() ? qt_("Code Preview")
+               : qt_("%1[[preview format name]] Preview")
+                 .arg(toqstr(translateIfPossible(format)));
+       setTitle(title);
+       setWindowTitle(title);
 }
 
 
diff --git a/src/frontends/qt4/GuiViewSource.h 
b/src/frontends/qt4/GuiViewSource.h
index dbe36c7..e4718d7 100644
--- a/src/frontends/qt4/GuiViewSource.h
+++ b/src/frontends/qt4/GuiViewSource.h
@@ -70,6 +70,11 @@ public Q_SLOTS:
        void contentsChanged();
        ///
        void gotoCursor();
+       /// Name of the current format. Empty if none.
+       docstring currentFormatName() const;
+
+Q_SIGNALS:
+       void formatChanged() const;
 
 private Q_SLOTS:
        /// update content
@@ -86,7 +91,7 @@ private:
        /// LaTeX syntax highlighter
        LaTeXHighlighter * highlighter_;
        ///
-       QString view_format_;
+       std::string view_format_;
        ///
        QTimer * update_timer_;
        /// TexRow information from the last source view. If TexRow is 
unavailable
@@ -122,8 +127,9 @@ public:
        bool wantInitialFocus() const { return false; }
        ///@}
 
+private Q_SLOTS:
        /// The title displayed by the dialog reflects source type.
-       QString title() const;
+       void updateTitle();
 
 private:
        /// The encapsulated widget.

Reply via email to