[nemiver] Fix clicking in the gutter with gsv >= 2.10



commit 9408baf02ed2e0a96ed2f55343396ca367a06a65
Author: Dodji Seketeli <dodji redhat com>
Date:   Mon Jul 19 07:39:42 2010 +0200

    Fix clicking in the gutter with gsv >= 2.10
    
    	* configure.ac (WITH_SOURCEVIEWMM_2_10): New macro defined when
    	Nemiver is compiled with a version of gtksourceview-2 >= 2.10.
    	* src/uicommon/nmv-source-editor.cc
    	(nemiver::on_line_mark_activated_signal): New callback.
    	(nemiver::SourceView::SourceView): Use it. Connect to the
    	line-mark-activated signal if we are compiled with a
    	gtksourceview-2 >= 2.10
    	(nemiver::SoureView::do_custom_button_press_event_handling): Don't
    	compile this function if we compile against a gtksourceview-2 < 2.10.
    	(nemiver::SourceView::on_button_press_event): Don't call
    	do_custom_button_press_event_handling if we compile against
    	gtksourceview-2 < 2.10

 configure.ac                      |    4 +++
 src/uicommon/nmv-source-editor.cc |   54 ++++++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ed432f9..0faa514 100644
--- a/configure.ac
+++ b/configure.ac
@@ -169,6 +169,10 @@ if test x$ENABLE_SOURCEVIEWMM2 = xyes ; then
     AC_DEFINE([WITH_SOURCEVIEWMM2], 1, [build with gtksourceviewmm 2.x instead of 1.x])
     LIBGTKSOURCEVIEWMM_VERSION=$LIBGTKSOURCEVIEWMM2_VERSION
     LIBGTKSOURCEVIEWMM_PKG=gtksourceviewmm-2.0
+    PKG_CHECK_EXISTS([gtksourceviewmm-2.0 >= 2.10], [ENABLE_SOURCEVIEW_2_10=yes], [ENABLE_SOURCEVIEW_2_10=no])
+    if test x$ENABLE_SOURCEVIEW_2_10 = xyes; then
+       AC_DEFINE(WITH_SOURCEVIEW_2_10, 1, [build with gtksourceview higher than 2.10])
+    fi
 else
     ENABLE_SOURCEVIEWMM2=no
     LIBGTKSOURCEVIEWMM_VERSION=$LIBGTKSOURCEVIEWMM1_VERSION
diff --git a/src/uicommon/nmv-source-editor.cc b/src/uicommon/nmv-source-editor.cc
index ae68daa..8d712eb 100644
--- a/src/uicommon/nmv-source-editor.cc
+++ b/src/uicommon/nmv-source-editor.cc
@@ -51,10 +51,24 @@ const char* WHERE_CATEGORY = "line-pointer-category";
 
 const char* WHERE_MARK = "where-marker";
 
+#ifdef WITH_SOURCEVIEW_2_10
+void
+on_line_mark_activated_signal (GtkSourceView *a_view,
+                               GtkTextIter *a_iter,
+                               GdkEvent *a_event,
+                               gpointer a_pointer);
+#endif
+
 class SourceView : public gtksourceview::SourceView
 {
 
     sigc::signal<void, int, bool> m_marker_region_got_clicked_signal;
+#ifdef WITH_SOURCEVIEW_2_10
+    friend void on_line_mark_activated_signal (GtkSourceView *a_view,
+                                               GtkTextIter *a_iter,
+                                               GdkEvent *a_event,
+                                               gpointer a_pointer);
+#endif
 
 public:
     SourceView (Glib::RefPtr<SourceBuffer> &a_buf) :
@@ -62,6 +76,12 @@ public:
     {
         init_font ();
         enable_events ();
+#ifdef WITH_SOURCEVIEW_2_10
+        g_signal_connect (gobj (),
+                          "line-mark-activated",
+                          G_CALLBACK (&on_line_mark_activated_signal),
+                          this);
+#endif
     }
 
     SourceView () :
@@ -82,15 +102,18 @@ public:
                     |Gdk::BUTTON_PRESS_MASK);
     }
 
+#if (WITH_SOURCEVIEWMM2 && !WITH_SOURCEVIEW_2_10)
     void do_custom_button_press_event_handling (GdkEventButton *a_event)
     {
         THROW_IF_FAIL (a_event);
 
-        if (a_event->type == GDK_BUTTON_PRESS && a_event->button != 1) {
+        if (a_event->type == GDK_BUTTON_PRESS
+            && a_event->button != 1) {
+            // We are only intersted in the left button press here
             return;
         }
         Glib::RefPtr<Gdk::Window> markers_window =
-                                        get_window (Gtk::TEXT_WINDOW_LEFT);
+            get_window (Gtk::TEXT_WINDOW_LEFT);
         THROW_IF_FAIL (markers_window);
 
         if (markers_window.operator->()->gobj () != a_event->window) {
@@ -112,14 +135,20 @@ public:
         marker_region_got_clicked_signal ().emit (iter.get_line () + 1,
                                                   false/*no dialog requested*/);
     }
+#endif
+
 
     bool on_button_press_event (GdkEventButton *a_event)
     {
-        if (a_event->type == GDK_BUTTON_PRESS && a_event->button == 3) {
+        if (a_event->type == GDK_BUTTON_PRESS
+            && a_event->button == 3) {
+            // The right button has been pressed. Get out.
             return false;
         } else {
             Gtk::Widget::on_button_press_event (a_event);
+#if (WITH_SOURCEVIEWMM2 && !WITH_SOURCEVIEW_2_10)            
             do_custom_button_press_event_handling (a_event);
+#endif
             return false;
         }
     }
@@ -131,6 +160,25 @@ public:
 
 };//end class Sourceview
 
+#if WITH_SOURCEVIEW_2_10
+void
+on_line_mark_activated_signal (GtkSourceView *a_view,
+                               GtkTextIter *a_iter,
+                               GdkEvent *a_event,
+                               gpointer a_pointer)
+{
+    RETURN_IF_FAIL (a_view && a_iter && a_event && a_pointer);
+
+    SourceView *sv = static_cast<SourceView*> (a_pointer);
+
+    if (a_event->type == GDK_BUTTON_PRESS
+        && ((GdkEventButton*)a_event)->button == 1)
+        sv->marker_region_got_clicked_signal ().emit
+            (gtk_text_iter_get_line (a_iter) + 1,
+             false/*No dialog requested*/);
+}
+#endif
+
 struct SourceEditor::Priv {
     Sequence sequence;
     UString root_dir;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]