Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/knewfilemenu.cpp
Show First 20 Lines • Show All 243 Lines • ▼ Show 20 Line(s) | 242 | : m_menuItemsVersion(0), | |||
---|---|---|---|---|---|
244 | m_viewShowsHiddenFiles(false), | 244 | m_viewShowsHiddenFiles(false), | ||
245 | m_firstFileEntry(nullptr), | 245 | m_firstFileEntry(nullptr), | ||
246 | q(qq) | 246 | q(qq) | ||
247 | {} | 247 | {} | ||
248 | 248 | | |||
249 | bool checkSourceExists(const QString &src); | 249 | bool checkSourceExists(const QString &src); | ||
250 | 250 | | |||
251 | /** | 251 | /** | ||
252 | * Asks user whether to create a hidden directory with a dialog | 252 | * Asks user depending on whether they wants to create a hidden directory or a directory named "~" with a dialog | ||
253 | */ | 253 | */ | ||
254 | void confirmCreatingHiddenDir(const QString &name); | 254 | void confirmCreatingDir(const QString &name); | ||
255 | 255 | | |||
256 | /** | 256 | /** | ||
257 | * The strategy used for other desktop files than Type=Link. Example: Application, Device. | 257 | * The strategy used for other desktop files than Type=Link. Example: Application, Device. | ||
258 | */ | 258 | */ | ||
259 | void executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry); | 259 | void executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry); | ||
260 | 260 | | |||
261 | /** | 261 | /** | ||
262 | * The strategy used for "real files or directories" (the common case) | 262 | * The strategy used for "real files or directories" (the common case) | ||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | 385 | if (!QFile::exists(src)) { | |||
400 | 400 | | |||
401 | dialog->show(); | 401 | dialog->show(); | ||
402 | 402 | | |||
403 | return false; | 403 | return false; | ||
404 | } | 404 | } | ||
405 | return true; | 405 | return true; | ||
406 | } | 406 | } | ||
407 | 407 | | |||
408 | void KNewFileMenuPrivate::confirmCreatingHiddenDir(const QString &name) | 408 | void KNewFileMenuPrivate::confirmCreatingDir(const QString &name) | ||
409 | { | 409 | { | ||
410 | if (!KMessageBox::shouldBeShownContinue(QStringLiteral("confirm_create_hidden_dir"))) { | 410 | if (!KMessageBox::shouldBeShownContinue(QStringLiteral("confirm_create_hidden_dir"))) { | ||
411 | _k_slotCreateHiddenDirectory(); | 411 | _k_slotCreateHiddenDirectory(); | ||
412 | return; | 412 | return; | ||
413 | } | 413 | } | ||
pino: renaming confirmCreatingHiddenDir and using it also for another case means that the… | |||||
414 | 414 | | |||
415 | KGuiItem continueGuiItem(KStandardGuiItem::cont()); | 415 | KGuiItem continueGuiItem(KStandardGuiItem::cont()); | ||
416 | continueGuiItem.setText(i18nc("@action:button", "Create directory")); | 416 | continueGuiItem.setText(i18nc("@action:button", "Create directory")); | ||
417 | KGuiItem cancelGuiItem(KStandardGuiItem::cancel()); | 417 | KGuiItem cancelGuiItem(KStandardGuiItem::cancel()); | ||
418 | cancelGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | 418 | cancelGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | ||
419 | cancelGuiItem.setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | 419 | cancelGuiItem.setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | ||
420 | 420 | | |||
421 | QDialog *confirmDialog = new QDialog(m_parentWidget); | 421 | QDialog *confirmDialog = new QDialog(m_parentWidget); | ||
422 | confirmDialog->setWindowTitle(i18n("Create hidden directory?")); | 422 | confirmDialog->setWindowTitle(i18n("Create hidden directory?")); | ||
pino: this is redundant now, as done in both the if branches below | |||||
423 | confirmDialog->setModal(m_modal); | 423 | confirmDialog->setModal(m_modal); | ||
424 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | 424 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | ||
425 | 425 | | |||
426 | QDialogButtonBox *buttonBox = new QDialogButtonBox(confirmDialog); | 426 | QDialogButtonBox *buttonBox = new QDialogButtonBox(confirmDialog); | ||
427 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | 427 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||
428 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), continueGuiItem); | 428 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), continueGuiItem); | ||
429 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), cancelGuiItem); | 429 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), cancelGuiItem); | ||
430 | 430 | | |||
431 | if (name.startsWith(QLatin1Char('.'))) { | ||||
432 | confirmDialog->setWindowTitle(i18n("Create hidden directory?")); | ||||
431 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Warning, | 433 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Warning, | ||
432 | i18n("The name \"%1\" starts with a dot, so the directory will be hidden by default.", name), | 434 | i18n("The name \"%1\" starts with a dot, so the directory will be hidden by default.", name), | ||
433 | QStringList(), | 435 | QStringList(), | ||
434 | i18n("Do not ask again"), | 436 | i18n("Do not ask again"), | ||
435 | nullptr, | 437 | nullptr, | ||
436 | KMessageBox::NoExec); | 438 | KMessageBox::NoExec); | ||
439 | } else if (name.operator==(QLatin1String("~"))) { | ||||
Please simply write name == QStringLiteral (...) instead of operator==. Same below. dhaumann: Please simply write name == QStringLiteral (...) instead of operator==. Same below. | |||||
shubham: This is faster than simple == | |||||
dhaumann: Really? But isn't == not exactly the same? Can you elaborate? | |||||
shubham: ```
==
```
internally calls
```
operator==()
```
| |||||
The compiler automatically replaces the operators into the calls to the appropriate functions. There is no speed penalty. pino: The compiler automatically replaces the operators into the calls to the appropriate functions. | |||||
440 | confirmDialog->setWindowTitle(i18n("Create directory named ~?")); | ||||
ngraham: That's not accurate; the dir just //begins with// `~`. | |||||
ngraham: Oops, never mind, ignore this. | |||||
441 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Warning, | ||||
442 | i18n("A directory named \"%1\" (tilde) is not recommended because it may be confusing or dangerous if directories are deleted using the terminal", name), | ||||
Hmm, that might be too technical an explanation. How about this instead? Beginning a file name with a tilde character ("~") is not recommended because it may be confusing or dangerous if files are deleted using the terminal. ngraham: Hmm, that might be too technical an explanation. How about this instead?
`Beginning a file… | |||||
Actually maybe this: Naming a folder \$1\ is not recommended because it may be confusing or dangerous when using the terminal to delete things. ngraham: Actually maybe this:
`Naming a folder \$1\ is not recommended because it may be confusing or… | |||||
443 | QStringList(), | ||||
444 | i18n("Do not ask again"), | ||||
445 | nullptr, | ||||
446 | KMessageBox::NoExec); | ||||
447 | } | ||||
437 | 448 | | |||
438 | QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(_k_slotCreateHiddenDirectory())); | 449 | QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(_k_slotCreateHiddenDirectory())); | ||
439 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &KNewFileMenu::createDirectory); | 450 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &KNewFileMenu::createDirectory); | ||
440 | 451 | | |||
441 | m_fileDialog = confirmDialog; | 452 | m_fileDialog = confirmDialog; | ||
442 | confirmDialog->show(); | 453 | confirmDialog->show(); | ||
443 | 454 | | |||
444 | } | 455 | } | ||
▲ Show 20 Lines • Show All 406 Lines • ▼ Show 20 Line(s) | |||||
851 | 862 | | |||
852 | } | 863 | } | ||
853 | 864 | | |||
854 | void KNewFileMenuPrivate::_k_slotCreateDirectory(bool writeHiddenDir) | 865 | void KNewFileMenuPrivate::_k_slotCreateDirectory(bool writeHiddenDir) | ||
855 | { | 866 | { | ||
856 | QUrl url; | 867 | QUrl url; | ||
857 | QUrl baseUrl = m_popupFiles.first(); | 868 | QUrl baseUrl = m_popupFiles.first(); | ||
858 | 869 | | |||
859 | QString name = expandTilde(m_text); | 870 | QString name = m_text; | ||
860 | 871 | | |||
861 | if (!name.isEmpty()) { | 872 | if (!name.isEmpty()) { | ||
862 | if (QDir::isAbsolutePath(name)) { | 873 | if (QDir::isAbsolutePath(name)) { | ||
863 | url = QUrl::fromLocalFile(name); | 874 | url = QUrl::fromLocalFile(name); | ||
864 | } else { | 875 | } else { | ||
865 | if (name == QLatin1String(".") || name == QLatin1String("..")) { | 876 | if (name == QLatin1String(".") || name == QLatin1String("..")) { | ||
866 | KGuiItem enterNewNameGuiItem(KStandardGuiItem::ok()); | 877 | KGuiItem enterNewNameGuiItem(KStandardGuiItem::ok()); | ||
867 | enterNewNameGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | 878 | enterNewNameGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | ||
Show All 17 Lines | 890 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Critical, | |||
885 | QString()); | 896 | QString()); | ||
886 | 897 | | |||
887 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &KNewFileMenu::createDirectory); | 898 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &KNewFileMenu::createDirectory); | ||
888 | m_fileDialog = confirmDialog; | 899 | m_fileDialog = confirmDialog; | ||
889 | confirmDialog->show(); | 900 | confirmDialog->show(); | ||
890 | _k_slotAbortDialog(); | 901 | _k_slotAbortDialog(); | ||
891 | return; | 902 | return; | ||
892 | } | 903 | } | ||
893 | if (!m_viewShowsHiddenFiles && name.startsWith(QLatin1Char('.'))) { | 904 | | ||
905 | if ((!m_viewShowsHiddenFiles && name.startsWith(QLatin1Char('.'))) || (name.operator==(QLatin1String("~")))) { | ||||
894 | if (!writeHiddenDir) { | 906 | if (!writeHiddenDir) { | ||
895 | confirmCreatingHiddenDir(name); | 907 | confirmCreatingDir(name); | ||
Now the name of this function is no longer accurate since you're using it to display a message for a name that wouldn't result in in the file or folder being hidden. ngraham: Now the name of this function is no longer accurate since you're using it to display a message… | |||||
896 | return; | 908 | return; | ||
897 | } | 909 | } | ||
898 | } | 910 | } | ||
911 | | ||||
pino: extra line added | |||||
899 | url = baseUrl; | 912 | url = baseUrl; | ||
900 | url.setPath(concatPaths(url.path(), name)); | 913 | url.setPath(concatPaths(url.path(), name)); | ||
901 | } | 914 | } | ||
902 | } | 915 | } | ||
903 | 916 | | |||
904 | KIO::Job *job; | 917 | KIO::Job *job; | ||
905 | if (name.contains(QLatin1Char('/'))) { | 918 | if (name.contains(QLatin1Char('/'))) { | ||
906 | // If the name contains any slashes, use mkpath so that a/b/c works. | 919 | // If the name contains any slashes, use mkpath so that a/b/c works. | ||
▲ Show 20 Lines • Show All 444 Lines • Show Last 20 Lines |
renaming confirmCreatingHiddenDir and using it also for another case means that the "confirm_create_hidden_dir" messagebox confirmation also applies to the other cases (filename == '~' in this case)