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), | ||||
250 | m_creatingDirectory(false), | ||||
246 | q(qq) | 251 | q(qq) | ||
247 | {} | 252 | {} | ||
248 | 253 | | |||
249 | bool checkSourceExists(const QString &src); | 254 | bool checkSourceExists(const QString &src); | ||
250 | 255 | | |||
251 | /** | 256 | /** | ||
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. | 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) | ||
263 | */ | 263 | */ | ||
264 | void executeRealFileOrDir(const KNewFileMenuSingleton::Entry &entry); | 264 | void executeRealFileOrDir(const KNewFileMenuSingleton::Entry &entry); | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
350 | 350 | | |||
351 | KActionCollection *m_actionCollection; | 351 | KActionCollection *m_actionCollection; | ||
352 | QDialog *m_fileDialog; | 352 | QDialog *m_fileDialog; | ||
353 | 353 | | |||
354 | KActionMenu *m_menuDev; | 354 | KActionMenu *m_menuDev; | ||
355 | int m_menuItemsVersion; | 355 | int m_menuItemsVersion; | ||
356 | bool m_modal; | 356 | bool m_modal; | ||
357 | QAction *m_newDirAction; | 357 | QAction *m_newDirAction; | ||
358 | KMessageWidget* m_messageWidget; | ||||
359 | QDialogButtonBox* m_buttonBox; | ||||
360 | | ||||
361 | // This is used to allow _k_slotTextChanged to know whether it's being used to | ||||
362 | // create a file or a directory without duplicating code across two functions | ||||
363 | bool m_creatingDirectory; | ||||
358 | 364 | | |||
359 | /** | 365 | /** | ||
360 | * The action group that our actions belong to | 366 | * The action group that our actions belong to | ||
361 | */ | 367 | */ | ||
362 | QActionGroup *m_newMenuGroup; | 368 | QActionGroup *m_newMenuGroup; | ||
363 | QWidget *m_parentWidget; | 369 | QWidget *m_parentWidget; | ||
364 | 370 | | |||
365 | /** | 371 | /** | ||
Show All 20 Lines | 391 | if (!QFile::exists(src)) { | |||
386 | qWarning() << src << "doesn't exist"; | 392 | qWarning() << src << "doesn't exist"; | ||
387 | 393 | | |||
388 | QDialog *dialog = new QDialog(m_parentWidget); | 394 | QDialog *dialog = new QDialog(m_parentWidget); | ||
389 | dialog->setWindowTitle(i18n("Sorry")); | 395 | dialog->setWindowTitle(i18n("Sorry")); | ||
390 | dialog->setObjectName(QStringLiteral("sorry")); | 396 | dialog->setObjectName(QStringLiteral("sorry")); | ||
391 | dialog->setModal(q->isModal()); | 397 | dialog->setModal(q->isModal()); | ||
392 | dialog->setAttribute(Qt::WA_DeleteOnClose); | 398 | dialog->setAttribute(Qt::WA_DeleteOnClose); | ||
393 | 399 | | |||
394 | QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); | 400 | m_buttonBox = new QDialogButtonBox(dialog); | ||
395 | buttonBox->setStandardButtons(QDialogButtonBox::Ok); | 401 | m_buttonBox->setStandardButtons(QDialogButtonBox::Ok); | ||
396 | 402 | | |||
397 | KMessageBox::createKMessageBox(dialog, buttonBox, QMessageBox::Warning, | 403 | KMessageBox::createKMessageBox(dialog, m_buttonBox, QMessageBox::Warning, | ||
398 | i18n("<qt>The template file <b>%1</b> does not exist.</qt>", src), | 404 | i18n("<qt>The template file <b>%1</b> does not exist.</qt>", src), | ||
399 | QStringList(), QString(), nullptr, KMessageBox::NoExec); | 405 | QStringList(), QString(), nullptr, KMessageBox::NoExec); | ||
400 | 406 | | |||
401 | dialog->show(); | 407 | dialog->show(); | ||
402 | 408 | | |||
403 | return false; | 409 | return false; | ||
404 | } | 410 | } | ||
405 | return true; | 411 | return true; | ||
406 | } | 412 | } | ||
407 | 413 | | |||
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) | 414 | void KNewFileMenuPrivate::executeOtherDesktopFile(const KNewFileMenuSingleton::Entry &entry) | ||
447 | { | 415 | { | ||
448 | if (!checkSourceExists(entry.templatePath)) { | 416 | if (!checkSourceExists(entry.templatePath)) { | ||
449 | return; | 417 | return; | ||
450 | } | 418 | } | ||
451 | 419 | | |||
452 | QList<QUrl>::const_iterator it = m_popupFiles.constBegin(); | 420 | QList<QUrl>::const_iterator it = m_popupFiles.constBegin(); | ||
453 | for (; it != m_popupFiles.constEnd(); ++it) { | 421 | for (; it != m_popupFiles.constEnd(); ++it) { | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 466 | { | |||
506 | const QUrl directory = mostLocalUrl(m_popupFiles.first()); | 474 | const QUrl directory = mostLocalUrl(m_popupFiles.first()); | ||
507 | const QUrl defaultFile = QUrl::fromLocalFile(directory.toLocalFile() + QLatin1Char('/') + KIO::encodeFileName(text)); | 475 | const QUrl defaultFile = QUrl::fromLocalFile(directory.toLocalFile() + QLatin1Char('/') + KIO::encodeFileName(text)); | ||
508 | if (defaultFile.isLocalFile() && QFile::exists(defaultFile.toLocalFile())) { | 476 | if (defaultFile.isLocalFile() && QFile::exists(defaultFile.toLocalFile())) { | ||
509 | text = KIO::suggestName(directory, text); | 477 | text = KIO::suggestName(directory, text); | ||
510 | } | 478 | } | ||
511 | 479 | | |||
512 | QDialog *fileDialog = new QDialog(m_parentWidget); | 480 | QDialog *fileDialog = new QDialog(m_parentWidget); | ||
513 | fileDialog->setAttribute(Qt::WA_DeleteOnClose); | 481 | fileDialog->setAttribute(Qt::WA_DeleteOnClose); | ||
482 | fileDialog->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); | ||||
514 | fileDialog->setModal(q->isModal()); | 483 | fileDialog->setModal(q->isModal()); | ||
484 | m_fileDialog = fileDialog; | ||||
515 | 485 | | |||
516 | QVBoxLayout *layout = new QVBoxLayout; | 486 | QVBoxLayout *layout = new QVBoxLayout; | ||
487 | layout->setSizeConstraint(QLayout::SetFixedSize); | ||||
488 | | ||||
489 | m_messageWidget = new KMessageWidget(fileDialog); | ||||
490 | m_messageWidget->setCloseButtonVisible(false); | ||||
491 | m_messageWidget->setWordWrap(true); | ||||
492 | m_messageWidget->hide(); | ||||
517 | QLabel *label = new QLabel(entry.comment, fileDialog); | 493 | QLabel *label = new QLabel(entry.comment, fileDialog); | ||
518 | 494 | | |||
519 | QLineEdit *lineEdit = new QLineEdit(fileDialog); | 495 | QLineEdit *lineEdit = new QLineEdit(fileDialog); | ||
520 | lineEdit->setClearButtonEnabled(true); | 496 | lineEdit->setClearButtonEnabled(true); | ||
521 | lineEdit->setText(text); | 497 | lineEdit->setText(text); | ||
498 | lineEdit->setMinimumWidth(400); | ||||
499 | | ||||
500 | m_buttonBox = new QDialogButtonBox(fileDialog); | ||||
501 | m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||||
502 | QObject::connect(m_buttonBox, &QDialogButtonBox::accepted, fileDialog, &QDialog::accept); | ||||
503 | QObject::connect(m_buttonBox, &QDialogButtonBox::rejected, fileDialog, &QDialog::reject); | ||||
522 | 504 | | |||
505 | m_creatingDirectory = false; | ||||
523 | _k_slotTextChanged(text); | 506 | _k_slotTextChanged(text); | ||
524 | QObject::connect(lineEdit, SIGNAL(textChanged(QString)), q, SLOT(_k_slotTextChanged(QString))); | 507 | QObject::connect(lineEdit, SIGNAL(textChanged(QString)), q, SLOT(_k_slotTextChanged(QString))); | ||
525 | 508 | | |||
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); | 509 | layout->addWidget(label); | ||
532 | layout->addWidget(lineEdit); | 510 | layout->addWidget(lineEdit); | ||
533 | layout->addWidget(buttonBox); | 511 | layout->addWidget(m_buttonBox); | ||
512 | layout->addWidget(m_messageWidget); | ||||
513 | layout->addStretch(); | ||||
534 | 514 | | |||
535 | fileDialog->setLayout(layout); | 515 | fileDialog->setLayout(layout); | ||
536 | QObject::connect(fileDialog, SIGNAL(accepted()), q, SLOT(_k_slotRealFileOrDir())); | 516 | QObject::connect(fileDialog, SIGNAL(accepted()), q, SLOT(_k_slotRealFileOrDir())); | ||
537 | QObject::connect(fileDialog, SIGNAL(rejected()), q, SLOT(_k_slotAbortDialog())); | 517 | QObject::connect(fileDialog, SIGNAL(rejected()), q, SLOT(_k_slotAbortDialog())); | ||
538 | 518 | | |||
539 | fileDialog->show(); | 519 | fileDialog->show(); | ||
540 | lineEdit->selectAll(); | 520 | lineEdit->selectAll(); | ||
541 | lineEdit->setFocus(); | 521 | lineEdit->setFocus(); | ||
▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Line(s) | 845 | if (name == QLatin1String(".") || name == QLatin1String("..")) { | |||
867 | enterNewNameGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | 847 | enterNewNameGuiItem.setText(i18nc("@action:button", "Enter a Different Name")); | ||
868 | enterNewNameGuiItem.setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | 848 | enterNewNameGuiItem.setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | ||
869 | 849 | | |||
870 | QDialog *confirmDialog = new QDialog(m_parentWidget); | 850 | QDialog *confirmDialog = new QDialog(m_parentWidget); | ||
871 | confirmDialog->setWindowTitle(i18n("Invalid Directory Name")); | 851 | confirmDialog->setWindowTitle(i18n("Invalid Directory Name")); | ||
872 | confirmDialog->setModal(m_modal); | 852 | confirmDialog->setModal(m_modal); | ||
873 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | 853 | confirmDialog->setAttribute(Qt::WA_DeleteOnClose); | ||
874 | 854 | | |||
875 | QDialogButtonBox *buttonBox = new QDialogButtonBox(confirmDialog); | 855 | m_buttonBox = new QDialogButtonBox(confirmDialog); | ||
876 | buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | 856 | m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||
877 | KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), enterNewNameGuiItem); | 857 | KGuiItem::assign(m_buttonBox->button(QDialogButtonBox::Ok), enterNewNameGuiItem); | ||
878 | 858 | | |||
879 | KMessageBox::createKMessageBox(confirmDialog, buttonBox, QMessageBox::Critical, | 859 | 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), | 860 | 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(), | 861 | QStringList(), | ||
882 | QString(), | 862 | QString(), | ||
883 | nullptr, | 863 | nullptr, | ||
884 | KMessageBox::NoExec, | 864 | KMessageBox::NoExec, | ||
885 | QString()); | 865 | QString()); | ||
886 | 866 | | |||
887 | QObject::connect(buttonBox, &QDialogButtonBox::accepted, q, &KNewFileMenu::createDirectory); | 867 | m_creatingDirectory = true; | ||
868 | QObject::connect(m_buttonBox, &QDialogButtonBox::accepted, q, &KNewFileMenu::createDirectory); | ||||
888 | m_fileDialog = confirmDialog; | 869 | m_fileDialog = confirmDialog; | ||
889 | confirmDialog->show(); | 870 | confirmDialog->show(); | ||
890 | _k_slotAbortDialog(); | 871 | _k_slotAbortDialog(); | ||
891 | return; | 872 | return; | ||
892 | } | 873 | } | ||
893 | if (!m_viewShowsHiddenFiles && name.startsWith(QLatin1Char('.'))) { | | |||
894 | if (!writeHiddenDir) { | | |||
895 | confirmCreatingHiddenDir(name); | | |||
896 | return; | | |||
897 | } | | |||
898 | } | | |||
899 | url = baseUrl; | 874 | url = baseUrl; | ||
900 | url.setPath(concatPaths(url.path(), name)); | 875 | url.setPath(concatPaths(url.path(), name)); | ||
901 | } | 876 | } | ||
902 | } | 877 | } | ||
903 | 878 | | |||
904 | KIO::Job *job; | 879 | KIO::Job *job; | ||
905 | if (name.contains(QLatin1Char('/'))) { | 880 | if (name.contains(QLatin1Char('/'))) { | ||
906 | // If the name contains any slashes, use mkpath so that a/b/c works. | 881 | // 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) | 1034 | { | |||
1067 | } | 1042 | } | ||
1068 | 1043 | | |||
1069 | m_copyData.m_src = linkTarget; | 1044 | m_copyData.m_src = linkTarget; | ||
1070 | executeStrategy(); | 1045 | executeStrategy(); | ||
1071 | } | 1046 | } | ||
1072 | 1047 | | |||
1073 | void KNewFileMenuPrivate::_k_slotTextChanged(const QString &text) | 1048 | void KNewFileMenuPrivate::_k_slotTextChanged(const QString &text) | ||
1074 | { | 1049 | { | ||
1050 | m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); | ||||
1051 | // Validate input, displaying a KMessageWidget for questionable names | ||||
1052 | | ||||
1053 | if (text.length() == 0) { | ||||
1054 | m_messageWidget->hide(); | ||||
meven: I would rather disable the ok button, as long as the user has not entered text, rather than… | |||||
1055 | m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||||
1056 | } | ||||
1057 | | ||||
1058 | // Don't allow creating folders that would mask . or .. | ||||
1059 | else if (text == QLatin1String(".") || text == QLatin1String("..")) { | ||||
1060 | m_messageWidget->setText(xi18nc("@info", "The name <filename>%1</filename> cannot be used because it is reserved for use by the operating system.", text)); | ||||
1061 | m_messageWidget->setMessageType(KMessageWidget::Error); | ||||
1062 | m_messageWidget->animatedShow(); | ||||
1063 | m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||||
1064 | } | ||||
1065 | | ||||
1066 | // File or folder would be hidden; show warning | ||||
1067 | else if (text.startsWith(QLatin1Char('.'))) { | ||||
1068 | m_messageWidget->setText(xi18nc("@info", "The name <filename>%1</filename> starts with a dot, so it will be hidden by default.", text)); | ||||
1069 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||||
1070 | m_messageWidget->animatedShow(); | ||||
1071 | } | ||||
1072 | | ||||
1073 | #ifndef Q_OS_WIN | ||||
1074 | // Inform the user that slashes in folder names create a directory tree | ||||
1075 | else if (text.contains(QLatin1Char('/'))) { | ||||
1076 | if (m_creatingDirectory) { | ||||
1077 | QStringList folders = text.split(QLatin1Char('/')); | ||||
1078 | if (!folders.isEmpty()) { | ||||
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. | |||||
1079 | if (folders.first().isEmpty()) { | ||||
1080 | folders.removeFirst(); | ||||
1081 | } | ||||
1082 | } | ||||
1083 | QString label; | ||||
1084 | if (folders.count() > 1) { | ||||
1085 | label = i18n("Using slashes in folder names will create sub-folders, like so:"); | ||||
1086 | QString indentation = QString(); | ||||
1087 | for (const QString &folder : folders) { | ||||
1088 | label.append(QStringLiteral("\n")); | ||||
1089 | label.append(indentation); | ||||
1090 | label.append(folder); | ||||
1091 | label.append(QStringLiteral("/")); | ||||
1092 | indentation.append(QStringLiteral(" ")); | ||||
1093 | } | ||||
1094 | } else { | ||||
1095 | label = i18n("Using slashes in folder names will create sub-folders."); | ||||
1096 | } | ||||
1097 | m_messageWidget->setText(label); | ||||
1098 | m_messageWidget->setMessageType(KMessageWidget::Information); | ||||
1099 | m_messageWidget->animatedShow(); | ||||
meven: Shouldn't we disable the ok button here ? | |||||
ngraham: No, because this isn't an error condition (it's just a warning). | |||||
1100 | } | ||||
1101 | } | ||||
1102 | #endif | ||||
1103 | | ||||
1104 | #ifdef Q_OS_WIN | ||||
1105 | // Slashes and backslashes are not allowed in Windows filenames; show error | ||||
1106 | else if (text.contains(QLatin1Char('/'))) { | ||||
1107 | m_messageWidget->setText(i18n("Slashes cannot be used in file and folder names.")); | ||||
1108 | m_messageWidget->setMessageType(KMessageWidget::Error); | ||||
1109 | m_messageWidget->animatedShow(); | ||||
meven: Shouldn't we disable the ok button here too ? | |||||
1110 | m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||||
1111 | } | ||||
1112 | else if (text.contains(QLatin1Char('\\'))) { | ||||
1113 | m_messageWidget->setText(i18n("Backslashes cannot be used in file and folder names.")); | ||||
1114 | m_messageWidget->setMessageType(KMessageWidget::Error); | ||||
meven: Same here | |||||
1115 | m_messageWidget->animatedShow(); | ||||
1116 | m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||||
1117 | } | ||||
1118 | #endif | ||||
1119 | | ||||
1120 | // Using a tilde to begin a file or folder name is not recommended | ||||
1121 | else if (text.startsWith(QLatin1Char('~'))) { | ||||
1122 | 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)); | ||||
meven: Same here | |||||
ngraham: No, because this isn't an error condition (it's just a warning). | |||||
1123 | m_messageWidget->setMessageType(KMessageWidget::Warning); | ||||
1124 | m_messageWidget->animatedShow(); | ||||
1125 | } | ||||
1126 | | ||||
1127 | else { | ||||
1128 | m_messageWidget->hide(); | ||||
1129 | } | ||||
1075 | m_text = text; | 1130 | m_text = text; | ||
1076 | } | 1131 | } | ||
1077 | 1132 | | |||
1078 | void KNewFileMenuPrivate::_k_slotUrlDesktopFile() | 1133 | void KNewFileMenuPrivate::_k_slotUrlDesktopFile() | ||
1079 | { | 1134 | { | ||
1080 | KNameAndUrlInputDialog *dlg = static_cast<KNameAndUrlInputDialog *>(m_fileDialog); | 1135 | KNameAndUrlInputDialog *dlg = static_cast<KNameAndUrlInputDialog *>(m_fileDialog); | ||
1081 | 1136 | | |||
1082 | m_copyData.m_chosenFileName = dlg->name(); // no path | 1137 | m_copyData.m_chosenFileName = dlg->name(); // no path | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 1251 | { | |||
1211 | 1266 | | |||
1212 | if (baseUrl.isLocalFile() && QFileInfo::exists(baseUrl.toLocalFile() + QLatin1Char('/') + name)) { | 1267 | if (baseUrl.isLocalFile() && QFileInfo::exists(baseUrl.toLocalFile() + QLatin1Char('/') + name)) { | ||
1213 | name = KIO::suggestName(baseUrl, name); | 1268 | name = KIO::suggestName(baseUrl, name); | ||
1214 | } | 1269 | } | ||
1215 | 1270 | | |||
1216 | QDialog *fileDialog = new QDialog(d->m_parentWidget); | 1271 | QDialog *fileDialog = new QDialog(d->m_parentWidget); | ||
1217 | fileDialog->setModal(isModal()); | 1272 | fileDialog->setModal(isModal()); | ||
1218 | fileDialog->setAttribute(Qt::WA_DeleteOnClose); | 1273 | fileDialog->setAttribute(Qt::WA_DeleteOnClose); | ||
1274 | fileDialog->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); | ||||
1219 | fileDialog->setWindowTitle(i18nc("@title:window", "New Folder")); | 1275 | fileDialog->setWindowTitle(i18nc("@title:window", "New Folder")); | ||
1276 | d->m_fileDialog = fileDialog; | ||||
1220 | 1277 | | |||
1221 | QVBoxLayout *layout = new QVBoxLayout; | 1278 | QVBoxLayout *layout = new QVBoxLayout; | ||
1222 | QLabel *label = new QLabel(i18n("Create new folder in:\n%1", baseUrl.toDisplayString(QUrl::PreferLocalFile)), fileDialog); | 1279 | layout->setSizeConstraint(QLayout::SetFixedSize); | ||
1280 | | ||||
1281 | d->m_messageWidget = new KMessageWidget(fileDialog); | ||||
1282 | d->m_messageWidget->setCloseButtonVisible(false); | ||||
1283 | d->m_messageWidget->setWordWrap(true); | ||||
1284 | d->m_messageWidget->hide(); | ||||
1285 | QLabel *label = new QLabel(i18n("Create new folder in %1:", baseUrl.toDisplayString(QUrl::PreferLocalFile)), fileDialog); | ||||
1223 | 1286 | | |||
1224 | QLineEdit *lineEdit = new QLineEdit(fileDialog); | 1287 | QLineEdit *lineEdit = new QLineEdit(fileDialog); | ||
1225 | lineEdit->setClearButtonEnabled(true); | 1288 | lineEdit->setClearButtonEnabled(true); | ||
1226 | lineEdit->setText(name); | 1289 | lineEdit->setText(name); | ||
1290 | lineEdit->setMinimumWidth(400); | ||||
1227 | 1291 | | |||
1292 | d->m_buttonBox = new QDialogButtonBox(fileDialog); | ||||
1293 | d->m_buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | ||||
1294 | QObject::connect(d->m_buttonBox, &QDialogButtonBox::accepted, fileDialog, &QDialog::accept); | ||||
1295 | QObject::connect(d->m_buttonBox, &QDialogButtonBox::rejected, fileDialog, &QDialog::reject); | ||||
1296 | | ||||
1297 | d->m_creatingDirectory = true; | ||||
1228 | d->_k_slotTextChanged(name); // have to save string in d->m_text in case user does not touch dialog | 1298 | 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))); | 1299 | connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(_k_slotTextChanged(QString))); | ||
1230 | 1300 | | |||
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); | 1301 | layout->addWidget(label); | ||
1237 | layout->addWidget(lineEdit); | 1302 | layout->addWidget(lineEdit); | ||
1238 | layout->addWidget(buttonBox); | 1303 | layout->addWidget(d->m_buttonBox); | ||
1304 | layout->addWidget(d->m_messageWidget); | ||||
1305 | layout->addStretch(); | ||||
1239 | 1306 | | |||
1240 | fileDialog->setLayout(layout); | 1307 | fileDialog->setLayout(layout); | ||
1241 | connect(fileDialog, SIGNAL(accepted()), this, SLOT(_k_slotCreateDirectory())); | 1308 | connect(fileDialog, SIGNAL(accepted()), this, SLOT(_k_slotCreateDirectory())); | ||
1242 | connect(fileDialog, SIGNAL(rejected()), this, SLOT(_k_slotAbortDialog())); | 1309 | connect(fileDialog, SIGNAL(rejected()), this, SLOT(_k_slotAbortDialog())); | ||
1243 | 1310 | | |||
1244 | d->m_fileDialog = fileDialog; | | |||
1245 | 1311 | | |||
1246 | fileDialog->show(); | 1312 | fileDialog->show(); | ||
1247 | lineEdit->selectAll(); | 1313 | lineEdit->selectAll(); | ||
1248 | lineEdit->setFocus(); | 1314 | lineEdit->setFocus(); | ||
1249 | } | 1315 | } | ||
1250 | 1316 | | |||
1251 | void KNewFileMenu::createFile() | 1317 | void KNewFileMenu::createFile() | ||
1252 | { | 1318 | { | ||
▲ 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.