From e33095f10d2289ad9e1faa60baa44edbe61db970 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 14 Jul 2009 13:00:42 +0000 Subject: [PATCH] Move special handling of paste function from InsetCollapsable to InsetText git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30562 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Text3.cpp | 7 +++++++ src/insets/InsetCollapsable.cpp | 32 +---------------------------- src/insets/InsetCollapsable.h | 2 -- src/insets/InsetText.cpp | 36 ++++++++++++++++++++++++++++----- src/insets/InsetText.h | 3 +++ 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/Text3.cpp b/src/Text3.cpp index fe8b508b16..5c726f97c9 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -512,6 +512,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) { LYXERR(Debug::ACTION, "Text::dispatch: cmd: " << cmd); + // Dispatch if the cursor is inside the text. It is not the + // case for context menus (bug 5797). + if (cur.text() != this) { + cur.undispatched(); + return; + } + BufferView * bv = &cur.bv(); TextMetrics * tm = &bv->textMetrics(this); if (!tm->contains(cur.pit())) { diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 51c7048a40..de8561f69b 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -180,7 +180,7 @@ void InsetCollapsable::read(Lexer & lex) // since new text inherits the language from the last position of the // existing text. As a side effect this makes us also robust against // bugs in LyX that might lead to font changes in ERT in .lyx files. - resetParagraphsFont(); + fixParagraphsFont(); } @@ -557,19 +557,6 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) cur.dispatched(); break; - case LFUN_PASTE: - case LFUN_CLIPBOARD_PASTE: - case LFUN_SELECTION_PASTE: - case LFUN_PRIMARY_SELECTION_PASTE: { - InsetText::doDispatch(cur, cmd); - // Since we can only store plain text, we must reset all - // attributes. - // FIXME: Change only the pasted paragraphs - - resetParagraphsFont(); - break; - } - case LFUN_TAB_INSERT: { bool const multi_par_selection = cur.selection() && cur.selBegin().pit() != cur.selEnd().pit(); @@ -668,23 +655,6 @@ void InsetCollapsable::doDispatch(Cursor & cur, FuncRequest & cmd) } -void InsetCollapsable::resetParagraphsFont() -{ - Font font(inherit_font, buffer().params().language); - if (getLayout().isForceLtr()) - font.setLanguage(latex_language); - if (getLayout().isPassThru()) { - ParagraphList::iterator par = paragraphs().begin(); - ParagraphList::iterator const end = paragraphs().end(); - while (par != end) { - par->resetFonts(font); - par->params().clear(); - ++par; - } - } -} - - bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { diff --git a/src/insets/InsetCollapsable.h b/src/insets/InsetCollapsable.h index 0ed8bcf63f..85ded86eaf 100644 --- a/src/insets/InsetCollapsable.h +++ b/src/insets/InsetCollapsable.h @@ -159,8 +159,6 @@ protected: /// docstring floatName(std::string const & type) const; /// - virtual void resetParagraphsFont(); - /// mutable CollapseStatus status_; private: /// diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index a396041a30..0a5cb92764 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -29,6 +29,7 @@ #include "InsetCaption.h" #include "InsetList.h" #include "Intl.h" +#include "Language.h" #include "Lexer.h" #include "lyxfind.h" #include "LyXRC.h" @@ -265,12 +266,20 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd) LYXERR(Debug::ACTION, "InsetText::doDispatch()" << " [ cmd.action = " << cmd.action << ']'); - // Dispatch only to text_ if the cursor is inside - // the text_. It is not for context menus (bug 5797). - if (cur.text() == &text_) + switch (cmd.action) { + case LFUN_PASTE: + case LFUN_CLIPBOARD_PASTE: + case LFUN_SELECTION_PASTE: + case LFUN_PRIMARY_SELECTION_PASTE: text_.dispatch(cur, cmd); - else - cur.undispatched(); + // If we we can only store plain text, we must reset all + // attributes. + // FIXME: Change only the pasted paragraphs + fixParagraphsFont(); + break; + default: + text_.dispatch(cur, cmd); + } if (!cur.result().dispatched()) Inset::doDispatch(cur, cmd); @@ -306,6 +315,23 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd, } +void InsetText::fixParagraphsFont() +{ + Font font(inherit_font, buffer().params().language); + if (getLayout().isForceLtr()) + font.setLanguage(latex_language); + if (getLayout().isPassThru()) { + ParagraphList::iterator par = paragraphs().begin(); + ParagraphList::iterator const end = paragraphs().end(); + while (par != end) { + par->resetFonts(font); + par->params().clear(); + ++par; + } + } +} + + void InsetText::setChange(Change const & change) { ParagraphList::iterator pit = paragraphs().begin(); diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index d2526a6afa..c0efea092e 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -111,6 +111,9 @@ public: /// virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; + /// + void fixParagraphsFont(); + /// set the change for the entire inset void setChange(Change const & change); /// accept the changes within the inset -- 2.39.2