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
This commit is contained in:
Tommaso Cucinotta 2011-10-29 15:42:01 +00:00
parent 37c4b71a3e
commit 824d640227
6 changed files with 56 additions and 2 deletions

View File

@ -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"

View File

@ -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)
{

View File

@ -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.

View File

@ -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
};

View File

@ -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 [<ARG>]
* \li Params: <ARG>: "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.

View File

@ -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;