[gedit] Make labels in the docinfo plugin selectable, but not focusable.



commit ee306cc9f678051bfee835f937181d9e7e324c1e
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat May 1 16:14:29 2010 +0200

    Make labels in the docinfo plugin selectable, but not focusable.
    
    Fixes bug #616590

 plugins/docinfo/docinfo.ui             |   40 +++++++++++++++++++-------
 plugins/docinfo/gedit-docinfo-plugin.c |   49 ++++++++++++++++++++++++++++---
 2 files changed, 73 insertions(+), 16 deletions(-)
---
diff --git a/plugins/docinfo/docinfo.ui b/plugins/docinfo/docinfo.ui
index 987b3f2..28bbe79 100644
--- a/plugins/docinfo/docinfo.ui
+++ b/plugins/docinfo/docinfo.ui
@@ -25,6 +25,7 @@
                 <property name="visible">True</property>
                 <property name="xalign">0</property>
                 <property name="label" translatable="yes">File Name</property>
+                <property name="selectable">True</property>
                 <attributes>
                   <attribute name="weight" value="bold"/>
                 </attributes>
@@ -58,10 +59,11 @@
                     <property name="column_spacing">18</property>
                     <property name="row_spacing">6</property>
                     <child>
-                      <object class="GtkLabel" id="label26">
+                      <object class="GtkLabel" id="bytes_label">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">Bytes</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="top_attach">5</property>
@@ -71,10 +73,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="bytes_label">
+                      <object class="GtkLabel" id="document_bytes_label">
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -86,10 +89,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label5">
+                      <object class="GtkLabel" id="chars_ns_label">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">Characters (no spaces)</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="top_attach">4</property>
@@ -99,10 +103,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="chars_ns_label">
+                      <object class="GtkLabel" id="document_chars_ns_label">
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -114,10 +119,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label4">
+                      <object class="GtkLabel" id="chars_label">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">Characters (with spaces)</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="top_attach">3</property>
@@ -127,10 +133,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="chars_label">
+                      <object class="GtkLabel" id="document_chars_label">
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -142,10 +149,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="words_label">
+                      <object class="GtkLabel" id="document_words_label">
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -157,10 +165,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label2">
+                      <object class="GtkLabel" id="words_label">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">Words</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="top_attach">2</property>
@@ -170,10 +179,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="label6">
+                      <object class="GtkLabel" id="lines_label">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">Lines</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="top_attach">1</property>
@@ -183,10 +193,11 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="lines_label">
+                      <object class="GtkLabel" id="document_lines_label">
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -198,13 +209,14 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkLabel" id="documet_label">
+                      <object class="GtkLabel" id="document_label">
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">Document</property>
                         <property name="use_markup">True</property>
                         <property name="use_underline">True</property>
                         <property name="justify">center</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -218,6 +230,7 @@
                         <property name="visible">True</property>
                         <property name="xalign">0</property>
                         <property name="label" translatable="yes">Selection</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">2</property>
@@ -229,6 +242,7 @@
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">2</property>
@@ -242,6 +256,7 @@
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">2</property>
@@ -255,6 +270,7 @@
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">2</property>
@@ -268,6 +284,7 @@
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">2</property>
@@ -281,6 +298,7 @@
                         <property name="visible">True</property>
                         <property name="xalign">1</property>
                         <property name="label">0</property>
+                        <property name="selectable">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">2</property>
diff --git a/plugins/docinfo/gedit-docinfo-plugin.c b/plugins/docinfo/gedit-docinfo-plugin.c
index 4119937..7de9138 100644
--- a/plugins/docinfo/gedit-docinfo-plugin.c
+++ b/plugins/docinfo/gedit-docinfo-plugin.c
@@ -35,6 +35,8 @@
 #include <gedit/gedit-debug.h>
 #include <gedit/gedit-utils.h>
 
+#include <gedit/gseal-gtk-compat.h>
+
 #define WINDOW_DATA_KEY "GeditDocInfoWindowData"
 #define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_2"
 
@@ -49,6 +51,12 @@ typedef struct
 	GtkWidget *chars_label;
 	GtkWidget *chars_ns_label;
 	GtkWidget *bytes_label;
+	GtkWidget *document_label;
+	GtkWidget *document_lines_label;
+	GtkWidget *document_words_label;
+	GtkWidget *document_chars_label;
+	GtkWidget *document_chars_ns_label;
+	GtkWidget *document_bytes_label;
 	GtkWidget *selection_label;
 	GtkWidget *selected_lines_label;
 	GtkWidget *selected_words_label;
