SF.net SVN: geany: [2120] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Fri Dec 21 13:09:09 UTC 2007


Revision: 2120
          http://geany.svn.sourceforge.net/geany/?rev=2120&view=rev
Author:   ntrel
Date:     2007-12-21 05:09:09 -0800 (Fri, 21 Dec 2007)

Log Message:
-----------
Add combo box input history for Make Custom Target dialog.
Make dialogs_show_input() automatically activate on pressing enter in
the GtkEntry, use a callback for input text, and have a 'persistent'
option to hide the dialog instead of deleting it, using a combo box
for input text history.

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	2007-12-20 12:56:54 UTC (rev 2119)
+++ trunk/ChangeLog	2007-12-21 13:09:09 UTC (rev 2120)
@@ -1,3 +1,13 @@
+2007-12-21  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/build.c, src/dialogs.c, src/dialogs.h, src/callbacks.c:
+   Add combo box input history for Make Custom Target dialog.
+   Make dialogs_show_input() automatically activate on pressing enter in
+   the GtkEntry, use a callback for input text, and have a 'persistent'
+   option to hide the dialog instead of deleting it, using a combo box
+   for input text history.
+
+
 2007-12-19  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * TODO, src/main.c: Apply patch Jeff Pohlmeyer to handle unknown

Modified: trunk/src/build.c
===================================================================
--- trunk/src/build.c	2007-12-20 12:56:54 UTC (rev 2119)
+++ trunk/src/build.c	2007-12-21 13:09:09 UTC (rev 2120)
@@ -98,8 +98,6 @@
 static gboolean build_iofunc(GIOChannel *ioc, GIOCondition cond, gpointer data);
 static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, gboolean autoclose);
 static GPid build_spawn_cmd(gint idx, const gchar *cmd, const gchar *dir);
-static void on_make_target_dialog_response(GtkDialog *dialog, gint response, gpointer user_data);
-static void on_make_target_entry_activate(GtkEntry *entry, gpointer user_data);
 static void set_stop_button(gboolean stop);
 static void build_exit_cb(GPid child_pid, gint status, gpointer user_data);
 static void run_exit_cb(GPid child_pid, gint status, gpointer user_data);
@@ -1931,6 +1929,36 @@
 
 
 static void
