Author: tommaso
Date: Sat Oct 29 17:42:01 2011
New Revision: 40060
URL: http://www.lyx.org/trac/changeset/40060

Log:
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.

Modified:
   lyx-devel/trunk/lib/ui/stdmenus.inc
   lyx-devel/trunk/src/CutAndPaste.cpp
   lyx-devel/trunk/src/CutAndPaste.h
   lyx-devel/trunk/src/FuncCode.h
   lyx-devel/trunk/src/LyXAction.cpp
   lyx-devel/trunk/src/Text3.cpp

Modified: lyx-devel/trunk/lib/ui/stdmenus.inc
==============================================================================
--- lyx-devel/trunk/lib/ui/stdmenus.inc Sat Oct 29 17:34:06 2011        (r40059)
+++ lyx-devel/trunk/lib/ui/stdmenus.inc Sat Oct 29 17:42:01 2011        (r40060)
@@ -157,6 +157,9 @@
                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"

Modified: lyx-devel/trunk/src/CutAndPaste.cpp
==============================================================================
--- lyx-devel/trunk/src/CutAndPaste.cpp Sat Oct 29 17:34:06 2011        (r40059)
+++ lyx-devel/trunk/src/CutAndPaste.cpp Sat Oct 29 17:42:01 2011        (r40060)
@@ -1049,6 +1049,39 @@
 }
 
 
+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)
 {

Modified: lyx-devel/trunk/src/CutAndPaste.h
==============================================================================
--- lyx-devel/trunk/src/CutAndPaste.h   Sat Oct 29 17:34:06 2011        (r40059)
+++ lyx-devel/trunk/src/CutAndPaste.h   Sat Oct 29 17:42:01 2011        (r40060)
@@ -97,6 +97,8 @@
 /// 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.

Modified: lyx-devel/trunk/src/FuncCode.h
==============================================================================
--- lyx-devel/trunk/src/FuncCode.h      Sat Oct 29 17:34:06 2011        (r40059)
+++ lyx-devel/trunk/src/FuncCode.h      Sat Oct 29 17:42:01 2011        (r40060)
@@ -448,9 +448,10 @@
        LFUN_PREVIEW_INSERT,            // vfr, 20100328
        LFUN_FORWARD_SEARCH,
        LFUN_SCRIPT_INSERT,             // gb, 20101123
+       LFUN_BUFFER_EXPORT_AS,          // tommaso 20111006
        // 350
+       LFUN_CLIPBOARD_PASTE_SIMPLE,    // tommaso, 20111028
 
-       LFUN_BUFFER_EXPORT_AS,          // tommaso 20111006
        LFUN_LASTACTION                 // end of the table
 };
 

Modified: lyx-devel/trunk/src/LyXAction.cpp
==============================================================================
--- lyx-devel/trunk/src/LyXAction.cpp   Sat Oct 29 17:34:06 2011        (r40059)
+++ lyx-devel/trunk/src/LyXAction.cpp   Sat Oct 29 17:42:01 2011        (r40060)
@@ -1210,6 +1210,14 @@
  */
                { 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.
  * \li Syntax: undo

Modified: lyx-devel/trunk/src/Text3.cpp
==============================================================================
--- lyx-devel/trunk/src/Text3.cpp       Sat Oct 29 17:34:06 2011        (r40059)
+++ lyx-devel/trunk/src/Text3.cpp       Sat Oct 29 17:42:01 2011        (r40060)
@@ -93,6 +93,7 @@
 using cap::replaceSelection;
 using cap::grabAndEraseSelection;
 using cap::selClearOrDel;
+using cap::pasteSimpleText;
 
 // globals...
 static Font freefont(ignore_font, ignore_language);
@@ -1318,6 +1319,11 @@
                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 @@
         }
 
        case LFUN_CLIPBOARD_PASTE:
+       case LFUN_CLIPBOARD_PASTE_SIMPLE:
                enable = !theClipboard().empty();
                break;
 

Reply via email to