From 824d640227d92f01296d69e85761a790d328b488 Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Sat, 29 Oct 2011 15:42:01 +0000 Subject: [PATCH] Adding the capability to paste as simple unformatted text. Documentation (and perhaps menu items) need still to be a bit clarified in order to distinguish the various paste options for the average user. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40060 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ui/stdmenus.inc | 3 +++ src/CutAndPaste.cpp | 33 +++++++++++++++++++++++++++++++++ src/CutAndPaste.h | 2 ++ src/FuncCode.h | 5 +++-- src/LyXAction.cpp | 8 ++++++++ src/Text3.cpp | 7 +++++++ 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc index 4751500fea..b7640469f6 100644 --- a/lib/ui/stdmenus.inc +++ b/lib/ui/stdmenus.inc @@ -157,6 +157,9 @@ Menuset Item "Selection|S" "primary-selection-paste" Item "Selection, Join Lines|i" "primary-selection-paste paragraph" Separator + Item "Unformatted Text|U" "clipboard-paste-simple" + Item "Unformatted, Join Lines|o" "clipboard-paste-simple paragraph" + Separator Item "Paste as LinkBack PDF" "paste linkback" Item "Paste as PDF" "paste pdf" Item "Paste as PNG" "paste png" diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index b9e6bd41ce..c8e99abcab 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -1049,6 +1049,39 @@ void pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs) } +void pasteSimpleText(Cursor & cur, bool asParagraphs) +{ + docstring text; + // Use internal clipboard if it is the most recent one + if (theClipboard().isInternal()) { + if (!checkPastePossible(0)) + return; + + ParagraphList const & pars = theCuts[0].first; + ParagraphList::const_iterator it = pars.begin(); + for (; it != pars.end(); ++it) { + if (it != pars.begin()) + text += "\n"; + text += (*it).asString(); + } + asParagraphs = false; + } else { + // Then try plain text + text = theClipboard().getAsText(); + } + + if (text.empty()) + return; + + cur.recordUndo(); + cutSelection(cur, true, false); + if (asParagraphs) + cur.text()->insertStringAsParagraphs(cur, text, cur.current_font); + else + cur.text()->insertStringAsLines(cur, text, cur.current_font); +} + + void pasteClipboardGraphics(Cursor & cur, ErrorList & /* errorList */, Clipboard::GraphicsType preferedType) { diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index a4e975b8a1..abaad3728d 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -97,6 +97,8 @@ void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList, /// Replace the current selection with cut buffer \c sel_index /// Does handle undo. Does only work in text, not mathed. void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index); +/// Paste the clipboard as simple text, removing any formatting +void pasteSimpleText(Cursor & cur, bool asParagraphs); /// Paste the paragraph list \p parlist at the position given by \p cur. /// Does not handle undo. Does only work in text, not mathed. diff --git a/src/FuncCode.h b/src/FuncCode.h index 977036d189..dd60d33cc9 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -448,9 +448,10 @@ enum FuncCode LFUN_PREVIEW_INSERT, // vfr, 20100328 LFUN_FORWARD_SEARCH, LFUN_SCRIPT_INSERT, // gb, 20101123 - // 350 - LFUN_BUFFER_EXPORT_AS, // tommaso 20111006 + // 350 + LFUN_CLIPBOARD_PASTE_SIMPLE, // tommaso, 20111028 + LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 6a0bd86c1f..6b78bf0ca8 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -1209,6 +1209,14 @@ void LyXAction::init() * \endvar */ { LFUN_SELECTION_PASTE, "selection-paste", Noop, Edit }, +/*! + * \var lyx::FuncCode lyx::LFUN_CLIPBOARD_PASTE_SIMPLE + * \li Action: Pastes simple unformatted text from the active clipboard. + * \li Syntax: clipboard-paste-simple [] + * \li Params: : "paragraph" will cause pasting as one paragraph, i.e. "Join lines". + * \endvar + */ + { LFUN_CLIPBOARD_PASTE_SIMPLE, "clipboard-paste-simple", Noop, Edit }, /*! * \var lyx::FuncCode lyx::LFUN_UNDO * \li Action: Undoes the last edit. diff --git a/src/Text3.cpp b/src/Text3.cpp index 1aee50488a..f3d25d49eb 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -93,6 +93,7 @@ using cap::pasteClipboardGraphics; using cap::replaceSelection; using cap::grabAndEraseSelection; using cap::selClearOrDel; +using cap::pasteSimpleText; // globals... static Font freefont(ignore_font, ignore_language); @@ -1318,6 +1319,11 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bv->buffer().errors("Paste"); break; + case LFUN_CLIPBOARD_PASTE_SIMPLE: + cur.clearSelection(); + pasteSimpleText(cur, cmd.argument() == "paragraph"); + break; + case LFUN_PRIMARY_SELECTION_PASTE: pasteString(cur, theSelection().get(), cmd.argument() == "paragraph"); @@ -2583,6 +2589,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, } case LFUN_CLIPBOARD_PASTE: + case LFUN_CLIPBOARD_PASTE_SIMPLE: enable = !theClipboard().empty(); break;