Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/knewfilemenu.cpp
Show All 24 Lines | |||||
25 | #include <QDialog> | 25 | #include <QDialog> | ||
26 | #include <QDialogButtonBox> | 26 | #include <QDialogButtonBox> | ||
27 | #include <QDir> | 27 | #include <QDir> | ||
28 | #include <QVBoxLayout> | 28 | #include <QVBoxLayout> | ||
29 | #include <QList> | 29 | #include <QList> | ||
30 | #include <QLabel> | 30 | #include <QLabel> | ||
31 | #include <QLineEdit> | 31 | #include <QLineEdit> | ||
32 | #include <QMenu> | 32 | #include <QMenu> | ||
33 | #include <QPushButton> | ||||
33 | #include <QStandardPaths> | 34 | #include <QStandardPaths> | ||
34 | 35 | | |||
35 | #include <qtemporaryfile.h> | 36 | #include <qtemporaryfile.h> | ||
36 | #include <kactioncollection.h> | 37 | #include <kactioncollection.h> | ||
37 | #include <kconfiggroup.h> | 38 | #include <kconfiggroup.h> | ||
38 | #include <QDebug> | 39 | #include <QDebug> | ||
39 | #include <kdesktopfile.h> | 40 | #include <kdesktopfile.h> | ||
40 | #include <kdirwatch.h> | 41 | #include <kdirwatch.h> | ||
41 | #include <kdirnotify.h> | 42 | #include <kdirnotify.h> | ||
42 | #include <kjobwidgets.h> | 43 | #include <kjobwidgets.h> | ||
43 | #include <klocalizedstring.h> | 44 | #include <klocalizedstring.h> | ||
44 | #include <kmessagebox.h> | 45 | #include <kmessagebox.h> | ||
46 | #include <kmessagewidget.h> | ||||
45 | #include <kprotocolinfo.h> | 47 | #include <kprotocolinfo.h> | ||
46 | #include <kprotocolmanager.h> | 48 | #include <kprotocolmanager.h> | ||
47 | #include <krun.h> | 49 | #include <krun.h> | ||
48 | #include <kshell.h> | 50 | #include <kshell.h> | ||
49 | #include <kio/job.h> | 51 | #include <kio/job.h> | ||
50 | #include <kio/copyjob.h> | 52 | #include <kio/copyjob.h> | ||
51 | #include <kio/jobuidelegate.h> | 53 | #include <kio/jobuidelegate.h> | ||
52 | #include <kio/fileundomanager.h> | 54 | #include <kio/fileundomanager.h> | ||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Line(s) | |||||
238 | class KNewFileMenuPrivate | 240 | class KNewFileMenuPrivate | ||
239 | { | 241 | { | ||
240 | public: | 242 | public: | ||
241 | explicit KNewFileMenuPrivate(KNewFileMenu *qq) | 243 | explicit KNewFileMenuPrivate(KNewFileMenu *qq) | ||
242 | : m_menuItemsVersion(0), | 244 | : m_menuItemsVersion(0), | ||
243 | m_modal(true), | 245 | m_modal(true), | ||
244 | m_viewShowsHiddenFiles(false), | 246 | m_viewShowsHiddenFiles(false), | ||
245 | m_firstFileEntry(nullptr), | 247 | m_firstFileEntry(nullptr), | ||
248 | m_messageWidget(nullptr), | ||||
249 | m_buttonBox(nullptr), | ||||
246 | q(qq) | 250 | q(qq) | ||
247 | {} | 251 | {} | ||
248 | 252 | | |||
249 | bool checkSourceExists(const QString &src); | 253 | bool checkSourceExists(const QString &src); | ||
250 | 254 | | |||
251 | /** | 255 | /** | ||
252 | * Asks user whether to create a hidden directory with a dialog | | |||
253 | */ | | |||
254 | void confirmCreatingHiddenDir(const QString &name); | | |||
255 | | ||||
256 | /** | | |||
257 | * The strategy used for other desktop files than Type=Link. Example: Application, Device. | 256 | * The strategy used for other desktop files than Type=Link. Example: Application, Device. | ||
258 | */ | 257 | */ | ||
259 | void executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry); | 258 | void executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry); | ||
260 | 259 | | |||
261 | /** | 260 | /** | ||
262 | * The strategy used for "real files or directories" (the common case) | 261 | * The strategy used for "real files or directories" (the common case) | ||
263 | */ | 262 | */ | ||
264 | void executeRealFileOrDir(const KNewFileMenuSingleton::Entry &entry); | 263 | void executeRealFileOrDir(const KNewFileMenuSingleton::Entry &entry); | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
350 | 349 | | |||
351 | KActionCollection *m_actionCollection; | 350 | KActionCollection *m_actionCollection; | ||
352 | QDialog *m_fileDialog; | 351 | QDialog *m_fileDialog; | ||
353 | 352 | | |||
354 | KActionMenu *m_menuDev; | 353 | KActionMenu *m_menuDev; | ||
355 | int m_menuItemsVersion; | 354 | int m_menuItemsVersion; | ||
356 | bool m_modal; | 355 | bool m_modal; | ||
357 | QAction *m_newDirAction; | 356 | QAction *m_newDirAction; | ||
357 | KMessageWidget* m_messageWidget; | ||||
358 | QDialogButtonBox* m_buttonBox; | ||||
358 | 359 | | |||
359 | /** | 360 | /** | ||
360 | * The action group that our actions belong to | 361 | * The action group that our actions belong to | ||
361 | */ | 362 | */ | ||
362 | QActionGroup *m_newMenuGroup; | 363 | QActionGroup *m_newMenuGroup; | ||
363 | QWidget *m_parentWidget; | 364 | QWidget *m_parentWidget; | ||
364 | 365 | | |||
365 | /** | 366 | /** | ||
Show All 20 Lines | 386 | if (!QFile::exists(src)) { | |||
386 | qWarning() << src << "doesn't exist"; | 387 | qWarning() << src << "doesn't exist"; | ||
387 | 388 | | |||
388 | QDialog *dialog = new QDialog(m_parentWidget); | 389 | QDialog *dialog = new QDialog(m_parentWidget); | ||
389 | dialog->setWindowTitle(i18n("Sorry")); | 390 | dialog->setWindowTitle(i18n("Sorry")); | ||
390 | dialog->setObjectName(QStringLiteral("sorry")); | 391 | dialog->setObjectName(QStringLiteral("sorry")); | ||
391 | dialog->setModal(q->isModal()); | 392 | dialog->setModal(q->isModal()); | ||
392 | dialog->setAttribute(Qt::WA_DeleteOnClose); | 393 | dialog->setAttribute(Qt::WA_DeleteOnClose); | ||
393 | 394 | | |||
394 | QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); | 395 | m_buttonBox = new QDialogButtonBox(dialog); | ||
395 | buttonBox->setStandardButtons(QDialogButtonBox::Ok); | 396 | m_buttonBox->setStandardButtons(QDialogButtonBox::Ok); | ||
396 | 397 | | |||
397 | KMessageBox::createKMessageBox(dialog, buttonBox, QMessageBox::Warning, | 398 | KMessageBox::createKMessageBox(dialog, m_buttonBox, QMessageBox::Warning, | ||
398 | i18n("<qt>The template file <b>%1</b> does not exist.</qt>", src), | 399 | i18n("<qt>The template file <b>%1</b> does not exist.</qt>", src), | ||
399 | QStringList(), QString(), nullptr, KMessageBox::NoExec); | 400 | QStringList(), QString(), nullptr, KMessageBox::NoExec); | ||
400 | 401 | | |||
401 | dialog->show(); | 402 | dialog->show(); | ||
402 | 403 | | |||
403 | return false; | 404 | return false; | ||
404 | } | 405 | } | ||
405 | return true; | 406 | return true; | ||
406 | } | 407 | } | ||
407 | 408 | | |||
408 | void KNewFileMenuPrivate::confirmCreatingHiddenDir(const QString &name) | | |||
409 | { | | |||
410 | if (!KMessageBox::shouldBeShownContinue(QStringLiteral("confirm_create_hidden_dir"))) { | | |||
411 | _k_slotCreateHiddenDirectory(); | | |||
412 | return; | | |||
413 | } | | |||
414 | | ||||
415 | KGuiItem continueGuiItem(KStandardGuiItem::cont()); | | |||
416 | continueGuiItem.setText(i18nc("@action:button", "Create directory")); | | |||
417 | KGuiItem cancelGuiItem(KStandardGuiItem::cancel()); | | |||
418 | cancelGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | | |||
419 | cancelGuiItem.setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | | |||
420 | | ||||
421 | QDialog *confirmDialog = new QDialog(m_parentWidget); | | |||
422 | confirmDialog->setWindowTitle(i18n("Create hidden directory?")); | | |||
423 | confirmDialog->setModal(m_modal); | | |||
424 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | | |||
425 | | ||||
426 | QDialogButtonBox *buttonBox = new QDialogButtonBox(confirmDialog); | | |||
427 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | | |||
428 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), continueGuiItem); | | |||
429 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), cancelGuiItem); | | |||
430 | | ||||
431 | 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 | QStringList(), | | |||
434 | i18n("Do not ask again"), | | |||
435 | nullptr, | | |||
436 | KMessageBox::NoExec); | | |||
437 | | ||||
438 | QObject::connect(buttonBox, SIGNAL(accepted()), q, SLOT(_k_slotCreateHiddenDirectory())); | | |||
439 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, q, &KNewFileMenu::createDirectory); | | |||
440 | | ||||
441 | m_fileDialog = confirmDialog; | | |||
442 | confirmDialog->show(); | | |||
443 | | ||||
444 | } | | |||
445 | | ||||
446 | void KNewFileMenuPrivate::executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry) | 409 | void KNewFileMenuPrivate::executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry) | ||
447 | { | 410 | { | ||
448 | if (!checkSourceExists(entry.templatePath)) { | 411 | if (!checkSourceExists(entry.templatePath)) { | ||
449 | return; | 412 | return; | ||
450 | } | 413 | } | ||
451 | 414 | | |||
452 | QList<QUrl>::const_iterator it = m_popupFiles.constBegin(); | 415 | QList<QUrl>::const_iterator it = m_popupFiles.constBegin(); | ||
453 | for (; it != m_popupFiles.constEnd(); ++it) { | 416 | for (; it != m_popupFiles.constEnd(); ++it) { | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 461 | { | |||
506 | const QUrl directory = mostLocalUrl(m_popupFiles.first()); | 469 | const QUrl directory = mostLocalUrl(m_popupFiles.first()); | ||
507 | const QUrl defaultFile = QUrl::fromLocalFile(directory.toLocalFile() + QLatin1Char('/') + KIO::encodeFileName(text)); | 470 | const QUrl defaultFile = QUrl::fromLocalFile(directory.toLocalFile() + QLatin1Char('/') + KIO::encodeFileName(text)); | ||
508 | if (defaultFile.isLocalFile() && QFile::exists(defaultFile.toLocalFile())) { | 471 | if (defaultFile.isLocalFile() && QFile::exists(defaultFile.toLocalFile())) { | ||
509 | text = KIO::suggestName(directory, text); | 472 | text = KIO::suggestName(directory, text); | ||
510 | } | 473 | } | ||
511 | 474 | | |||
512 | QDialog *fileDialog = new QDialog(m_parentWidget); | 475 | QDialog *fileDialog = new QDialog(m_parentWidget); | ||
513 | fileDialog->setAttribute(Qt::WA_DeleteOnClose); | 476 | fileDialog->setAttribute(Qt::WA_DeleteOnClose); | ||
477 | fileDialog->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); | ||||
514 | fileDialog->setModal(q->isModal()); | 478 | fileDialog->setModal(q->isModal()); | ||
479 | m_fileDialog = fileDialog; | ||||
515 | 480 | | |||
516 | QVBoxLayout *layout = new QVBoxLayout; | 481 | QVBoxLayout *layout = new QVBoxLayout; | ||
482 | layout->setSizeConstraint(QLayout::SetFixedSize); | ||||
483 | | ||||
484 | m_messageWidget = new KMessageWidget(fileDialog); | ||||
485 | m_messageWidget->setCloseButtonVisible(false); | ||||
486 | m_messageWidget->setWordWrap(true); | ||||
487 | m_messageWidget->hide(); | ||||
517 | QLabel *label = new QLabel(entry.comment, fileDialog); | 488 | QLabel *label = new QLabel(entry.comment, fileDialog); | ||
518 | 489 | | |||
519 | QLineEdit *lineEdit = new QLineEdit(fileDialog); | 490 | QLineEdit *lineEdit = new QLineEdit(fileDialog); | ||
520 | lineEdit->setClearButtonEnabled(true); | 491 | lineEdit->setClearButtonEnabled(true); | ||
521 | lineEdit->setText(text); | 492 | lineEdit->setText(text); | ||
493 | lineEdit->setMinimumWidth(400); | ||||
494 | | ||||
495 | m_buttonBox = new QDialogButtonBox(fileDialog); | ||||
496 | m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||||
497 | QObject::connect(m_buttonBox, &QDialogButtonBox::accepted, fileDialog, &QDialog::accept); | ||||
498 | QObject::connect(m_buttonBox, &QDialogButtonBox::rejected, fileDialog, &QDialog::reject); | ||||
522 | 499 | | |||
523 | _k_slotTextChanged(text); | 500 | _k_slotTextChanged(text); | ||
524 | QObject::connect(lineEdit, SIGNAL(textChanged(QString)), q, SLOT(_k_slotTextChanged(QString))); | 501 | QObject::connect(lineEdit, SIGNAL(textChanged(QString)), q, SLOT(_k_slotTextChanged(QString))); | ||
525 | 502 | | |||
526 | QDialogButtonBox *buttonBox = new QDialogButtonBox(fileDialog); | | |||
527 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | | |||
528 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, fileDialog, &QDialog::accept); | | |||
529 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, fileDialog, &QDialog::reject); | | |||
530 | | ||||
531 | layout->addWidget(label); | 503 | layout->addWidget(label); | ||
532 | layout->addWidget(lineEdit); | 504 | layout->addWidget(lineEdit); | ||
533 | layout->addWidget(buttonBox); | 505 | layout->addWidget(m_buttonBox); | ||
506 | layout->addWidget(m_messageWidget); | ||||
507 | layout->addStretch(); | ||||
534 | 508 | | |||
535 | fileDialog->setLayout(layout); | 509 | fileDialog->setLayout(layout); | ||
536 | QObject::connect(fileDialog, SIGNAL(accepted()), q, SLOT(_k_slotRealFileOrDir())); | 510 | QObject::connect(fileDialog, SIGNAL(accepted()), q, SLOT(_k_slotRealFileOrDir())); | ||
537 | QObject::connect(fileDialog, SIGNAL(rejected()), q, SLOT(_k_slotAbortDialog())); | 511 | QObject::connect(fileDialog, SIGNAL(rejected()), q, SLOT(_k_slotAbortDialog())); | ||
538 | 512 | | |||
539 | fileDialog->show(); | 513 | fileDialog->show(); | ||
540 | lineEdit->selectAll(); | 514 | lineEdit->selectAll(); | ||
541 | lineEdit->setFocus(); | 515 | lineEdit->setFocus(); | ||
▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Line(s) | 839 | if (name == QLatin1String(".") || name == QLatin1String("..")) { | |||
867 | enterNewNameGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | 841 | enterNewNameGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | ||
868 | enterNewNameGuiItem.setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | 842 | enterNewNameGuiItem.setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | ||
869 | 843 | | |||
870 | QDialog *confirmDialog = new QDialog(m_parentWidget); | 844 | QDialog *confirmDialog = new QDialog(m_parentWidget); | ||
871 | confirmDialog->setWindowTitle(i18n("Invalid Directory Name")); | 845 | confirmDialog->setWindowTitle(i18n("Invalid Directory Name")); | ||
872 | confirmDialog->setModal(m_modal); | 846 | confirmDialog->setModal(m_modal); | ||
873 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | 847 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | ||
874 | 848 | | |||
875 | QDialogButtonBox *buttonBox = new QDialogButtonBox(confirmDialog); | 849 | m_buttonBox = new QDialogButtonBox(confirmDialog); | ||
876 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | 850 | m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||
877 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), enterNewNameGuiItem); | 851 | KGuiItem::assign(m_buttonBox->button(QDialogButtonBox::Ok), enterNewNameGuiItem); | ||
878 | 852 | | |||
879 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Critical, | 853 | KMessageBox::createKMessageBox(confirmDialog, m_buttonBox, QMessageBox::Critical, | ||
880 | xi18nc("@info", "Could not create a folder with the name <filename>%1</filename><nl/>because it is reserved for use by the operating system.", name), | 854 | xi18nc("@info", "Could not create a folder with the name <filename>%1</filename><nl/>because it is reserved for use by the operating system.", name), | ||
881 | QStringList(), | 855 | QStringList(), | ||
882 | QString(), | 856 | QString(), | ||
883 | nullptr, | 857 | nullptr, | ||
884 | KMessageBox::NoExec, | 858 | KMessageBox::NoExec, | ||
885 | QString()); | 859 | QString()); | ||
886 | 860 | | |||
887 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &KNewFileMenu::createDirectory); | 861 | QObject::connect(m_buttonBox, &QDialogButtonBox::accepted, q, &KNewFileMenu::createDirectory); | ||
888 | m_fileDialog = confirmDialog; | 862 | m_fileDialog = confirmDialog; | ||
889 | confirmDialog->show(); | 863 | confirmDialog->show(); | ||
890 | _k_slotAbortDialog(); | 864 | _k_slotAbortDialog(); | ||
891 | return; | 865 | return; | ||
892 | } | 866 | } | ||
893 | if (!m_viewShowsHiddenFiles && name.startsWith(QLatin1Char('.'))) { | | |||
894 | if (!writeHiddenDir) { | | |||
895 | confirmCreatingHiddenDir(name); | | |||
896 | return; | | |||
897 | } | | |||
898 | } | | |||
899 | url = baseUrl; | 867 | url = baseUrl; | ||
900 | url.setPath(concatPaths(url.path(), name)); | 868 | url.setPath(concatPaths(url.path(), name)); | ||
901 | } | 869 | } | ||
902 | } | 870 | } | ||
903 | 871 | | |||
904 | KIO::Job *job; | 872 | KIO::Job *job; | ||
905 | if (name.contains(QLatin1Char('/'))) { | 873 | if (name.contains(QLatin1Char('/'))) { | ||
906 | // If the name contains any slashes, use mkpath so that a/b/c works. | 874 | // If the name contains any slashes, use mkpath so that a/b/c works. | ||
▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Line(s) | 1027 | { | |||
1067 | } | 1035 | } | ||
1068 | 1036 | | |||
1069 | m_copyData.m_src = linkTarget; | 1037 | m_copyData.m_src = linkTarget; | ||
1070 | executeStrategy(); | 1038 | executeStrategy(); | ||
1071 | } | 1039 | } | ||
1072 | 1040 | | |||
1073 | void KNewFileMenuPrivate::_k_slotTextChanged(const QString &text) | 1041 | void KNewFileMenuPrivate::_k_slotTextChanged(const QString &text) | ||
1074 | { | 1042 | { | ||
1043 | m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); | ||||
1044 | // Validate input, displaying a KMessageWidget for questionable names | ||||
1045 | | ||||
1046 | if (text.length() == 0) { | ||||
1047 | m_messageWidget->setText(i18n("Name cannot be blank.")); | ||||
meven: I would rather disable the ok button, as long as the user has not entered text, rather than… | |||||
1048 | m_messageWidget->setMessageType(KMessageWidget::Error); | ||||
1049 | m_messageWidget->animatedShow(); | ||||
1050 | m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||||
1051 | } | ||||
1052 | | ||||
1053 | // Don't allow creating folders that would mask . or .. | ||||
1054 | else if (text == QLatin1String(".") || text == QLatin1String("..")) { | ||||
1055 | m_messageWidget->setText(xi18nc("@info", "The name <filename>%1</filename> cannot be used because it is reserved for use by the operating system.", text)); | ||||
1056 | m_messageWidget->setMessageType(KMessageWidget::Error); | ||||
1057 | m_messageWidget->animatedShow(); | ||||
1058 | m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||||
1059 | } | ||||
1060 | | ||||
1061 | // File or folder would be hidden; show warning | ||||
1062 | else if (text.startsWith(QLatin1Char('.'))) { | ||||
1063 | m_messageWidget->setText(xi18nc("@info", "The name <filename>%1</filename> starts with a dot, so it will be hidden by default.", text)); | ||||
1064 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||||
1065 | m_messageWidget->animatedShow(); | ||||
1066 | } | ||||
1067 | | ||||
1068 | // Inform the user that slashes in folder names create a directory tree | ||||
1069 | else if (text.contains(QLatin1Char('/'))) { | ||||
1070 | if (true /*folders*/) { | ||||
1071 | QStringList folders = text.split(QLatin1Char('/')); | ||||
meven: What about Windows ? maybe use QDir::separator() ? | |||||
read the docu for QDir::separator() , you seldom ever want to use it. aacid: read the docu for QDir::separator() , you seldom ever want to use it.
https://agateau. | |||||
1072 | if (!folders.isEmpty()) { | ||||
1073 | if (folders.first().isEmpty()) { | ||||
1074 | folders.removeFirst(); | ||||
1075 | } | ||||
1076 | } | ||||
1077 | QString label; | ||||
1078 | if (folders.count() > 1) { | ||||
1079 | label = i18n("Using slashes in folder names will create sub-folders, like so:"); | ||||
1080 | QString indentation = QString(); | ||||
1081 | for (const QString &folder : folders) { | ||||
1082 | label.append(QStringLiteral("\n")); | ||||
1083 | label.append(indentation); | ||||
1084 | label.append(folder); | ||||
1085 | label.append(QStringLiteral("/")); | ||||
1086 | indentation.append(QStringLiteral(" ")); | ||||
1087 | } | ||||
1088 | } else { | ||||
1089 | label = i18n("Using slashes in folder names will create sub-folders."); | ||||
1090 | } | ||||
1091 | m_messageWidget->setText(label); | ||||
1092 | m_messageWidget->setMessageType(KMessageWidget::Information); | ||||
meven: Shouldn't we disable the ok button here ? | |||||
ngraham: No, because this isn't an error condition (it's just a warning). | |||||
1093 | m_messageWidget->animatedShow(); | ||||
1094 | } | ||||
1095 | } | ||||
1096 | | ||||
1097 | #ifdef Q_OS_WIN | ||||
1098 | // Backslashes not allowed in Windows filenames; show error | ||||
1099 | else if (text.contains(QLatin1Char('\\'))) { | ||||
1100 | m_messageWidget->setText(i18n("Backslashes cannot be used in file and folder names.")); | ||||
1101 | m_messageWidget->setMessageType(KMessageWidget::Error); | ||||
1102 | m_messageWidget->animatedShow(); | ||||
meven: Shouldn't we disable the ok button here too ? | |||||
1103 | } | ||||
1104 | #endif | ||||
1105 | | ||||
1106 | // Using a tilde to begin a file or folder name is not recommended | ||||
1107 | else if (text.startsWith(QLatin1Char('~'))) { | ||||
meven: Same here | |||||
1108 | m_messageWidget->setText(i18n("Starting a file or folder name with a tilde is not recommended because it may be confusing or dangerous when using the terminal to delete things.", text)); | ||||
1109 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||||
1110 | m_messageWidget->animatedShow(); | ||||
1111 | } | ||||
1112 | | ||||
1113 | else { | ||||
1114 | m_messageWidget->hide(); | ||||
1115 | } | ||||
meven: Same here | |||||
ngraham: No, because this isn't an error condition (it's just a warning). | |||||
1075 | m_text = text; | 1116 | m_text = text; | ||
1076 | } | 1117 | } | ||
1077 | 1118 | | |||
1078 | void KNewFileMenuPrivate::_k_slotUrlDesktopFile() | 1119 | void KNewFileMenuPrivate::_k_slotUrlDesktopFile() | ||
1079 | { | 1120 | { | ||
1080 | KNameAndUrlInputDialog *dlg = static_cast<KNameAndUrlInputDialog *>(m_fileDialog); | 1121 | KNameAndUrlInputDialog *dlg = static_cast<KNameAndUrlInputDialog *>(m_fileDialog); | ||
1081 | 1122 | | |||
1082 | m_copyData.m_chosenFileName = dlg->name(); // no path | 1123 | m_copyData.m_chosenFileName = dlg->name(); // no path | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 1237 | { | |||
1211 | 1252 | | |||
1212 | if (baseUrl.isLocalFile() && QFileInfo::exists(baseUrl.toLocalFile() + QLatin1Char('/') + name)) { | 1253 | if (baseUrl.isLocalFile() && QFileInfo::exists(baseUrl.toLocalFile() + QLatin1Char('/') + name)) { | ||
1213 | name = KIO::suggestName(baseUrl, name); | 1254 | name = KIO::suggestName(baseUrl, name); | ||
1214 | } | 1255 | } | ||
1215 | 1256 | | |||
1216 | QDialog *fileDialog = new QDialog(d->m_parentWidget); | 1257 | QDialog *fileDialog = new QDialog(d->m_parentWidget); | ||
1217 | fileDialog->setModal(isModal()); | 1258 | fileDialog->setModal(isModal()); | ||
1218 | fileDialog->setAttribute(Qt::WA_DeleteOnClose); | 1259 | fileDialog->setAttribute(Qt::WA_DeleteOnClose); | ||
1260 | fileDialog->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); | ||||
1219 | fileDialog->setWindowTitle(i18nc("@title:window", "New Folder")); | 1261 | fileDialog->setWindowTitle(i18nc("@title:window", "New Folder")); | ||
1262 | d->m_fileDialog = fileDialog; | ||||
1220 | 1263 | | |||
1221 | QVBoxLayout *layout = new QVBoxLayout; | 1264 | QVBoxLayout *layout = new QVBoxLayout; | ||
1222 | QLabel *label = new QLabel(i18n("Create new folder in:\n%1", baseUrl.toDisplayString(QUrl::PreferLocalFile)), fileDialog); | 1265 | layout->setSizeConstraint(QLayout::SetFixedSize); | ||
1266 | | ||||
1267 | d->m_messageWidget = new KMessageWidget(fileDialog); | ||||
1268 | d->m_messageWidget->setCloseButtonVisible(false); | ||||
1269 | d->m_messageWidget->setWordWrap(true); | ||||
1270 | d->m_messageWidget->hide(); | ||||
1271 | QLabel *label = new QLabel(i18n("Create new folder in %1:", baseUrl.toDisplayString(QUrl::PreferLocalFile)), fileDialog); | ||||
1223 | 1272 | | |||
1224 | QLineEdit *lineEdit = new QLineEdit(fileDialog); | 1273 | QLineEdit *lineEdit = new QLineEdit(fileDialog); | ||
1225 | lineEdit->setClearButtonEnabled(true); | 1274 | lineEdit->setClearButtonEnabled(true); | ||
1226 | lineEdit->setText(name); | 1275 | lineEdit->setText(name); | ||
1276 | lineEdit->setMinimumWidth(400); | ||||
1277 | | ||||
1278 | d->m_buttonBox = new QDialogButtonBox(fileDialog); | ||||
1279 | d->m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||||
1280 | QObject::connect(d->m_buttonBox, &QDialogButtonBox::accepted, fileDialog, &QDialog::accept); | ||||
1281 | QObject::connect(d->m_buttonBox, &QDialogButtonBox::rejected, fileDialog, &QDialog::reject); | ||||
1227 | 1282 | | |||
1228 | d->_k_slotTextChanged(name); // have to save string in d->m_text in case user does not touch dialog | 1283 | d->_k_slotTextChanged(name); // have to save string in d->m_text in case user does not touch dialog | ||
1229 | connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(_k_slotTextChanged(QString))); | 1284 | connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(_k_slotTextChanged(QString))); | ||
1230 | 1285 | | |||
1231 | QDialogButtonBox *buttonBox = new QDialogButtonBox(fileDialog); | | |||
1232 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | | |||
1233 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, fileDialog, &QDialog::accept); | | |||
1234 | QObject::connect(buttonBox, &QDialogButtonBox::rejected, fileDialog, &QDialog::reject); | | |||
1235 | | ||||
1236 | layout->addWidget(label); | 1286 | layout->addWidget(label); | ||
1237 | layout->addWidget(lineEdit); | 1287 | layout->addWidget(lineEdit); | ||
1238 | layout->addWidget(buttonBox); | 1288 | layout->addWidget(d->m_buttonBox); | ||
1289 | layout->addWidget(d->m_messageWidget); | ||||
1290 | layout->addStretch(); | ||||
1239 | 1291 | | |||
1240 | fileDialog->setLayout(layout); | 1292 | fileDialog->setLayout(layout); | ||
1241 | connect(fileDialog, SIGNAL(accepted()), this, SLOT(_k_slotCreateDirectory())); | 1293 | connect(fileDialog, SIGNAL(accepted()), this, SLOT(_k_slotCreateDirectory())); | ||
1242 | connect(fileDialog, SIGNAL(rejected()), this, SLOT(_k_slotAbortDialog())); | 1294 | connect(fileDialog, SIGNAL(rejected()), this, SLOT(_k_slotAbortDialog())); | ||
1243 | 1295 | | |||
1244 | d->m_fileDialog = fileDialog; | | |||
1245 | 1296 | | |||
1246 | fileDialog->show(); | 1297 | fileDialog->show(); | ||
1247 | lineEdit->selectAll(); | 1298 | lineEdit->selectAll(); | ||
1248 | lineEdit->setFocus(); | 1299 | lineEdit->setFocus(); | ||
1249 | } | 1300 | } | ||
1250 | 1301 | | |||
1251 | void KNewFileMenu::createFile() | 1302 | void KNewFileMenu::createFile() | ||
1252 | { | 1303 | { | ||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |
I would rather disable the ok button, as long as the user has not entered text, rather than using an error.