From: Bo Peng Date: Sun, 9 Apr 2006 02:48:54 +0000 (+0000) Subject: view-source feature, from Bo Peng X-Git-Tag: 1.6.10~13373 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=eb485caa9653a20dc87649ebe17ed7b877cdf651;p=features.git view-source feature, from Bo Peng * src/buffer.h buffer.C - getSourceCode() * src/lyxfunc.C - open view-source dialog * src/text3.C - change LFUN_MOUSE_RELEASE * src/output_linuxdoc.C, src/output_docbook.C, src/output_latex.C - intercept output * src/outputparams.h, outputparams.C - add par_begin, par_end, dryrun * src/insets/insetgraphics.C - add dryrun mode of file conversion * lib/ui/stdmenus.ui - add view-source menu item under view * Add view-source dialog, add src/frontends/qt2/QViewSourceDialog.h, QViewSource.C, QViewSource.h, QViewSourceDialog.C src/frontends/qt2/ui/QViewSourceDialogBase.ui src/frontends/controllers/ControlViewSource.h ControlViewSource.C modify src/frontends/qt2/Makefile.dialogs, Makefile.am, Dialogs.C, src/frontends/controllers/Makefile.am, po.POTFILES.in git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13610 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ui/stdmenus.ui b/lib/ui/stdmenus.ui index 0cd352acfa..3d19e5cdd9 100644 --- a/lib/ui/stdmenus.ui +++ b/lib/ui/stdmenus.ui @@ -217,6 +217,7 @@ Menuset # Item "Close All Footnotes|C" "close-footnotes" Item "Display Tooltips|i" "toggle-tooltips" Separator + Item "View source|s" "dialog-show view-source" Submenu "Update|U" "document_update" ViewFormats Separator diff --git a/po/POTFILES.in b/po/POTFILES.in index 42d47e246d..7871b4089b 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -26,6 +26,7 @@ src/frontends/controllers/ControlExternal.C src/frontends/controllers/ControlGraphics.C src/frontends/controllers/ControlInclude.C src/frontends/controllers/ControlLog.C +src/frontends/controllers/ControlViewSource.C src/frontends/controllers/ControlPrefs.C src/frontends/controllers/ControlPrint.C src/frontends/controllers/ControlSpellchecker.C diff --git a/src/buffer.C b/src/buffer.C index a03aface32..a4d257ee9f 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -64,6 +64,7 @@ #include "graphics/Previews.h" +#include "support/types.h" #include "support/lyxalgo.h" #include "support/filetools.h" #include "support/fs_extras.h" @@ -1575,3 +1576,40 @@ void Buffer::changeRefsIfUnique(string const & from, string const & to) } } } + + +void Buffer::getSourceCode(ostream& os, lyx::pit_type par_begin, lyx::pit_type par_end) +{ + 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; + + // set source type for the view-source dialog + if (isLatex()) + os << "%LaTeX\n"; + else if (isLinuxDoc()) + os << "%LinuxDoc\n"; + else if (isDocBook()) + os << "%DocBook\n"; + else + BOOST_ASSERT(false); + // start text + 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); +} + diff --git a/src/buffer.h b/src/buffer.h index 1eb455fc81..4a680e65c4 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -333,6 +333,8 @@ 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); private: /** Inserts a file into a document diff --git a/src/frontends/controllers/ControlViewSource.C b/src/frontends/controllers/ControlViewSource.C new file mode 100644 index 0000000000..17ac479607 --- /dev/null +++ b/src/frontends/controllers/ControlViewSource.C @@ -0,0 +1,66 @@ +/** + * \file ControlViewSource.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Angus Leeming + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "ControlViewSource.h" +#include "gettext.h" + +using std::string; + +namespace lyx { +namespace frontend { + +ControlViewSource::ControlViewSource(Dialog & parent) + : Dialog::Controller(parent) +{} + + +bool ControlViewSource::initialiseParams(string const & source) +{ + string sourcetype = source.substr(1, 5); + if (sourcetype == "LaTeX") { + type_ = LatexSource; + source_ = source.substr(7); + } else if (sourcetype == "Linux") { + type_ = LinuxDocSource; + source_ = source.substr(10); + } else if (sourcetype == "DocBo") { + type_ = DocBookSource; + source_ = source.substr(9); + } else + return false; + + return true; +} + + +void ControlViewSource::clearParams() +{ + source_.erase(); +} + + +string const ControlViewSource::title() const +{ + switch (type_) { + case LatexSource: + return _("LaTeX Source"); + case LinuxDocSource: + return _("LinuxDoc Source"); + case DocBookSource: + return _("DocBook Source"); + } +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/controllers/ControlViewSource.h b/src/frontends/controllers/ControlViewSource.h new file mode 100644 index 0000000000..3e9d2f52fe --- /dev/null +++ b/src/frontends/controllers/ControlViewSource.h @@ -0,0 +1,60 @@ +// -*- C++ -*- +/** + * \file ControlViewSource.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Angus Leeming + * \Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef CONTROLVIEWSOURCE_H +#define CONTROLVIEWSOURCE_H + +#include "Dialog.h" + +namespace lyx { +namespace frontend { + +/** + * A controller for a read-only text browser. + */ +class ControlViewSource : public Dialog::Controller { +public: + /// + ControlViewSource(Dialog &); + /** \param source source code to be displayed + */ + virtual bool initialiseParams(std::string const & source); + /// + virtual void clearParams(); + /// + virtual void dispatchParams() {} + /// + virtual bool isBufferDependent() const { return true; } + + /// The title displayed by the dialog reflects the \c VIEWSOURCETYPE + std::string const title() const; + + /// get the source code + std::string const str() const { return source_; } + +private: + /// Recognized source code type + enum SOURCETYPE { + LatexSource, + LinuxDocSource, + DocBookSource + }; + + SOURCETYPE type_; + std::string source_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // CONTROLVIEWSOURCE_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index a334b687f7..2d5f9469a4 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -63,6 +63,8 @@ libcontrollers_la_SOURCES= \ ControlInclude.h \ ControlLog.C \ ControlLog.h \ + ControlViewSource.C \ + ControlViewSource.h \ ControlMath.C \ ControlMath.h \ ControlNote.C \ diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 88e4c09c94..b9c522cd70 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -27,6 +27,7 @@ #include "ControlGraphics.h" #include "ControlInclude.h" #include "ControlLog.h" +#include "ControlViewSource.h" #include "ControlMath.h" #include "ControlNote.h" #include "ControlParagraph.h" @@ -66,6 +67,7 @@ #include "QInclude.h" #include "QIndex.h" #include "QLog.h" +#include "QViewSource.h" #include "QMath.h" #include "QNote.h" #include "QParagraph.h" @@ -102,7 +104,7 @@ namespace { char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", "citation", "document", "errorlist", "ert", "external", "file", -"findreplace", "float", "graphics", "include", "index", "label", "log", +"findreplace", "float", "graphics", "include", "index", "label", "log", "view-source", "mathpanel", "mathdelimiter", "mathmatrix", "note", "paragraph", "preamble", "prefs", "print", "ref", "sendto", "spellchecker","tabular", "tabularcreate", @@ -242,6 +244,10 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setController(new ControlLog(*dialog)); dialog->setView(new QLog(*dialog)); dialog->bc().bp(new OkCancelPolicy); + } else if (name == "view-source") { + dialog->setController(new ControlViewSource(*dialog)); + dialog->setView(new QViewSource(*dialog)); + dialog->bc().bp(new OkCancelPolicy); } else if (name == "mathpanel") { dialog->setController(new ControlMath(*dialog)); dialog->setView(new QMath(*dialog)); diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 1ca211f3a1..05f74b5c04 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -49,6 +49,7 @@ libqt2_la_SOURCES = \ QIndex.C QIndex.h \ QLImage.C QLImage.h \ QLog.C QLog.h \ + QViewSource.C QViewSource.h \ QLPainter.C QLPainter.h \ QLyXKeySym.C QLyXKeySym.h \ QMath.C QMath.h \ diff --git a/src/frontends/qt2/Makefile.dialogs b/src/frontends/qt2/Makefile.dialogs index 5beced3c8a..ccc952a4f6 100644 --- a/src/frontends/qt2/Makefile.dialogs +++ b/src/frontends/qt2/Makefile.dialogs @@ -33,6 +33,7 @@ UIFILES = \ QIncludeDialogBase.ui \ QIndexDialogBase.ui \ QLogDialogBase.ui \ + QViewSourceDialogBase.ui \ QMathDialogBase.ui \ QMathMatrixDialogBase.ui \ QNoteDialogBase.ui \ @@ -100,6 +101,7 @@ MOCFILES = \ QIncludeDialog.C QIncludeDialog.h \ QIndexDialog.C QIndexDialog.h \ QLogDialog.C QLogDialog.h \ + QViewSourceDialog.C QViewSourceDialog.h \ QLPopupMenu.C QLPopupMenu.h \ QLPrintDialog.C QLPrintDialog.h \ QMathDialog.C QMathDialog.h \ diff --git a/src/frontends/qt2/QViewSource.C b/src/frontends/qt2/QViewSource.C new file mode 100644 index 0000000000..1f4f46ccec --- /dev/null +++ b/src/frontends/qt2/QViewSource.C @@ -0,0 +1,58 @@ +/** + * \file QViewSource.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "QViewSource.h" +#include "QViewSourceDialog.h" +#include "qt_helpers.h" + +#include "controllers/ControlViewSource.h" + +#include + +#include +#include + +namespace lyx { +namespace frontend { + +typedef QController > base_class; + +QViewSource::QViewSource(Dialog & parent) + : base_class(parent, "") +{} + + +void QViewSource::build_dialog() +{ + dialog_.reset(new QViewSourceDialog(this)); + dialog_->viewSourceTV->setReadOnly(true); + dialog_->viewSourceTV->setTextFormat(Qt::PlainText); + // this is personal. I think source code should be in fixed-size font + QFont font("Courier New"); + font.setFixedPitch(true); + font.setStyleHint(QFont::TypeWriter); + dialog_->viewSourceTV->setFont(font); + // again, personal taste + dialog_->viewSourceTV->setWordWrap(QTextEdit::NoWrap); +} + + +void QViewSource::update_contents() +{ + setTitle(controller().title()); + + dialog_->viewSourceTV->setText(toqstr(controller().str())); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/qt2/QViewSource.h b/src/frontends/qt2/QViewSource.h new file mode 100644 index 0000000000..029bacb5f9 --- /dev/null +++ b/src/frontends/qt2/QViewSource.h @@ -0,0 +1,45 @@ +// -*- C++ -*- +/** + * \file QViewSource.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef QVIEWSOURCE_H +#define QVIEWSOURCE_H + +#include "QDialogView.h" + +namespace lyx { +namespace frontend { + +class ControlViewSource; +class QViewSourceDialog; + +/// +class QViewSource + : public QController > +{ +public: + /// + friend class QViewSourceDialog; + /// + QViewSource(Dialog &); +private: + /// Apply changes + virtual void apply() {} + /// update + virtual void update_contents(); + /// build the dialog + virtual void build_dialog(); +}; + +} // namespace frontend +} // namespace lyx + +#endif // QVIEWSOURCE_H diff --git a/src/frontends/qt2/QViewSourceDialog.C b/src/frontends/qt2/QViewSourceDialog.C new file mode 100644 index 0000000000..7ab0ac85a2 --- /dev/null +++ b/src/frontends/qt2/QViewSourceDialog.C @@ -0,0 +1,40 @@ +/** + * \file QViewSourceDialog.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "QViewSourceDialog.h" +#include "QViewSource.h" + +#include + + +namespace lyx { +namespace frontend { + +QViewSourceDialog::QViewSourceDialog(QViewSource * form) + : QViewSourceDialogBase(0, 0, false, 0), + form_(form) +{ + connect(closePB, SIGNAL(clicked()), + form, SLOT(slotClose())); +} + + +void QViewSourceDialog::closeEvent(QCloseEvent * e) +{ + form_->slotWMHide(); + e->accept(); +} + + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/qt2/QViewSourceDialog.h b/src/frontends/qt2/QViewSourceDialog.h new file mode 100644 index 0000000000..bd8b69bf58 --- /dev/null +++ b/src/frontends/qt2/QViewSourceDialog.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +/** + * \file QViewSourceDialog.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Levon + * \author Bo Peng + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef QVIEWSOURCEDIALOG_H +#define QVIEWSOURCEDIALOG_H + +#include "ui/QViewSourceDialogBase.h" + +namespace lyx { +namespace frontend { + +class QViewSource; + +class QViewSourceDialog : public QViewSourceDialogBase { + Q_OBJECT +public: + QViewSourceDialog(QViewSource * form); +protected: + virtual void closeEvent(QCloseEvent * e); +private: + QViewSource * form_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // QVIEWSOURCEDIALOG_H diff --git a/src/frontends/qt2/ui/QViewSourceDialogBase.ui b/src/frontends/qt2/ui/QViewSourceDialogBase.ui new file mode 100644 index 0000000000..ae195fe2d6 --- /dev/null +++ b/src/frontends/qt2/ui/QViewSourceDialogBase.ui @@ -0,0 +1,99 @@ + +QViewSourceDialogBase +config.h +qt_helpers.h + + QDialog + + name + QViewSourceDialogBase + + + geometry + + 0 + 0 + 420 + 328 + + + + caption + + + + sizeGripEnabled + true + + + + margin + 11 + + + spacing + 6 + + + QTextEdit + + name + viewSourceTV + + + + QLayoutWidget + + name + Layout27 + + + + margin + 0 + + + spacing + 6 + + + + name + Spacer3 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + closePB + + + text + &Close + + + + + + + + viewSourceTV + closePB + + diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 31e096efdc..35fa59ed1b 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -559,6 +559,10 @@ string const InsetGraphics::prepareFile(Buffer const & buf, string const orig_file = params().filename.absFilename(); string const rel_file = params().filename.relFilename(buf.filePath()); + // previewing source code, no file copying or file format conversion + if (runparams.dryrun) + return stripExtensionIfPossible(rel_file); + // If the file is compressed and we have specified that it // should not be uncompressed, then just return its name and // let LaTeX do the rest! diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 28ccc8d97d..0379b6b6f6 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -131,6 +131,7 @@ using std::make_pair; using std::pair; using std::string; using std::istringstream; +using std::ostringstream; namespace biblio = lyx::biblio; namespace fs = boost::filesystem; @@ -522,6 +523,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const #endif else if (name == "vclog") enable = buf->lyxvc().inUse(); + else if (name == "view-source") + enable = buf; break; } @@ -1183,6 +1186,25 @@ void LyXFunc::dispatch(FuncRequest const & cmd) owner->buffer()->lyxvc().getLogFile(); owner->getDialogs().show("log", data); } + else if (name == "view-source") { + // get the *top* level paragraphs that contain the cursor, + // or the selected text + lyx::pit_type par_begin; + lyx::pit_type par_end; + if (!view()->cursor().selection()) { + par_begin = view()->cursor().bottom().pit(); + par_end = par_begin; + } else { + par_begin = view()->cursor().selectionBegin().bottom().pit(); + par_end = view()->cursor().selectionEnd().bottom().pit(); + } + if (par_begin > par_end) + std::swap(par_begin, par_end); + ostringstream ostr; + view()->buffer()->getSourceCode(ostr, par_begin, par_end + 1); + // display the dialog and show source code + owner->getDialogs().show("view-source", ostr.str()); + } else owner->getDialogs().show(name, data); break; diff --git a/src/output_docbook.C b/src/output_docbook.C index 45c2aa78d5..a54fc303f6 100644 --- a/src/output_docbook.C +++ b/src/output_docbook.C @@ -16,6 +16,7 @@ #include "buffer.h" #include "buffer_funcs.h" #include "bufferparams.h" +#include "outputparams.h" #include "counters.h" #include "debug.h" #include "paragraph.h" @@ -285,8 +286,20 @@ void docbookParagraphs(ParagraphList const & paragraphs, ParagraphList::const_iterator par = paragraphs.begin(); ParagraphList::const_iterator pend = paragraphs.end(); + BOOST_ASSERT(runparams.par_begin <= runparams.par_end); + // if only part of the paragraphs will be outputed + if (runparams.par_begin != runparams.par_end) { + par = boost::next(paragraphs.begin(), runparams.par_begin); + pend = boost::next(paragraphs.begin(), runparams.par_end); + // runparams will be passed to nested paragraphs, so + // we have to reset the range parameters. + const_cast(runparams).par_begin = 0; + const_cast(runparams).par_end = 0; + } + while (par != pend) { LyXLayout_ptr const & style = par->layout(); + ParagraphList::const_iterator lastpar = par; ParagraphList::const_iterator send; switch (style->latextype) { @@ -308,5 +321,8 @@ void docbookParagraphs(ParagraphList const & paragraphs, default: break; } + // makeEnvironment may process more than one paragraphs and bypass pend + if (std::distance(lastpar, par) >= std::distance(lastpar, pend)) + break; } } diff --git a/src/output_latex.C b/src/output_latex.C index 7d2d6380d7..c945e19c2d 100644 --- a/src/output_latex.C +++ b/src/output_latex.C @@ -463,8 +463,20 @@ void latexParagraphs(Buffer const & buf, ParagraphList::const_iterator par = paragraphs.begin(); ParagraphList::const_iterator endpar = paragraphs.end(); + BOOST_ASSERT(runparams.par_begin <= runparams.par_end); + // if only part of the paragraphs will be outputed + if (runparams.par_begin != runparams.par_end) { + par = boost::next(paragraphs.begin(), runparams.par_begin); + endpar = boost::next(paragraphs.begin(), runparams.par_end); + // runparams will be passed to nested paragraphs, so + // we have to reset the range parameters. + const_cast(runparams).par_begin = 0; + const_cast(runparams).par_end = 0; + } + // if only_body while (par != endpar) { + ParagraphList::const_iterator lastpar = par; // well we have to check if we are in an inset with unlimited // length (all in one row) if that is true then we don't allow // any special options in the paragraph and also we don't allow @@ -516,6 +528,8 @@ void latexParagraphs(Buffer const & buf, par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams, everypar); } + if (std::distance(lastpar, par) >= std::distance(lastpar, endpar)) + break; } // It might be that we only have a title in this document if (was_title && !already_title) { diff --git a/src/output_linuxdoc.C b/src/output_linuxdoc.C index f704556fca..459c23b324 100644 --- a/src/output_linuxdoc.C +++ b/src/output_linuxdoc.C @@ -15,6 +15,7 @@ #include "buffer.h" #include "bufferparams.h" +#include "outputparams.h" #include "paragraph.h" #include "paragraph_funcs.h" #include "ParagraphList.h" @@ -40,6 +41,18 @@ void linuxdocParagraphs(Buffer const & buf, ParagraphList::const_iterator pit = paragraphs.begin(); ParagraphList::const_iterator pend = paragraphs.end(); + + BOOST_ASSERT(runparams.par_begin <= runparams.par_end); + // if only part of the paragraphs will be outputed + if (runparams.par_begin != runparams.par_end) { + pit = boost::next(paragraphs.begin(), runparams.par_begin); + pend = boost::next(paragraphs.begin(), runparams.par_end); + // runparams will be passed to nested paragraphs, so + // we have to reset the range parameters. + const_cast(runparams).par_begin = 0; + const_cast(runparams).par_end = 0; + } + for (; pit != pend; ++pit) { LyXLayout_ptr const & style = pit->layout(); // treat as a special case for compatibility with old code diff --git a/src/outputparams.C b/src/outputparams.C index 8ce1158112..6b9a817d86 100644 --- a/src/outputparams.C +++ b/src/outputparams.C @@ -19,7 +19,9 @@ OutputParams::OutputParams() local_font(0), free_spacing(false), use_babel(false), linelen(0), depth(0), exportdata(new ExportData), - inComment(false) + inComment(false), + par_begin(0), par_end(0), + dryrun(false) {} diff --git a/src/outputparams.h b/src/outputparams.h index 40a119d7d2..e5976cd754 100644 --- a/src/outputparams.h +++ b/src/outputparams.h @@ -24,7 +24,6 @@ class LyXFont; class OutputParams { public: - // enum FLAVOR { LATEX, PDFLATEX, @@ -97,6 +96,22 @@ public: * if this flag is true, since they may not exist. */ bool inComment; + + /** allow output of only part of the top-level paragraphs + * par_begin: beginning paragraph + */ + lyx::pit_type par_begin; + + /** allow output of only part of the top-level paragraphs + * par_end: par_end-1 is the ending paragraph + * if par_begin=par_end, output all paragraphs + */ + lyx::pit_type par_end; + + /** whether or not do actual file copying and image conversion + * This mode will be used to preview the source code + */ + bool dryrun; }; #endif // NOT OUTPUTPARAMS_H diff --git a/src/text3.C b/src/text3.C index 2c51c5153e..fadfb888f5 100644 --- a/src/text3.C +++ b/src/text3.C @@ -81,6 +81,7 @@ using lyx::support::token; using std::endl; using std::string; using std::istringstream; +using std::ostringstream; extern string current_layout; @@ -1107,6 +1108,21 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) bv->switchKeyMap(); bv->owner()->updateMenubar(); bv->owner()->updateToolbars(); + + // if view-source dialog is visible, send source code of selected + // text to the dialog + if (cmd.button() == mouse_button::button1 && cur.selection() + && bv->owner()->getDialogs().visible("view-source")) { + // get *top* level paragraphs that contain the selection + lyx::pit_type par_begin = bv->cursor().selectionBegin().bottom().pit(); + lyx::pit_type par_end = bv->cursor().selectionEnd().bottom().pit(); + if (par_begin > par_end) + std::swap(par_begin, par_end); + ostringstream ostr; + bv->buffer()->getSourceCode(ostr, par_begin, par_end + 1); + // display the dialog and show source code + bv->owner()->getDialogs().update("view-source", ostr.str()); + } break; }