mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-26 06:15:16 +00:00
Introduce InsetPreview.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33890 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
69f46cf1b2
commit
bb69584112
@ -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
|
||||
|
@ -411,3 +411,9 @@ InsetLayout Caption
|
||||
EndHTMLStyle
|
||||
End
|
||||
|
||||
|
||||
InsetLayout Preview
|
||||
LabelString Preview
|
||||
Decoration minimalistic
|
||||
MultiPar true
|
||||
End
|
@ -592,6 +592,14 @@ Menuset
|
||||
End
|
||||
|
||||
|
||||
# InsetPreview context menu
|
||||
#
|
||||
|
||||
Menu "context-preview"
|
||||
Item "Dissolve Inset|D" "inset-dissolve"
|
||||
End
|
||||
|
||||
|
||||
#
|
||||
# Toc Changes context menu
|
||||
#
|
||||
|
@ -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"
|
||||
|
@ -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" },
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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.
|
||||
|
@ -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 \
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -221,6 +221,8 @@ enum InsetCode {
|
||||
///
|
||||
ARGUMENT_PROXY_CODE, // 100
|
||||
///
|
||||
PREVIEW_CODE,
|
||||
///
|
||||
INSET_CODE_SIZE,
|
||||
};
|
||||
|
||||
|
164
src/insets/InsetPreview.cpp
Normal file
164
src/insets/InsetPreview.cpp
Normal file
@ -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 <sstream>
|
||||
|
||||
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
|
92
src/insets/InsetPreview.h
Normal file
92
src/insets/InsetPreview.h
Normal file
@ -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 <boost/scoped_ptr.hpp>
|
||||
|
||||
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<RenderPreview> preview_;
|
||||
///
|
||||
mutable bool use_preview_;
|
||||
|
||||
private:
|
||||
///
|
||||
mutable Dimension dim_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user