SF.net SVN: geany:[4754] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Fri Mar 12 13:06:35 UTC 2010


Revision: 4754
          http://geany.svn.sourceforge.net/geany/?rev=4754&view=rev
Author:   ntrel
Date:     2010-03-12 13:06:34 +0000 (Fri, 12 Mar 2010)

Log Message:
-----------
Make Build Commands dialog show menu item labels as a button (to
help show that menu labels don't normally need to be edited &
display the mnemonic correctly). Clicking shows an input dialog to
set a new menu item label.
Split dialogs_show_input() into 2 functions: one simple, one for
a persistent dialog.
Fix possible double-destroy of input dialog when closed by user.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/build.c
    trunk/src/callbacks.c
    trunk/src/dialogs.c
    trunk/src/dialogs.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-03-12 11:23:22 UTC (rev 4753)
+++ trunk/ChangeLog	2010-03-12 13:06:34 UTC (rev 4754)
@@ -3,6 +3,14 @@
  * src/ui_utils.c:
    Fix ui_button_new_with_image() to call gtk_button_set_image() so
    that gtk_button_[sg]et_label() work as expected.
+ * src/build.c, src/dialogs.c, src/dialogs.h, src/callbacks.c:
+   Make Build Commands dialog show menu item labels as a button (to
+   help show that menu labels don't normally need to be edited &
+   display the mnemonic correctly). Clicking shows an input dialog to
+   set a new menu item label.
+   Split dialogs_show_input() into 2 functions: one simple, one for
+   a persistent dialog.
+   Fix possible double-destroy of input dialog when closed by user.
 
 
 2010-03-10  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/src/build.c
===================================================================
--- trunk/src/build.c	2010-03-12 11:23:22 UTC (rev 4753)
+++ trunk/src/build.c	2010-03-12 13:06:34 UTC (rev 4754)
@@ -1239,9 +1239,9 @@
 
 		if (! dialog)
 		{
-			dialog = dialogs_show_input(_("Custom Text"),
+			dialog = dialogs_show_input_persistent(_("Custom Text"),
 				_("Enter custom text here, all entered text is appended to the command."),
-				build_info.custom_target, TRUE, &on_make_custom_input_response);
+				build_info.custom_target, &on_make_custom_input_response);
 		}
 		else
 		{
@@ -1716,6 +1716,15 @@
 } RowWidgets;
 
 
+static void set_build_command_entry_text(GtkWidget *wid, const gchar *text)
+{
+	if (GTK_IS_BUTTON(wid))
+		gtk_button_set_label(GTK_BUTTON(wid), text);
+	else
+		gtk_entry_set_text(GTK_ENTRY(wid), text);
+}
+
+
 static void on_clear_dialog_row(GtkWidget *unused, gpointer user_data)
 {
 	RowWidgets *r = (RowWidgets*)user_data;
@@ -1729,7 +1738,7 @@
 		r->src = src;
 		for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++)
 		{
-			gtk_entry_set_text(GTK_ENTRY(r->entries[i]),
+			set_build_command_entry_text(r->entries[i],
 				id_to_str(bc,i) != NULL ? id_to_str(bc,i) : "");
 		}
 	}
@@ -1738,7 +1747,7 @@
 		r->cmdsrc = NULL;
 		for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++)
 		{
-			gtk_entry_set_text(GTK_ENTRY(r->entries[i]), "");
+			set_build_command_entry_text(r->entries[i], "");
 		}
 	}
 	r->cleared = TRUE;
@@ -1751,6 +1760,16 @@
 }
 
 