@@ -112,6 +120,12 @@ get_docinfo_dialog (GeditWindow *window,
 					  "lines_label", &dialog->lines_label,
 					  "chars_label", &dialog->chars_label,
 					  "chars_ns_label", &dialog->chars_ns_label,
+					  "document_label", &dialog->document_label,
+					  "document_words_label", &dialog->document_words_label,
+					  "document_bytes_label", &dialog->document_bytes_label,
+					  "document_lines_label", &dialog->document_lines_label,
+					  "document_chars_label", &dialog->document_chars_label,
+					  "document_chars_ns_label", &dialog->document_chars_ns_label,
 					  "selection_label", &dialog->selection_label,
 					  "selected_words_label", &dialog->selected_words_label,
 					  "selected_bytes_label", &dialog->selected_bytes_label,
@@ -150,6 +164,31 @@ get_docinfo_dialog (GeditWindow *window,
 			  G_CALLBACK (docinfo_dialog_response_cb),
 			  window);
 
+	/* We set this explictely with code since glade does not
+	 * save the can_focus property when set to false :(
+	 * Making sure the labels are not focusable is needed to
+	 * prevent loosing the selection in the document when
+	 * creating the dialog.
+	 */
+	gtk_widget_set_can_focus (dialog->file_name_label, FALSE);
+	gtk_widget_set_can_focus (dialog->words_label, FALSE);
+	gtk_widget_set_can_focus (dialog->bytes_label, FALSE);
+	gtk_widget_set_can_focus (dialog->lines_label, FALSE);
+	gtk_widget_set_can_focus (dialog->chars_label, FALSE);
+	gtk_widget_set_can_focus (dialog->chars_ns_label, FALSE);
+	gtk_widget_set_can_focus (dialog->document_label, FALSE);
+	gtk_widget_set_can_focus (dialog->document_words_label, FALSE);
+	gtk_widget_set_can_focus (dialog->document_bytes_label, FALSE);
+	gtk_widget_set_can_focus (dialog->document_lines_label, FALSE);
+	gtk_widget_set_can_focus (dialog->document_chars_label, FALSE);
+	gtk_widget_set_can_focus (dialog->document_chars_ns_label, FALSE);
+	gtk_widget_set_can_focus (dialog->selection_label, FALSE);
+	gtk_widget_set_can_focus (dialog->selected_words_label, FALSE);
+	gtk_widget_set_can_focus (dialog->selected_bytes_label, FALSE);
+	gtk_widget_set_can_focus (dialog->selected_lines_label, FALSE);
+	gtk_widget_set_can_focus (dialog->selected_chars_label, FALSE);
+	gtk_widget_set_can_focus (dialog->selected_chars_ns_label, FALSE);
+
 	return dialog;
 }
 
@@ -249,23 +288,23 @@ docinfo_real (GeditDocument *doc,
 	g_free (tmp_str);
 
 	tmp_str = g_strdup_printf("%d", lines);
-	gtk_label_set_text (GTK_LABEL (dialog->lines_label), tmp_str);
+	gtk_label_set_text (GTK_LABEL (dialog->document_lines_label), tmp_str);
 	g_free (tmp_str);
 
 	tmp_str = g_strdup_printf("%d", words);
-	gtk_label_set_text (GTK_LABEL (dialog->words_label), tmp_str);
+	gtk_label_set_text (GTK_LABEL (dialog->document_words_label), tmp_str);
 	g_free (tmp_str);
 
 	tmp_str = g_strdup_printf("%d", chars);
-	gtk_label_set_text (GTK_LABEL (dialog->chars_label), tmp_str);
+	gtk_label_set_text (GTK_LABEL (dialog->document_chars_label), tmp_str);
 	g_free (tmp_str);
 
 	tmp_str = g_strdup_printf("%d", chars - white_chars);
-	gtk_label_set_text (GTK_LABEL (dialog->chars_ns_label), tmp_str);
+	gtk_label_set_text (GTK_LABEL (dialog->document_chars_ns_label), tmp_str);
 	g_free (tmp_str);
 
 	tmp_str = g_strdup_printf("%d", bytes);
-	gtk_label_set_text (GTK_LABEL (dialog->bytes_label), tmp_str);
+	gtk_label_set_text (GTK_LABEL (dialog->document_bytes_label), tmp_str);
 	g_free (tmp_str);
 }
 



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