zenity r1346 - in trunk: . src



Author: lucasr
Date: Sat Mar 29 22:13:50 2008
New Revision: 1346
URL: http://svn.gnome.org/viewvc/zenity?rev=1346&view=rev

Log:
2008-03-30  Lucas Rocha  <lucasr gnome org>

	Allow question dialogs to use custom button label text (Fixes 
	bug #335763). Patch from Cosimo Cecchi <anarki lilik it> and 
	Thomas Thurman <tthurman gnome org>.

	* src/msg.c (zenity_msg_construct_question_dialog), (zenity_msg):
	dynamically add dialog buttons with provided labels.
	* src/option.c (zenity_option_free): free input labels.
	(zenity_question_post_callback): set button labels provided by the
	respective command line options.
	* src/zenity.glade: remove pre-defined dialog button from question
	dialog.
	* src/zenity.h: added ok_label and cancel_label to ZenityMsgData.


Modified:
   trunk/ChangeLog
   trunk/src/msg.c
   trunk/src/option.c
   trunk/src/zenity.glade
   trunk/src/zenity.h

Modified: trunk/src/msg.c
==============================================================================
--- trunk/src/msg.c	(original)
+++ trunk/src/msg.c	Sat Mar 29 22:13:50 2008
@@ -29,6 +29,29 @@
 
 static void zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data);
 
+static void
+zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data)
+{
+  GtkWidget *cancel_button, *ok_button;
+  
+  cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+  ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_OK);
+
+  gtk_widget_grab_focus (ok_button);
+
+  if (msg_data->cancel_label) {
+    gtk_button_set_label (GTK_BUTTON (cancel_button), g_strdup (msg_data->cancel_label));
+    gtk_button_set_image (GTK_BUTTON (cancel_button), 
+                          gtk_image_new_from_stock (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON));
+  }
+
+  if (msg_data->ok_label) {
+    gtk_button_set_label (GTK_BUTTON (ok_button), g_strdup (msg_data->ok_label));
+    gtk_button_set_image (GTK_BUTTON (ok_button), 
+                          gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
+  }
+}
+
 void 
 zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
 {
@@ -92,6 +115,7 @@
 
     case ZENITY_MSG_QUESTION:
       zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_QUESTION);
+      zenity_msg_construct_question_dialog (dialog, msg_data);
       break;
       
     case ZENITY_MSG_ERROR:

Modified: trunk/src/option.c
==============================================================================
--- trunk/src/option.c	(original)
+++ trunk/src/option.c	Sat Mar 29 22:13:50 2008
@@ -87,6 +87,8 @@
 
 /* Question Dialog Options */
 static gboolean zenity_question_active;
+static gchar   *zenity_question_ok_button;
+static gchar   *zenity_question_cancel_button;
 
 /* Text Dialog Options */
 static gboolean zenity_text_active;
@@ -609,6 +611,24 @@
     N_("TEXT")
   },
   {
+    "ok-label",
+    '\0',
+    G_OPTION_FLAG_NOALIAS,
+    G_OPTION_ARG_STRING,
+    &zenity_question_ok_button,
+    N_("Sets the label of the Ok button"),
+    N_("TEXT")
+  },
+  {
+    "cancel-label",
+    '\0',
+    G_OPTION_FLAG_NOALIAS,
+    G_OPTION_ARG_STRING,
+    &zenity_question_cancel_button,
+    N_("Sets the label of the Cancel button"),
+    N_("TEXT")
+  },
+  {
     "no-wrap",
     '\0',
     G_OPTION_FLAG_NOALIAS,
@@ -837,6 +857,11 @@
   if (zenity_list_hide_column)
     g_free (zenity_list_hide_column);
 
+  if (zenity_question_ok_button)
+    g_free (zenity_question_ok_button);
+  if (zenity_question_cancel_button)
+    g_free (zenity_question_cancel_button);
+
   g_option_context_free (ctx);
 }
 
@@ -1342,7 +1367,9 @@
   if (results->mode == MODE_QUESTION) {
     results->msg_data->dialog_text = zenity_general_dialog_text;
     results->msg_data->mode = ZENITY_MSG_QUESTION;
-    results->msg_data->no_wrap = zenity_general_dialog_no_wrap; 
+    results->msg_data->no_wrap = zenity_general_dialog_no_wrap;
+    results->msg_data->ok_label = zenity_question_ok_button;
+    results->msg_data->cancel_label = zenity_question_cancel_button;
   }
 
   return TRUE;

Modified: trunk/src/zenity.glade
==============================================================================
--- trunk/src/zenity.glade	(original)
+++ trunk/src/zenity.glade	Sat Mar 29 22:13:50 2008
@@ -242,6 +242,7 @@
 	  <child>
 	    <widget class="GtkLabel" id="zenity_warning_text">
 	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
 	      <property name="label" translatable="yes">Are you sure you want to proceed?</property>
 	      <property name="use_underline">False</property>
 	      <property name="use_markup">True</property>
@@ -339,36 +340,9 @@
       <property name="spacing">14</property>
 
       <child internal-child="action_area">
-	<widget class="GtkHButtonBox" id="dialog-action_area3">
+	<widget class="GtkHButtonBox" id="zenity_question_button_box">
 	  <property name="visible">True</property>
 	  <property name="layout_style">GTK_BUTTONBOX_END</property>
-
-	  <child>
-	    <widget class="GtkButton" id="zenity_question_cancel_button">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-cancel</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <property name="response_id">-6</property>
-	    </widget>
-	  </child>
-
-	  <child>
-	    <widget class="GtkButton" id="zenity_question_ok_button">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="has_focus">True</property>
-	      <property name="label">gtk-ok</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <property name="response_id">-5</property>
-	    </widget>
-	  </child>
 	</widget>
 	<packing>
 	  <property name="padding">0</property>
@@ -405,6 +379,7 @@
 	  <child>
 	    <widget class="GtkLabel" id="zenity_question_text">
 	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
 	      <property name="label" translatable="yes">Are you sure you want to proceed?</property>
 	      <property name="use_underline">False</property>
 	      <property name="use_markup">True</property>
@@ -872,6 +847,7 @@
 	      <child>
 		<widget class="GtkLabel" id="zenity_error_text">
 		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
 		  <property name="label" translatable="yes">An error has occurred.</property>
 		  <property name="use_underline">False</property>
 		  <property name="use_markup">True</property>
@@ -1126,6 +1102,7 @@
 	  <child>
 	    <widget class="GtkLabel" id="zenity_info_text">
 	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
 	      <property name="label" translatable="yes">All updates are complete.</property>
 	      <property name="use_underline">False</property>
 	      <property name="use_markup">True</property>

Modified: trunk/src/zenity.h
==============================================================================
--- trunk/src/zenity.h	(original)
+++ trunk/src/zenity.h	Sat Mar 29 22:13:50 2008
@@ -60,6 +60,8 @@
   gchar   *dialog_text;
   MsgMode  mode;
   gboolean no_wrap;
+  gchar   *ok_label;
+  gchar   *cancel_label;
 } ZenityMsgData;
 
 typedef struct {



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