The Paste Recent patch

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7182 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-06-17 15:33:49 +00:00
parent a0892f87e9
commit 5dd63a2768
17 changed files with 148 additions and 31 deletions

View 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

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

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

View 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")/
@ -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.

View 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,

View 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,

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

View 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;
///

View 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);

View 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

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

View 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

View 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
}

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

View 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_;

View 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"));

View 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();