[Xfce4-commits] <mousepad:master> Fix kludge from last commit (FIXME comment).

Matthew Brush noreply at xfce.org
Sat May 5 21:31:42 CEST 2012


Updating branch refs/heads/master
         to 349066029e579a6dc1014aff3759e0f78ec52eb7 (commit)
       from ba38b4940b2998c30ba9bde6c707bf1c589cae0b (commit)

commit 349066029e579a6dc1014aff3759e0f78ec52eb7
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Mon Oct 3 23:47:52 2011 -0700

    Fix kludge from last commit (FIXME comment).
    
    Add a new signal 'language-changed' to MousepadDocument for the window
    to use to get notified of when to update the language/filetype in the
    statusbar.

 mousepad/mousepad-document.c |   35 +++++++++++++++++++++++++++++++++++
 mousepad/mousepad-window.c   |   23 +++++++++++++++++------
 2 files changed, 52 insertions(+), 6 deletions(-)

diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c
index 1f80b12..843cd14 100644
--- a/mousepad/mousepad-document.c
+++ b/mousepad/mousepad-document.c
@@ -52,6 +52,9 @@ static void      mousepad_document_notify_has_selection    (GtkTextBuffer
 static void      mousepad_document_notify_overwrite        (GtkTextView            *textview,
                                                             GParamSpec             *pspec,
                                                             MousepadDocument       *document);
+static void      mousepad_document_notify_language         (GtkSourceBuffer        *buffer,
+                                                            GParamSpec             *pspec,
+                                                            MousepadDocument       *document);
 static void      mousepad_document_drag_data_received      (GtkWidget              *widget,
                                                             GdkDragContext         *context,
                                                             gint                    x,
@@ -73,6 +76,7 @@ enum
   CURSOR_CHANGED,
   SELECTION_CHANGED,
   OVERWRITE_CHANGED,
+  LANGUAGE_CHANGED,
   LAST_SIGNAL
 };
 
@@ -156,6 +160,14 @@ mousepad_document_class_init (MousepadDocumentClass *klass)
                   0, NULL, NULL,
                   g_cclosure_marshal_VOID__BOOLEAN,
                   G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+  
+  document_signals[LANGUAGE_CHANGED] =
+    g_signal_new (I_("language-changed"),
+                  G_TYPE_FROM_CLASS (gobject_class),
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL,
+                  g_cclosure_marshal_VOID__OBJECT,
+                  G_TYPE_NONE, 1, GTK_TYPE_SOURCE_LANGUAGE);
 }
 
 
@@ -246,6 +258,7 @@ mousepad_document_init (MousepadDocument *document)
   g_signal_connect_swapped (G_OBJECT (document->file), "readonly-changed", G_CALLBACK (mousepad_document_label_color), document);
   g_signal_connect (G_OBJECT (document->textview), "notify::overwrite", G_CALLBACK (mousepad_document_notify_overwrite), document);
   g_signal_connect (G_OBJECT (document->textview), "drag-data-received", G_CALLBACK (mousepad_document_drag_data_received), document);
+  g_signal_connect (G_OBJECT (document->buffer), "notify::language", G_CALLBACK (mousepad_document_notify_language), document);
 }
 
 
