X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5c1420fec990f268b9abbbaedbe45b9388f1fddd..5454283008f2:/src/views/renamedialog.cpp diff --git a/src/views/renamedialog.cpp b/src/views/renamedialog.cpp index 6556cbe22..6309bfbdf 100644 --- a/src/views/renamedialog.cpp +++ b/src/views/renamedialog.cpp @@ -19,24 +19,24 @@ #include "renamedialog.h" -#include -#include +#include #include -#include #include #include -#include -#include //TODO port to QCollator -#include -#include +#include #include #include #include #include +#include +#include +#include +#include +#include RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : - KDialog(parent), + QDialog(parent), m_renameOneItem(false), m_newName(), m_lineEdit(0), @@ -51,16 +51,24 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : Q_ASSERT(itemCount >= 1); m_renameOneItem = (itemCount == 1); - setCaption(m_renameOneItem ? + setWindowTitle(m_renameOneItem ? i18nc("@title:window", "Rename Item") : i18nc("@title:window", "Rename Items")); - setButtons(Ok | Cancel); - setDefaultButton(Ok); - - setButtonGuiItem(Ok, KGuiItem(i18nc("@action:button", "&Rename"), "dialog-ok-apply")); + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); + QVBoxLayout *mainLayout = new QVBoxLayout; + setLayout(mainLayout); + m_okButton = buttonBox->button(QDialogButtonBox::Ok); + m_okButton->setDefault(true); + m_okButton->setShortcut(Qt::CTRL | Qt::Key_Return); + connect(buttonBox, &QDialogButtonBox::accepted, this, &RenameDialog::slotAccepted); + connect(buttonBox, &QDialogButtonBox::rejected, this, &RenameDialog::reject); + m_okButton->setDefault(true); + + KGuiItem::assign(m_okButton, KGuiItem(i18nc("@action:button", "&Rename"), QStringLiteral("dialog-ok-apply"))); QWidget* page = new QWidget(this); - setMainWidget(page); + mainLayout->addWidget(page); + mainLayout->addWidget(buttonBox); QVBoxLayout* topLayout = new QVBoxLayout(page); @@ -78,8 +86,9 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : page); } - m_lineEdit = new KLineEdit(page); - connect(m_lineEdit, &KLineEdit::textChanged, this, &RenameDialog::slotTextChanged); + m_lineEdit = new QLineEdit(page); + mainLayout->addWidget(m_lineEdit); + connect(m_lineEdit, &QLineEdit::textChanged, this, &RenameDialog::slotTextChanged); int selectionLength = m_newName.length(); if (m_renameOneItem) { @@ -99,7 +108,6 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : m_lineEdit->setText(m_newName); m_lineEdit->setSelection(0, selectionLength); - m_lineEdit->setFocus(); topLayout->addWidget(editLabel); topLayout->addWidget(m_lineEdit); @@ -119,7 +127,13 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : } QLabel* infoLabel = new QLabel(i18nc("@info", "# will be replaced by ascending numbers starting with:"), page); - m_spinBox = new KIntSpinBox(0, 10000, 1, 1, page, 10); + mainLayout->addWidget(infoLabel); + m_spinBox = new QSpinBox(page); + m_spinBox->setMaximum(10000); + m_spinBox->setMinimum(0); + m_spinBox->setSingleStep(1); + m_spinBox->setValue(1); + m_spinBox->setDisplayIntegerBase(10); QHBoxLayout* horizontalLayout = new QHBoxLayout(page); horizontalLayout->setMargin(0); @@ -145,26 +159,28 @@ void RenameDialog::renameItem(const KFileItem &item, const QString& newName) widget = this; } - KIO::Job * job = KIO::moveAs(oldUrl, newUrl); + KIO::Job * job = KIO::moveAs(oldUrl, newUrl, KIO::HideProgressInfo); KJobWidgets::setWindow(job, widget); - KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, QList() << oldUrl, newUrl, job); - job->ui()->setAutoErrorHandlingEnabled(true); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); + + if (!job->error()) { + m_renamedItems << newUrl; + } + + job->uiDelegate()->setAutoErrorHandlingEnabled(true); } -void RenameDialog::slotButtonClicked(int button) +void RenameDialog::slotAccepted() { - if (button == KDialog::Ok) { - m_newName = m_lineEdit->text(); + m_newName = m_lineEdit->text(); - if (m_renameOneItem) { - Q_ASSERT(m_items.count() == 1); - renameItem(m_items.first(), m_newName); - } else { - renameItems(); - } + if (m_renameOneItem) { + Q_ASSERT(m_items.count() == 1); + renameItem(m_items.first(), m_newName); + } else { + renameItems(); } - - KDialog::slotButtonClicked(button); + accept(); } void RenameDialog::slotTextChanged(const QString& newName) @@ -182,7 +198,14 @@ void RenameDialog::slotTextChanged(const QString& newName) enable = (last - first + 1 == count); } } - enableButtonOk(enable); + m_okButton->setEnabled(enable); +} + +void RenameDialog::showEvent(QShowEvent* event) +{ + m_lineEdit->setFocus(); + + QDialog::showEvent(event); } void RenameDialog::renameItems() @@ -205,6 +228,10 @@ void RenameDialog::renameItems() renameItem(item, newName); } } + + if (!m_items.empty()) { + emit renamingFinished(m_renamedItems); + } } QString RenameDialog::indexedName(const QString& name, int index, const QChar& indexPlaceHolder)