summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Berla <corey@berla.me>2022-09-02 11:37:30 -0700
committerAntónio Fernandes <antoniof@gnome.org>2022-09-03 10:37:52 +0000
commita9214ba53e2766e721942ec0207d76e1ebe9c450 (patch)
tree12cb2b6fe03725b6ce8c30681c3c13c80a50fb12
parent7700c17bb373c284603c0c4289b95428dc0bba2d (diff)
downloadnautilus-a9214ba53e2766e721942ec0207d76e1ebe9c450.tar.gz
files-view-dnd: Improve filename generated from dropped text
Make several improvements: 1) Max filename was too long at 128 characters, half it to 64 2) Tweak min filename to 8 characters (still meaningful) 3) Stop at the first sentence rather than last sentence. A filename should be short and concise, multiple sentences don't make sense. 4) Start at the start_sentence (i.e. eliminate leading whitespace) Importantly this patch eliminates the potential inclusion of newlines which is problematic in the views (it causes more than 3 lines of the filename to appear because of the GtkLabel behavior).
-rw-r--r--src/nautilus-files-view-dnd.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/nautilus-files-view-dnd.c b/src/nautilus-files-view-dnd.c
index 5d3220d37..96a5c8240 100644
--- a/src/nautilus-files-view-dnd.c
+++ b/src/nautilus-files-view-dnd.c
@@ -120,8 +120,8 @@ nautilus_files_view_handle_uri_list_drop (NautilusFilesView *view,
g_free (container_uri);
}
-#define MAX_LEN_FILENAME 128
-#define MIN_LEN_FILENAME 10
+#define MAX_LEN_FILENAME 64
+#define MIN_LEN_FILENAME 8
static char *
get_drop_filename (const char *text)
@@ -130,8 +130,9 @@ get_drop_filename (const char *text)
char trimmed[MAX_LEN_FILENAME];
int i;
int last_word = -1;
- int last_sentence = -1;
+ int end_sentence = -1;
int last_nonspace = -1;
+ int start_sentence = -1;
int num_attrs;
PangoLogAttr *attrs;
gchar *current_char;
@@ -144,35 +145,39 @@ get_drop_filename (const char *text)
/* since the end of the text will always match a word boundary don't include it */
for (i = 0; (i < num_attrs - 1); i++)
{
- if (!attrs[i].is_white)
+ if (attrs[i].is_sentence_start && start_sentence == -1)
{
- last_nonspace = i;
+ start_sentence = i;
}
- if (attrs[i].is_sentence_end)
+ if (!attrs[i].is_white)
{
- last_sentence = last_nonspace;
+ last_nonspace = i;
}
if (attrs[i].is_word_boundary)
{
last_word = last_nonspace;
}
+ if (attrs[i].is_sentence_end)
+ {
+ end_sentence = last_nonspace;
+ break;
+ }
}
g_free (attrs);
- if (last_sentence > 0)
+ if (end_sentence > 0)
{
- i = last_sentence;
+ i = end_sentence;
}
else
{
i = last_word;
}
- if (i > MIN_LEN_FILENAME)
+ if (i - start_sentence > MIN_LEN_FILENAME)
{
- char basename[MAX_LEN_FILENAME];
- g_utf8_strncpy (basename, trimmed, i);
- filename = g_strdup_printf ("%s.txt", basename);
+ g_autofree char *substring = g_utf8_substring (trimmed, start_sentence, i);
+ filename = g_strdup_printf ("%s.txt", substring);
}
else
{