]> cloud.milkyroute.net Git - dolphin.git/commitdiff
improve renaming for n selected items/1 selected item
authorPeter Penz <peter.penz19@gmail.com>
Tue, 13 Mar 2007 18:33:00 +0000 (18:33 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 13 Mar 2007 18:33:00 +0000 (18:33 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=642235

src/dolphinview.cpp
src/renamedialog.cpp
src/renamedialog.h
src/viewpropsprogressinfo.cpp

index 3602d1563668b3ac85b065e8a5573651284e7757..da8aa3c820271c534d23f99ad487a83f0e6740bc 100644 (file)
@@ -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;
index e68feff8d29d4cc8957476148dd7441126fdf536..4055b32a6091528fdcf5c9b246514d8c8feed466 100644 (file)
 #include <QVBoxLayout>
 
 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.");
         }
index c08856f8c8aaac9870a076071e7fb37abbf2af86..220b8b803c3fda666e858f92943c5d2242d2965d 100644 (file)
@@ -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;
index 36aac51e969a216b2a10f91c029ffea892b67433..61f6423c449588f1c481f5cdfcc374f0739e1f7c 100644 (file)
@@ -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);