+static void on_label_button_clicked(GtkWidget *wid)
+{
+	const gchar *old = gtk_button_get_label(GTK_BUTTON(wid));
+	gchar *str = dialogs_show_input(_("Set menu item label"), NULL, old);
+
+	gtk_button_set_label(GTK_BUTTON(wid), str);
+	g_free(str);
+}
+
+
 /* Column headings, array NULL-terminated */
 static gchar *colheads[] =
 {
@@ -1793,7 +1812,15 @@
 		gint xflags = (i == GEANY_BC_COMMAND) ? GTK_FILL | GTK_EXPAND : GTK_FILL;
 
 		column += 1;
-		roww->entries[i] = gtk_entry_new();
+		if (i == GEANY_BC_LABEL)
+		{
+			GtkWidget *wid = roww->entries[i] = gtk_button_new();
+			gtk_button_set_use_underline(GTK_BUTTON(wid), TRUE);
+			ui_widget_set_tooltip_text(wid, _("Click to set menu item label"));
+			g_signal_connect(wid, "clicked", G_CALLBACK(on_label_button_clicked), NULL);
+		}
+		else
+			roww->entries[i] = gtk_entry_new();
 		gtk_table_attach(table, roww->entries[i], column, column + 1, row, row + 1, xflags,
 			GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding);
 	}
@@ -1813,7 +1840,7 @@
 		gchar *str = "";
 		if (bc != NULL && (str = bc->entries[i]) == NULL)
 			str = "";
-		gtk_entry_set_text(GTK_ENTRY(roww->entries[i]), str);
+		set_build_command_entry_text(roww->entries[i], str);
 	}
 	if (src > (gint)dst || (grp == GEANY_GBG_FT && (doc == NULL || doc->file_type == NULL)))
 	{
@@ -1982,6 +2009,15 @@
 }
 
 
+static const gchar *get_build_command_entry_text(GtkWidget *wid)
+{
+	if (GTK_IS_BUTTON(wid))
+		return gtk_button_get_label(GTK_BUTTON(wid));
+	else
+		return gtk_entry_get_text(GTK_ENTRY(wid));
+}
+
+
 static gboolean read_row(BuildDestination *dst, TableData table_data, gint drow, gint grp, gint cmd)
 {
 	gchar			*entries[GEANY_BC_CMDENTRIES_COUNT];
@@ -1993,7 +2029,7 @@
 
 	for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++)
 	{
-		entries[i] = g_strdup(gtk_entry_get_text(GTK_ENTRY(table_data->rows[drow]->entries[i])));
+		entries[i] = g_strdup(get_build_command_entry_text(table_data->rows[drow]->entries[i]));
 	}
 	if (table_data->rows[drow]->cleared)
 	{

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2010-03-12 11:23:22 UTC (rev 4753)
+++ trunk/src/callbacks.c	2010-03-12 13:06:34 UTC (rev 4754)
@@ -1480,13 +1480,6 @@
 }
 
 
-static void
-on_custom_date_input_response(const gchar *input)
-{
-	setptr(ui_prefs.custom_date_format, g_strdup(input));
-}
-
-
 void
 on_insert_date_activate                (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
@@ -1520,9 +1513,11 @@
 		format = ui_prefs.custom_date_format;
 	else
 	{
-		dialogs_show_input(_("Custom Date Format"),
-			_("Enter here a custom date and time format. You can use any conversion specifiers which can be used with the ANSI C strftime function."),
-			ui_prefs.custom_date_format, FALSE, &on_custom_date_input_response);
+		setptr(ui_prefs.custom_date_format,
+			dialogs_show_input(_("Custom Date Format"),
+				_("Enter here a custom date and time format. "
+				"You can use any conversion specifiers which can be used with the ANSI C strftime function."),
+				ui_prefs.custom_date_format));
 		return;
 	}
 

Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c	2010-03-12 11:23:22 UTC (rev 4753)
+++ trunk/src/dialogs.c	2010-03-12 13:06:34 UTC (rev 4754)
@@ -822,8 +822,8 @@
 	if (response == GTK_RESPONSE_ACCEPT)
 	{
 		const gchar *str = gtk_entry_get_text(GTK_ENTRY(entry));
-		InputCallback input_cb =
-			(InputCallback) g_object_get_data(G_OBJECT(dialog), "input_cb");
+		GeanyInputCallback input_cb =
+			(GeanyInputCallback) g_object_get_data(G_OBJECT(dialog), "input_cb");
 
 		if (persistent)
 		{
@@ -832,23 +832,22 @@
 		}
 		input_cb(str);
 	}
-
-	if (persistent)
-		gtk_widget_hide(GTK_WIDGET(dialog));
-	else
-		gtk_widget_destroy(GTK_WIDGET(dialog));
+	gtk_widget_hide(GTK_WIDGET(dialog));
 }
 
 
 static void add_input_widgets(GtkWidget *dialog, GtkWidget *vbox,
 		const gchar *label_text, const gchar *default_text, gboolean persistent)
 {
-	GtkWidget *label, *entry;
+	GtkWidget *entry;
 
-	label = gtk_label_new(label_text);
-	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
-	gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-	gtk_container_add(GTK_CONTAINER(vbox), label);
+	if (label_text)
+	{
+		GtkWidget *label = gtk_label_new(label_text);
+		gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+		gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+		gtk_container_add(GTK_CONTAINER(vbox), label);
+	}
 
 	if (persistent)	/* remember previous entry text in a combo box */
 	{
@@ -884,9 +883,9 @@
  * 	in this case the dialog returned is not destroyed on a response,
  * 	and can be reshown.
  * Returns: the dialog widget. */
-GtkWidget *
-dialogs_show_input(const gchar *title, const gchar *label_text, const gchar *default_text,
-						gboolean persistent, InputCallback input_cb)
+static GtkWidget *
+dialogs_show_input_full(const gchar *title, const gchar *label_text, const gchar *default_text,
+						gboolean persistent, GeanyInputCallback input_cb)
 {
 	GtkWidget *dialog, *vbox;
 
@@ -903,15 +902,46 @@
 	add_input_widgets(dialog, vbox, label_text, default_text, persistent);
 
 	if (persistent)
-		g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
-	else
-		g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_widget_destroy), NULL);
-
+	{
+		gtk_widget_show_all(dialog);
+		return dialog;
+	}
 	gtk_widget_show_all(dialog);
-	return dialog;
+	gtk_dialog_run(GTK_DIALOG(dialog));
+	gtk_widget_destroy(dialog);
+	return NULL;
 }
 
 
