From 5c2a33bba3852e1f4b51e28d720b7f3d1cbd127a Mon Sep 17 00:00:00 2001 From: Christian Soffke Date: Sat, 11 Nov 2023 01:09:04 +0100 Subject: [PATCH] Hide extension in Rename dialog when viewing single file type Hides the file name extension when renaming a file in places other than the File Browser, such as in the Playlists menu, where only a single file type is displayed. Otherwise, a file can disappear from view if its extension is accidentally changed. Plus, it becomes a little easier to edit playlist names, because you don't have to skip past the extension in the keyboard picker anymore. Change-Id: I39fc2b008d5504080e0aa728acf88ceedc2b4617 --- apps/fileop.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/fileop.c b/apps/fileop.c index a42cffa8a8..3f1ad6bd48 100644 --- a/apps/fileop.c +++ b/apps/fileop.c @@ -613,6 +613,7 @@ int rename_file(const char *selected_file) { int rc; char newname[MAX_PATH]; + char *newext = NULL; const char *oldbase, *selection = selected_file; path_basename(selection, &oldbase); @@ -622,11 +623,20 @@ int rename_file(const char *selected_file) if (strmemccpy(newname, selection, sizeof (newname)) == NULL) return FORC_PATH_TOO_LONG; + if ((*tree_get_context()->dirfilter > NUM_FILTER_MODES) && + (newext = strrchr(newbase, '.'))) + /* hide extension when renaming in lists restricted to a + single file format, such as in the Playlists menu */ + *newext = '\0'; + rc = prompt_name(newbase, sizeof (newname) - pathlen); if (rc != FORC_SUCCESS) return rc; + if (newext) /* re-add original extension */ + strlcat(newbase, strrchr(selection, '.'), sizeof (newname) - pathlen); + if (!strcmp(oldbase, newbase)) return FORC_NOOP; /* No change at all */