From 5dd63a2768cb994f76018747f370d6dcaadc0942 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Tue, 17 Jun 2003 15:33:49 +0000 Subject: [PATCH] The Paste Recent patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7182 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 5 +++++ lib/ui/stdmenus.ui | 5 +++++ src/BufferView_pimpl.C | 2 +- src/ChangeLog | 26 ++++++++++++++++++++++- src/CutAndPaste.C | 41 ++++++++++++++++++++----------------- src/CutAndPaste.h | 7 +++++++ src/MenuBackend.C | 28 +++++++++++++++++++++++++ src/MenuBackend.h | 9 +++++--- src/ToolbarBackend.C | 2 +- src/insets/ChangeLog | 5 +++++ src/insets/insettext.C | 9 +++++++- src/lyxtext.h | 2 +- src/paragraph.C | 6 ++++++ src/support/ChangeLog | 5 +++++ src/support/limited_stack.h | 10 +++++++++ src/text2.C | 4 ++-- src/text3.C | 13 ++++++++++-- 17 files changed, 148 insertions(+), 31 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 49b3664aa6..c9fd28827f 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2003-06-17 Lars Gullik Bjønnes + + * ui/stdmenus.ui: add submenu "Paste Recent" to edit. Also add + pasterecent menu. + 2003-06-17 John Levon * examples/splash.lyx: remove mention of lyxrc diff --git a/lib/ui/stdmenus.ui b/lib/ui/stdmenus.ui index d2c35013a0..12a7e561d9 100644 --- a/lib/ui/stdmenus.ui +++ b/lib/ui/stdmenus.ui @@ -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" diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index f8f8fd4bbc..6f32514272 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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; diff --git a/src/ChangeLog b/src/ChangeLog index db1698728e..a6fc2bb988 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,27 @@ +2003-06-17 Lars Gullik Bjønnes + + * 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 * lyxfunc.C (dispatch): s/showMathPanel/show("mathpanel")/ @@ -3019,7 +3043,7 @@ * 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. diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 0fbb7848ab..9eeebfd887 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -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 > CutStack; namespace { -limited_stack > cuts(10); +CutStack cuts(10); } // namespace anon +vector +CutAndPaste::availableSelections(Buffer const & buffer) +{ + vector 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 CutAndPaste::pasteSelection(Buffer const & buffer, ParagraphList & pars, diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index 8e47b6829b..615222ce2b 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -15,6 +15,8 @@ #include "support/types.h" #include "ParagraphList.h" +#include + class Paragraph; class BufferParams; class LyXTextClass; @@ -22,6 +24,11 @@ class ErrorList; /// namespace CutAndPaste { + +/// +std::vector +CutAndPaste::availableSelections(Buffer const & buffer); + /// PitPosPair cutSelection(BufferParams const & params, ParagraphList & pars, diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 9a506537b0..3ce73b3636 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -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 const selL = + CutAndPaste::availableSelections(*view->buffer()); + + vector::const_iterator cit = selL.begin(); + vector::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; diff --git a/src/MenuBackend.h b/src/MenuBackend.h index f5450cec0f..5366515f2c 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -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; /// diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index 487648eb80..412616db59 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -69,7 +69,7 @@ void ToolbarBackend::read(LyXLex & lex) Toolbar tb; tb.name = lex.getString(); - + bool quit = false; lex.pushTable(toolTags, TO_LAST - 1); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index bc7d3b7bbf..dd3f33084a 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2003-06-17 Lars Gullik Bjønnes + + * insettext.C (localDispatch): handle arg to LFUN_PASTE, call + pasteSelection with index + 2003-06-13 Jean-Marc Lasgouttes * insettext.C (localDispatch): fix call to cutSelection for LFUN_CUT diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 027049eac0..21a1ee50c5 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -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; diff --git a/src/lyxtext.h b/src/lyxtext.h index 9978e0d53f..6aa0bdc3b1 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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 diff --git a/src/paragraph.C b/src/paragraph.C index ceb72f6847..fbedfeedc9 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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 } diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 04f9a86f39..1af545ab55 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2003-06-17 Lars Gullik Bjønnes + + * limited_stack.h: make it have a const_iterator, add begin, and + end as interface. + 2003-06-10 Angus Leeming * filetools.C (copyFileToDir): ensure that temp files have unique names. diff --git a/src/support/limited_stack.h b/src/support/limited_stack.h index 319a05c2d5..21a5059c50 100644 --- a/src/support/limited_stack.h +++ b/src/support/limited_stack.h @@ -26,6 +26,7 @@ public: typedef std::deque 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_; diff --git a/src/text2.C b/src/text2.C index e068784223..917412bea2 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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")); diff --git a/src/text3.C b/src/text3.C index 2b3496b90c..4cb6d8a322 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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(); -- 2.39.2