]> git.lyx.org Git - features.git/commitdiff
The Paste Recent patch
authorLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 17 Jun 2003 15:33:49 +0000 (15:33 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Tue, 17 Jun 2003 15:33:49 +0000 (15:33 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7182 a592a061-630c-0410-9148-cb99ea01b6c8

17 files changed:
lib/ChangeLog
lib/ui/stdmenus.ui
src/BufferView_pimpl.C
src/ChangeLog
src/CutAndPaste.C
src/CutAndPaste.h
src/MenuBackend.C
src/MenuBackend.h
src/ToolbarBackend.C
src/insets/ChangeLog
src/insets/insettext.C
src/lyxtext.h
src/paragraph.C
src/support/ChangeLog
src/support/limited_stack.h
src/text2.C
src/text3.C

index 49b3664aa67083e1fedd34a89b88971e8a8c1870..c9fd28827f9e98722095f40baf0c02891f1f49ef 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-17  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * ui/stdmenus.ui: add submenu "Paste Recent" to edit. Also add
+       pasterecent menu.
+
 2003-06-17  John Levon  <levon@movementarian.org>
 
        * examples/splash.lyx: remove mention of lyxrc
index d2c35013a03c93f4858175b5abbf2225501ca9c6..12a7e561d93ca1a89df4fb0f927fed29f1562157 100644 (file)
@@ -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"
@@ -97,6 +98,10 @@ Menuset
                OptItem "Table Settings...|a" "layout-tabular"
        End
 
+       Menu "pasterecent"
+               PasteRecent
+       End
+
 # not much we can do to help here
        Menu "edit_tabular"
                Item "Add Row|A" "tabular-feature append-row"
index f8f8fd4bbcad0e4108f3c547a03aa7ef8a1ca20d..6f325142723b510f387f8fcef63cc40a094fcc36 100644 (file)
@@ -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 db1698728e2fb0e8919a2a907e1402d68a082887..a6fc2bb9889e2521b3c92f23e4953858de7f9ab7 100644 (file)
@@ -1,3 +1,27 @@
+2003-06-17  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * text3.C (dispatch): handle arg to LFUN_PASTE, call
+       pasteSelection with index
+
+       * text2.C (pasteSelection): modify, call pasteSelection with index
+
+       * paragraph.C (asString): reimplement version with no interval to
+       call the one with interval.
+
+       * lyxtext.h: add index arg to pasteSelection
+
+       * MenuBackend.C (MenuItem): handle PasteRecent
+       (Menu::read::Menutags): add md_pasterecent
+       (read): handle it
+       (expandPasteRecent): new function
+       (expand): use it
+
+       * MenuBackend.h: add PasteRecent to MenuItem::Kind
+
+       * CutAndPaste.C: get rid of some stale comments. Add typdefe for
+       the limited stack
+       (availableSelections): new function
+
 2003-06-17  Angus Leeming  <leeming@lyx.org>
 
        * lyxfunc.C (dispatch): s/showMathPanel/show("mathpanel")/
        * lyxtext.h:
        * text.C: implement accept/rejectChange()
 
-       * lyxtext.h: 
+       * lyxtext.h:
        * text.C: paint changebars. Paint new/deleted text in the chosen
        colours. Strike through deleted text.
 
index 0fbb7848abea02557d642a9392b1d23c5eaf4451..9eeebfd8875e39046f3d844b7739248025fa56e9 100644 (file)
@@ -35,35 +35,37 @@ using std::endl;
 using std::pair;
 using std::make_pair;
 using std::for_each;
+using std::vector;
 
 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
 
+vector<string>
+CutAndPaste::availableSelections(Buffer const & buffer)
+{
+       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,
@@ -202,6 +204,7 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
        return pasteSelection(buffer, pars, pit, pos, tc, 0, errorlist);
 }
 
+
 pair<PitPosPair, ParagraphList::iterator>
 CutAndPaste::pasteSelection(Buffer const & buffer,
                            ParagraphList & pars,
index 8e47b6829b6fb251883646446dff5292ef94442a..615222ce2bc887963b227cec8eac4c05518d4763 100644 (file)
@@ -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 9a506537b07022445ae917812f37f949a463f6f5..3ce73b3636b7e20b8c8c2ab615200c2ee398a7bc 100644 (file)
@@ -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 const & label,
        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,22 @@ void expandToc(Menu & tomenu, LyXView const * view)
 }
 
 
+void expandPasteRecent(Menu & tomenu, LyXView const * view)
+{
+       vector<string> const selL =
+               CutAndPaste::availableSelections(*view->buffer());
+       
+       vector<string>::const_iterator cit = selL.begin();
+       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
 
 
@@ -639,6 +663,10 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
                        expandFloatInsert(tomenu, view);
                        break;
 
+               case MenuItem::PasteRecent:
+                       expandPasteRecent(tomenu, view);
+                       break;
+
                case MenuItem::Toc:
                        expandToc(tomenu, view);
                        break;
index f5450cec0f704b0602604eaa5034e7cebfb60335..5366515f2cb23f34c10bb31f4bc1fd09bf517a47 100644 (file)
@@ -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 487648eb80403fa6402791e5fe22d84235a1500c..412616db598b901f96871a0f62fb2db25e8447ed 100644 (file)
@@ -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 bc7d3b7bbf15e052203189a2ccbc12969564a8f9..dd3f33084ab0719d1515185c4857d3194ab4734c 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-17  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * insettext.C (localDispatch): handle arg to LFUN_PASTE, call
+       pasteSelection with index
+
 2003-06-13  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * insettext.C (localDispatch): fix call to cutSelection for LFUN_CUT
index 027049eac0d7bcb55d52adc9e4b77441501ca7fb..21a1ee50c5b251d7182acffca7c77ad257ed98d7 100644 (file)
@@ -1250,7 +1250,14 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
                        }
                }
 
-               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 9978e0d53f2c26ea66d7bab0ccd2303e23799730..6aa0bdc3b16d96db610add00a78d9392bd20c518 100644 (file)
@@ -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 ceb72f684731ee8b78698c20d3b4dc9481bace3b..fbedfeedc9ebcf65a828d1212cc7926d429e9d2a 100644 (file)
@@ -1192,6 +1192,7 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams)
 // 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 const * buffer, bool label) const
        }
 
        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 04f9a86f399b56a660e14318de239f5fee40a94a..1af545ab55113b37795b328946d78f3a69d7d645 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-17  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * limited_stack.h: make it have a const_iterator, add begin, and
+       end as interface.
+
 2003-06-10  Angus Leeming  <leeming@lyx.org>
 
        * filetools.C (copyFileToDir): ensure that temp files have unique names.
index 319a05c2d5df8316772c0fd0e94c6fa2c98ebb94..21a5059c5087ed36fa90f8fb9bd4b23d324b2828 100644 (file)
@@ -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_;
index e0687842238f333b00319e6bbba97ede1bbc4eef..917412bea205c2f57f4c48f0154f9d021691695c 100644 (file)
@@ -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 2b3496b90c620cc190628386295b620be03e6c5c..4cb6d8a32295874db017694f8921b7eed94735c3 100644 (file)
@@ -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(FuncRequest const & cmd)
                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();