mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 13:04:58 +00:00
implement undo for textclass switches in order to avoid a crash
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10190 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
275f6172ac
commit
4b7d477809
@ -1,8 +1,13 @@
|
|||||||
|
|
||||||
|
2005-05-07 André Pönitz <poenitz@gmx.net>
|
||||||
|
|
||||||
|
* undo.C (recordUndoFullBuffer): implement undo for
|
||||||
|
textclass switches
|
||||||
|
|
||||||
2005-05-07 André Pönitz <poenitz@gmx.net>
|
2005-05-07 André Pönitz <poenitz@gmx.net>
|
||||||
|
|
||||||
* cursor.C (setSelection): open insets when selection is set there
|
* cursor.C (setSelection): open insets when selection is set there
|
||||||
to avoid crashs with cold coord cache
|
to avoid crashs with cold coord cache
|
||||||
|
|
||||||
2005-05-07 André Pönitz <poenitz@gmx.net>
|
2005-05-07 André Pönitz <poenitz@gmx.net>
|
||||||
|
|
||||||
|
@ -213,8 +213,8 @@ Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Buffer::Buffer(string const & file, bool ronly)
|
Buffer::Buffer(string const & file, bool readonly)
|
||||||
: pimpl_(new Impl(*this, file, ronly))
|
: pimpl_(new Impl(*this, file, readonly))
|
||||||
{
|
{
|
||||||
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
|
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ int replaceAll(BufferView * bv,
|
|||||||
if (!searchAllowed(bv, searchstr) || buf.isReadonly())
|
if (!searchAllowed(bv, searchstr) || buf.isReadonly())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
recordUndoFullDocument(bv->cursor());
|
recordUndoFullDocument(bv);
|
||||||
|
|
||||||
MatchString const match(searchstr, cs, mw);
|
MatchString const match(searchstr, cs, mw);
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
@ -1455,6 +1455,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case LFUN_TEXTCLASS_APPLY: {
|
case LFUN_TEXTCLASS_APPLY: {
|
||||||
|
recordUndoFullDocument(view());
|
||||||
Buffer * buffer = owner->buffer();
|
Buffer * buffer = owner->buffer();
|
||||||
|
|
||||||
lyx::textclass_type const old_class =
|
lyx::textclass_type const old_class =
|
||||||
@ -1573,15 +1574,14 @@ void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & cmd)
|
|||||||
|
|
||||||
string const shortcuts = toplevel_keymap->printbindings(cmd);
|
string const shortcuts = toplevel_keymap->printbindings(cmd);
|
||||||
|
|
||||||
if (!shortcuts.empty()) {
|
if (!shortcuts.empty())
|
||||||
comname += ": " + shortcuts;
|
comname += ": " + shortcuts;
|
||||||
} else if (!argsadded && !cmd.argument.empty()) {
|
else if (!argsadded && !cmd.argument.empty())
|
||||||
comname += ' ' + cmd.argument;
|
comname += ' ' + cmd.argument;
|
||||||
}
|
|
||||||
|
|
||||||
if (!comname.empty()) {
|
if (!comname.empty()) {
|
||||||
comname = rtrim(comname);
|
comname = rtrim(comname);
|
||||||
dispatch_msg += '(' + comname + ')';
|
dispatch_msg += '(' + rtrim(comname) + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
|
lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
|
||||||
|
@ -88,7 +88,7 @@ string const latex_path(string const & original_path,
|
|||||||
{
|
{
|
||||||
string path = subst(original_path, "\\", "/");
|
string path = subst(original_path, "\\", "/");
|
||||||
path = subst(path, "~", "\\string~");
|
path = subst(path, "~", "\\string~");
|
||||||
if (path.find(' ') != string::npos)
|
if (path.find(' ') != string::npos) {
|
||||||
// We can't use '"' because " is sometimes active (e.g. if
|
// We can't use '"' because " is sometimes active (e.g. if
|
||||||
// babel is loaded with the "german" option)
|
// babel is loaded with the "german" option)
|
||||||
if (extension == EXCLUDE_EXTENSION) {
|
if (extension == EXCLUDE_EXTENSION) {
|
||||||
@ -97,11 +97,12 @@ string const latex_path(string const & original_path,
|
|||||||
// ChangeExtension calls os::internal_path internally
|
// ChangeExtension calls os::internal_path internally
|
||||||
// so don't use it to re-add the extension.
|
// so don't use it to re-add the extension.
|
||||||
path = "\\string\"" + base + "\\string\"." + ext;
|
path = "\\string\"" + base + "\\string\"." + ext;
|
||||||
} else
|
} else {
|
||||||
path = "\\string\"" + path + "\\string\"";
|
path = "\\string\"" + path + "\\string\"";
|
||||||
if (dots == ESCAPE_DOTS)
|
}
|
||||||
return subst(path, ".", "\\lyxdot ");
|
}
|
||||||
return path;
|
|
||||||
|
return dots == ESCAPE_DOTS ? subst(path, ".", "\\lyxdot ") : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -111,19 +112,18 @@ string const MakeLatexName(string const & file)
|
|||||||
string name = OnlyFilename(file);
|
string name = OnlyFilename(file);
|
||||||
string const path = OnlyPath(file);
|
string const path = OnlyPath(file);
|
||||||
|
|
||||||
for (string::size_type i = 0; i < name.length(); ++i) {
|
for (string::size_type i = 0; i < name.length(); ++i)
|
||||||
name[i] &= 0x7f; // set 8th bit to 0
|
name[i] &= 0x7f; // set 8th bit to 0
|
||||||
};
|
|
||||||
|
|
||||||
// ok so we scan through the string twice, but who cares.
|
// ok so we scan through the string twice, but who cares.
|
||||||
string const keep("abcdefghijklmnopqrstuvwxyz"
|
string const keep = "abcdefghijklmnopqrstuvwxyz"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"@!\"'()*+,-./0123456789:;<=>?[]`|");
|
"@!\"'()*+,-./0123456789:;<=>?[]`|";
|
||||||
|
|
||||||
string::size_type pos = 0;
|
string::size_type pos = 0;
|
||||||
while ((pos = name.find_first_not_of(keep, pos)) != string::npos) {
|
while ((pos = name.find_first_not_of(keep, pos)) != string::npos)
|
||||||
name[pos++] = '_';
|
name[pos++] = '_';
|
||||||
}
|
|
||||||
return AddName(path, name);
|
return AddName(path, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ bool IsDirWriteable(string const & path)
|
|||||||
{
|
{
|
||||||
lyxerr[Debug::FILES] << "IsDirWriteable: " << path << endl;
|
lyxerr[Debug::FILES] << "IsDirWriteable: " << path << endl;
|
||||||
|
|
||||||
string const tmpfl(tempName(path, "lyxwritetest"));
|
string const tmpfl = tempName(path, "lyxwritetest");
|
||||||
|
|
||||||
if (tmpfl.empty())
|
if (tmpfl.empty())
|
||||||
return false;
|
return false;
|
||||||
@ -175,7 +175,7 @@ string const FileOpenSearch(string const & path, string const & name,
|
|||||||
while (notfound && !path_element.empty()) {
|
while (notfound && !path_element.empty()) {
|
||||||
path_element = os::internal_path(path_element);
|
path_element = os::internal_path(path_element);
|
||||||
if (!suffixIs(path_element, '/'))
|
if (!suffixIs(path_element, '/'))
|
||||||
path_element+= '/';
|
path_element += '/';
|
||||||
path_element = subst(path_element, "$$LyX",
|
path_element = subst(path_element, "$$LyX",
|
||||||
package().system_support());
|
package().system_support());
|
||||||
path_element = subst(path_element, "$$User",
|
path_element = subst(path_element, "$$User",
|
||||||
@ -243,16 +243,12 @@ string const FileSearch(string const & path, string const & name,
|
|||||||
// search first without extension, then with it.
|
// search first without extension, then with it.
|
||||||
if (IsFileReadable(fullname))
|
if (IsFileReadable(fullname))
|
||||||
return fullname;
|
return fullname;
|
||||||
else if (ext.empty())
|
if (ext.empty())
|
||||||
return string();
|
return string();
|
||||||
else { // Is it not more reasonable to use ChangeExtension()? (SMiyata)
|
// Is it not more reasonable to use ChangeExtension()? (SMiyata)
|
||||||
fullname += '.';
|
fullname += '.';
|
||||||
fullname += ext;
|
fullname += ext;
|
||||||
if (IsFileReadable(fullname))
|
return IsFileReadable(fullname) ? fullname : string();
|
||||||
return fullname;
|
|
||||||
else
|
|
||||||
return string();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -278,8 +274,7 @@ string const LibFileSearch(string const & dir, string const & name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string const
|
string const i18nLibFileSearch(string const & dir, string const & name,
|
||||||
i18nLibFileSearch(string const & dir, string const & name,
|
|
||||||
string const & ext)
|
string const & ext)
|
||||||
{
|
{
|
||||||
// the following comments are from intl/dcigettext.c. We try
|
// the following comments are from intl/dcigettext.c. We try
|
||||||
@ -321,7 +316,7 @@ i18nLibFileSearch(string const & dir, string const & name,
|
|||||||
|
|
||||||
string const LibScriptSearch(string const & command_in)
|
string const LibScriptSearch(string const & command_in)
|
||||||
{
|
{
|
||||||
string const token_scriptpath("$$s/");
|
static string const token_scriptpath = "$$s/";
|
||||||
|
|
||||||
string command = command_in;
|
string command = command_in;
|
||||||
// Find the starting position of "$$s/"
|
// Find the starting position of "$$s/"
|
||||||
@ -360,7 +355,7 @@ string const createTmpDir(string const & tempdir, string const & mask)
|
|||||||
<< "createTmpDir: tempdir=`" << tempdir << "'\n"
|
<< "createTmpDir: tempdir=`" << tempdir << "'\n"
|
||||||
<< "createTmpDir: mask=`" << mask << '\'' << endl;
|
<< "createTmpDir: mask=`" << mask << '\'' << endl;
|
||||||
|
|
||||||
string const tmpfl(tempName(tempdir, mask));
|
string const tmpfl = tempName(tempdir, mask);
|
||||||
// lyx::tempName actually creates a file to make sure that it
|
// lyx::tempName actually creates a file to make sure that it
|
||||||
// stays unique. So we have to delete it before we can create
|
// stays unique. So we have to delete it before we can create
|
||||||
// a dir with the same name. Note also that we are not thread
|
// a dir with the same name. Note also that we are not thread
|
||||||
@ -437,28 +432,22 @@ string const createLyXTmpDir(string const & deflt)
|
|||||||
|
|
||||||
bool createDirectory(string const & path, int permission)
|
bool createDirectory(string const & path, int permission)
|
||||||
{
|
{
|
||||||
string temp(rtrim(os::internal_path(path), "/"));
|
string temp = rtrim(os::internal_path(path), "/");
|
||||||
|
|
||||||
BOOST_ASSERT(!temp.empty());
|
BOOST_ASSERT(!temp.empty());
|
||||||
|
return mkdir(temp, permission) == 0;
|
||||||
if (mkdir(temp, permission))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Strip filename from path name
|
// Strip filename from path name
|
||||||
string const OnlyPath(string const & Filename)
|
string const OnlyPath(string const & filename)
|
||||||
{
|
{
|
||||||
// If empty filename, return empty
|
// If empty filename, return empty
|
||||||
if (Filename.empty()) return Filename;
|
if (filename.empty())
|
||||||
|
return filename;
|
||||||
|
|
||||||
// Find last / or start of filename
|
// Find last / or start of filename
|
||||||
string::size_type j = Filename.rfind('/');
|
string::size_type j = filename.rfind('/');
|
||||||
if (j == string::npos)
|
return j == string::npos ? "./" : filename.substr(0, j + 1);
|
||||||
return "./";
|
|
||||||
return Filename.substr(0, j + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -472,7 +461,7 @@ string const MakeAbsPath(string const & RelPath, string const & BasePath)
|
|||||||
return RelPath;
|
return RelPath;
|
||||||
|
|
||||||
// Copies given paths
|
// Copies given paths
|
||||||
string TempRel(os::internal_path(RelPath));
|
string TempRel = os::internal_path(RelPath);
|
||||||
// Since TempRel is NOT absolute, we can safely replace "//" with "/"
|
// Since TempRel is NOT absolute, we can safely replace "//" with "/"
|
||||||
TempRel = subst(TempRel, "//", "/");
|
TempRel = subst(TempRel, "//", "/");
|
||||||
|
|
||||||
@ -488,7 +477,7 @@ string const MakeAbsPath(string const & RelPath, string const & BasePath)
|
|||||||
TempBase.erase(TempBase.length() - 2);
|
TempBase.erase(TempBase.length() - 2);
|
||||||
|
|
||||||
// processes relative path
|
// processes relative path
|
||||||
string RTemp(TempRel);
|
string RTemp = TempRel;
|
||||||
string Temp;
|
string Temp;
|
||||||
|
|
||||||
while (!RTemp.empty()) {
|
while (!RTemp.empty()) {
|
||||||
@ -500,12 +489,16 @@ string const MakeAbsPath(string const & RelPath, string const & BasePath)
|
|||||||
// Remove one level of TempBase
|
// Remove one level of TempBase
|
||||||
string::difference_type i = TempBase.length() - 2;
|
string::difference_type i = TempBase.length() - 2;
|
||||||
#ifndef __EMX__
|
#ifndef __EMX__
|
||||||
if (i < 0) i = 0;
|
if (i < 0)
|
||||||
while (i > 0 && TempBase[i] != '/') --i;
|
i = 0;
|
||||||
|
while (i > 0 && TempBase[i] != '/')
|
||||||
|
--i;
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
#else
|
#else
|
||||||
if (i < 2) i = 2;
|
if (i < 2)
|
||||||
while (i > 2 && TempBase[i] != '/') --i;
|
i = 2;
|
||||||
|
while (i > 2 && TempBase[i] != '/')
|
||||||
|
--i;
|
||||||
if (i > 2)
|
if (i > 2)
|
||||||
#endif
|
#endif
|
||||||
TempBase.erase(i, string::npos);
|
TempBase.erase(i, string::npos);
|
||||||
@ -532,9 +525,7 @@ string const MakeAbsPath(string const & RelPath, string const & BasePath)
|
|||||||
// Chops any path of filename.
|
// Chops any path of filename.
|
||||||
string const AddName(string const & path, string const & fname)
|
string const AddName(string const & path, string const & fname)
|
||||||
{
|
{
|
||||||
// Get basename
|
string const basename = OnlyFilename(fname);
|
||||||
string const basename(OnlyFilename(fname));
|
|
||||||
|
|
||||||
string buf;
|
string buf;
|
||||||
|
|
||||||
if (path != "." && path != "./" && !path.empty()) {
|
if (path != "." && path != "./" && !path.empty()) {
|
||||||
@ -569,38 +560,36 @@ bool AbsolutePath(string const & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Create absolute path. If impossible, don't do anything
|
// Create absolute path. If impossible, don't do anything
|
||||||
// Supports ./ and ~/. Later we can add support for ~logname/. (Asger)
|
// Supports ./ and ~/. Later we can add support for ~logname/. (Asger)
|
||||||
string const ExpandPath(string const & path)
|
string const ExpandPath(string const & path)
|
||||||
{
|
{
|
||||||
// checks for already absolute path
|
// checks for already absolute path
|
||||||
string RTemp(ReplaceEnvironmentPath(path));
|
string RTemp = ReplaceEnvironmentPath(path);
|
||||||
if (os::is_absolute_path(RTemp))
|
if (os::is_absolute_path(RTemp))
|
||||||
return RTemp;
|
return RTemp;
|
||||||
|
|
||||||
string Temp;
|
string Temp;
|
||||||
string const copy(RTemp);
|
string const copy = RTemp;
|
||||||
|
|
||||||
// Split by next /
|
// Split by next /
|
||||||
RTemp = split(RTemp, Temp, '/');
|
RTemp = split(RTemp, Temp, '/');
|
||||||
|
|
||||||
if (Temp == ".") {
|
if (Temp == ".")
|
||||||
return getcwd() + '/' + RTemp;
|
return getcwd() + '/' + RTemp;
|
||||||
}
|
|
||||||
if (Temp == "~") {
|
if (Temp == "~")
|
||||||
return package().home_dir() + '/' + RTemp;
|
return package().home_dir() + '/' + RTemp;
|
||||||
}
|
|
||||||
if (Temp == "..") {
|
if (Temp == "..")
|
||||||
return MakeAbsPath(copy);
|
return MakeAbsPath(copy);
|
||||||
}
|
|
||||||
// Don't know how to handle this
|
// Don't know how to handle this
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Normalize a path
|
// Normalize a path. Constracts path/../path
|
||||||
// Constracts path/../path
|
|
||||||
// Can't handle "../../" or "/../" (Asger)
|
// Can't handle "../../" or "/../" (Asger)
|
||||||
// Also converts paths like /foo//bar ==> /foo/bar
|
// Also converts paths like /foo//bar ==> /foo/bar
|
||||||
string const NormalizePath(string const & path)
|
string const NormalizePath(string const & path)
|
||||||
@ -613,7 +602,7 @@ string const NormalizePath(string const & path)
|
|||||||
RTemp = path;
|
RTemp = path;
|
||||||
else
|
else
|
||||||
// Make implicit current directory explicit
|
// Make implicit current directory explicit
|
||||||
RTemp = "./" +path;
|
RTemp = "./" + path;
|
||||||
|
|
||||||
// Normalise paths like /foo//bar ==> /foo/bar
|
// Normalise paths like /foo//bar ==> /foo/bar
|
||||||
boost::RegEx regex("/{2,}");
|
boost::RegEx regex("/{2,}");
|
||||||
@ -832,13 +821,13 @@ string const getFormatFromContents(string const & filename)
|
|||||||
return string();
|
return string();
|
||||||
|
|
||||||
// gnuzip
|
// gnuzip
|
||||||
string const gzipStamp = "\037\213";
|
static string const gzipStamp = "\037\213";
|
||||||
|
|
||||||
// PKZIP
|
// PKZIP
|
||||||
string const zipStamp = "PK";
|
static string const zipStamp = "PK";
|
||||||
|
|
||||||
// compress
|
// compress
|
||||||
string const compressStamp = "\037\235";
|
static string const compressStamp = "\037\235";
|
||||||
|
|
||||||
// Maximum strings to read
|
// Maximum strings to read
|
||||||
int const max_count = 50;
|
int const max_count = 50;
|
||||||
@ -857,7 +846,7 @@ string const getFormatFromContents(string const & filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
getline(ifs, str);
|
getline(ifs, str);
|
||||||
string const stamp = str.substr(0,2);
|
string const stamp = str.substr(0, 2);
|
||||||
if (firstLine && str.size() >= 2) {
|
if (firstLine && str.size() >= 2) {
|
||||||
// at first we check for a zipped file, because this
|
// at first we check for a zipped file, because this
|
||||||
// information is saved in the first bytes of the file!
|
// information is saved in the first bytes of the file!
|
||||||
@ -1008,8 +997,7 @@ string const unzipFile(string const & zipped_file, string const & unzipped_file)
|
|||||||
string const MakeDisplayPath(string const & path, unsigned int threshold)
|
string const MakeDisplayPath(string const & path, unsigned int threshold)
|
||||||
{
|
{
|
||||||
string str = path;
|
string str = path;
|
||||||
|
string const home = package().home_dir();
|
||||||
string const home(package().home_dir());
|
|
||||||
|
|
||||||
// replace /home/blah with ~/
|
// replace /home/blah with ~/
|
||||||
if (prefixIs(str, home))
|
if (prefixIs(str, home))
|
||||||
@ -1084,9 +1072,9 @@ cmd_ret const RunCommand(string const & cmd)
|
|||||||
|
|
||||||
// (Claus Hentschel) Check if popen was succesful ;-)
|
// (Claus Hentschel) Check if popen was succesful ;-)
|
||||||
if (!inf) {
|
if (!inf) {
|
||||||
return make_pair(-1, string());
|
|
||||||
lyxerr << "RunCommand:: could not start child process" << endl;
|
lyxerr << "RunCommand:: could not start child process" << endl;
|
||||||
}
|
return make_pair(-1, string());
|
||||||
|
}
|
||||||
|
|
||||||
string ret;
|
string ret;
|
||||||
int c = fgetc(inf);
|
int c = fgetc(inf);
|
||||||
@ -1194,8 +1182,7 @@ string const readBB_from_PSFile(string const & file)
|
|||||||
// %%BoundingBox: (atend)
|
// %%BoundingBox: (atend)
|
||||||
// In this case we must check the end.
|
// In this case we must check the end.
|
||||||
bool zipped = zippedFile(file);
|
bool zipped = zippedFile(file);
|
||||||
string const file_ = zipped ?
|
string const file_ = zipped ? unzipFile(file) : file;
|
||||||
string(unzipFile(file)) : string(file);
|
|
||||||
string const format = getFormatFromContents(file_);
|
string const format = getFormatFromContents(file_);
|
||||||
|
|
||||||
if (format != "eps" && format != "ps") {
|
if (format != "eps" && format != "ps") {
|
||||||
@ -1220,7 +1207,8 @@ string const readBB_from_PSFile(string const & file)
|
|||||||
|
|
||||||
int compare_timestamps(string const & file1, string const & file2)
|
int compare_timestamps(string const & file1, string const & file2)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(AbsolutePath(file1) && AbsolutePath(file2));
|
BOOST_ASSERT(AbsolutePath(file1));
|
||||||
|
BOOST_ASSERT(AbsolutePath(file2));
|
||||||
|
|
||||||
// If the original is newer than the copy, then copy the original
|
// If the original is newer than the copy, then copy the original
|
||||||
// to the new directory.
|
// to the new directory.
|
||||||
|
@ -492,7 +492,7 @@ vector<string> const getVectorFromString(string const & str,
|
|||||||
vector<string> vec;
|
vector<string> vec;
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
return vec;
|
return vec;
|
||||||
string keys(rtrim(str));
|
string keys = rtrim(str);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
string::size_type const idx = keys.find(delim);
|
string::size_type const idx = keys.find(delim);
|
||||||
if (idx == string::npos) {
|
if (idx == string::npos) {
|
||||||
|
97
src/undo.C
97
src/undo.C
@ -48,10 +48,12 @@ std::ostream & operator<<(std::ostream & os, Undo const & undo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void recordUndo(Undo::undo_kind kind,
|
void doRecordUndo(Undo::undo_kind kind,
|
||||||
DocIterator & cell,
|
DocIterator const & cell,
|
||||||
pit_type first_pit, pit_type last_pit,
|
pit_type first_pit, pit_type last_pit,
|
||||||
DocIterator & cur,
|
DocIterator const & cur,
|
||||||
|
BufferParams const & bparams,
|
||||||
|
bool isFullBuffer,
|
||||||
limited_stack<Undo> & stack)
|
limited_stack<Undo> & stack)
|
||||||
{
|
{
|
||||||
if (first_pit > last_pit)
|
if (first_pit > last_pit)
|
||||||
@ -61,6 +63,8 @@ void recordUndo(Undo::undo_kind kind,
|
|||||||
undo.kind = kind;
|
undo.kind = kind;
|
||||||
undo.cell = cell;
|
undo.cell = cell;
|
||||||
undo.cursor = cur;
|
undo.cursor = cur;
|
||||||
|
undo.bparams = bparams ;
|
||||||
|
undo.isFullBuffer = isFullBuffer;
|
||||||
lyxerr << "recordUndo: cur: " << cur << endl;
|
lyxerr << "recordUndo: cur: " << cur << endl;
|
||||||
lyxerr << "recordUndo: pos: " << cur.pos() << endl;
|
lyxerr << "recordUndo: pos: " << cur.pos() << endl;
|
||||||
//lyxerr << "recordUndo: cell: " << cell << endl;
|
//lyxerr << "recordUndo: cell: " << cell << endl;
|
||||||
@ -87,7 +91,7 @@ void recordUndo(Undo::undo_kind kind,
|
|||||||
// some more effort needed here as 'the whole cell' of the
|
// some more effort needed here as 'the whole cell' of the
|
||||||
// main LyXText _is_ the whole document.
|
// main LyXText _is_ the whole document.
|
||||||
// record the relevant paragraphs
|
// record the relevant paragraphs
|
||||||
LyXText * text = cell.text();
|
LyXText const * text = cell.text();
|
||||||
BOOST_ASSERT(text);
|
BOOST_ASSERT(text);
|
||||||
ParagraphList & plist = text->paragraphs();
|
ParagraphList & plist = text->paragraphs();
|
||||||
ParagraphList::iterator first = plist.begin();
|
ParagraphList::iterator first = plist.begin();
|
||||||
@ -113,15 +117,45 @@ void recordUndo(Undo::undo_kind kind,
|
|||||||
BOOST_ASSERT(first_pit <= cur.lastpit());
|
BOOST_ASSERT(first_pit <= cur.lastpit());
|
||||||
BOOST_ASSERT(last_pit <= cur.lastpit());
|
BOOST_ASSERT(last_pit <= cur.lastpit());
|
||||||
|
|
||||||
recordUndo(kind, cur, first_pit, last_pit, cur, stack);
|
doRecordUndo(kind, cur, first_pit, last_pit, cur,
|
||||||
|
cur.bv().buffer()->params(), false, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void performUndoOrRedo(BufferView & bv, Undo const & undo)
|
|
||||||
|
// Returns false if no undo possible.
|
||||||
|
bool textUndoOrRedo(BufferView & bv,
|
||||||
|
limited_stack<Undo> & stack, limited_stack<Undo> & otherstack)
|
||||||
{
|
{
|
||||||
|
finishUndo();
|
||||||
|
|
||||||
|
if (stack.empty()) {
|
||||||
|
// Nothing to do.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust undo stack and get hold of current undo data.
|
||||||
|
Undo undo = stack.top();
|
||||||
|
stack.pop();
|
||||||
|
|
||||||
|
// We will store in otherstack the part of the document under 'undo'
|
||||||
|
Buffer * buf = bv.buffer();
|
||||||
|
DocIterator cell_dit = undo.cell.asDocIterator(&buf->inset());
|
||||||
|
|
||||||
|
doRecordUndo(Undo::ATOMIC, cell_dit,
|
||||||
|
undo.from, cell_dit.lastpit() - undo.end, bv.cursor(),
|
||||||
|
undo.bparams, undo.isFullBuffer,
|
||||||
|
otherstack);
|
||||||
|
|
||||||
|
// This does the actual undo/redo.
|
||||||
//lyxerr << "undo, performing: " << undo << std::endl;
|
//lyxerr << "undo, performing: " << undo << std::endl;
|
||||||
DocIterator dit = undo.cell.asDocIterator(&bv.buffer()->inset());
|
DocIterator dit = undo.cell.asDocIterator(&buf->inset());
|
||||||
if (dit.inMathed()) {
|
if (undo.isFullBuffer) {
|
||||||
|
// This is a full document
|
||||||
|
otherstack.top().bparams = buf->params();
|
||||||
|
buf->params() = undo.bparams;
|
||||||
|
buf->paragraphs() = undo.pars;
|
||||||
|
} else if (dit.inMathed()) {
|
||||||
// We stored the full cell here as there is not much to be
|
// We stored the full cell here as there is not much to be
|
||||||
// gained by storing just 'a few' paragraphs (most if not
|
// gained by storing just 'a few' paragraphs (most if not
|
||||||
// all math inset cells have just one paragraph!)
|
// all math inset cells have just one paragraph!)
|
||||||
@ -148,42 +182,18 @@ void performUndoOrRedo(BufferView & bv, Undo const & undo)
|
|||||||
ParagraphList::const_iterator pit = undo.pars.begin();
|
ParagraphList::const_iterator pit = undo.pars.begin();
|
||||||
ParagraphList::const_iterator end = undo.pars.end();
|
ParagraphList::const_iterator end = undo.pars.end();
|
||||||
for (; pit != end; ++pit)
|
for (; pit != end; ++pit)
|
||||||
const_cast<Paragraph &>(*pit).setInsetOwner(dynamic_cast<UpdatableInset *>(&dit.inset()));
|
const_cast<Paragraph &>(*pit).setInsetOwner(
|
||||||
|
dynamic_cast<UpdatableInset *>(&dit.inset()));
|
||||||
plist.insert(first, undo.pars.begin(), undo.pars.end());
|
plist.insert(first, undo.pars.begin(), undo.pars.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set cursor
|
||||||
LCursor & cur = bv.cursor();
|
LCursor & cur = bv.cursor();
|
||||||
cur.setCursor(undo.cursor.asDocIterator(&bv.buffer()->inset()));
|
cur.setCursor(undo.cursor.asDocIterator(&buf->inset()));
|
||||||
cur.selection() = false;
|
cur.selection() = false;
|
||||||
cur.resetAnchor();
|
cur.resetAnchor();
|
||||||
finishUndo();
|
finishUndo();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Returns false if no undo possible.
|
|
||||||
bool textUndoOrRedo(BufferView & bv,
|
|
||||||
limited_stack<Undo> & stack, limited_stack<Undo> & otherstack)
|
|
||||||
{
|
|
||||||
finishUndo();
|
|
||||||
|
|
||||||
if (stack.empty()) {
|
|
||||||
// Nothing to do.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adjust undo stack and get hold of current undo data.
|
|
||||||
Undo undo = stack.top();
|
|
||||||
stack.pop();
|
|
||||||
|
|
||||||
// We will store in otherstack the part of the document under 'undo'
|
|
||||||
DocIterator cell_dit = undo.cell.asDocIterator(&bv.buffer()->inset());
|
|
||||||
|
|
||||||
recordUndo(Undo::ATOMIC, cell_dit,
|
|
||||||
undo.from, cell_dit.lastpit() - undo.end,
|
|
||||||
bv.cursor(), otherstack);
|
|
||||||
|
|
||||||
// This does the actual undo/redo.
|
|
||||||
performUndoOrRedo(bv, undo);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,8 +266,17 @@ void recordUndo(LCursor & cur, Undo::undo_kind kind,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void recordUndoFullDocument(LCursor & cur)
|
void recordUndoFullDocument(BufferView * bv)
|
||||||
{
|
{
|
||||||
recordUndo(Undo::ATOMIC, cur, 0,
|
Buffer * buf = bv->buffer();
|
||||||
cur.bv().text()->paragraphs().size() - 1);
|
doRecordUndo(
|
||||||
|
Undo::ATOMIC,
|
||||||
|
doc_iterator_begin(buf->inset()),
|
||||||
|
0, buf->paragraphs().size() - 1,
|
||||||
|
bv->cursor(),
|
||||||
|
buf->params(),
|
||||||
|
true,
|
||||||
|
buf->undostack()
|
||||||
|
);
|
||||||
|
undo_finished = false;
|
||||||
}
|
}
|
||||||
|
12
src/undo.h
12
src/undo.h
@ -18,13 +18,15 @@
|
|||||||
|
|
||||||
#include "dociterator.h"
|
#include "dociterator.h"
|
||||||
#include "ParagraphList_fwd.h"
|
#include "ParagraphList_fwd.h"
|
||||||
|
#include "bufferparams.h"
|
||||||
|
|
||||||
#include "support/types.h"
|
#include "support/types.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class LCursor;
|
class BufferParams;
|
||||||
class BufferView;
|
class BufferView;
|
||||||
|
class LCursor;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,6 +83,10 @@ public:
|
|||||||
ParagraphList pars;
|
ParagraphList pars;
|
||||||
/// the stringified contents of the saved MathArray (for mathed)
|
/// the stringified contents of the saved MathArray (for mathed)
|
||||||
std::string array;
|
std::string array;
|
||||||
|
/// Only used in case of full backups
|
||||||
|
BufferParams bparams;
|
||||||
|
/// Only used in case of full backups
|
||||||
|
bool isFullBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -116,7 +122,7 @@ void recordUndoInset(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
|||||||
/// Convenience: prepare undo for the selected paragraphs
|
/// Convenience: prepare undo for the selected paragraphs
|
||||||
void recordUndoSelection(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
void recordUndoSelection(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
|
||||||
|
|
||||||
/// Convenience: prepare undo for the single paragraph containing the cursor
|
/// Convenience: prepare undo for the whole buffer
|
||||||
void recordUndoFullDocument(LCursor & cur);
|
void recordUndoFullDocument(BufferView * bv);
|
||||||
|
|
||||||
#endif // UNDO_FUNCS_H
|
#endif // UNDO_FUNCS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user