@@ -351,6 +364,25 @@ mousepad_document_notify_overwrite (GtkTextView      *textview,
 
 
 static void
+mousepad_document_notify_language (GtkSourceBuffer  *buffer,
+                                   GParamSpec       *pspec,
+                                   MousepadDocument *document)
+{
+  GtkSourceLanguage *language;
+  
+  mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (document));
+  mousepad_return_if_fail (GTK_IS_SOURCE_BUFFER (buffer));
+  
+  /* the new language */
+  language = gtk_source_buffer_get_language (buffer);
+  
+  /* emit the signal */
+  g_signal_emit (G_OBJECT (document), document_signals[LANGUAGE_CHANGED], 0, language);
+}
+
+
+
+static void
 mousepad_document_drag_data_received (GtkWidget        *widget,
                                       GdkDragContext   *context,
                                       gint              x,
@@ -510,6 +542,9 @@ mousepad_document_send_signals (MousepadDocument *document)
 
   /* re-send the selection status */
   mousepad_document_notify_has_selection (document->buffer, NULL, document);
+  
+  /* re-send the language signal */
+  mousepad_document_notify_language (GTK_SOURCE_BUFFER (document->buffer), NULL, document);
 }
 
 
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 54a3520..45a9f82 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -152,6 +152,9 @@ static void              mousepad_window_selection_changed            (MousepadD
 static void              mousepad_window_overwrite_changed            (MousepadDocument       *document,
                                                                        gboolean                overwrite,
                                                                        MousepadWindow         *window);
+static void              mousepad_window_language_changed             (MousepadDocument       *document,
+                                                                       GtkSourceLanguage      *language,
+                                                                       MousepadWindow         *window);
 static void              mousepad_window_can_undo                     (MousepadWindow         *window,
                                                                        GParamSpec             *unused,
                                                                        GObject                *buffer);
@@ -1307,7 +1310,6 @@ mousepad_window_notebook_switch_page (GtkNotebook     *notebook,
                                       MousepadWindow  *window)
 {
   MousepadDocument  *document;
-  GtkSourceLanguage *language;
 
   mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
   mousepad_return_if_fail (GTK_IS_NOTEBOOK (notebook));
@@ -1329,11 +1331,6 @@ mousepad_window_notebook_switch_page (GtkNotebook     *notebook,
 
       /* update the statusbar */
       mousepad_document_send_signals (window->active);
-      
-      /* set the filetype in the status bar 
-       * FIXME: this doesn't belong here */
-      language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (window->active->buffer));
-      mousepad_statusbar_set_language (MOUSEPAD_STATUSBAR (window->statusbar), language);
     }
 }
 
@@ -1372,6 +1369,7 @@ mousepad_window_notebook_added (GtkNotebook     *notebook,
   g_signal_connect (G_OBJECT (page), "cursor-changed", G_CALLBACK (mousepad_window_cursor_changed), window);
   g_signal_connect (G_OBJECT (page), "selection-changed", G_CALLBACK (mousepad_window_selection_changed), window);
   g_signal_connect (G_OBJECT (page), "overwrite-changed", G_CALLBACK (mousepad_window_overwrite_changed), window);
+  g_signal_connect (G_OBJECT (page), "language-changed", G_CALLBACK (mousepad_window_language_changed), window);
   g_signal_connect (G_OBJECT (page), "drag-data-received", G_CALLBACK (mousepad_window_drag_data_received), window);
   g_signal_connect_swapped (G_OBJECT (document->buffer), "notify::can-undo", G_CALLBACK (mousepad_window_can_undo), window);
   g_signal_connect_swapped (G_OBJECT (document->buffer), "notify::can-redo", G_CALLBACK (mousepad_window_can_redo), window);
@@ -1412,6 +1410,7 @@ mousepad_window_notebook_removed (GtkNotebook     *notebook,
   g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_cursor_changed, window);
   g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_selection_changed, window);
   g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_overwrite_changed, window);
+  g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_language_changed, window);
   g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_drag_data_received, window);
   g_signal_handlers_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_can_undo, window);
   g_signal_handlers_disconnect_by_func (G_OBJECT (document->buffer), mousepad_window_can_redo, window);
@@ -1682,6 +1681,18 @@ mousepad_window_overwrite_changed (MousepadDocument *document,
 
 
 static void
+mousepad_window_language_changed (MousepadDocument  *document,
+                                  GtkSourceLanguage *language,
+                                  MousepadWindow    *window)
+{
+  /* set the filetype in the statusbar */
+  if (window->statusbar)
+    mousepad_statusbar_set_language (MOUSEPAD_STATUSBAR (window->statusbar), language);
+}
+
+
+
+static void
 mousepad_window_can_undo (MousepadWindow *window,
                           GParamSpec     *unused,
                           GObject        *buffer)


More information about the Xfce4-commits mailing list