diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index c7ebea6102..8b8eec6931 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -1035,6 +1035,7 @@ src_insets_header_files = Split(''' InsetNote.h InsetOptArg.h InsetPhantom.h + InsetPreview.h InsetQuotes.h InsetRef.h InsetSpace.h @@ -1090,6 +1091,7 @@ src_insets_files = Split(''' InsetNote.cpp InsetOptArg.cpp InsetPhantom.cpp + InsetPreview.cpp InsetQuotes.cpp InsetRef.cpp InsetSpace.cpp diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc index 368ef2183e..c44da78a50 100644 --- a/lib/layouts/stdinsets.inc +++ b/lib/layouts/stdinsets.inc @@ -411,3 +411,9 @@ InsetLayout Caption EndHTMLStyle End + +InsetLayout Preview + LabelString Preview + Decoration minimalistic + MultiPar true +End \ No newline at end of file diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index 8d95099a77..583e49eb16 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -592,6 +592,14 @@ Menuset End +# InsetPreview context menu +# + + Menu "context-preview" + Item "Dissolve Inset|D" "inset-dissolve" + End + + # # Toc Changes context menu # diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index df9e77d76a..a73e103c31 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -70,13 +70,13 @@ Menuset Menu "file_vc" OptItem "Register...|R" "vc-register" - OptItem "Check In Changes...|I" "vc-check-in" - OptItem "Check Out for Edit|O" "vc-check-out" + OptItem "Check In Changes...|I" "vc-command DR \".\" \"TortoiseProc /command:commit /path:$$p\"" + OptItem "Check Out for Edit|O" "vc-command DR \".\" \"TortoiseProc /command:update /path:$$p\"" OptItem "Update Local Directory From Repository|d" "vc-repo-update" - OptItem "Revert to Repository Version|v" "vc-revert" + OptItem "Revert to Repository Version|v" "vc-command DR \".\" \"TortoiseProc /command:revert /path:$$p\"" OptItem "Undo Last Check In|U" "vc-undo-last" OptItem "Compare with Older Revision|C" "vc-compare" - OptItem "Show History...|H" "dialog-show vclog" + OptItem "Show History...|H" "vc-command D \".\" \"TortoiseProc /command:log /path:$$p\"" OptItem "Use Locking Property|L" "vc-locking-toggle" End @@ -366,6 +366,7 @@ Menuset Item "TeX Code|X" "ert-insert" Item "Program Listing[[Menu]]" "listing-insert" Item "Date" "date-insert" + Item "Preview|w" "preview-insert" End Menu "insert_special" diff --git a/src/Color.cpp b/src/Color.cpp index 8536991a30..f2b5965e18 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -240,6 +240,7 @@ ColorSet::ColorSet() { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "buttonbg" }, { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "buttonhoverbg" }, { Color_paragraphmarker, N_("paragraph marker"), "paragraphmarker", grey80, "paragraphmarker"}, + { Color_previewframe, N_("preview frame"), "previewframe", "black", "previewframe"}, { Color_inherit, N_("inherit"), "inherit", "black", "inherit" }, { Color_regexpframe, N_("regexp frame"), "green", "green", "green" }, { Color_ignore, N_("ignore"), "ignore", "black", "ignore" }, diff --git a/src/ColorCode.h b/src/ColorCode.h index fff1a54aed..4b1b78cab2 100644 --- a/src/ColorCode.h +++ b/src/ColorCode.h @@ -191,6 +191,8 @@ enum ColorCode Color_buttonhoverbg, /// Color used for the pilcrow sign to mark the end of a paragraph Color_paragraphmarker, + /// Preview frame color + Color_previewframe, // Logical attributes diff --git a/src/FuncCode.h b/src/FuncCode.h index e137083bd4..8aa37890dd 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -445,6 +445,7 @@ enum FuncCode LFUN_SPELLING_ADD, // spitz 20100118 // 345 LFUN_SPELLING_IGNORE, // spitz 20100118 + LFUN_PREVIEW_INSERT, // vfr, 20100328 LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 5d123b61fd..af1f6041de 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -368,6 +368,14 @@ void LyXAction::init() * \endvar */ { LFUN_LISTING_INSERT, "listing-insert", Noop, Edit }, +/*! + * \var lyx::FuncCode lyx::LFUN_PREVIEW_INSERT + * \li Action: Inserts a new preview inset. + * \li Syntax: preview-insert + * \li Origin: vfr, 28 Mar 2010 + * \endvar + */ + { LFUN_PREVIEW_INSERT, "preview-insert", Noop, Edit }, /*! * \var lyx::FuncCode lyx::LFUN_TAB_INSERT * \li Action: Insert a tab into a listings inset. diff --git a/src/Makefile.am b/src/Makefile.am index f4a5701d0c..e6c2dacf41 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -549,6 +549,7 @@ SOURCEFILESINSETS = \ insets/InsetNote.cpp \ insets/InsetOptArg.cpp \ insets/InsetPhantom.cpp \ + insets/InsetPreview.cpp \ insets/InsetQuotes.cpp \ insets/InsetRef.cpp \ insets/InsetSpace.cpp \ @@ -591,6 +592,7 @@ HEADERFILESINSETS = \ insets/InsetInclude.h \ insets/InsetIndex.h \ insets/InsetInfo.h \ + insets/InsetPreview.h \ insets/InsetLabel.h \ insets/InsetLayout.h \ insets/InsetLine.h \ diff --git a/src/Text3.cpp b/src/Text3.cpp index 699058cf88..704adceac6 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -1571,6 +1571,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) case LFUN_MARGINALNOTE_INSERT: case LFUN_OPTIONAL_INSERT: case LFUN_INDEX_INSERT: + case LFUN_PREVIEW_INSERT: // Open the inset, and move the current selection // inside it. doInsertInset(cur, this, cmd, true, true); @@ -2388,6 +2389,9 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, if (cur.inTexted()) code = SPACE_CODE; break; + case LFUN_PREVIEW_INSERT: + code = PREVIEW_CODE; + break; case LFUN_MATH_INSERT: case LFUN_MATH_AMS_MATRIX: diff --git a/src/factory.cpp b/src/factory.cpp index 3f1bf64267..bdad713932 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -47,6 +47,7 @@ #include "insets/InsetNote.h" #include "insets/InsetOptArg.h" #include "insets/InsetPhantom.h" +#include "insets/InsetPreview.h" #include "insets/InsetRef.h" #include "insets/InsetSpace.h" #include "insets/InsetTabular.h" @@ -211,6 +212,9 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd) return inset; } + case LFUN_PREVIEW_INSERT: + return new InsetPreview(buf); + case LFUN_INSET_INSERT: { string const name = cmd.getArg(0); InsetCode code = insetCode(name); @@ -323,6 +327,9 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd) InsetVSpace::string2params(to_utf8(cmd.argument()), vspace); return new InsetVSpace(vspace); } + + case PREVIEW_CODE: + return new InsetPreview(buf); default: lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT." @@ -571,6 +578,8 @@ Inset * readInset(Lexer & lex, Buffer * buf) inset.reset(new InsetFloatList(buf)); } else if (tmptok == "Info") { inset.reset(new InsetInfo(buf)); + } else if (tmptok == "Preview") { + inset.reset(new InsetPreview(buf)); } else { lyxerr << "unknown Inset type '" << tmptok << "'" << endl; diff --git a/src/insets/InsetCode.h b/src/insets/InsetCode.h index cd2b38b863..714d478ba6 100644 --- a/src/insets/InsetCode.h +++ b/src/insets/InsetCode.h @@ -221,6 +221,8 @@ enum InsetCode { /// ARGUMENT_PROXY_CODE, // 100 /// + PREVIEW_CODE, + /// INSET_CODE_SIZE, }; diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp new file mode 100644 index 0000000000..8b44b98aa8 --- /dev/null +++ b/src/insets/InsetPreview.cpp @@ -0,0 +1,164 @@ +/** + * \file InsetPreview.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Vincent van Ravesteijn + * + * Full author contact details are available in file CREDITS. + */ +#include "config.h" + +#include "InsetPreview.h" + +#include "Buffer.h" +#include "BufferParams.h" +#include "BufferView.h" +#include "Cursor.h" +#include "Lexer.h" +#include "LyXRC.h" +#include "MetricsInfo.h" +#include "OutputParams.h" + +#include "frontends/Painter.h" + +#include "graphics/PreviewImage.h" + +#include + +using namespace std; + +namespace lyx { + + +InsetPreview::InsetPreview(Buffer * buf) + : InsetText(buf), + preview_(new RenderPreview(this)), use_preview_(true) +{ + setAutoBreakRows(true); + setDrawFrame(true); + setFrameColor(Color_previewframe); +} + + +InsetPreview::~InsetPreview() +{} + + +InsetPreview::InsetPreview(InsetPreview const & other) + : InsetText(other) +{ + preview_.reset(new RenderPreview(*other.preview_, this)); +} + + +void InsetPreview::write(ostream & os) const +{ + os << "Preview" << "\n"; + text().write(os); +} + + +void InsetPreview::addPreview(DocIterator const & inset_pos, + graphics::PreviewLoader & ploader) const +{ + preparePreview(inset_pos); +} + + +void InsetPreview::preparePreview(DocIterator const & pos) const +{ + odocstringstream str; + OutputParams runparams(&pos.buffer()->params().encoding()); + latex(str, runparams); + docstring const snippet = str.str(); + preview_->addPreview(snippet, *pos.buffer()); +} + + +bool InsetPreview::previewState(BufferView * bv) const +{ + if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) { + graphics::PreviewImage const * pimage = + preview_->getPreviewImage(bv->buffer()); + return pimage && pimage->image(); + } + return false; +} + + +void InsetPreview::reloadPreview(DocIterator const & pos) const +{ + preparePreview(pos); + preview_->startLoading(*pos.buffer()); +} + + +void InsetPreview::draw(PainterInfo & pi, int x, int y) const +{ + use_preview_ = previewState(pi.base.bv); + + if (use_preview_) { + // one pixel gap in front + preview_->draw(pi, x + 1 + TEXT_TO_INSET_OFFSET, y); + setPosCache(pi, x, y); + return; + } + InsetText::draw(pi, x, y); +} + + +void InsetPreview::edit(Cursor & cur, bool front, EntryDirection entry_from) +{ + cur.push(*this); + InsetText::edit(cur, front, entry_from); +} + + +Inset * InsetPreview::editXY(Cursor & cur, int x, int y) +{ + if (use_preview_) { + edit(cur, true, ENTRY_DIRECTION_IGNORE); + return this; + } + cur.push(*this); + return InsetText::editXY(cur, x, y); +} + + +void InsetPreview::metrics(MetricsInfo & mi, Dimension & dim) const +{ + if (previewState(mi.base.bv)) { + preview_->metrics(mi, dim); + mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET; + + dim.wid = max(dim.wid, 4); + dim.asc = max(dim.asc, 4); + + dim.asc += TEXT_TO_INSET_OFFSET; + dim.des += TEXT_TO_INSET_OFFSET; + dim.wid += TEXT_TO_INSET_OFFSET; + dim_ = dim; + dim.wid += TEXT_TO_INSET_OFFSET; + // insert a one pixel gap + dim.wid += 1; + // Cache the inset dimension. + setDimCache(mi, dim); + Dimension dim_dummy; + MetricsInfo mi_dummy = mi; + InsetText::metrics(mi_dummy, dim_dummy); + return; + } + InsetText::metrics(mi, dim); +} + + +bool InsetPreview::notifyCursorLeaves(Cursor const & old, Cursor & cur) +{ + reloadPreview(old); + cur.updateFlags(Update::Force); + return InsetText::notifyCursorLeaves(old, cur); +} + + +} // namespace lyx diff --git a/src/insets/InsetPreview.h b/src/insets/InsetPreview.h new file mode 100644 index 0000000000..3886d247ad --- /dev/null +++ b/src/insets/InsetPreview.h @@ -0,0 +1,92 @@ +// -*- C++ -*- +/** + * \file InsetPreview.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Vincent van Ravesteijn + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef INSETPREVIEW_H +#define INSETPREVIEW_H + +#include "InsetText.h" + +#include "Dimension.h" +#include "RenderPreview.h" + +#include "graphics/PreviewLoader.h" + +#include + +namespace lyx { + +/// An inset with an instant preview +class InsetPreview : public InsetText { + +public: + /// + InsetPreview(Buffer *); + /// + ~InsetPreview(); + /// + InsetPreview(InsetPreview const & other); + + /// \name Methods inherited from Inset class + //@{ + Inset * clone() const { return new InsetPreview(*this); } + + bool neverIndent() const { return true; } + + InsetCode lyxCode() const { return PREVIEW_CODE; } + + docstring name() const { return from_ascii("Preview"); } + + bool descendable(BufferView const & /*bv*/) const { return true; } + + docstring contextMenu(BufferView const & bv, int x, int y) const + { return from_ascii("context-preview"); } + + void metrics(MetricsInfo & mi, Dimension & dim) const; + + Inset * editXY(Cursor & cur, int x, int y); + + void draw(PainterInfo & pi, int x, int y) const; + + void addPreview(DocIterator const & inset_pos, + graphics::PreviewLoader & ploader) const; + + bool notifyCursorLeaves(Cursor const & old, Cursor & cur); + + void write(std::ostream & os) const; + + void edit(Cursor & cur, bool front, EntryDirection entry_from); + //@} + +protected: + /// Retrieves the preview state. Returns true if preview + /// is enabled and the preview image is availabled. + bool previewState(BufferView * bv) const; + /// Recreates the preview if preview is enabled. + void reloadPreview(DocIterator const & pos) const; + /// Prepare the preview if preview is enabled. + void preparePreview(DocIterator const & pos) const; + + /// + boost::scoped_ptr preview_; + /// + mutable bool use_preview_; + +private: + /// + mutable Dimension dim_; +}; + + +} // namespace lyx + + +#endif + diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 99987196c9..d398c87f4c 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -4288,6 +4288,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_BRANCH_INSERT: case LFUN_PHANTOM_INSERT: case LFUN_WRAP_INSERT: + case LFUN_PREVIEW_INSERT: case LFUN_ERT_INSERT: { if (cur.selIsMultiCell()) { status.setEnabled(false);