[gedit] Add shortcuts to change text case



commit 05968491fd3750d00a450dc49c713a08d751e48c
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Mar 3 21:11:33 2014 +0100

    Add shortcuts to change text case
    
    ctrl+shift+L to change to uppercase, ctrl+l for lowercase and ctrl+~ to
    toggle case.

 gedit/gedit-view.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 gedit/gedit-view.h |    4 ++--
 2 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/gedit/gedit-view.c b/gedit/gedit-view.c
index 3ed15f2..256b7e3 100644
--- a/gedit/gedit-view.c
+++ b/gedit/gedit-view.c
@@ -65,6 +65,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GeditView, gedit_view, GTK_SOURCE_TYPE_VIEW)
 enum
 {
        DROP_URIS,
+       CHANGE_CASE,
        LAST_SIGNAL
 };
 
@@ -744,6 +745,26 @@ gedit_view_delete_from_cursor (GtkTextView   *text_view,
 }
 
 static void
+gedit_view_change_case (GeditView               *view,
+                       GtkSourceChangeCaseType  case_type)
+{
+       GtkSourceBuffer *buffer;
+       GtkTextIter start, end;
+
+       buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+
+       gtk_text_view_reset_im_context (GTK_TEXT_VIEW (view));
+
+       if (!gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &start, &end))
+       {
+               /* if no selection, change the current char */
+               gtk_text_iter_forward_char (&end);
+       }
+
+       gtk_source_buffer_change_case (buffer, case_type, &start, &end);
+}
+
+static void
 gedit_view_class_init (GeditViewClass *klass)
 {
        GObjectClass     *object_class = G_OBJECT_CLASS (klass);
@@ -780,6 +801,7 @@ gedit_view_class_init (GeditViewClass *klass)
        widget_class->unrealize = gedit_view_unrealize;
 
        text_view_class->delete_from_cursor = gedit_view_delete_from_cursor;
+       klass->change_case = gedit_view_change_case;
 
        /* A new signal DROP_URIS has been added to allow plugins to intercept
         * the default dnd behaviour of 'text/uri-list'. GeditView now handles
@@ -799,6 +821,15 @@ gedit_view_class_init (GeditViewClass *klass)
                              g_cclosure_marshal_VOID__BOXED,
                              G_TYPE_NONE, 1, G_TYPE_STRV);
 
+       view_signals[CHANGE_CASE] =
+               g_signal_new ("change-case",
+                             G_TYPE_FROM_CLASS (object_class),
+                             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                             G_STRUCT_OFFSET (GeditViewClass, change_case),
+                             NULL, NULL,
+                             g_cclosure_marshal_VOID__ENUM,
+                             G_TYPE_NONE, 1, GTK_SOURCE_TYPE_CHANGE_CASE_TYPE);
+
        binding_set = gtk_binding_set_by_class (klass);
 
        gtk_binding_entry_add_signal (binding_set,
@@ -807,6 +838,22 @@ gedit_view_class_init (GeditViewClass *klass)
                                      "delete_from_cursor", 2,
                                      G_TYPE_ENUM, GTK_DELETE_PARAGRAPHS,
                                      G_TYPE_INT, 1);
+
+       gtk_binding_entry_add_signal (binding_set,
+                                     GDK_KEY_l,
+                                     GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+                                     "change_case", 1,
+                                     G_TYPE_ENUM, GTK_SOURCE_CHANGE_CASE_UPPER);
+       gtk_binding_entry_add_signal (binding_set,
+                                     GDK_KEY_l,
+                                     GDK_CONTROL_MASK,
+                                     "change_case", 1,
+                                     G_TYPE_ENUM, GTK_SOURCE_CHANGE_CASE_LOWER);
+       gtk_binding_entry_add_signal (binding_set,
+                                     GDK_KEY_asciitilde,
+                                     GDK_CONTROL_MASK,
+                                     "change_case", 1,
+                                     G_TYPE_ENUM, GTK_SOURCE_CHANGE_CASE_TOGGLE);
 }
 
 /**
diff --git a/gedit/gedit-view.h b/gedit/gedit-view.h
index cf9d8e6..b12a51a 100644
--- a/gedit/gedit-view.h
+++ b/gedit/gedit-view.h
@@ -65,10 +65,10 @@ struct _GeditViewClass
 {
        GtkSourceViewClass parent_class;
 
-       /* FIXME: Do we need placeholders ? */
-
        void     (* drop_uris)                  (GeditView       *view,
                                                 gchar          **uri_list);
+       void     (* change_case)                (GeditView               *view,
+                                                GtkSourceChangeCaseType  case_type);
 };
 
 /*


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