]> git.lyx.org Git - lyx.git/blob - src/CutAndPaste.h
Revert part of 21965 which was debugging code.
[lyx.git] / src / CutAndPaste.h
1 // -*- C++ -*-
2 /**
3  * \file CutAndPaste.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  * \author Alfredo Braunstein
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef CUTANDPASTE_H
15 #define CUTANDPASTE_H
16
17 #include "TextClassPtr.h"
18
19 #include "support/types.h"
20 #include "support/docstring.h"
21
22 #include <vector>
23
24 namespace lyx {
25
26 class Buffer;
27 class ErrorList;
28 class InsetText;
29 class Cursor;
30 class ParagraphList;
31
32 namespace cap {
33
34 /// Get all elements of the cut buffer in plain text format.
35 std::vector<docstring> const availableSelections(Buffer const & buffer);
36 /// Get the number of available elements in the cut buffer.
37 size_type numberOfSelections();
38 /// Get the sel_index-th element of the cut buffer in plain text format.
39 docstring getSelection(Buffer const & buffer, size_t sel_index);
40
41 /**
42  * Replace using the font of the first selected character and select
43  * the new string. When \c backwards == false, set anchor before
44  * cursor; otherwise set cursor before anchor.
45  * Does handle undo.
46  */
47 void replaceSelectionWithString(Cursor & cur, docstring const & str,
48                                 bool backwards);
49 /// If a selection exists, delete it without pushing it to the cut buffer.
50 /// Does handle undo.
51 void replaceSelection(Cursor & cur);
52
53 /**
54  * Cut the current selection and possibly push it to the cut buffer and
55  * system clipboard.
56  * Does handle undo. Calls saveSelection.
57  * \param doclear If this is true: Delete leading spaces in paragraphs before
58  *                they get merged.
59  * \param realcut If this is true: Push the selection to the cut buffer and
60  *                system clipboard. Set this to false to only delete the
61  *                selection.
62  */
63 void cutSelection(Cursor & cur, bool doclear = true, bool realcut = true);
64 /// Push the current selection to the cut buffer and the system clipboard.
65 void copySelection(Cursor & cur);
66 /**
67  * Push the current selection to the cut buffer and the system clipboard.
68  * \param plaintext plain text version of the selection for the system
69  *        clipboard
70  */
71 void copySelection(Cursor & cur, docstring const & plaintext);
72 /// Push the selection buffer to the cut buffer.
73 void copySelectionToStack();
74 /// Store the current selection in the internal selection buffer
75 void saveSelection(Cursor & cur);
76 /// Is a selection available in our selection buffer?
77 bool selection();
78 /// Clear our selection buffer
79 void clearSelection();
80 /// Clear our cut stack.
81 void clearCutStack();
82 /// Paste the current selection at \p cur
83 /// Does handle undo. Does only work in text, not mathed.
84 void pasteSelection(Cursor & cur, ErrorList &);
85 /// Replace the current selection with the clipboard contents (internal or
86 /// external: which is newer)
87 /// Does handle undo. Does only work in text, not mathed.
88 void pasteClipboard(Cursor & cur, ErrorList & errorList, bool asParagraphs = true);
89 /// Replace the current selection with cut buffer \c sel_index
90 /// Does handle undo. Does only work in text, not mathed.
91 void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
92
93 /// Paste the paragraph list \p parlist at the position given by \p cur.
94 /// Does not handle undo. Does only work in text, not mathed.
95 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
96                         TextClassPtr textclass, ErrorList & errorList);
97
98
99 /** Needed to switch between different classes. This works
100  *  for a list of paragraphs beginning with the specified par.
101  *  It changes layouts and character styles.
102  */
103 void switchBetweenClasses(TextClassPtr const & c1, 
104         TextClassPtr const & c2, InsetText & in, ErrorList &);
105
106 /// Get the current selection as a string. Does not change the selection.
107 /// Does only work if the whole selection is in mathed.
108 docstring grabSelection(Cursor const & cur);
109 /// Erase the current selection.
110 /// Does not handle undo. Does only work if the whole selection is in mathed.
111 /// Calls saveSelection.
112 void eraseSelection(Cursor & cur);
113 /// Erase the selection and return it as a string.
114 /// Does not handle undo. Does only work if the whole selection is in mathed.
115 docstring grabAndEraseSelection(Cursor & cur);
116 // other selection methods
117 /// Erase the selection if one exists.
118 /// Does not handle undo. Does only work if the whole selection is in mathed.
119 void selDel(Cursor & cur);
120 /// Clear or delete the selection if one exists, depending on lyxrc setting.
121 /// Does not handle undo. Does only work if the whole selection is in mathed.
122 void selClearOrDel(Cursor & cur);
123
124 /** Tabular has its own paste stack for multiple cells
125  *  but it needs to know whether there is a more recent
126  *  ordinary paste. Therefore which one is newer.
127  */
128 //FIXME: this is a workaround for bug 1919. Replace this by
129 //an all-for-one-paste mechanism in 1.5
130 /// store whether tabular or ordinary paste stack is newer
131 void dirtyTabularStack(bool b);
132 /// is the tabular paste stack newer than the ordinary one?
133 bool tabularStackDirty();
134 } // namespace cap
135 } // namespce lyx
136
137 #endif