Attached is a fix for the branches color issues in qt (1. branches color was 
not immediately updated, buffer reload was necessary; 2. new branches had 
black background). Everything works as expected now.

Martin, I have introduced a setColor() function in ControlDocument, similar to 
the one in ControlPrefs. I think you could use that also in the xforms 
frontend, instead of the colorhandler thing you have now.
BTW do you have any idea why (un)collapsing branches sets the document's state 
to "changed"?

If I'll get no objections I will commit this on monday.

Jürgen.
Index: src/frontends/controllers/ControlDocument.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlDocument.C,v
retrieving revision 1.41
diff -u -r1.41 ControlDocument.C
--- src/frontends/controllers/ControlDocument.C	6 Oct 2003 15:42:45 -0000	1.41
+++ src/frontends/controllers/ControlDocument.C	25 Oct 2003 12:35:25 -0000
@@ -24,6 +24,9 @@
 #include "language.h"
 #include "lyxtextclasslist.h"
 #include "paragraph.h"
+#include "funcrequest.h"
+#include "LColor.h"
+#include "lfuns.h"

 #include "frontends/Alert.h"
 #include "frontends/LyXView.h"
@@ -115,6 +118,13 @@
 		else
 		    lv_.buffer()->updateDocLang(newL);
 	}
+}
+
+
+void ControlDocument::setColor(LColor_color col, string const & hex)
+{
+	string const s = lcolor.getLyXName(col) + ' ' + hex;
+	lv_.dispatch(FuncRequest(LFUN_SET_COLOR, s));
 }
 
 
Index: src/frontends/controllers/ControlDocument.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlDocument.h,v
retrieving revision 1.9
diff -u -r1.9 ControlDocument.h
--- src/frontends/controllers/ControlDocument.h	9 Sep 2003 11:24:22 -0000	1.9
+++ src/frontends/controllers/ControlDocument.h	25 Oct 2003 12:35:25 -0000
@@ -20,6 +20,7 @@
 
 class BufferParams;
 class Language;
+class LColor_color;
 class LyXTextClass;
 
 
@@ -33,6 +34,8 @@
 	~ControlDocument();
 	///
 	void setLanguage();
+	///
+	void setColor(LColor_color col, std::string const & hex);
 	///
 	LyXTextClass textClass();
 	///
Index: src/frontends/qt2/QDocument.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QDocument.C,v
retrieving revision 1.61
diff -u -r1.61 QDocument.C
--- src/frontends/qt2/QDocument.C	23 Oct 2003 11:58:00 -0000	1.61
+++ src/frontends/qt2/QDocument.C	25 Oct 2003 12:35:27 -0000
@@ -27,6 +27,7 @@
 #include "support/lstrings.h"
 #include "lyxtextclasslist.h"
 #include "floatplacement.h"
+#include "LColor.h"
 
 #include <qpushbutton.h>
 #include <qmultilineedit.h>
@@ -38,6 +39,7 @@
 
 
 using lyx::support::bformat;
+using lyx::support::getVectorFromString;
 
 using std::vector;
 using std::string;
@@ -375,6 +377,27 @@
 	params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
 
 	params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
+
+	// branches
+	string const all_branches = params.branchlist().allBranches();
+	if (!all_branches.empty()) {
+		std::vector<string> all = getVectorFromString(all_branches, "|");
+		for (unsigned i = 0; i < all.size(); ++i) {
+			string const current_branch = all[i].c_str();
+			LColor::color col = lcolor.getFromLyXName(current_branch);
+			string x11hexname = params.branchlist().getColor(current_branch);
+			// check that we have a valid color!
+			if (x11hexname[0] != '#')
+				x11hexname = lcolor.getX11Name(LColor::background);
+			lcolor.setColor(current_branch, x11hexname);
+			// display the new color
+			controller().setColor(col, x11hexname);
+		}
+	}
+	if (branchlist_.empty())
+		branchlist_ = params.branchlist();
+	params.branchlist() = branchlist_;
+	branchlist_.clear();
 }
 
 
Index: src/frontends/qt2/QDocumentDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QDocumentDialog.C,v
retrieving revision 1.39
diff -u -r1.39 QDocumentDialog.C
--- src/frontends/qt2/QDocumentDialog.C	23 Oct 2003 11:58:00 -0000	1.39
+++ src/frontends/qt2/QDocumentDialog.C	25 Oct 2003 12:35:28 -0000
@@ -426,7 +426,6 @@
 	BufferParams & params = cntrl.params();
 
 	string const all_branches = params.branchlist().allBranches();
-	string const all_selected = params.branchlist().allSelected();
 	branchesModule->branchesLV->clear();
 	if (!all_branches.empty()) {
 		std::vector<string> all = getVectorFromString(all_branches, "|");
@@ -445,6 +444,7 @@
 			newItem->setPixmap(2, coloritem);
 		}
 	}
+	form_->branchlist_ = params.branchlist();
 	form_->changed();
 }
 
@@ -514,16 +514,14 @@
 		sel_branch = selItem->text(0);
 	if (sel_branch) {
 		QColor initial;
-		string x11hexname = params.branchlist().getColor(fromqstr(sel_branch));
+		string current_branch = fromqstr(sel_branch);
+		string x11hexname = params.branchlist().getColor(current_branch);
 		if (x11hexname[0] == '#')
 			initial.setNamedColor(toqstr(x11hexname));
 		QColor ncol(QColorDialog::getColor(initial));
 		if (ncol.isValid()){
-			// FIXME: The color does not apply unless buffer restart
-			// XForms has this hack. What can we do?
-			// lyxColorHandler->getGCForeground(c);
-			// lyxColorHandler->updateColor(c);
-			params.branchlist().setColor(fromqstr(sel_branch), fromqstr(ncol.name()));
+			// add the color to the branchlist
+			params.branchlist().setColor(current_branch, fromqstr(ncol.name()));
 			branchesModule->newBranchLE->clear();
 			updateBranchView();
 		}

Reply via email to