[EMAIL PROTECTED] (Lars Gullik Bjønnes) writes:

| Alfredo Braunstein <[EMAIL PROTECTED]> writes:
| 
| | Forthcoming multiple copy/paste buffers (Lars is almost there?)
| 
| Super close really.

And finished.

Unless I hear objections, this will go in as is.

? newfile1.lyx
? src/frontends/xforms/lyx_forms.h
? src/frontends/xforms/lyx_xpm.h
Index: lib/ui/stdmenus.ui
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ui/stdmenus.ui,v
retrieving revision 1.11
diff -u -p -r1.11 stdmenus.ui
--- lib/ui/stdmenus.ui	30 May 2003 12:44:23 -0000	1.11
+++ lib/ui/stdmenus.ui	17 Jun 2003 14:43:35 -0000
@@ -70,6 +70,7 @@ Menuset
 		Item "Cut" "cut"
 		Item "Copy" "copy"
 		Item "Paste" "paste"
+		Submenu "Paste recent" "pasterecent"
 		Item "Find & Replace...|F" "find-replace"
 		Separator
 		Item "Text Style...|S" "layout-character"
@@ -95,6 +96,10 @@ Menuset
 # This is in the Table submenu instead for now.
 #	OptItem "Table Settings...|a" "inset-settings tabular"
 		OptItem "Table Settings...|a" "layout-tabular"
+	End
+
+	Menu "pasterecent"
+		PasteRecent
 	End
 
 # not much we can do to help here