+/* Remember previous entry text in a combo box.
+ * Returns: the dialog widget. */
+GtkWidget *
+dialogs_show_input_persistent(const gchar *title, const gchar *label_text, const gchar *default_text,
+		GeanyInputCallback input_cb)
+{
+	return dialogs_show_input_full(title, label_text, default_text, TRUE, input_cb);
+}
+
+
+/* ugly hack - user_data not supported for callback */
+gchar *dialog_input = NULL;
+
+static void on_dialog_input(const gchar *str)
+{
+	dialog_input = g_strdup(str);
+}
+
+
+/* Returns: newly allocated string - a copy of either the entry text or default_text. */
+gchar *dialogs_show_input(const gchar *title, const gchar *label_text,
+	const gchar *default_text)
+{
+	dialog_input = NULL;
+	dialogs_show_input_full(title, label_text, default_text, FALSE, on_dialog_input);
+	return NVL(dialog_input, g_strdup(default_text));
+}
+
+
 /**
  *  Show an input box to enter a numerical value using a GtkSpinButton.
  *  If the dialog is aborted, @a value remains untouched.

Modified: trunk/src/dialogs.h
===================================================================
--- trunk/src/dialogs.h	2010-03-12 11:23:22 UTC (rev 4753)
+++ trunk/src/dialogs.h	2010-03-12 13:06:34 UTC (rev 4754)
@@ -30,7 +30,7 @@
 #ifndef GEANY_DIALOGS_H
 #define GEANY_DIALOGS_H 1
 
-typedef void (*InputCallback)(const gchar *);
+typedef void (*GeanyInputCallback)(const gchar *text);
 
 
 void dialogs_show_open_file(void);
@@ -45,9 +45,12 @@
 
 void dialogs_show_color(gchar *colour);
 
-GtkWidget *dialogs_show_input(const gchar *title, const gchar *label_text,
-	const gchar *default_text, gboolean persistent, InputCallback input_cb);
+gchar *dialogs_show_input(const gchar *title, const gchar *label_text,
+	const gchar *default_text);
 
+GtkWidget *dialogs_show_input_persistent(const gchar *title, const gchar *label_text,
+	const gchar *default_text, GeanyInputCallback input_cb);
+
 gboolean dialogs_show_input_numeric(const gchar *title, const gchar *label_text,
 									gdouble *value, gdouble min, gdouble max, gdouble step);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list