Commit Graph

216 Commits

Author SHA1 Message Date
Jean-Marc Lasgouttes
fd50fb720f Introduce (Inset|InsetList|Paragraph)::resetBuffer
This avoids an ugly cast like
     setBuffer(*static_cast<Buffer *>(0));
that clang does not appreciate.
2016-12-05 14:48:32 +01:00
Jean-Marc Lasgouttes
004fdf6aeb Clear temp cutstack before exiting LyX.
Otherwise it is done in the exit handler, which leads to crashes.
2016-11-21 17:03:50 +01:00
Jean-Marc Lasgouttes
fb264663d8 Make insertInset use a temporary cut-and-paste area.
This is a long wanted feature, although it does not go all the way to
fix #6604 (private-cut/private-paste).

Additionally, it fixes a crash that can happen when using undefined
branches. This is done by making the action when pasting unknown
branches configurable.

Fixes bug #6570.
2016-11-09 15:28:11 +01:00
Guillaume Munch
e1492a3ab1 Use the new infrastructure to select rows during error reporting 2016-10-22 23:24:00 +02:00
Guillaume Munch
2fd2e65745 C++11 supports thread-safe initialization of statics
A static local variable is guaranteed to be initialized only once, and in time.

Lambda expressions can be used to perform complex initialization of those static
variables on the spot.

(starting from: gcc >= 4.8, msvc >= 2015)
2016-07-31 18:34:33 +01:00
Richard Heck
f49556b3ed Fix bug #8782: We need to query the cell, not just the inset. 2016-06-29 21:23:39 -04:00
Richard Heck
6ecb05e6ea Add missing buffer update after pasting unformatted text.
Fixes bug #8735.
2016-06-29 13:32:30 -04:00
Guillaume Munch
b95b77c631 Replace boost::tuple with std::tuple 2016-06-09 15:21:39 +01:00
Guillaume Munch
ca8709aaf5 Replace boost::scoped_ptr with unique_ptr 2016-06-09 15:21:39 +01:00
Jean-Marc Lasgouttes
0437d8dc1a Variables of type pit_type should be named pit, not par
It is easier to use always the same conventions for naming.
2016-05-29 17:55:46 -04:00
Jean-Marc Lasgouttes
83d8e12cc1 Rename Cursor::setSelection(bool) to selection(bool)
The old name would be confusing wrt setSelection(), which does additional checks.
This one is a pure acessor, and the more complete methods are
* setSelection(), which avoids empty selections
* clearSelection(), which resets anchor, and sets word selection and mark more to false.

Most of the code should use these two instead of selection(bool), but this is for later.
2016-05-29 17:55:46 -04:00
Guillaume Munch
3a4af5a3e1 Do not omit the starting space when copying (#9995)
The offending code appears to have been introduced a long time ago. My
understanding is that it is no longer relevant. Notably, it only appears on copy
and not on cut, which tells us that: 1) it should be safe to remove it, 2) we
should remove it for consistency.
2016-05-28 17:42:31 -04:00
Stephan Witt
7e72c1d0d3 Call lyx::next and lyx::prev explicitely. In case libc++ provides
std::next even when not in C++11 mode this is necessary. E.g. with
clang from Xcode7 on Mac OS X.
2016-01-10 18:06:15 +01:00
Guillaume Munch
bb344452c8 Consistency of ellipses across the UI
Use the function support:truncateWithEllipsis() to shorten a docstring with
... at the end. Actually we use U+2026 HORIZONTAL ELLIPSIS instead of "..." when
automatically shortening strings. This is to be consistent with Qt's own
truncation and is much nicer on the screen.

This includes the bugs #9575 and #9572 regarding broken text elision in the
outliner.

Known issues (non-regressions):

