Add more controls to the view-source dialog.

* src/buffer.[nC]: can write full source, separaet/rename makeXXXFile.
	* src/graphics/PreviewLoader.C: rename maleLaTeXFile to writeLaTeXSource
	* src/frontends/qt3/QViewSourceDialog.h, ui/QViewSourceDialogBase.ui,
		QViewSource.[hC], QViewSourceDialog.[hC]: qt3 frontend
	* src/frontends/qt4/QViewSource.[hC], ui/QViewSourceUi.ui,
		QViewSourceDialog.[hC]: qt4 frontend
	* src/frontends/controllers/ControlViewSource.[hC]: controller


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14539 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2006-08-04 13:59:12 +00:00
parent 7f552526fc
commit 3002118616
15 changed files with 278 additions and 71 deletions

View File

@ -827,7 +827,7 @@ void Buffer::makeLaTeXFile(string const & fname,
if (!openFileWrite(ofs, fname))
return;
makeLaTeXFile(ofs, original_path,
writeLaTeXSource(ofs, original_path,
runparams, output_preamble, output_body);
ofs.close();
@ -836,7 +836,7 @@ void Buffer::makeLaTeXFile(string const & fname,
}
void Buffer::makeLaTeXFile(ostream & os,
void Buffer::writeLaTeXSource(ostream & os,
string const & original_path,
OutputParams const & runparams_in,
bool const output_preamble, bool const output_body)
@ -994,10 +994,24 @@ void Buffer::makeLinuxDocFile(string const & fname,
OutputParams const & runparams,
bool const body_only)
{
lyxerr[Debug::LATEX] << "makeLinuxDocFile..." << endl;
ofstream ofs;
if (!openFileWrite(ofs, fname))
return;
writeLinuxDocSource(ofs, fname, runparams, body_only);
ofs.close();
if (ofs.fail())
lyxerr << "File '" << fname << "' was not closed properly." << endl;
}
void Buffer::writeLinuxDocSource(ostream &os, string const & fname,
OutputParams const & runparams,
bool const body_only)
{
LaTeXFeatures features(*this, params(), runparams);
validate(features);
@ -1008,7 +1022,7 @@ void Buffer::makeLinuxDocFile(string const & fname,
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,30 +1031,44 @@ void Buffer::makeLinuxDocFile(string const & fname,
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;
writeDocBookSource(ofs, fname, runparams, body_only);
ofs.close();
if (ofs.fail())
@ -1048,14 +1076,10 @@ void Buffer::makeLinuxDocFile(string const & fname,
}
void Buffer::makeDocBookFile(string const & fname,
void Buffer::writeDocBookSource(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 @@ void Buffer::makeDocBookFile(string const & fname,
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 @@ void Buffer::makeDocBookFile(string const & fname,
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 @@ void Buffer::makeDocBookFile(string const & fname,
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,17 +1667,26 @@ void Buffer::changeRefsIfUnique(string const & from, string const & to)
}
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 (full_source) {
os << "% Preview source code\n\n";
if (isLatex())
writeLaTeXSource(os, filePath(), runparams, true, true);
else if (isLinuxDoc())
writeLinuxDocSource(os, fileName(), runparams, false);
else
writeDocBookSource(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
@ -1670,6 +1699,7 @@ void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type
linuxdocParagraphs(*this, paragraphs(), os, runparams);
else // DocBook
docbookParagraphs(paragraphs(), *this, os, runparams);
}
}

View File

@ -149,7 +149,7 @@ public:
bool output_preamble = true,
bool output_body = true);
///
void makeLaTeXFile(std::ostream & os,
void writeLaTeXSource(std::ostream & os,
std::string const & original_path,
OutputParams const &,
bool output_preamble = true,
@ -159,9 +159,17 @@ public:
OutputParams const & runparams_in,
bool only_body = false);
///
void writeLinuxDocSource(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 writeDocBookSource(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 @@ public:
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;

View File

@ -36,7 +36,7 @@ bool ControlViewSource::initialiseParams(string const & /*source*/)
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 @@ string const ControlViewSource::updateContent()
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();
}

View File

@ -39,8 +39,10 @@ public:
/// 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

View File

@ -22,6 +22,7 @@
#include <qtextview.h>
#include <qpushbutton.h>
#include <qcheckbox.h>
namespace lyx {
namespace frontend {
@ -48,10 +49,18 @@ void QViewSource::build_dialog()
}
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

View File

@ -33,6 +33,8 @@ public:
private:
/// Apply changes
virtual void apply() {}
///
void update_source();
/// update
virtual void update_contents();
/// build the dialog

View File

@ -15,6 +15,7 @@
#include "QViewSource.h"
#include <qpushbutton.h>
#include <qcheckbox.h>
namespace lyx {
@ -26,6 +27,12 @@ QViewSourceDialog::QViewSourceDialog(QViewSource * form)
{
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::closeEvent(QCloseEvent * e)
}
void QViewSourceDialog::slotUpdate()
{
form_->update_source();
}
} // namespace frontend
} // namespace lyx

View File

@ -26,6 +26,9 @@ public:
QViewSourceDialog(QViewSource * form);
protected:
virtual void closeEvent(QCloseEvent * e);
private slots:
// update content
void slotUpdate();
private:
QViewSource * form_;
};

View File

@ -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,17 +35,46 @@
</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="spacing">
<number>6</number>
<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>
<spacer>
<property name="name">
@ -59,7 +88,35 @@
</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>
@ -71,6 +128,9 @@
<property name="text">
<string>&amp;Close</string>
</property>
<property name="accel">
<string>Alt+C</string>
</property>
</widget>
</hbox>
</widget>

View File

@ -99,10 +99,18 @@ void QViewSource::build_dialog()
}
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();
}

View File

@ -35,6 +35,8 @@ public:
private:
/// Apply changes
virtual void apply() {}
///
void update_source();
/// update
virtual void update_contents();
/// build the dialog

View File

@ -26,6 +26,12 @@ QViewSourceDialog::QViewSourceDialog(QViewSource * form)
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::closeEvent(QCloseEvent * e)
}
void QViewSourceDialog::slotUpdate()
{
form_->update_source();
}
} // namespace frontend
} // namespace lyx

View File

@ -26,6 +26,9 @@ public:
QViewSourceDialog(QViewSource * form);
protected:
virtual void closeEvent(QCloseEvent * e);
private Q_SLOTS:
// update content
void slotUpdate();
private:
QViewSource * form_;
};

View File

@ -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>
@ -32,6 +32,36 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<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" >
@ -50,8 +80,34 @@
</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>&amp;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>

View File

@ -592,7 +592,7 @@ void PreviewLoader::Impl::dumpPreamble(ostream & os) const
runparams.nice = true;
runparams.moving_arg = true;
runparams.free_spacing = true;
tmp.makeLaTeXFile(os, buffer_.filePath(), runparams, true, false);
tmp.writeLaTeXSource(os, buffer_.filePath(), runparams, true, false);
// FIXME! This is a HACK! The proper fix is to control the 'true'
// passed to WriteStream below: