diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 3602d1563..da8aa3c82 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -265,45 +265,31 @@ void DolphinView::renameSelectedItems() } else { // TODO: check how this can be integrated into KonqUndoManager/KonqOperations - - //UndoManager& undoMan = UndoManager::instance(); - //undoMan.beginMacro(); - + // as one operation instead of n rename operations like it is done now... Q_ASSERT(newName.contains('#')); - const int urlsCount = urls.count(); - // iterate through all selected items and rename them... const int replaceIndex = newName.indexOf('#'); Q_ASSERT(replaceIndex >= 0); - for (int i = 0; i < urlsCount; ++i) { - const KUrl& source = urls[i]; + int index = 1; + + KUrl::List::const_iterator it = urls.begin(); + KUrl::List::const_iterator end = urls.end(); + while (it != end) { + const KUrl& oldUrl = *it; QString number; - number.setNum(i + 1); + number.setNum(index++); QString name(newName); name.replace(replaceIndex, 1, number); - if (source.fileName() != name) { - KUrl dest(source.upUrl()); - dest.addPath(name); - - const bool destExists = KIO::NetAccess::exists(dest, false, view); - if (destExists) { - view->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name), - DolphinStatusBar::Error); - break; - } - else if (KIO::NetAccess::file_move(source, dest)) { - // TODO: From the users point of view he executed one 'rename n files' operation, - // but internally we store it as n 'rename 1 file' operations for the undo mechanism. - //DolphinCommand command(DolphinCommand::Rename, source, dest); - //undoMan.addCommand(command); - } + if (oldUrl.fileName() != name) { + KUrl newUrl(oldUrl.upUrl()); + newUrl.addPath(name); + m_mainWindow->rename(oldUrl, newUrl); } + ++it; } - - //undoMan.endMacro(); } } else { @@ -311,8 +297,9 @@ void DolphinView::renameSelectedItems() // renaming mechanism from the views. Q_ASSERT(urls.count() == 1); - // TODO: until KFileItemDelegate supports editing, use the the Dolphin - // rename dialog as temporary workaround: + // TODO: Think about using KFileItemDelegate as soon as it supports editing. + // Currently the RenameDialog is used, but I'm not sure whether inline renaming + // is a benefit for the user at all -> let's wait for some input first... RenameDialog dialog(urls); if (dialog.exec() == QDialog::Rejected) { return; diff --git a/src/renamedialog.cpp b/src/renamedialog.cpp index e68feff8d..4055b32a6 100644 --- a/src/renamedialog.cpp +++ b/src/renamedialog.cpp @@ -26,9 +26,17 @@ #include RenameDialog::RenameDialog(const KUrl::List& items) : - KDialog() + KDialog(), + m_renameOneItem(false) { - setCaption(i18n("Rename Items")); + const QSize minSize = minimumSize(); + setMinimumSize(QSize(320, minSize.height())); + + const int itemCount = items.count(); + Q_ASSERT(itemCount >= 1); + m_renameOneItem = (itemCount == 1); + + setCaption(m_renameOneItem ? i18n("Rename Item") : i18n("Rename Items")); setButtons(Ok|Cancel); setDefaultButton(Ok); @@ -40,16 +48,19 @@ RenameDialog::RenameDialog(const KUrl::List& items) : QVBoxLayout* topLayout = new QVBoxLayout(page); topLayout->setMargin(KDialog::marginHint()); - const int itemCount = items.count(); - QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:", itemCount), - page); + QLabel* editLabel = 0; + if (m_renameOneItem) { + const KUrl& url = items.first(); + editLabel = new QLabel(i18n("Rename the item '%1' to:", url.fileName()), + page); + } + else { + editLabel = new QLabel(i18n("Rename the %1 selected items to:", itemCount), + page); + } m_lineEdit = new KLineEdit(page); - m_newName = i18n("New name #"); - - // TODO: reactivate assertion as soon as KFileItemDelegate supports renaming of - // single items - //Q_ASSERT(itemCount > 1); + m_newName = m_renameOneItem ? i18n("New name") : i18n("New name #"); QString postfix(items[0].prettyUrl().section('.',1)); if (postfix.length() > 0) { @@ -66,19 +77,25 @@ RenameDialog::RenameDialog(const KUrl::List& items) : } } - const int selectionLength = m_newName.length(); + int selectionLength = m_newName.length(); + if (!m_renameOneItem) { + --selectionLength; // don't select the # character + } + if (postfix.length() > 0) { m_newName.append(postfix); } m_lineEdit->setText(m_newName); - m_lineEdit->setSelection(0, selectionLength - 1); + m_lineEdit->setSelection(0, selectionLength); m_lineEdit->setFocus(); - QLabel* infoLabel = new QLabel(i18n("(# will be replaced by ascending numbers)"), page); - topLayout->addWidget(editLabel); topLayout->addWidget(m_lineEdit); - topLayout->addWidget(infoLabel); + + if (!m_renameOneItem) { + QLabel* infoLabel = new QLabel(i18n("(# will be replaced by ascending numbers)"), page); + topLayout->addWidget(infoLabel); + } } RenameDialog::~RenameDialog() @@ -87,12 +104,12 @@ RenameDialog::~RenameDialog() void RenameDialog::slotButtonClicked(int button) { - if (button==Ok) { + if (button == Ok) { m_newName = m_lineEdit->text(); if (m_newName.isEmpty()) { m_errorString = i18n("The new name is empty. A name with at least one character must be entered."); } - else if (m_newName.contains('#') != 1) { + else if (!m_renameOneItem && m_newName.contains('#') != 1) { m_newName.truncate(0); m_errorString = i18n("The name must contain exactly one # character."); } diff --git a/src/renamedialog.h b/src/renamedialog.h index c08856f8c..220b8b803 100644 --- a/src/renamedialog.h +++ b/src/renamedialog.h @@ -54,10 +54,13 @@ public: virtual ~RenameDialog(); /** - * Returns the new name of the items. If the returned string is not empty, - * then it is assured that the string contains exactly one character #, - * which should be replaced by ascending numbers. An empty string indicates - * that the user has removed the # character. + * Returns the new name of the items. If more than one + * item should be renamed, then it is assured that the # character + * is part of the returned string. If the returned string is empty, + * then RenameDialog::errorString() should be used to show the reason + * of having an empty string (e. g. if the # character has + * been deleted by the user, although more then one item should be + * renamed). */ const QString& newName() const { return m_newName; } @@ -70,6 +73,7 @@ protected slots: virtual void slotButtonClicked(int button); private: + bool m_renameOneItem; KLineEdit* m_lineEdit; QString m_newName; QString m_errorString; diff --git a/src/viewpropsprogressinfo.cpp b/src/viewpropsprogressinfo.cpp index 36aac51e9..61f6423c4 100644 --- a/src/viewpropsprogressinfo.cpp +++ b/src/viewpropsprogressinfo.cpp @@ -44,7 +44,10 @@ ViewPropsProgressInfo::ViewPropsProgressInfo(QWidget* parent, m_applyViewPropsJob(0), m_timer(0) { - setCaption(i18n("Applying view properties")); + const QSize minSize = minimumSize(); + setMinimumSize(QSize(320, minSize.height())); + + setCaption(i18n("Applying View Properties")); setButtons(KDialog::Cancel); m_viewProps = new ViewProperties(dir);