+on_make_custom_input_response(const gchar *input)
+{
+	gint idx = document_get_cur_idx();
+
+	if (doc_list[idx].changed)
+		document_save_file(idx, FALSE);
+
+	setptr(build_info.custom_target, g_strdup(input));
+
+	build_make_file(idx, GBO_MAKE_CUSTOM);
+}
+
+
+static void
+show_make_custom()
+{
+	static GtkWidget *dialog = NULL;	// keep dialog for combo history
+
+	if (! dialog)
+		dialog = dialogs_show_input(_("Make Custom Target"),
+			_("Enter custom options here, all entered text is passed to the make command."),
+			build_info.custom_target, TRUE, &on_make_custom_input_response);
+	else
+	{
+		gtk_widget_show(dialog);
+	}
+}
+
+
+static void
 on_build_make_activate                 (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
@@ -1943,11 +1971,7 @@
 	{
 		case GBO_MAKE_CUSTOM:
 		{
-			dialogs_show_input(_("Make Custom Target"),
-				_("Enter custom options here, all entered text is passed to the make command."),
-				build_info.custom_target,
-				G_CALLBACK(on_make_target_dialog_response),
-				G_CALLBACK(on_make_target_entry_activate));
+			show_make_custom();
 			break;
 		}
 
@@ -2035,34 +2059,6 @@
 }
 
 
-static void
-on_make_target_dialog_response         (GtkDialog *dialog,
-                                        gint response,
-                                        gpointer user_data)
-{
-	if (response == GTK_RESPONSE_ACCEPT)
-	{
-		gint idx = document_get_cur_idx();
-
-		if (doc_list[idx].changed) document_save_file(idx, FALSE);
-
-		g_free(build_info.custom_target);
-		build_info.custom_target = g_strdup(gtk_entry_get_text(GTK_ENTRY(user_data)));
-
-		build_make_file(idx, GBO_MAKE_CUSTOM);
-	}
-	gtk_widget_destroy(GTK_WIDGET(dialog));
-}
-
-
-static void
-on_make_target_entry_activate          (GtkEntry        *entry,
-                                        gpointer         user_data)
-{
-	on_make_target_dialog_response(GTK_DIALOG(user_data), GTK_RESPONSE_ACCEPT, entry);
-}
-
-
 static void kill_process(GPid *pid)
 {
 	/* Unix: SIGQUIT is not the best signal to use because it causes a core dump (this should not

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2007-12-20 12:56:54 UTC (rev 2119)
+++ trunk/src/callbacks.c	2007-12-21 13:09:09 UTC (rev 2120)
@@ -1424,29 +1424,14 @@
 }
 
 
-void
-on_custom_date_dialog_response         (GtkDialog *dialog,
-                                        gint response,
-                                        gpointer user_data)
+static void
+on_custom_date_input_response(const gchar *input)
 {
-	if (response == GTK_RESPONSE_ACCEPT)
-	{
-		g_free(ui_prefs.custom_date_format);
-		ui_prefs.custom_date_format = g_strdup(gtk_entry_get_text(GTK_ENTRY(user_data)));
-	}
-	gtk_widget_destroy(GTK_WIDGET(dialog));
+	setptr(ui_prefs.custom_date_format, g_strdup(input));
 }
 
 
 void
-on_custom_date_entry_activate          (GtkEntry        *entry,
-                                        gpointer         user_data)
-{
-	on_custom_date_dialog_response(GTK_DIALOG(user_data), GTK_RESPONSE_ACCEPT, entry);
-}
-
-
-void
 on_insert_date_activate                (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
@@ -1484,9 +1469,7 @@
 
 		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,
-			G_CALLBACK(on_custom_date_dialog_response),
-			G_CALLBACK(on_custom_date_entry_activate));
+			ui_prefs.custom_date_format, FALSE, &on_custom_date_input_response);
 		return;
 	}
 

Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c	2007-12-20 12:56:54 UTC (rev 2119)
+++ trunk/src/dialogs.c	2007-12-21 13:09:09 UTC (rev 2120)
@@ -729,22 +729,72 @@
 }
 
 
-void dialogs_show_input(const gchar *title, const gchar *label_text, const gchar *default_text,
-						GCallback cb_dialog, GCallback cb_entry)
+static void
+on_input_dialog_show(GtkDialog *dialog, GtkWidget *entry)
 {
-	GtkWidget *dialog, *label, *entry, *vbox;
+	gtk_widget_grab_focus(entry);
+}
 
-	dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(app->window),
-						GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-						GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
-	vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
-	gtk_widget_set_name(dialog, "GeanyDialog");
-	gtk_box_set_spacing(GTK_BOX(vbox), 6);
 
+static void
+on_input_entry_activate(GtkEntry *entry, GtkDialog *dialog)
+{
+	gtk_dialog_response(dialog, GTK_RESPONSE_ACCEPT);
+}
+
+
+static void
+on_input_dialog_response(GtkDialog *dialog,
+                         gint response,
+                         GtkWidget *entry)
+{
+	gboolean persistent = (gboolean) g_object_get_data(G_OBJECT(dialog), "has_combo");
+
+	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");
+
+		if (persistent)
+		{
+			GtkWidget *combo = (GtkWidget *) g_object_get_data(G_OBJECT(dialog), "combo");
+			ui_combo_box_add_to_history(GTK_COMBO_BOX(combo), str);
+		}
+		input_cb(str);
+	}
+
+	if (persistent)
+		gtk_widget_hide(GTK_WIDGET(dialog));
+	else
+		gtk_widget_destroy(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;
+
 	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);
-	entry = gtk_entry_new();
+	gtk_container_add(GTK_CONTAINER(vbox), label);
+
+	if (persistent)	// remember previous entry text in a combo box
+	{
+		GtkWidget *combo = gtk_combo_box_entry_new_text();
+
+		entry = GTK_BIN(combo)->child;
+		g_object_set_data(G_OBJECT(dialog), "combo", combo);
+		gtk_container_add(GTK_CONTAINER(vbox), combo);
+	}
+	else
+	{
+		entry = gtk_entry_new();
+		gtk_container_add(GTK_CONTAINER(vbox), entry);
+	}
+
 	if (default_text != NULL)
 	{
 		gtk_entry_set_text(GTK_ENTRY(entry), default_text);
@@ -752,13 +802,47 @@
 	gtk_entry_set_max_length(GTK_ENTRY(entry), 255);
 	gtk_entry_set_width_chars(GTK_ENTRY(entry), 30);
 
-	if (cb_entry != NULL) g_signal_connect((gpointer) entry, "activate", cb_entry, dialog);
-	g_signal_connect((gpointer) dialog, "response", cb_dialog, entry);
-	g_signal_connect((gpointer) dialog, "delete_event", G_CALLBACK(gtk_widget_destroy), NULL);
+	g_signal_connect((gpointer) entry, "activate",
+		G_CALLBACK(on_input_entry_activate), dialog);
+	g_signal_connect((gpointer) dialog, "show",
+		G_CALLBACK(on_input_dialog_show), entry);
+	g_signal_connect((gpointer) dialog, "response",
+		G_CALLBACK(on_input_dialog_response), entry);
+}
 
-	gtk_container_add(GTK_CONTAINER(vbox), label);
-	gtk_container_add(GTK_CONTAINER(vbox), entry);
+
+/* Create and display an input dialog.
+ * persistent: whether to remember previous entry text in a combo box;
+ * 	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)
+{
+	GtkWidget *dialog, *vbox;
+
+	dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(app->window),
+		GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+		GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
+	vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
+	gtk_widget_set_name(dialog, "GeanyDialog");
+	gtk_box_set_spacing(GTK_BOX(vbox), 6);
+
+	g_object_set_data(G_OBJECT(dialog), "has_combo", (gpointer) persistent);
+	g_object_set_data(G_OBJECT(dialog), "input_cb", (gpointer) input_cb);
+
+	add_input_widgets(dialog, vbox, label_text, default_text, persistent);
+
+	if (persistent)
+		g_signal_connect((gpointer) dialog, "delete_event",
+			G_CALLBACK(gtk_widget_hide_on_delete), NULL);
+	else
+		g_signal_connect((gpointer) dialog, "delete_event",
+			G_CALLBACK(gtk_widget_destroy), NULL);
+
 	gtk_widget_show_all(dialog);
+	return dialog;
 }
 
 

Modified: trunk/src/dialogs.h
===================================================================
--- trunk/src/dialogs.h	2007-12-20 12:56:54 UTC (rev 2119)
+++ trunk/src/dialogs.h	2007-12-21 13:09:09 UTC (rev 2120)
@@ -25,23 +25,23 @@
 #ifndef GEANY_DIALOGS_H
 #define GEANY_DIALOGS_H 1
 
-/* This shows the file selection dialog to open a file. */
+typedef void (*InputCallback)(const gchar *);
+
+
 void dialogs_show_open_file();
 
-/* This shows the file selection dialog to save a file. */
 gboolean dialogs_show_save_as();
 
 gboolean dialogs_show_unsaved_file(gint idx);
 
-/* This shows the font selection dialog to choose a font. */
 void dialogs_show_open_font();
 
 void dialogs_show_word_count();
 
 void dialogs_show_color(gchar *colour);
 
-void dialogs_show_input(const gchar *title, const gchar *label_text, const gchar *default_text,
-						GCallback cb_dialog, GCallback cb_entry);
+GtkWidget *dialogs_show_input(const gchar *title, const gchar *label_text,
+	const gchar *default_text, gboolean persistent, InputCallback input_cb);
 
 void dialogs_show_goto_line();
 
@@ -49,7 +49,6 @@
 
 gboolean dialogs_show_question(const gchar *text, ...) G_GNUC_PRINTF (1, 2);
 
-/* extra_text can be NULL; otherwise it is displayed below main_text. */
 gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn,
 	const gchar *extra_text, const gchar *main_text, ...) G_GNUC_PRINTF (5, 6);
 


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