Index: src/BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.375
diff -u -p -r1.375 BufferView_pimpl.C
--- src/BufferView_pimpl.C	12 Jun 2003 11:09:50 -0000	1.375
+++ src/BufferView_pimpl.C	17 Jun 2003 14:43:36 -0000
@@ -861,7 +861,7 @@ void BufferView::Pimpl::trackChanges()
 
 	if (!tracking) {
 		ParIterator const end = buf->par_iterator_end();
-		for (ParIterator it = buf->par_iterator_begin(); it != end; ++it) 
+		for (ParIterator it = buf->par_iterator_begin(); it != end; ++it)
 			it->trackChanges();
 		buf->params.tracking_changes = true;
 
Index: src/CutAndPaste.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/CutAndPaste.C,v
retrieving revision 1.102
diff -u -p -r1.102 CutAndPaste.C
--- src/CutAndPaste.C	12 Jun 2003 11:09:52 -0000	1.102
+++ src/CutAndPaste.C	17 Jun 2003 14:43:36 -0000
@@ -39,31 +39,32 @@ using std::for_each;
 using lyx::pos_type;
 using lyx::textclass_type;
 
-// Jürgen, note that this means that you cannot currently have a list
-// of selections cut/copied. So IMHO later we should have a
-// list/vector/deque that we could store
-// struct selection_item {
-//       ParagraphList copy_pars;
-//       LyXTextClassList::size_type textclass;
-// };
-// in and some method of choosing beween them (based on the first few chars
-// in the selection probably.) This would be a nice feature and quite
-// easy to implement. (Lgb)
-//
-// Sure but I just cleaned up this code for now with the same functionality
-// as before. I also want to add a XClipboard function so that we can copy
-// text from LyX to some other X-application in the form of ASCII or in the
-// form of LaTeX (or Docbook depending on the document-class!). Think how nice
-// it could be to select a math-inset do a "Copy to X-Clipboard as LaTeX" and
-// then do a middle mouse button click in the application you want and have
-// the whole formula there in LaTeX-Code. (Jug)
+
+typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
 
 namespace {
 
-limited_stack<pair<ParagraphList, textclass_type> > cuts(10);
+CutStack cuts(10);
 
 } // namespace anon
 
+std::vector<string>
+CutAndPaste::availableSelections(Buffer const & buffer)
+{
+	std::vector<string> selList;
+
+	CutStack::const_iterator cit = cuts.begin();
+	CutStack::const_iterator end = cuts.end();
+	for (; cit != end; ++cit) {
+		ParagraphList const & pars = cit->first;
+		string asciiPar(pars.front().asString(&buffer, false), 0, 25);
+		selList.push_back(asciiPar);
+	}
+
+	return selList;
+}
+
+
 PitPosPair CutAndPaste::cutSelection(BufferParams const & params,
 				     ParagraphList & pars,
 				     ParagraphList::iterator startpit,
@@ -201,6 +202,7 @@ CutAndPaste::pasteSelection(Buffer const
 {
 	return pasteSelection(buffer, pars, pit, pos, tc, 0, errorlist);
 }
+
 
 pair<PitPosPair, ParagraphList::iterator>
 CutAndPaste::pasteSelection(Buffer const & buffer,
Index: src/CutAndPaste.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/CutAndPaste.h,v
retrieving revision 1.27
diff -u -p -r1.27 CutAndPaste.h
--- src/CutAndPaste.h	10 Jun 2003 14:39:41 -0000	1.27
+++ src/CutAndPaste.h	17 Jun 2003 14:43:36 -0000
@@ -15,6 +15,8 @@
 #include "support/types.h"
 #include "ParagraphList.h"
 
+#include <vector>
+
 class Paragraph;
 class BufferParams;
 class LyXTextClass;
@@ -22,6 +24,11 @@ class ErrorList;
 
 ///
 namespace CutAndPaste {
+
+///
+std::vector<string>
+CutAndPaste::availableSelections(Buffer const & buffer);
+
 ///
 PitPosPair cutSelection(BufferParams const & params,
 			ParagraphList & pars,
Index: src/MenuBackend.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/MenuBackend.C,v
retrieving revision 1.71
diff -u -p -r1.71 MenuBackend.C
--- src/MenuBackend.C	13 May 2003 14:36:19 -0000	1.71
+++ src/MenuBackend.C	17 Jun 2003 14:43:36 -0000
@@ -27,6 +27,7 @@
 #include "importer.h"
 #include "FloatList.h"
 #include "toc.h"
+#include "CutAndPaste.h"
 #include "frontends/LyXView.h"
 #include "support/LAssert.h"
 #include "support/filetools.h"
@@ -65,6 +66,7 @@ MenuItem::MenuItem(Kind kind, string con
 	case ImportFormats:
 	case FloatListInsert:
 	case FloatInsert:
+	case PasteRecent:
 		break;
 	case Command:
 		action_ = lyxaction.LookupFunc(command);
@@ -199,6 +201,7 @@ Menu & Menu::read(LyXLex & lex)
 		md_viewformats,
 		md_floatlistinsert,
 		md_floatinsert,
+		md_pasterecent,
 		md_last
 	};
 
@@ -213,6 +216,7 @@ Menu & Menu::read(LyXLex & lex)
 		{ "lastfiles", md_lastfiles },
 		{ "optitem", md_optitem },
 		{ "optsubmenu", md_optsubmenu },
+		{ "pasterecent", md_pasterecent },
 		{ "separator", md_separator },
 		{ "submenu", md_submenu },
 		{ "toc", md_toc },
@@ -283,6 +287,10 @@ Menu & Menu::read(LyXLex & lex)
 			add(MenuItem(MenuItem::FloatInsert));
 			break;
 
+		case md_pasterecent:
+			add(MenuItem(MenuItem::PasteRecent));
+			break;
+
 		case md_optsubmenu:
 			optional = true;
 			// fallback to md_submenu
@@ -607,6 +615,19 @@ void expandToc(Menu & tomenu, LyXView co
 }
 
 
+void expandPasteRecent(Menu & tomenu, LyXView const * view)
+{
+	std::vector<string> selL = CutAndPaste::availableSelections(*view->buffer());
+	std::vector<string>::const_iterator cit = selL.begin();
+	std::vector<string>::const_iterator end = selL.end();
+	for (unsigned int index = 0; cit != end; ++cit, ++index) {
+		int const action = lyxaction.getPseudoAction(LFUN_PASTE,
+							     tostr(index));
+		tomenu.add(MenuItem(MenuItem::Command, *cit, action));
+	}
+}
+
+
 } // namespace anon
 
 
@@ -637,6 +658,10 @@ void MenuBackend::expand(Menu const & fr
 
 		case MenuItem::FloatInsert:
 			expandFloatInsert(tomenu, view);
+			break;
+
+		case MenuItem::PasteRecent:
+			expandPasteRecent(tomenu, view);
 			break;
 
 		case MenuItem::Toc:
Index: src/MenuBackend.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/MenuBackend.h,v
retrieving revision 1.26
diff -u -p -r1.26 MenuBackend.h
--- src/MenuBackend.h	2 Apr 2003 18:08:02 -0000	1.26
+++ src/MenuBackend.h	17 Jun 2003 14:43:36 -0000
@@ -62,7 +62,10 @@ public:
 		FloatListInsert,
 		/** This is the list of floats that we can
 		    insert. */
-		FloatInsert
+		FloatInsert,
+		/** This is the list of selections that can
+		    be pasted. */
+		PasteRecent
 	};
 	/// Create a Command type MenuItem
 	MenuItem(Kind kind,
@@ -183,9 +186,9 @@ public:
 	///
 	bool hasMenu(string const &) const;
 	///
-	Menu & getMenu (string const &);
+	Menu & getMenu(string const &);
 	///
-	Menu const & getMenu (string const &) const;
+	Menu const & getMenu(string const &) const;
 	///
 	Menu const & getMenubar() const;
 	///
Index: src/ToolbarBackend.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ToolbarBackend.C,v
retrieving revision 1.10
diff -u -p -r1.10 ToolbarBackend.C
--- src/ToolbarBackend.C	11 Jun 2003 20:06:40 -0000	1.10
+++ src/ToolbarBackend.C	17 Jun 2003 14:43:36 -0000
@@ -69,7 +69,7 @@ void ToolbarBackend::read(LyXLex & lex)
 
 	Toolbar tb;
 	tb.name = lex.getString();
-	
+
 	bool quit = false;
 
 	lex.pushTable(toolTags, TO_LAST - 1);
Index: src/lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.174
diff -u -p -r1.174 lyxtext.h
--- src/lyxtext.h	23 May 2003 15:30:46 -0000	1.174
+++ src/lyxtext.h	17 Jun 2003 14:43:36 -0000
@@ -418,7 +418,7 @@ public:
 	///
 	void copySelection();
 	///
-	void pasteSelection();
+	void pasteSelection(size_t sel_index = 0);
 
 	/** the DTP switches for paragraphs. LyX will store the top settings
 	 always in the first physical paragraph, the bottom settings in the
Index: src/paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.284
diff -u -p -r1.284 paragraph.C
--- src/paragraph.C	16 Jun 2003 11:49:28 -0000	1.284
+++ src/paragraph.C	17 Jun 2003 14:43:36 -0000
@@ -1192,6 +1192,7 @@ bool Paragraph::isMultiLingual(BufferPar
 // Used for building the table of contents
 string const Paragraph::asString(Buffer const * buffer, bool label) const
 {
+#if 0
 	string s;
 	if (label && !params().labelString().empty())
 		s += params().labelString() + ' ';
@@ -1209,6 +1210,11 @@ string const Paragraph::asString(Buffer 
 	}
 
 	return s;
+#else
+	// This should really be done by the caller and not here.
+	string ret(asString(buffer, 0, size(), label));
+	return subst(ret, '\n', ' ');
+#endif
 }
 
 
Index: src/text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.370
diff -u -p -r1.370 text2.C
--- src/text2.C	10 Jun 2003 14:39:43 -0000	1.370
+++ src/text2.C	17 Jun 2003 14:43:36 -0000
@@ -1394,7 +1394,7 @@ void LyXText::copySelection()
 }
 
 
-void LyXText::pasteSelection()
+void LyXText::pasteSelection(size_t sel_index)
 {
 	// this does not make sense, if there is nothing to paste
 	if (!CutAndPaste::checkPastePossible())
@@ -1412,7 +1412,7 @@ void LyXText::pasteSelection()
 					    ownerParagraphs(),
 					    cursor.par(), cursor.pos(),
 					    bv()->buffer()->params.textclass,
-					    el);
+					    sel_index, el);
 	bv()->setErrorList(el);
 	bv()->showErrorList(_("Paste"));
 
Index: src/text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.80
diff -u -p -r1.80 text3.C
--- src/text3.C	16 Jun 2003 14:21:51 -0000	1.80
+++ src/text3.C	17 Jun 2003 14:43:37 -0000
@@ -27,6 +27,7 @@
 #include "box.h"
 #include "language.h"
 #include "support/tostr.h"
+#include "support/lstrings.h"
 #include "frontends/LyXView.h"
 #include "frontends/screen.h"
 #include "frontends/Dialogs.h"
@@ -1020,17 +1021,25 @@ Inset::RESULT LyXText::dispatch(FuncRequ
 		update();
 		break;
 
-	case LFUN_PASTE:
+	case LFUN_PASTE: {
 		cmd.message(_("Paste"));
 		// clear the selection
 		bv->toggleSelection();
 		clearSelection();
 		update();
-		pasteSelection();
+		size_t sel_index = 0;
+		string const & arg = cmd.argument;
+		if (isStrUnsignedInt(arg)) {
+			size_t const paste_arg = strToUnsignedInt(arg);
+#warning FIXME Check if the arg is in the domain of available selections.
+			sel_index = paste_arg;
+		}
+		pasteSelection(sel_index);
 		clearSelection(); // bug 393
 		update();
 		bv->switchKeyMap();
 		break;
+	}
 
 	case LFUN_CUT:
 		update();
Index: src/insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.408
diff -u -p -r1.408 insettext.C
--- src/insets/insettext.C	16 Jun 2003 14:21:52 -0000	1.408
+++ src/insets/insettext.C	17 Jun 2003 14:43:37 -0000
@@ -1250,7 +1250,14 @@ Inset::RESULT InsetText::localDispatch(F
 			}
 		}
 
-		lt->pasteSelection();
+		size_t sel_index = 0;
+		string const & arg = cmd.argument;
+		if (isStrUnsignedInt(arg)) {
+			size_t const paste_arg = strToUnsignedInt(arg);
+#warning FIXME Check if the arg is in the domain of available selections.
+			sel_index = paste_arg;
+		}
+		lt->pasteSelection(sel_index);
 		// bug 393
 		lt->clearSelection();
 		updwhat = CURSOR_PAR;
Index: src/support/limited_stack.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/limited_stack.h,v
retrieving revision 1.7
diff -u -p -r1.7 limited_stack.h
--- src/support/limited_stack.h	4 Jun 2003 07:14:05 -0000	1.7
+++ src/support/limited_stack.h	17 Jun 2003 14:43:37 -0000
@@ -26,6 +26,7 @@ public:
 	typedef std::deque<T> container_type;
 	typedef typename container_type::value_type value_type;
 	typedef typename container_type::size_type size_type;
+	typedef typename container_type::const_iterator const_iterator;
 
 	/// limit is the maximum size of the stack
 	limited_stack(size_type limit = 100) {
@@ -70,6 +71,15 @@ public:
 	size_type size() const {
 		return c_.size();
 	}
+
+	const_iterator begin() const {
+		return c_.begin();
+	}
+
+	const_iterator end() const {
+		return c_.end();
+	}
+
 private:
 	/// Internal contents.
 	container_type c_;
-- 
        Lgb

Reply via email to