From b08cea86c9729a46ced10a7074b5fc5327ed619d Mon Sep 17 00:00:00 2001 From: Shubham Jangra Date: Thu, 8 Nov 2018 14:18:36 +0530 Subject: [PATCH] Warn user before renaming the file/folder to start with a ' . ' Summary: For normal "casual" linux users, renaming the file/folder starting with dot may get irritating, they will be wondering their file is deleted. Test Plan: 1. Make new file/folder. 2. Rename it to .foo 3. Question dialog appears. Reviewers: elvisangelaccio, ngraham, pino Reviewed By: elvisangelaccio, ngraham Subscribers: cfeck, emateli, elvisangelaccio, pino, kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D15980 --- src/views/dolphinview.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 3e966792d..617c41ace 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1575,6 +1575,29 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename); newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); +#ifndef Q_OS_WIN + //Confirm hiding file/directory by renaming inline + if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) { + KGuiItem yesGuiItem(KStandardGuiItem::yes()); + yesGuiItem.setText(i18nc("@action:button", "Rename and Hide")); + + const auto code = KMessageBox::questionYesNo(this, + oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n" + "Do you still want to rename it?") + : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n" + "Do you still want to rename it?"), + oldItem.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"), + yesGuiItem, + KStandardGuiItem::cancel(), + QStringLiteral("ConfirmHide") + ); + + if (code == KMessageBox::No) { + return; + } + } +#endif + const bool newNameExistsAlready = (m_model->index(newUrl) >= 0); if (!newNameExistsAlready) { // Only change the data in the model if no item with the new name -- 2.47.3