After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 347563 - Give dragged text a better file name than "new file"
Give dragged text a better file name than "new file"
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: general
2.15.x
Other Linux
: Normal minor
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
Depends on:
Blocks:
 
 
Reported: 2006-07-14 23:08 UTC by Sergej Kotliar
Modified: 2012-08-16 15:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Try to use dropped text to make a filename (2.82 KB, patch)
2012-08-16 12:56 UTC, William Jon McCann
needs-work Details | Review
Try to use dropped text to make a filename (2.90 KB, patch)
2012-08-16 15:19 UTC, William Jon McCann
committed Details | Review

Description Sergej Kotliar 2006-07-14 23:08:53 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.
Comment 1 Allan Day 2010-07-10 11:55:46 UTC
Agreed. Nice suggestion. Thanks for the report!
Comment 2 William Jon McCann 2012-08-16 12:56:28 UTC
Created attachment 221364 [details] [review]
Try to use dropped text to make a filename
Comment 3 Cosimo Cecchi 2012-08-16 14:50:55 UTC
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.
Comment 4 William Jon McCann 2012-08-16 15:19:24 UTC
Created attachment 221413 [details] [review]
Try to use dropped text to make a filename
Comment 5 Cosimo Cecchi 2012-08-16 15:35:49 UTC
Review of attachment 221413 [details] [review]:

Thanks, looks good now.
Comment 6 William Jon McCann 2012-08-16 15:40:05 UTC
Attachment 221413 [details] pushed as 7ec7d42 - Try to use dropped text to make a filename