http://bugzilla.lyx.org/show_bug.cgi?id=2423

This patch should finally fix bug 2423. What it does is add a new
signal focusChange to WorkArea and emit it from
QContentPane::focusIn/Out.

The action on focus change is to update the toolbars. 

This seems to work well for me. Of course, the way icons get
enabled/disabled may seem arbitrary, but at least the annoying bug is
gone.

I guess this will need adaptations for the new world of 1.5, but the
idea is simple.

JMarc

Index: src/BufferView_pimpl.C
===================================================================
--- src/BufferView_pimpl.C	(revision 14801)
+++ src/BufferView_pimpl.C	(working copy)
@@ -122,6 +122,7 @@ boost::signals::connection resizecon;
 boost::signals::connection kpresscon;
 boost::signals::connection selectioncon;
 boost::signals::connection lostcon;
+boost::signals::connection focuscon;
 
 
 /// Return an inset of this class if it exists at the current cursor position
@@ -164,6 +165,8 @@ BufferView::Pimpl::Pimpl(BufferView & bv
 		.connect(boost::bind(&BufferView::Pimpl::selectionRequested, this));
 	lostcon = workarea().selectionLost
 		.connect(boost::bind(&BufferView::Pimpl::selectionLost, this));
+	focuscon = workarea().focusChange
+		.connect(boost::bind(&BufferView::Pimpl::focusChange, this));
 
 	timecon = cursor_timeout.timeout
 		.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
@@ -612,6 +615,12 @@ void BufferView::Pimpl::selectionLost()
 }
 
 
+void BufferView::Pimpl::focusChange()
+{
+	owner_->updateToolbars();
+}
+
+
 void BufferView::Pimpl::workAreaResize()
 {
 	static int work_area_width;
Index: src/BufferView_pimpl.h
===================================================================
--- src/BufferView_pimpl.h	(revision 14801)
+++ src/BufferView_pimpl.h	(working copy)
@@ -82,6 +82,8 @@ public:
 	///
 	void selectionLost();
 	///
+	void focusChange();
+	///
 	void cursorToggle();
 	///
 	bool available() const;
Index: src/frontends/WorkArea.h
===================================================================
--- src/frontends/WorkArea.h	(revision 14801)
+++ src/frontends/WorkArea.h	(working copy)
@@ -74,6 +74,8 @@ public:
 	boost::signal<void()> selectionRequested;
 	/// emitted when another X client has stolen our selection
 	boost::signal<void()> selectionLost;
+	/// emitted when workarea got/lost focus
+	boost::signal<void()> focusChange;
 };
 
 #endif // WORKAREA_H
Index: src/frontends/qt2/QContentPane.h
===================================================================
--- src/frontends/qt2/QContentPane.h	(revision 14801)
+++ src/frontends/qt2/QContentPane.h	(working copy)
@@ -112,6 +112,10 @@ protected:
 	void wheelEvent(QWheelEvent * e);
 	/// key press
 	void keyPressEvent(QKeyEvent * e);
+	/// focus in
+	virtual void focusInEvent(QFocusEvent * ev);
+	/// focus out
+	virtual void focusOutEvent(QFocusEvent * ev);
 #if USE_INPUT_METHODS
 	/// IM events
 	void imStartEvent(QIMEvent *);
Index: src/frontends/qt2/QContentPane.C
===================================================================
--- src/frontends/qt2/QContentPane.C	(revision 14801)
+++ src/frontends/qt2/QContentPane.C	(working copy)
@@ -17,6 +17,8 @@
 #include "QContentPane.h"
 #include "QLyXKeySym.h"
 
+#include "debug.h"
+
 #include <qapplication.h>
 #include <qpainter.h>
 
@@ -351,6 +353,20 @@ void QContentPane::paintEvent(QPaintEven
 }
 
 
+void QContentPane::focusInEvent(QFocusEvent * ev)
+{
+	QWidget::focusInEvent(ev);
+	wa_->focusChange();
+}
+
+
+void QContentPane::focusOutEvent(QFocusEvent * ev)
+{
+	QWidget::focusOutEvent(ev);
+	wa_->focusChange();
+}
+
+
 void QContentPane::trackScrollbar(bool track_on)
 {
 	track_scrollbar_ = track_on;

Reply via email to