Dear list, Attached patch adds to the view-source dialog (qt3/4):
1. 'automatic update' check box. If unchecked, stop automatic updating of the view source dialog. This is useful for slow machines, and when full source is displayed. 2. update button: force update if 'auto update' checkbox is unchecked 3. 'display complete source' checkbox: if checked, display complete source, including preamble. This is useful to debug errors related to layout added preamble stuff. Please comment. If there is no objection, I will apply tomorrow. Bo Commented pieces of the patch: Index: src/buffer.C =================================================================== --- src/buffer.C (revision 14538) +++ src/buffer.C (working copy) +void Buffer::makeLinuxDocFile(ostream &os, string const & fname, + OutputParams const & runparams, + bool const body_only) Separate makeLinuxDocFile, and makeDocBookFile to two parts so that the file can be written to ostream. (This part looks a bit ugly.) + if (full_source) { + os << "% Preview source code\n\n"; + if (isLatex()) + makeLaTeXFile(os, filePath(), runparams, true, true); + else if (isLinuxDoc()) + makeLinuxDocFile(os, fileName(), runparams, false); + else + makeDocBookFile(os, fileName(), runparams, false); Get full source code, including preamble. Index: src/frontends/qt3/QViewSourceDialog.h =================================================================== --- src/frontends/qt3/QViewSourceDialog.h (revision 14538) +++ src/frontends/qt3/QViewSourceDialog.h (working copy) @@ -26,6 +26,9 @@ QViewSourceDialog(QViewSource * form); protected: virtual void closeEvent(QCloseEvent * e); +private slots: + // update content + void slotUpdate(); Slot event triggered by 'full source' check box and update button. It will force update regardless of the status of 'auto update'. +void QViewSource::update_source() +{ + bool fullSource = dialog_->viewFullSourceCB->isChecked(); + dialog_->viewSourceTV->setText(toqstr(controller().updateContent(fullSource))); +} Will be called by update_contents (automatic) and slotUpdate (user triggered). void QViewSource::update_contents() { setTitle(controller().title()); - dialog_->viewSourceTV->setText(toqstr(controller().updateContent())); + if (dialog_->autoUpdateCB->isChecked()) + update_source(); } Auto update only if autoUpdateCB is checked. { connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + connect(viewFullSourceCB, SIGNAL(toggled(bool)), + this, SLOT(slotUpdate())); + connect(autoUpdateCB, SIGNAL(toggled(bool)), + updatePB, SLOT(setDisabled(bool))); + connect(updatePB, SIGNAL(clicked()), + this, SLOT(slotUpdate())); Events...
Index: src/buffer.C =================================================================== --- src/buffer.C (revision 14538) +++ src/buffer.C (working copy) @@ -994,10 +994,24 @@ OutputParams const & runparams, bool const body_only) { + lyxerr[Debug::LATEX] << "makeLinuxDocFile..." << endl; + ofstream ofs; if (!openFileWrite(ofs, fname)) return; + makeLinuxDocFile(ofs, fname, runparams, body_only); + + ofs.close(); + if (ofs.fail()) + lyxerr << "File '" << fname << "' was not closed properly." << endl; +} + + +void Buffer::makeLinuxDocFile(ostream &os, string const & fname, + OutputParams const & runparams, + bool const body_only) +{ LaTeXFeatures features(*this, params(), runparams); validate(features); @@ -1008,7 +1022,7 @@ string const & top_element = tclass.latexname(); if (!body_only) { - ofs << tclass.class_header(); + os << tclass.class_header(); string preamble = params().preamble; string const name = runparams.nice ? changeExtension(pimpl_->filename, ".sgml") @@ -1017,45 +1031,55 @@ preamble += features.getLyXSGMLEntities(); if (!preamble.empty()) { - ofs << " [ " << preamble << " ]"; + os << " [ " << preamble << " ]"; } - ofs << ">\n\n"; + os << ">\n\n"; if (params().options.empty()) - sgml::openTag(ofs, top_element); + sgml::openTag(os, top_element); else { string top = top_element; top += ' '; top += params().options; - sgml::openTag(ofs, top); + sgml::openTag(os, top); } } - ofs << "<!-- LyX " << lyx_version + os << "<!-- LyX " << lyx_version << " created this file. For more info see http://www.lyx.org/" << " -->\n"; - linuxdocParagraphs(*this, paragraphs(), ofs, runparams); + linuxdocParagraphs(*this, paragraphs(), os, runparams); if (!body_only) { - ofs << "\n\n"; - sgml::closeTag(ofs, top_element); + os << "\n\n"; + sgml::closeTag(os, top_element); } +} + +void Buffer::makeDocBookFile(string const & fname, + OutputParams const & runparams, + bool const body_only) +{ + lyxerr[Debug::LATEX] << "makeDocBookFile..." << endl; + + ofstream ofs; + if (!openFileWrite(ofs, fname)) + return; + + makeDocBookFile(ofs, fname, runparams, body_only); + ofs.close(); if (ofs.fail()) lyxerr << "File '" << fname << "' was not closed properly." << endl; } -void Buffer::makeDocBookFile(string const & fname, +void Buffer::makeDocBookFile(ostream & os, string const & fname, OutputParams const & runparams, bool const only_body) { - ofstream ofs; - if (!openFileWrite(ofs, fname)) - return; - LaTeXFeatures features(*this, params(), runparams); validate(features); @@ -1066,17 +1090,17 @@ if (!only_body) { if (runparams.flavor == OutputParams::XML) - ofs << "<?xml version=\"1.0\" encoding=\"" + os << "<?xml version=\"1.0\" encoding=\"" << params().language->encoding()->name() << "\"?>\n"; - ofs << "<!DOCTYPE " << top_element << " "; + os << "<!DOCTYPE " << top_element << " "; - if (! tclass.class_header().empty()) ofs << tclass.class_header(); + if (! tclass.class_header().empty()) os << tclass.class_header(); else if (runparams.flavor == OutputParams::XML) - ofs << "PUBLIC \"-//OASIS//DTD DocBook XML//EN\" " + os << "PUBLIC \"-//OASIS//DTD DocBook XML//EN\" " << "\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\""; else - ofs << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\""; + os << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\""; string preamble = params().preamble; if (runparams.flavor != OutputParams::XML ) { @@ -1092,9 +1116,9 @@ preamble += features.getLyXSGMLEntities(); if (!preamble.empty()) { - ofs << "\n [ " << preamble << " ]"; + os << "\n [ " << preamble << " ]"; } - ofs << ">\n\n"; + os << ">\n\n"; } string top = top_element; @@ -1110,20 +1134,16 @@ top += params().options; } - ofs << "<!-- " << ((runparams.flavor == OutputParams::XML)? "XML" : "SGML") + os << "<!-- " << ((runparams.flavor == OutputParams::XML)? "XML" : "SGML") << " file was created by LyX " << lyx_version << "\n See http://www.lyx.org/ for more information -->\n"; params().getLyXTextClass().counters().reset(); - sgml::openTag(ofs, top); - ofs << '\n'; - docbookParagraphs(paragraphs(), *this, ofs, runparams); - sgml::closeTag(ofs, top_element); - - ofs.close(); - if (ofs.fail()) - lyxerr << "File '" << fname << "' was not closed properly." << endl; + sgml::openTag(os, top); + os << '\n'; + docbookParagraphs(paragraphs(), *this, os, runparams); + sgml::closeTag(os, top_element); } @@ -1647,29 +1667,39 @@ } -void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end) +void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source) { OutputParams runparams; runparams.nice = true; runparams.flavor = OutputParams::LATEX; runparams.linelen = lyxrc.ascii_linelen; - runparams.par_begin = par_begin; - runparams.par_end = par_end; // No side effect of file copying and image conversion runparams.dryrun = true; - if (par_begin + 1 == par_end) - os << "% Preview source code for paragraph " << par_begin << "\n\n"; - else - os << "% Preview source code from paragraph " << par_begin << " to " << par_end - 1 << "\n\n"; - // output paragraphs - if (isLatex()) { - texrow().reset(); - latexParagraphs(*this, paragraphs(), os, texrow(), runparams); - } else if (isLinuxDoc()) - linuxdocParagraphs(*this, paragraphs(), os, runparams); - else // DocBook - docbookParagraphs(paragraphs(), *this, os, runparams); + if (full_source) { + os << "% Preview source code\n\n"; + if (isLatex()) + makeLaTeXFile(os, filePath(), runparams, true, true); + else if (isLinuxDoc()) + makeLinuxDocFile(os, fileName(), runparams, false); + else + makeDocBookFile(os, fileName(), runparams, false); + } else { + runparams.par_begin = par_begin; + runparams.par_end = par_end; + if (par_begin + 1 == par_end) + os << "% Preview source code for paragraph " << par_begin << "\n\n"; + else + os << "% Preview source code from paragraph " << par_begin << " to " << par_end - 1 << "\n\n"; + // output paragraphs + if (isLatex()) { + texrow().reset(); + latexParagraphs(*this, paragraphs(), os, texrow(), runparams); + } else if (isLinuxDoc()) + linuxdocParagraphs(*this, paragraphs(), os, runparams); + else // DocBook + docbookParagraphs(paragraphs(), *this, os, runparams); + } } Index: src/buffer.h =================================================================== --- src/buffer.h (revision 14538) +++ src/buffer.h (working copy) @@ -159,9 +159,17 @@ OutputParams const & runparams_in, bool only_body = false); /// + void makeLinuxDocFile(std::ostream & os, std::string const & filename, + OutputParams const & runparams_in, + bool only_body = false); + /// void makeDocBookFile(std::string const & filename, OutputParams const & runparams_in, bool only_body = false); + /// + void makeDocBookFile(std::ostream & os, std::string const & filename, + OutputParams const & runparams_in, + bool only_body = false); /// returns the main language for the buffer (document) Language const * getLanguage() const; /// get l10n translated to the buffers language @@ -345,8 +353,9 @@ StableDocIterator getAnchor() const { return anchor_; } /// void changeRefsIfUnique(std::string const & from, std::string const & to); - /// get source code (latex/docbook/linuxdoc) for some paragraphs - void getSourceCode(std::ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end); + /// get source code (latex/docbook/linuxdoc) for some paragraphs, or all paragraphs + /// including preamble + void getSourceCode(std::ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source); /// errorList_ accessor. ErrorList const & getErrorList() const; Index: src/frontends/qt3/QViewSourceDialog.h =================================================================== --- src/frontends/qt3/QViewSourceDialog.h (revision 14538) +++ src/frontends/qt3/QViewSourceDialog.h (working copy) @@ -26,6 +26,9 @@ QViewSourceDialog(QViewSource * form); protected: virtual void closeEvent(QCloseEvent * e); +private slots: + // update content + void slotUpdate(); private: QViewSource * form_; }; Index: src/frontends/qt3/ui/QViewSourceDialogBase.ui =================================================================== --- src/frontends/qt3/ui/QViewSourceDialogBase.ui (revision 14538) +++ src/frontends/qt3/ui/QViewSourceDialogBase.ui (working copy) @@ -8,8 +8,8 @@ <rect> <x>0</x> <y>0</y> - <width>420</width> - <height>328</height> + <width>473</width> + <height>394</height> </rect> </property> <property name="caption"> @@ -35,18 +35,47 @@ </widget> <widget class="QLayoutWidget"> <property name="name"> - <cstring>Layout27</cstring> + <cstring>layout2</cstring> </property> <hbox> <property name="name"> <cstring>unnamed</cstring> </property> - <property name="margin"> - <number>0</number> + <widget class="QCheckBox"> + <property name="name"> + <cstring>viewFullSourceCB</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Display complete source</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>autoUpdateCB</cstring> + </property> + <property name="text"> + <string>Automatic update</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> </property> - <property name="spacing"> - <number>6</number> - </property> <spacer> <property name="name"> <cstring>Spacer3</cstring> @@ -59,18 +88,49 @@ </property> <property name="sizeHint"> <size> - <width>20</width> + <width>240</width> <height>20</height> </size> </property> </spacer> <widget class="QPushButton"> <property name="name"> + <cstring>updatePB</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Update</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer3_2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Fixed</enum> + </property> + <property name="sizeHint"> + <size> + <width>30</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> <cstring>closePB</cstring> </property> <property name="text"> <string>&Close</string> </property> + <property name="accel"> + <string>Alt+C</string> + </property> </widget> </hbox> </widget> Index: src/frontends/qt3/QViewSource.C =================================================================== --- src/frontends/qt3/QViewSource.C (revision 14538) +++ src/frontends/qt3/QViewSource.C (working copy) @@ -22,6 +22,7 @@ #include <qtextview.h> #include <qpushbutton.h> +#include <qcheckbox.h> namespace lyx { namespace frontend { @@ -48,10 +49,18 @@ } +void QViewSource::update_source() +{ + bool fullSource = dialog_->viewFullSourceCB->isChecked(); + dialog_->viewSourceTV->setText(toqstr(controller().updateContent(fullSource))); +} + + void QViewSource::update_contents() { setTitle(controller().title()); - dialog_->viewSourceTV->setText(toqstr(controller().updateContent())); + if (dialog_->autoUpdateCB->isChecked()) + update_source(); } } // namespace frontend Index: src/frontends/qt3/QViewSource.h =================================================================== --- src/frontends/qt3/QViewSource.h (revision 14538) +++ src/frontends/qt3/QViewSource.h (working copy) @@ -33,6 +33,8 @@ private: /// Apply changes virtual void apply() {} + /// + void update_source(); /// update virtual void update_contents(); /// build the dialog Index: src/frontends/qt3/QViewSourceDialog.C =================================================================== --- src/frontends/qt3/QViewSourceDialog.C (revision 14538) +++ src/frontends/qt3/QViewSourceDialog.C (working copy) @@ -15,6 +15,7 @@ #include "QViewSource.h" #include <qpushbutton.h> +#include <qcheckbox.h> namespace lyx { @@ -26,6 +27,12 @@ { connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + connect(viewFullSourceCB, SIGNAL(toggled(bool)), + this, SLOT(slotUpdate())); + connect(autoUpdateCB, SIGNAL(toggled(bool)), + updatePB, SLOT(setDisabled(bool))); + connect(updatePB, SIGNAL(clicked()), + this, SLOT(slotUpdate())); } @@ -36,5 +43,10 @@ } +void QViewSourceDialog::slotUpdate() +{ + form_->update_source(); +} + } // namespace frontend } // namespace lyx Index: src/frontends/qt4/QViewSourceDialog.h =================================================================== --- src/frontends/qt4/QViewSourceDialog.h (revision 14538) +++ src/frontends/qt4/QViewSourceDialog.h (working copy) @@ -26,6 +26,9 @@ QViewSourceDialog(QViewSource * form); protected: virtual void closeEvent(QCloseEvent * e); +private Q_SLOTS: + // update content + void slotUpdate(); private: QViewSource * form_; }; Index: src/frontends/qt4/ui/QViewSourceUi.ui =================================================================== --- src/frontends/qt4/ui/QViewSourceUi.ui (revision 14538) +++ src/frontends/qt4/ui/QViewSourceUi.ui (working copy) @@ -8,8 +8,8 @@ <rect> <x>0</x> <y>0</y> - <width>420</width> - <height>328</height> + <width>460</width> + <height>424</height> </rect> </property> <property name="windowTitle" > @@ -20,7 +20,7 @@ </property> <layout class="QVBoxLayout" > <property name="margin" > - <number>11</number> + <number>9</number> </property> <property name="spacing" > <number>6</number> @@ -41,6 +41,36 @@ <number>6</number> </property> <item> + <widget class="QCheckBox" name="viewFullSourceCB" > + <property name="cursor" > + <cursor>0</cursor> + </property> + <property name="text" > + <string>Display complete source</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="autoUpdateCB" > + <property name="text" > + <string>Automatic update</string> + </property> + <property name="checked" > + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>6</number> + </property> + <item> <spacer> <property name="orientation" > <enum>Qt::Horizontal</enum> @@ -50,13 +80,39 @@ </property> <property name="sizeHint" > <size> - <width>20</width> - <height>20</height> + <width>201</width> + <height>44</height> </size> </property> </spacer> </item> <item> + <widget class="QPushButton" name="updatePB" > + <property name="enabled" > + <bool>false</bool> + </property> + <property name="text" > + <string>&Update</string> + </property> + </widget> + </item> + <item> + <spacer> + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType" > + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" > + <size> + <width>31</width> + <height>44</height> + </size> + </property> + </spacer> + </item> + <item> <widget class="QPushButton" name="closePB" > <property name="text" > <string>&Close</string> Index: src/frontends/qt4/QViewSource.C =================================================================== --- src/frontends/qt4/QViewSource.C (revision 14538) +++ src/frontends/qt4/QViewSource.C (working copy) @@ -98,11 +98,19 @@ dialog_->viewSourceTV->setWordWrapMode(QTextOption::NoWrap); } + +void QViewSource::update_source() +{ + bool fullSource = dialog_->viewFullSourceCB->isChecked(); + dialog_->viewSourceTV->setText(toqstr(controller().updateContent(fullSource))); +} + void QViewSource::update_contents() { setTitle(controller().title()); - dialog_->viewSourceTV->setText(toqstr(controller().updateContent())); + if (dialog_->autoUpdateCB->isChecked()) + update_source(); } Index: src/frontends/qt4/QViewSource.h =================================================================== --- src/frontends/qt4/QViewSource.h (revision 14538) +++ src/frontends/qt4/QViewSource.h (working copy) @@ -35,6 +35,8 @@ private: /// Apply changes virtual void apply() {} + /// + void update_source(); /// update virtual void update_contents(); /// build the dialog Index: src/frontends/qt4/QViewSourceDialog.C =================================================================== --- src/frontends/qt4/QViewSourceDialog.C (revision 14538) +++ src/frontends/qt4/QViewSourceDialog.C (working copy) @@ -26,6 +26,12 @@ setupUi(this); connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose())); + connect(viewFullSourceCB, SIGNAL(toggled(bool)), + this, SLOT(slotUpdate())); + connect(autoUpdateCB, SIGNAL(toggled(bool)), + updatePB, SLOT(setDisabled(bool))); + connect(updatePB, SIGNAL(clicked()), + this, SLOT(slotUpdate())); } @@ -36,6 +42,11 @@ } +void QViewSourceDialog::slotUpdate() +{ + form_->update_source(); +} + } // namespace frontend } // namespace lyx Index: src/frontends/controllers/ControlViewSource.C =================================================================== --- src/frontends/controllers/ControlViewSource.C (revision 14538) +++ src/frontends/controllers/ControlViewSource.C (working copy) @@ -36,7 +36,7 @@ return true; } -string const ControlViewSource::updateContent() +string const ControlViewSource::updateContent(bool fullSource) { // get the *top* level paragraphs that contain the cursor, // or the selected text @@ -54,7 +54,7 @@ if (par_begin > par_end) std::swap(par_begin, par_end); ostringstream ostr; - view->buffer()->getSourceCode(ostr, par_begin, par_end + 1); + view->buffer()->getSourceCode(ostr, par_begin, par_end + 1, fullSource); return ostr.str(); } Index: src/frontends/controllers/ControlViewSource.h =================================================================== --- src/frontends/controllers/ControlViewSource.h (revision 14538) +++ src/frontends/controllers/ControlViewSource.h (working copy) @@ -39,8 +39,10 @@ /// The title displayed by the dialog reflects source type. std::string const title() const; - /// get the source code of selected paragraphs - std::string const updateContent(); + /** get the source code of selected paragraphs, or the whole document + \param fullSource get full source code + */ + std::string const updateContent(bool fullSource); }; } // namespace frontend