* TocBackend::updateItem() should be rewritten to update all TOCs. (#8386)

* "..." should be replaced with … everywhere else on the interface (including
  translation strings).

* We should prefer to rely on QFontMetrics::elidedText() to truncate strings
  with an ellipsis whenever possible, or an equivalent for the buffer view
  dependent on the font metrics. See the warning in src/support/lstrings.h.
2015-10-05 21:16:16 +01:00
Georg Baum
b596330093 Fix compilation with boost 1.58
Newer boost versions use complicated type traits for boost::next and
boost::prior, which do not work with the RandomAccessList iterators.
The long term solution is to use std::next and std::prev, for now supply
simple replacements for compilers that do not support C++11 yet.
2015-05-16 00:05:23 +02:00
Georg Baum
c5782ff4bb Fix pasting insets into math (bug #9302)
The problem was that the conversion to plain text (which is used as an
intermediate step) requires for some insets a valid buffer pointer, but
insets in the cut stack do not have one. Now we use the same temp buffer
business as for copying to the external clipboard.
2015-01-19 21:37:01 +01:00
Richard Heck
be4646c8ac Whitespace. 2014-11-12 00:01:45 +00:00
Georg Baum
5deaaa3b13 Fix memory errors found by Alfredo with valgrind
BufferParams::setDocumentClass() deletes the old document class of the buffer
and creates a copy of the new one. Therefore, the stored layout pointers in
the paragraphs (actually only one paragraph exists) are dangling afterwards.
Resetting them before setting the document class helps here.
In the long term we need to get rid of BufferParams::setDocumentClass()
completely, this is very ugly.
2014-11-11 20:57:25 +01:00
Jean-Marc Lasgouttes
f58d9f27a2 Erase correctly math multi-cell selection
What a selection spans several cells in mathed, and a deletion occurs though LFUN_CHAR_DELETE_FORWARD for example, only the case of a proper grid was handled. When no such grid exists, all cells between the first and the last index are cleared now.
2014-10-16 16:16:15 +02:00
Richard Heck
54c2ab2732 Possible fix for the mystery crash, which is bug #9049.
Investigation of bug #9236 showed that crash to be due to a Paragraph's
holding a dangling pointer to an old and deleted Layout after the
DocumentClass was reset. Since the backtraces look almost identical, it
seems likely that we have the same problem here.

Since this crash seems almost always to involve tables, I looked at the
code in switchBetweenClasses() and found that the Paragraphs that belong
to "hidden" table cells are not seen by the initial recursion using a
ParIterator: It skips right over them. This was confirmed by test code
suggested by Enrico, with results reported in Trac.

The present patch attempts to deal with this problem in the second
recursion, over Insets. When we see an InsetTabular, we call a new
routine that recurses through the cells, looking for hidden ones. If it
finds a hidden one, it then resets the Layout for the cell's Paragraphs
(there should be only one, but we do not make any assumptions) to the
PlainLayout that belongs to the new DocumentClass. This is good enough,
since such cells never have content.

There is extensive discussion of the patch here:
  https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg185095.html
Additional testing by Enrico and me confirmed the existence of the
dangling pointer.
2014-08-15 10:44:37 -04:00
Richard Heck
96d75db418 Little bit of cleanup. 2014-08-12 13:13:47 -04:00
Georg Baum
f09a9fe2e6 Remove unsafe method FileName::tempName()
FileName::tempName() created a new temp file name by using qt to create a
temporary file with a unique name, and then deleting that file and returning
the name. This was unsafe, since other processes or even other threads of the
running LyX could create files with the same name between deletion and then
using the temp name.
This is fixed by using the TempFile class instead. As a side effect, a few
cases where the temp files were not deleted after usage were fixed as well.
The only place that is still unsafe is createTmpDir().
2014-06-09 13:05:50 +02:00
Richard Heck
0a6ff99f28 Typos and style. 2014-04-21 11:51:59 -04:00
Richard Heck
fdbe775b9f This is the result of an audit of all static variables, looking
for possible thread conflicts, of the sort Georg resolved at
6a30211f. I have made static variables const where possible,
and marked cases that looked potentially problematic with the
comment:
	// FIXME THREAD
Many of these definitely are vulnerable to concurrent access, such
as the static variables declared at the start of output_latex.cpp.
Suppose, e.g., we were outputting latex and also displaying the
source of a different document.

I'd appreciate it if others could grep for "FIXME THREAD" and see
if some of these are harmless, or what.
2014-04-21 11:51:57 -04:00
Georg Baum
270201ed67 Fix bug #8891 (wrong depth of copied text)
This was an obvious thinko: When pasting a paragraph list the depth of the
pasted paragraphs need to be adjusted, so that no paragraph has a negative
depth afterwards. However, the maximum allowed depth was only adjusted after
the second and following pasted paragraphs. Since the computed value was only
used for the subsequent paragrph this meant that the second paragraph did
still use the same maximum allowed depth as the first one, which came from the
paragraph the text as pasted into. This was wrong e.g. in case the outside
paragraph was a standard paragraph (max_depth = 0), and the first pasted
paragraph was an enumeration (max_depth = 1). Therefore, max_depth needs to
be adjusted also after the first pasted paragaph. Since the adjustment is
done aftre max_depth was used for the current paragraph the condition
mentioned in the comment is still met.
2014-02-22 11:02:50 +01:00
Georg Baum
be468136df Silence unwanted error popup on copying
The new HTML clipboard export could cause error message boxes on copying
data to the clipboard (bug #8866). These are now suppressed, like all other
errors which might occur for preparing the clipboard data.
2013-11-12 20:52:35 +01:00
Georg Baum
14a5d07df6 Fix encoding for copying LaTeX from clipboard
If we call tex2lyx on a temporary file created from the clipboard, the
file is always in utf8 encoding, without any temporary changes, even if it
contains encoding changing LaTeX commands. Therefore, we must tell tex2lyx
to use a fixed utf8 encoding for the whole file, and this is done using the
new latexclipboard format. Previously, tex2lyx thought the encoding was
latin1.
As a side effect, the -e option is now also documented in the man page.
2013-11-11 21:52:14 +01:00
Georg Baum
c0ea37f337 Fix image pasting regression
I introduced a regression in c14b9e67 for pasting images:
If an image is on the clipboard both as PNG and HTML with just an url,
but no plain text, pasting would fail. The reason for this was that
text contents was detected (the HTML code), nd preferred, but actually
pasting it resulted in an empty string, since the HTML import could not
handle the url This error was not checked.
The solution is first to try text paste if both text and image content
is present, and then  try image paste if the text failed.
2013-07-13 22:44:20 +02:00
Vincent van Ravesteijn
d9da8dc2c1 Fix assertion: label copy-paste-as-ref in new par
Because the reference got inserted without specifying a font,
Paragraph::fontSpan fired an assertion because the fontlist_ is empty.
2013-05-19 12:48:31 +02:00
Richard Heck
030326466f Set "dryrun" to true for XHTML copying routine. This suppresses
the production of images, etc, making copying even the entire
User's Guide and almost instantaneous operation.
2013-05-04 08:30:56 -04:00
Richard Heck
b4e2a65d50 The update here needs doing no matter what.
This fixes a bug introduced in db358a4315.
2013-05-02 21:21:24 -04:00
Georg Baum
5c63944ec2 Don't ask for creating branches on copying
As discussed on the list. This gets rid of the unwanted message boxes when
copying the complete Userguide.
2013-05-01 13:51:39 +02:00
Vincent van Ravesteijn
e115b006e6 Make sure MarkAsExporting is deleted before buffer
This fixes a crash when cutting something.
2013-04-28 18:51:21 +02:00
Vincent van Ravesteijn
ea118f2da5 Make staticbuffer static again
Otherwise the number of internal buffers in incremented on each cut
action.
2013-04-28 18:51:20 +02:00
Richard Heck
d79225ae98 Remove all messages to user related to assertions. We'll just use
a basic message which is defined in lassert.cpp now.
2013-04-27 17:52:55 -04:00
Kornel Benko
06d72d6ca0 Use doctring as LBUFFER() etc parameters 2013-04-27 21:38:01 +02:00
Kornel Benko
07ca50d905 Strings as parameters to LASSERT should not be translatable.
But empty strings are even worse.
2013-04-27 21:13:32 +02:00
Richard Heck
1b1f8dd235 Audit all the LASSERT calls, and try to do something sensible at
each failure.

There are several places I was not sure what to do. These are marked
by comments beginning "LASSERT:" so they can be found easily. At the
moment, they are at:

Author.cpp:105: // LASSERT: What should we do here?
Author.cpp:121: // LASSERT: What should we do here?
Buffer.cpp:4525:        // LASSERT: Is it safe to continue here, or should we just return?
Cursor.cpp:345:         // LASSERT: Is it safe to continue here, or should we return?
Cursor.cpp:403:         // LASSERT: Is it safe to continue here, or should we return?
Cursor.cpp:1143:                // LASSERT: There have been several bugs around this code, that seem
CursorSlice.cpp:83:     // LASSERT: This should only ever be called from an InsetMath.
CursorSlice.cpp:92:     // LASSERT: This should only ever be called from an InsetMath.
LayoutFile.cpp:303:                     // LASSERT: Why would this fail?
Text.cpp:995:           // LASSERT: Is it safe to continue here?
2013-04-25 17:27:10 -04:00
Georg Baum
928dc03324 Fic crash for repeated pasting from complex docs
Using a cloned buffer was an idea by Richard, and it works well.
2013-04-21 21:16:41 +02:00
Georg Baum
ed2f6a8599 Use MathML on the clipboard for formulas in HTML
This speeds up the copying, and although not many applications understand
MathML currently (MS word is supposed to understand it), their number should
go up in the future.
2013-04-21 21:16:41 +02:00
Richard Heck
db358a4315 Fix bug found by Scott concerning copying XHTML to clipboard. We
needed to updateMacros() before doing the export, which required a
bit of code massaging.
2013-04-20 21:07:07 -04:00
Georg Baum
c14b9e67bc Implement paste from LaTeX and HTML (bug #3096)
As discussed on the list. No automatic contents detection is done, the user
needs to use the special paste menu instead. I used the new TempFile class
for safe temporary file handling.
The documentation would go into section 2.2 of UserGuide.lyx, but I am not
allowed to edit that document.
2013-04-14 19:45:36 +02:00
Georg Baum
0613a218aa Also put HTML on the clipboard when copying
The HTML export is now mature enough so that it can be used to transfer
formatted text to the clipboard. This enhances interoperability e.g. with
office applications.
2013-04-12 22:12:47 +02:00
Lars Gullik Bjønnes
6b2232a29c src/*.cpp: reformatting to increase consistency 2012-10-28 17:42:07 +01:00
Lars Gullik Bjønnes
62394258da WS cleanup, remove extraeneous spaces 2012-10-27 01:25:38 +02:00
Jean-Marc Lasgouttes
ad7deaabeb Fix bug #7956: Assertion When Trying to Paste Into Table
For some unknown reason, the paste code likes to call Cursor::setSelection(), which is not appropriate here since we are not trying to set a selection at this point.
2012-06-04 17:05:43 +02:00
Richard Heck
ead697d4b6 Deal with memory issue reported some time ago in connection with DocumentClass
objects. The problem that led to the leak is that these objects can be held in
memory long after the Buffer that created them is gone, mostly due to their
use in the CutStack. So they were previously held in a storage facility, the
DocumentClassBundle. Unfortunately, they were now being created too often,
especially by cloning. It's not really a leak, because they're accessible, but
we weren't ever destroying them.

This new approach uses a shared_ptr instead.

Thanks to Vincent for pointing out const_pointer_cast.
2012-05-31 12:34:29 -04:00
Jean-Marc Lasgouttes
a756403301 "Performance" fixes suggested by cppcheck
While cppcheck did not turn out any suspicious error messages, using
the "performance" flag highlighted several nitpicks in three categories
 * do not use it++ for iterators, ++it is better
 * do not use size() to test for emptyness, empty() is here
 * do not use "const T" as a function parameter, "const & T" is better

I doubt that any of these is a real performance problem, but the code is cleaner anyway.
2012-05-28 22:42:44 +02:00
Vincent van Ravesteijn
6cf1847b31 New function BufferList::newInternalBuffer
This solves the problem that newBuffer() already use Buffer::isInternal
but there was no chance to set it yet.
2012-05-12 14:36:13 +02:00
Vincent van Ravesteijn
5279d5a8a5 Properly mark a buffer as internal
Checking the extension of the temporary filename doesn't work anymore
since the naming of temporary files was corrected.
2012-05-06 20:12:17 +02:00