Move LFUN_GRAPHICS_EDIT and LFUN_EXTERNAL_EDIT from LyXFunc.cpp to BufferView.cpp so that a valid inset can be retrieved and called upon; add context-menu for InsetGraphics and InsetListings

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23910 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2008-03-24 04:27:43 +00:00
parent cd07402c96
commit 057dd755f5
8 changed files with 61 additions and 21 deletions

View File

@ -601,4 +601,19 @@ Menuset
Item "Remove Last Parameter Spitting Out To The Right" "math-macro-remove-greedy-param"
End
Menu "context-listings"
Item "Cut" "cut"
Item "Copy" "copy"
Item "Paste" "paste"
Submenu "Paste Recent|e" "edit_pasterecent"
Separator
Item "Settings...|S" "inset-settings listings"
End
Menu "context-graphics"
Item "Edit...|E" "graphics-edit"
Separator
Item "Settings...|S" "next-inset-toggle"
End
End

View File

@ -55,6 +55,8 @@
#include "insets/InsetBibtex.h"
#include "insets/InsetCommand.h" // ChangeRefs
#include "insets/InsetExternal.h"
#include "insets/InsetGraphics.h"
#include "insets/InsetRef.h"
#include "insets/InsetText.h"
@ -846,6 +848,8 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
case LFUN_FONT_STATE:
case LFUN_LABEL_INSERT:
case LFUN_INFO_INSERT:
case LFUN_EXTERNAL_EDIT:
case LFUN_GRAPHICS_EDIT:
case LFUN_PARAGRAPH_GOTO:
case LFUN_NOTE_NEXT:
case LFUN_REFERENCE_NEXT:
@ -1030,6 +1034,25 @@ bool BufferView::dispatch(FuncRequest const & cmd)
gotoLabel(label);
break;
}
case LFUN_EXTERNAL_EDIT: {
FuncRequest fr(cmd);
InsetExternal * inset = getInsetByCode<InsetExternal>(d->cursor_,
EXTERNAL_CODE);
if (inset)
inset->dispatch(d->cursor_, fr);
break;
}
case LFUN_GRAPHICS_EDIT: {
FuncRequest fr(cmd);
InsetGraphics * inset = getInsetByCode<InsetGraphics>(d->cursor_,
GRAPHICS_CODE);
if (inset)
inset->dispatch(d->cursor_, fr);
break;
}
case LFUN_PARAGRAPH_GOTO: {
int const id = convert<int>(to_utf8(cmd.argument()));

View File

@ -1440,23 +1440,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
lyx_view_->message(from_utf8(argument));
break;
case LFUN_EXTERNAL_EDIT: {
BOOST_ASSERT(lyx_view_);
FuncRequest fr(action, argument);
InsetExternal ie;
ie.setBuffer(*lyx_view_->buffer());
ie.dispatch(view()->cursor(), fr);
break;
}
case LFUN_GRAPHICS_EDIT: {
BOOST_ASSERT(lyx_view_);
FuncRequest fr(action, argument);
InsetGraphics ig;
ig.setBuffer(*lyx_view_->buffer());
ig.dispatch(view()->cursor(), fr);
break;
}
case LFUN_ALL_INSETS_TOGGLE: {
BOOST_ASSERT(lyx_view_);

View File

@ -452,8 +452,9 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action) {
case LFUN_EXTERNAL_EDIT: {
InsetExternalParams p;
InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
InsetExternalParams p = params();
if (!cmd.argument().empty())
InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
external::editExternal(p, buffer());
break;
}

View File

@ -175,8 +175,9 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
case LFUN_GRAPHICS_EDIT: {
InsetGraphicsParams p;
InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
InsetGraphicsParams p = params();
if (!cmd.argument().empty())
InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer(), p);
editGraphics(p, buffer());
break;
}
@ -939,6 +940,12 @@ void InsetGraphics::addToToc(ParConstIterator const & cpit) const
}
docstring InsetGraphics::contextMenu(BufferView const &, int, int) const
{
return from_ascii("context-graphics");
}
string const InsetGraphicsMailer::name_("graphics");
InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)

View File

@ -84,6 +84,8 @@ public:
void updateEmbeddedFile(EmbeddedFile const &);
///
void addToToc(ParConstIterator const &) const;
///
docstring contextMenu(BufferView const & bv, int x, int y) const;
/// Force inset into LTR environment if surroundings are RTL?
virtual bool forceLTR() const { return true; }

View File

@ -197,6 +197,12 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const
}
docstring InsetListings::contextMenu(BufferView const &, int, int) const
{
return from_ascii("context-listings");
}
void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {

View File

@ -56,6 +56,9 @@ public:
InsetListingsParams const & params() const { return params_; }
///
InsetListingsParams & params() { return params_; }
///
docstring contextMenu(BufferView const & bv, int x, int y) const;
private:
///
void doDispatch(Cursor & cur, FuncRequest & cmd);