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 All 36 Lines | |||||
299 | void _k_slotActionTriggered(QAction *action); | 299 | void _k_slotActionTriggered(QAction *action); | ||
300 | 300 | | |||
301 | /** | 301 | /** | ||
302 | * Callback function that reads in directory name from dialog and processes it | 302 | * Callback function that reads in directory name from dialog and processes it | ||
303 | */ | 303 | */ | ||
304 | void _k_slotCreateDirectory(bool writeHiddenDir = false); | 304 | void _k_slotCreateDirectory(bool writeHiddenDir = false); | ||
305 | 305 | | |||
306 | /** | 306 | /** | ||
307 | * Callback function that reads in directory name from dialog and processes it. This will wirte | 307 | * Callback function that reads in directory name from dialog and processes it. This will write | ||
308 | * a hidden directory without further questions | 308 | * a hidden directory or a directory named ~(tilde) without further questions | ||
309 | */ | 309 | */ | ||
310 | void _k_slotCreateHiddenDirectory(); | 310 | void _k_slotCreateHiddenTildeDirectory(); | ||
311 | 311 | | |||
312 | /** | 312 | /** | ||
313 | * Fills the templates list. | 313 | * Fills the templates list. | ||
314 | */ | 314 | */ | ||
315 | void _k_slotFillTemplates(); | 315 | void _k_slotFillTemplates(); | ||
316 | 316 | | |||
317 | /** | 317 | /** | ||
318 | * Called when accepting the KPropertiesDialog (for "other desktop files") | 318 | * Called when accepting the KPropertiesDialog (for "other desktop files") | ||
▲ Show 20 Lines • Show All 81 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_tilde_dir"))) { | ||
411 | _k_slotCreateHiddenDirectory(); | 411 | _k_slotCreateHiddenTildeDirectory(); | ||
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?")); | | |||
423 | confirmDialog->setModal(m_modal); | 422 | confirmDialog->setModal(m_modal); | ||
pino: this is redundant now, as done in both the if branches below | |||||
424 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | 423 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | ||
425 | 424 | | |||
426 | QDialogButtonBox *buttonBox = new QDialogButtonBox(confirmDialog); | 425 | QDialogButtonBox *buttonBox = new QDialogButtonBox(confirmDialog); | ||
427 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | 426 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||
428 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), continueGuiItem); | 427 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), continueGuiItem); | ||
429 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), cancelGuiItem); | 428 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), cancelGuiItem); | ||
430 | 429 | | |||
430 | if (name.startsWith(QLatin1Char('.'))) { | ||||
431 | confirmDialog->setWindowTitle(i18n("Create hidden directory?")); | ||||
431 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Warning, | 432 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Warning, | ||
432 | i18n("The name \"%1\" starts with a dot, so the directory will be hidden by default.", name), | 433 | i18n("The name \"%1\" starts with a dot, so the directory will be hidden by default.", name), | ||
433 | QStringList(), | 434 | QStringList(), | ||
434 | i18n("Do not ask again"), | 435 | i18n("Do not ask again"), | ||
435 | nullptr, | 436 | nullptr, | ||
436 | KMessageBox::NoExec); | 437 | KMessageBox::NoExec); | ||
438 | } else if (name == 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. | |||||
439 | confirmDialog->setWindowTitle(i18n("Create directory named ~?")); | ||||
ngraham: That's not accurate; the dir just //begins with// `~`. | |||||
ngraham: Oops, never mind, ignore this. | |||||
440 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Warning, | ||||
441 | i18n("Naming a folder \"%1\" is not recommended because it may be confusing or dangerous when using the terminal to delete things.", 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… | |||||
442 | QStringList(), | ||||
443 | i18n("Do not ask again"), | ||||
444 | nullptr, | ||||
445 | KMessageBox::NoExec); | ||||
446 | } | ||||
437 | 447 | | |||
438 | QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(_k_slotCreateHiddenDirectory())); | 448 | QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(_k_slotCreateHiddenTildeDirectory())); | ||
439 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &KNewFileMenu::createDirectory); | 449 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &KNewFileMenu::createDirectory); | ||
440 | 450 | | |||
441 | m_fileDialog = confirmDialog; | 451 | m_fileDialog = confirmDialog; | ||
442 | confirmDialog->show(); | 452 | confirmDialog->show(); | ||
443 | 453 | | |||
444 | } | 454 | } | ||
445 | 455 | | |||
446 | void KNewFileMenuPrivate::executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry) | 456 | void KNewFileMenuPrivate::executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry) | ||
▲ Show 20 Lines • Show All 404 Lines • ▼ Show 20 Line(s) | |||||
851 | 861 | | |||
852 | } | 862 | } | ||
853 | 863 | | |||
854 | void KNewFileMenuPrivate::_k_slotCreateDirectory(bool writeHiddenDir) | 864 | void KNewFileMenuPrivate::_k_slotCreateDirectory(bool writeHiddenDir) | ||
855 | { | 865 | { | ||
856 | QUrl url; | 866 | QUrl url; | ||
857 | QUrl baseUrl = m_popupFiles.first(); | 867 | QUrl baseUrl = m_popupFiles.first(); | ||
858 | 868 | | |||
859 | QString name = expandTilde(m_text); | 869 | QString name = m_text; | ||
860 | 870 | | |||
861 | if (!name.isEmpty()) { | 871 | if (!name.isEmpty()) { | ||
862 | if (QDir::isAbsolutePath(name)) { | 872 | if (QDir::isAbsolutePath(name)) { | ||
863 | url = QUrl::fromLocalFile(name); | 873 | url = QUrl::fromLocalFile(name); | ||
864 | } else { | 874 | } else { | ||
865 | if (name == QLatin1String(".") || name == QLatin1String("..")) { | 875 | if (name == QLatin1String(".") || name == QLatin1String("..")) { | ||
866 | KGuiItem enterNewNameGuiItem(KStandardGuiItem::ok()); | 876 | KGuiItem enterNewNameGuiItem(KStandardGuiItem::ok()); | ||
867 | enterNewNameGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | 877 | enterNewNameGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | ||
Show All 17 Lines | 889 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Critical, | |||
885 | QString()); | 895 | QString()); | ||
886 | 896 | | |||
887 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &KNewFileMenu::createDirectory); | 897 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &KNewFileMenu::createDirectory); | ||
888 | m_fileDialog = confirmDialog; | 898 | m_fileDialog = confirmDialog; | ||
889 | confirmDialog->show(); | 899 | confirmDialog->show(); | ||
890 | _k_slotAbortDialog(); | 900 | _k_slotAbortDialog(); | ||
891 | return; | 901 | return; | ||
892 | } | 902 | } | ||
893 | if (!m_viewShowsHiddenFiles && name.startsWith(QLatin1Char('.'))) { | 903 | | ||
904 | if ((!m_viewShowsHiddenFiles && name.startsWith(QLatin1Char('.'))) || (name == QLatin1String("~"))) { | ||||
894 | if (!writeHiddenDir) { | 905 | if (!writeHiddenDir) { | ||
895 | confirmCreatingHiddenDir(name); | 906 | 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; | 907 | return; | ||
897 | } | 908 | } | ||
898 | } | 909 | } | ||
899 | url = baseUrl; | 910 | url = baseUrl; | ||
pino: extra line added | |||||
900 | url.setPath(concatPaths(url.path(), name)); | 911 | url.setPath(concatPaths(url.path(), name)); | ||
901 | } | 912 | } | ||
902 | } | 913 | } | ||
903 | 914 | | |||
904 | KIO::Job *job; | 915 | KIO::Job *job; | ||
905 | if (name.contains(QLatin1Char('/'))) { | 916 | if (name.contains(QLatin1Char('/'))) { | ||
906 | // If the name contains any slashes, use mkpath so that a/b/c works. | 917 | // If the name contains any slashes, use mkpath so that a/b/c works. | ||
907 | job = KIO::mkpath(url, baseUrl); | 918 | job = KIO::mkpath(url, baseUrl); | ||
Show All 10 Lines | |||||
918 | if (job) { | 929 | if (job) { | ||
919 | // We want the error handling to be done by slotResult so that subclasses can reimplement it | 930 | // We want the error handling to be done by slotResult so that subclasses can reimplement it | ||
920 | job->uiDelegate()->setAutoErrorHandlingEnabled(false); | 931 | job->uiDelegate()->setAutoErrorHandlingEnabled(false); | ||
921 | QObject::connect(job, &KJob::result, q, &KNewFileMenu::slotResult); | 932 | QObject::connect(job, &KJob::result, q, &KNewFileMenu::slotResult); | ||
922 | } | 933 | } | ||
923 | _k_slotAbortDialog(); | 934 | _k_slotAbortDialog(); | ||
924 | } | 935 | } | ||
925 | 936 | | |||
926 | void KNewFileMenuPrivate::_k_slotCreateHiddenDirectory() | 937 | void KNewFileMenuPrivate::_k_slotCreateHiddenTildeDirectory() | ||
927 | { | 938 | { | ||
928 | _k_slotCreateDirectory(true); | 939 | _k_slotCreateDirectory(true); | ||
929 | } | 940 | } | ||
930 | 941 | | |||
931 | struct EntryWithName { | 942 | struct EntryWithName { | ||
932 | QString key; | 943 | QString key; | ||
933 | KNewFileMenuSingleton::Entry entry; | 944 | KNewFileMenuSingleton::Entry entry; | ||
934 | }; | 945 | }; | ||
▲ Show 20 Lines • Show All 416 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)