[Xfce4-commits] <mousepad:master> Update statusbar filetype when notebook pages are changed.

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


Updating branch refs/heads/master
         to ba38b4940b2998c30ba9bde6c707bf1c589cae0b (commit)
       from 82b6e834ddeea4be8bf901307e6e093bde24631c (commit)

commit ba38b4940b2998c30ba9bde6c707bf1c589cae0b
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Mon Oct 3 22:33:51 2011 -0700

    Update statusbar filetype when notebook pages are changed.
    
    Note the FIXME in the comments, this will probably need some refactoring.

 mousepad/mousepad-statusbar.c |   31 +++++++++++++++++++++++++++++++
 mousepad/mousepad-statusbar.h |    3 +++
 mousepad/mousepad-window.c    |    8 +++++++-
 3 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/mousepad/mousepad-statusbar.c b/mousepad/mousepad-statusbar.c
index 9ed0d94..a7da0f8 100644
--- a/mousepad/mousepad-statusbar.c
+++ b/mousepad/mousepad-statusbar.c
@@ -50,6 +50,7 @@ struct _MousepadStatusbar
   guint               overwrite_enabled : 1;
 
   /* extra labels in the statusbar */
+  GtkWidget          *language;
   GtkWidget          *position;
   GtkWidget          *overwrite;
 };
@@ -119,6 +120,16 @@ mousepad_statusbar_init (MousepadStatusbar *statusbar)
   separator = gtk_vseparator_new ();
   gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
   gtk_widget_show (separator);
+  
+  /* language/filetype */
+  statusbar->language = gtk_label_new (_("Filetype: None"));
+  gtk_box_pack_start (GTK_BOX (box), statusbar->language, FALSE, TRUE, 0);
+  gtk_widget_show (statusbar->language);
+
+  /* separator */
+  separator = gtk_vseparator_new ();
+  gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
+  gtk_widget_show (separator);
 
   /* line and column numbers */
   statusbar->position = gtk_label_new (NULL);
@@ -169,6 +180,26 @@ mousepad_statusbar_overwrite_clicked (GtkWidget         *widget,
 
 
 void
+mousepad_statusbar_set_language (MousepadStatusbar *statusbar,
+                                 GtkSourceLanguage *language)
+{
+  gchar *label;
+  
+  mousepad_return_if_fail (MOUSEPAD_IS_STATUSBAR (statusbar));
+  
+  if (language == NULL)
+      gtk_label_set_text (GTK_LABEL (statusbar->language), _("Filetype: None"));
+  else
+    {
+      label = g_strdup_printf (_("Filetype: %s"), gtk_source_language_get_name (language));
+      gtk_label_set_text (GTK_LABEL (statusbar->language), label);
+      g_free (label);
+    }
+}
+
+
+
+void
 mousepad_statusbar_set_cursor_position (MousepadStatusbar *statusbar,
                                         gint               line,
                                         gint               column,
diff --git a/mousepad/mousepad-statusbar.h b/mousepad/mousepad-statusbar.h
index c44b54e..8ebe7a6 100644
--- a/mousepad/mousepad-statusbar.h
+++ b/mousepad/mousepad-statusbar.h
@@ -41,6 +41,9 @@ void        mousepad_statusbar_set_cursor_position  (MousepadStatusbar *statusba
 void        mousepad_statusbar_set_overwrite        (MousepadStatusbar *statusbar,
                                                      gboolean           overwrite);
 
+void        mousepad_statusbar_set_language         (MousepadStatusbar *statusbar,
+                                                     GtkSourceLanguage *language);
+
 G_END_DECLS
 
 #endif /* !__MOUSEPAD_STATUSBAR_H__ */
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 4c5e33e..54a3520 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -1306,7 +1306,8 @@ mousepad_window_notebook_switch_page (GtkNotebook     *notebook,
                                       guint            page_num,
                                       MousepadWindow  *window)
 {
-  MousepadDocument *document;
+  MousepadDocument  *document;
+  GtkSourceLanguage *language;
 
   mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
   mousepad_return_if_fail (GTK_IS_NOTEBOOK (notebook));
@@ -1328,6 +1329,11 @@ 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);
     }
 }
 


More information about the Xfce4-commits mailing list