diff src/gtkimhtmltoolbar.c @ 9599:a1029432ae4a

[gaim-migrate @ 10442] Simguy writes: This makes the insert link behavior a little better: 1) If there is a selection in the IMHTML to which you are inserting a link, prefill the Description field in the dialog. 2) Delete the selected text and replace it with whatever the description field contains when inserting the link (this is why we do #1) The former behavior was to prepend the description entered to the selection and link the whole block, which seemed illogical to me. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Mon, 26 Jul 2004 06:09:11 +0000
parents 4399fc6e667a
children 4d05b6e9e9cd
line wrap: on
line diff
--- a/src/gtkimhtmltoolbar.c	Mon Jul 26 04:05:08 2004 +0000
+++ b/src/gtkimhtmltoolbar.c	Mon Jul 26 06:09:11 2004 +0000
@@ -382,7 +382,9 @@
 		GaimRequestFields *fields;
 		GaimRequestFieldGroup *group;
 		GaimRequestField *field;
+		GtkTextIter start, end;
 		char *msg;
+		char *desc = NULL;
 
 		fields = gaim_request_fields_new();
 
@@ -394,8 +396,11 @@
 		gaim_request_field_group_add_field(group, field);
 
 		if(GTK_IMHTML(toolbar->imhtml)->format_functions & GTK_IMHTML_LINKDESC) {
+			if (gtk_text_buffer_get_selection_bounds(GTK_IMHTML(toolbar->imhtml)->text_buffer, &start, &end)) {
+				desc = gtk_imhtml_get_text(GTK_IMHTML(toolbar->imhtml), &start, &end);
+			}
 			field = gaim_request_field_string_new("description", _("_Description"),
-							      NULL, FALSE);
+							      desc, FALSE);
 			gaim_request_field_group_add_field(group, field);
 			msg = g_strdup(_("Please enter the URL and description of the "
 							 "link that you want to insert. The description "
@@ -414,6 +419,7 @@
 					    _("Cancel"), G_CALLBACK(cancel_link_cb),
 					    toolbar);
 		g_free(msg);
+		g_free(desc);
 	} else {
 		close_link_dialog(toolbar);
 	}