> It certainly feels like a > kludge that we're creating a temporary InsetGraphics just so we can call > one of its methods. But I don't know this code well enough to have any > more of an opinion than that...except to say, if we commit this, let's > do the context menu and see what Andre thinks about the other bit. So, > can you separate those out and repost?
As shown in the attached patch, I tent to remove the use of a temporary InsetGraphics by moving the lfun implementation to BufferView.cpp. + case LFUN_GRAPHICS_EDIT: { + FuncRequest fr(cmd); + InsetGraphics * inset = getInsetByCode<InsetGraphics>(d->cursor_, + GRAPHICS_CODE); + if (inset) + inset->dispatch(d->cursor_, fr); + break; + } + > I don't know, by the way, why you get InsetText back when you click on > an InsetGraphics. But I think it might be because the cursor isn't IN an > InsetGraphics. It's still IN the InsetText. I guess you are right, and this makes INSET_SETTINGS for InsetCommand and InsetGraphics difficult. I have solved the problem by 1. call showInsetDialog of the underlying inset in InsetText -bool InsetText::showInsetDialog(BufferView *) const +bool InsetText::showInsetDialog(BufferView * bv) const { + // this part is copied from getInsetByCode in BufferView.cpp + DocIterator it = bv->cursor(); + Inset * inset = it.nextInset(); + if (inset) + return inset->showInsetDialog(bv); return false; } 2. allow inset-settings for InsetCommand and InsetGraphics, + case TEXT_CODE: + case CAPTION_CODE: + // maybe we should return true for all InsetCommand derived insets + enable = + (cmd.argument() == "ref" && + getInsetByCode<InsetRef>(d->cursor_, REF_CODE)) || + (cmd.argument() == "label" && + getInsetByCode<InsetLabel>(d->cursor_, LABEL_CODE)) || + (cmd.argument() == "graphics" && + getInsetByCode<InsetGraphics>(d->cursor_, GRAPHICS_CODE)); + break; 3. This enables settings menu for InsetGraphics and InsetLabel, InsetRef. @@ -547,6 +547,8 @@ Item "Next Cross-Reference|N" "reference-next" Item "Go to Label|G" "label-goto" Item "Edit...|E" "next-inset-toggle" + Separator + Item "Settings...|S" "inset-settings ref" End # @@ -556,6 +558,8 @@ Item "Next Cross-Reference|N" "reference-next" Item "Go back to Reference|G" "bookmark-goto 0" Item "Edit...|E" "next-inset-toggle" + Separator + Item "Settings...|S" "inset-settings label" End + Menu "context-graphics" + Item "Edit...|E" "graphics-edit" + Separator + Item "Settings...|S" "inset-settings graphics" + End + The patch also adds edit menu item for InsetGraphics. I will commit the patch if your feedback is positive. Note that the mysterious listings setting crash is still there.... Bo
Index: src/insets/InsetGraphics.h =================================================================== --- src/insets/InsetGraphics.h (revision 23907) +++ src/insets/InsetGraphics.h (working copy) @@ -84,6 +84,10 @@ void updateEmbeddedFile(EmbeddedFile const &); /// void addToToc(ParConstIterator const &) const; + /// + virtual docstring contextMenu(BufferView const & bv, int x, int y) const; + /// + bool showInsetDialog(BufferView * bv) const; /// Force inset into LTR environment if surroundings are RTL? virtual bool forceLTR() const { return true; } Index: src/insets/InsetExternal.cpp =================================================================== --- src/insets/InsetExternal.cpp (revision 23907) +++ src/insets/InsetExternal.cpp (working copy) @@ -452,8 +452,9 @@ 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; } Index: src/insets/InsetGraphics.cpp =================================================================== --- src/insets/InsetGraphics.cpp (revision 23907) +++ src/insets/InsetGraphics.cpp (working copy) @@ -175,8 +175,9 @@ { 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,19 @@ } +docstring InsetGraphics::contextMenu(BufferView const &, int, int) const +{ + return from_ascii("context-graphics"); +} + + +bool InsetGraphics::showInsetDialog(BufferView * bv) const +{ + InsetGraphicsMailer(const_cast<InsetGraphics &>(*this)).showDialog(bv); + return true; +} + + string const InsetGraphicsMailer::name_("graphics"); InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset) Index: src/insets/InsetListings.h =================================================================== --- src/insets/InsetListings.h (revision 23907) +++ src/insets/InsetListings.h (working copy) @@ -56,6 +56,9 @@ InsetListingsParams const & params() const { return params_; } /// InsetListingsParams & params() { return params_; } + /// + virtual docstring contextMenu(BufferView const & bv, int x, int y) const; + private: /// void doDispatch(Cursor & cur, FuncRequest & cmd); Index: src/insets/InsetListings.cpp =================================================================== --- src/insets/InsetListings.cpp (revision 23907) +++ src/insets/InsetListings.cpp (working copy) @@ -197,6 +197,12 @@ } +docstring InsetListings::contextMenu(BufferView const &, int, int) const +{ + return from_ascii("context-listings"); +} + + void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action) { Index: src/insets/InsetCommand.h =================================================================== --- src/insets/InsetCommand.h (revision 23907) +++ src/insets/InsetCommand.h (working copy) @@ -86,6 +86,8 @@ virtual void updateCommand(docstring const &, bool) {}; /// virtual docstring contextMenu(BufferView const & bv, int x, int y) const; + /// + bool showInsetDialog(BufferView * bv) const; protected: /// Index: src/insets/InsetCommand.cpp =================================================================== --- src/insets/InsetCommand.cpp (revision 23907) +++ src/insets/InsetCommand.cpp (working copy) @@ -154,6 +154,15 @@ } +bool InsetCommand::showInsetDialog(BufferView * bv) const +{ + if (!mailer_name_.empty()) + // FIXME: why showInsetDialog is const?? + InsetCommandMailer(mailer_name_, const_cast<InsetCommand&>(*this)).showDialog(bv); + return true; +} + + void InsetCommand::edit(Cursor & cur, bool, EntryDirection) { if (!mailer_name_.empty()) Index: src/insets/InsetText.cpp =================================================================== --- src/insets/InsetText.cpp (revision 23907) +++ src/insets/InsetText.cpp (working copy) @@ -324,8 +324,13 @@ } -bool InsetText::showInsetDialog(BufferView *) const +bool InsetText::showInsetDialog(BufferView * bv) const { + // this part is copied from getInsetByCode in BufferView.cpp + DocIterator it = bv->cursor(); + Inset * inset = it.nextInset(); + if (inset) + return inset->showInsetDialog(bv); return false; } Index: src/BufferView.cpp =================================================================== --- src/BufferView.cpp (revision 23907) +++ src/BufferView.cpp (working copy) @@ -55,6 +55,9 @@ #include "insets/InsetBibtex.h" #include "insets/InsetCommand.h" // ChangeRefs +#include "insets/InsetExternal.h" +#include "insets/InsetGraphics.h" +#include "insets/InsetLabel.h" #include "insets/InsetRef.h" #include "insets/InsetText.h" @@ -846,6 +849,8 @@ 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: @@ -947,6 +952,17 @@ case LISTINGS_CODE: enable = cmd.argument() == "listings"; break; + case TEXT_CODE: + case CAPTION_CODE: + // maybe we should return true for all InsetCommand derived insets + enable = + (cmd.argument() == "ref" && + getInsetByCode<InsetRef>(d->cursor_, REF_CODE)) || + (cmd.argument() == "label" && + getInsetByCode<InsetLabel>(d->cursor_, LABEL_CODE)) || + (cmd.argument() == "graphics" && + getInsetByCode<InsetGraphics>(d->cursor_, GRAPHICS_CODE)); + break; default: break; } @@ -1030,7 +1046,26 @@ 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())); int i = 0; Index: src/LyXFunc.cpp =================================================================== --- src/LyXFunc.cpp (revision 23907) +++ src/LyXFunc.cpp (working copy) @@ -1440,24 +1440,7 @@ 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_); string action; Index: lib/ui/stdmenus.inc =================================================================== --- lib/ui/stdmenus.inc (revision 23907) +++ lib/ui/stdmenus.inc (working copy) @@ -547,6 +547,8 @@ Item "Next Cross-Reference|N" "reference-next" Item "Go to Label|G" "label-goto" Item "Edit...|E" "next-inset-toggle" + Separator + Item "Settings...|S" "inset-settings ref" End # @@ -556,6 +558,8 @@ Item "Next Cross-Reference|N" "reference-next" Item "Go back to Reference|G" "bookmark-goto 0" Item "Edit...|E" "next-inset-toggle" + Separator + Item "Settings...|S" "inset-settings label" End # @@ -601,4 +605,19 @@ 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" "inset-settings graphics" + End + End