[LyX/master] Prevent branch background color from leaking out of the document
Juergen Spitzmueller
spitz at lyx.org
Thu Jan 21 07:10:34 UTC 2021
commit 514cd879702dc946b75a4f688e3c67478a767a56
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Thu Jan 21 08:09:41 2021 +0100
Prevent branch background color from leaking out of the document
This is assured by a unique branchlist ID that is now part of the branch
color name
---
src/BranchList.cpp | 7 +++++--
src/BranchList.h | 13 ++++++++++++-
src/Buffer.cpp | 11 +----------
src/insets/InsetBranch.cpp | 5 ++++-
4 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/src/BranchList.cpp b/src/BranchList.cpp
index f21fec5..b9024e5 100644
--- a/src/BranchList.cpp
+++ b/src/BranchList.cpp
@@ -17,6 +17,7 @@
#include "frontends/Application.h"
+#include "support/convert.h"
#include "support/lstrings.h"
#include <algorithm>
@@ -125,7 +126,8 @@ void Branch::setColors(string const & lmcol, string const & dmcol)
dmcolor = lcolor.getX11HexName(lcolor.getFromLyXName(dmcolor), true);
// FIXME UNICODE
- lcolor.setColor(to_utf8(branch_), lmcolor, dmcolor);
+ lcolor.setColor("branch" + convert<string>(branch_list_id_)
+ + to_utf8(branch_), lmcolor, dmcolor);
}
@@ -174,6 +176,7 @@ bool BranchList::add(docstring const & s)
br.setBranch(name);
br.setSelected(false);
br.setFileNameSuffix(false);
+ br.setListID(id_);
list_.push_back(br);
}
if (j == docstring::npos)
@@ -200,7 +203,7 @@ bool BranchList::rename(docstring const & oldname,
if (find(newname)) {
// new name already taken
if (merge)
- return remove(oldname);
+ return remove(oldname);
return false;
}
diff --git a/src/BranchList.h b/src/BranchList.h
index 2c6d0eb..c221dc8 100644
--- a/src/BranchList.h
+++ b/src/BranchList.h
@@ -61,6 +61,8 @@ public:
/// Select/deselect filename suffix property.
void setFileNameSuffix(bool);
///
+ void setListID(int const id) { branch_list_id_ = id; }
+ ///
std::string const & color() const;
///
std::string const & lightModeColor() const;
@@ -77,6 +79,8 @@ public:
/// Set dark and light background colors
void setColors(std::string const & color,
std::string const & dmcolor = std::string());
+ ///
+ int listID() const { return branch_list_id_; }
private:
///
@@ -89,6 +93,8 @@ private:
std::string lmcolor_;
/// dark mode background color
std::string dmcolor_;
+ ///
+ int branch_list_id_;
};
@@ -99,12 +105,15 @@ public:
typedef List::const_iterator const_iterator;
///
- BranchList() : separator_(from_ascii("|")) {}
+ BranchList() : separator_(from_ascii("|")), id_(rand()) {}
///
docstring separator() const { return separator_; }
///
+ int id() const { return id_; }
+
+ ///
bool empty() const { return list_.empty(); }
///
void clear() { list_.clear(); }
@@ -139,6 +148,8 @@ private:
List list_;
///
docstring separator_;
+ ///
+ int id_;
};
} // namespace lyx
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 119e26d..7443931 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -2941,16 +2941,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
undo().recordUndoBufferParams(CursorData());
branch_list.add(branch_name);
branch = branch_list.find(branch_name);
- string x11hexname;
- string const bcolor = branch->color();
- if (bcolor.size() == 7 && bcolor[0] == '#')
- x11hexname = bcolor;
- else {
- bool const darkmode = theApp() ? theApp()->isInDarkMode() : false;
- x11hexname = lcolor.getX11HexName(lcolor.getFromLyXName(bcolor), darkmode);
- }
- docstring const str = branch_name + ' ' + from_ascii(x11hexname);
- lyx::dispatch(FuncRequest(LFUN_SET_COLOR, str));
+ branch->setColors("background", "background");
dr.setError(false);
dr.screenUpdate(Update::Force);
}
diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp
index c0d6bd3..95f7ba9 100644
--- a/src/insets/InsetBranch.cpp
+++ b/src/insets/InsetBranch.cpp
@@ -28,6 +28,7 @@
#include "TextClass.h"
#include "TocBackend.h"
+#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/lstrings.h"
@@ -134,7 +135,9 @@ ColorCode InsetBranch::backgroundColor(PainterInfo const & pi) const
if (params_.branch.empty())
return Inset::backgroundColor(pi);
// FIXME UNICODE
- ColorCode c = lcolor.getFromLyXName(to_utf8(params_.branch));
+ string const branchcol = "branch" + convert<string>(buffer().params().branchlist().id())
+ + to_utf8(params_.branch);
+ ColorCode c = lcolor.getFromLyXName(branchcol);
if (c == Color_none)
c = Color_error;
return c;
More information about the lyx-cvs
mailing list