Author: rgheck
Date: Mon Mar  5 23:51:53 2012
New Revision: 40864
URL: http://www.lyx.org/trac/changeset/40864

Log:
Backport fix for #7997.

The View->Source pane resets the format every time you click into
a new paragraph, which is very annoying. This commit fixes this bug.

If anyone has a better idea, please let me know. I posted to devel
about it but got no response.

Added:
   lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui.old
      - copied, changed from r40863, 
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui
Modified:
   lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiViewSource.cpp
   lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiViewSource.h
   lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui
   lyx-devel/branches/BRANCH_2_0_X/status.20x

Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiViewSource.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiViewSource.cpp Mon Mar 
 5 23:38:21 2012        (r40863)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiViewSource.cpp Mon Mar 
 5 23:51:53 2012        (r40864)
@@ -58,7 +58,7 @@
        connect(updatePB, SIGNAL(clicked()),
                this, SLOT(updateView()));
        connect(outputFormatCO, SIGNAL(activated(int)),
-               this, SLOT(updateView()));
+               this, SLOT(setViewFormat()));
 
        // setting a document at this point trigger an assertion in Qt
        // so we disable the signals here:
@@ -136,6 +136,13 @@
 }
 
 
+void ViewSourceWidget::setViewFormat()
+{
+       view_format_ = outputFormatCO->itemData(
+             outputFormatCO->currentIndex()).toString();
+       updateView();
+}
+
 void ViewSourceWidget::updateView()
 {
        if (!bv_) {
@@ -146,8 +153,7 @@
 
        setEnabled(true);
 
-       string const format = fromqstr(outputFormatCO->itemData(
-               outputFormatCO->currentIndex()).toString());
+       string const format = fromqstr(view_format_);
 
        QString content;
        Buffer::OutputWhat output = Buffer::CurrentParagraph;
@@ -190,13 +196,20 @@
        outputFormatCO->clear();
        outputFormatCO->addItem(qt_("Default"),
                                QVariant(QString("default")));
+
+       int index = 0;
        typedef vector<Format const *> Formats;
        Formats formats = bv_->buffer().params().exportableFormats(true);
        Formats::const_iterator cit = formats.begin();
        Formats::const_iterator end = formats.end();
-       for (; cit != end; ++cit)
+       for (; cit != end; ++cit) {
+               QString const fname = toqstr((*cit)->name());
                outputFormatCO->addItem(qt_((*cit)->prettyname()),
-                               QVariant(toqstr((*cit)->name())));
+                               QVariant(fname));
+               if (fname == view_format_)
+                   index = outputFormatCO->count() -1;
+       }
+       outputFormatCO->setCurrentIndex(index);
        outputFormatCO->blockSignals(false);
 }
 

Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiViewSource.h
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiViewSource.h   Mon Mar 
 5 23:38:21 2012        (r40863)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/GuiViewSource.h   Mon Mar 
 5 23:51:53 2012        (r40864)
@@ -42,9 +42,11 @@
        void setBufferView(BufferView const * bv);
 
 public Q_SLOTS:
-       // update content
+       /// update content
        void updateView();
        ///
+       void setViewFormat();
+       ///
        void updateDefaultFormat();
        ///
        void contentsChanged();
@@ -58,6 +60,8 @@
        LaTeXHighlighter * highlighter_;
        ///
        bool force_getcontent_;
+       ///
+       QString view_format_;
 };
 
 

Modified: lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui        
Mon Mar  5 23:38:21 2012        (r40863)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui        
Mon Mar  5 23:51:53 2012        (r40864)
@@ -45,6 +45,9 @@
      <property name="toolTip">
       <string>Select the output format</string>
      </property>
+     <property name="sizeAdjustPolicy">
+      <enum>QComboBox::AdjustToContents</enum>
+     </property>
     </widget>
    </item>
    <item row="1" column="1" colspan="2">

Copied and modified: 
lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui.old (from 
r40863, lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui)
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui        
Mon Mar  5 23:38:21 2012        (r40863, copy source)
+++ lyx-devel/branches/BRANCH_2_0_X/src/frontends/qt4/ui/ViewSourceUi.ui.old    
Mon Mar  5 23:51:53 2012        (r40864)
@@ -45,6 +45,9 @@
      <property name="toolTip">
       <string>Select the output format</string>
      </property>
+     <property name="sizeAdjustPolicy">
+      <enum>QComboBox::AdjustToContents</enum>
+     </property>
     </widget>
    </item>
    <item row="1" column="1" colspan="2">

Modified: lyx-devel/branches/BRANCH_2_0_X/status.20x
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/status.20x  Mon Mar  5 23:38:21 2012        
(r40863)
+++ lyx-devel/branches/BRANCH_2_0_X/status.20x  Mon Mar  5 23:51:53 2012        
(r40864)
@@ -80,6 +80,9 @@
 
 - Fixed stray warning when inserting inserting plaintext file (bug 7916).
 
+- Don't reset the selected format each time we click into a new paragraph
+  in View>Source (bug 7997).
+
 
 * DOCUMENTATION AND LOCALIZATION
 

Reply via email to