GNOME Bugzilla – Bug 347563
Give dragged text a better file name than "new file"
Last modified: 2012-08-16 15:40:08 UTC
When dragging text from an app to nautilus, it creates a text file. This is a great feature! But the text file's name should be something better than "new file", it should be a sample of the first parts of the dragged text. How long it should be isn't up to me to decide. Sorry for this being general, please move where appropriate.
Agreed. Nice suggestion. Thanks for the report!
Created attachment 221364 [details] [review] Try to use dropped text to make a filename
Review of attachment 221364 [details] [review]: Thanks, this sounds like a very nice touch. Some comments on the code below. ::: src/nautilus-view-dnd.c @@ +354,3 @@ + + num_attrs = g_utf8_strlen (text, -1) + 1; + int i; Since this comes from an arbitrary DnD operation, I'm not the biggest fan of allocating a possibly unbounded/very large array of PangoLogAttrs. I think you could change the following code by having num_attrs = MIN (g_utf8_strlen(text, -1) + 1, MAX_LEN_FILENAME); for (i = 0; (i < num_attrs -1); i++) { ... } You're also leaking the attrs. @@ +372,3 @@ + i = last_word; + + pango_get_log_attrs (text, -1, -1, pango_language_get_default (), attrs, num_attrs); Could use a #define MIN_LEN_FILENAME for this. @@ +373,3 @@ + + if (i > 10) { + pango_get_log_attrs (text, -1, -1, pango_language_get_default (), attrs, num_attrs); No need to malloc this if you use a fixed size, can just use char trimmed[MAX_LEN_FILENAME] @@ +420,3 @@ + nautilus_view_new_file_with_initial_contents (view, + target_uri != NULL ? target_uri : container_uri, + /* Translator: This is the filename used for when you dnd text to a directory */ This comment should be moved to the block above.
Created attachment 221413 [details] [review] Try to use dropped text to make a filename
Review of attachment 221413 [details] [review]: Thanks, looks good now.
Attachment 221413 [details] pushed as 7ec7d42 - Try to use dropped text to make a filename