]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/treeviewcontextmenu.cpp
* Fix triggering an assertion when the elastic band is already hidden.
[dolphin.git] / src / treeviewcontextmenu.cpp
index c04fc746ea5d2831dca193ff7652ec8bffe52297..ec6d322008b5e98e66f14e2f86e6fd16111cfdb4 100644 (file)
 #include "treeviewcontextmenu.h"
 
 #include <kiconloader.h>
+#include <kio/deletejob.h>
 #include <kmenu.h>
 #include <konqmimedata.h>
 #include <konq_operations.h>
 #include <klocale.h>
 #include <kpropertiesdialog.h>
 
-#include <QApplication>
-#include <QClipboard>
+#include "renamedialog.h"
+
+#include <QtGui/QApplication>
+#include <QtGui/QClipboard>
 
 TreeViewContextMenu::TreeViewContextMenu(QWidget* parent,
                                          KFileItem* fileInfo) :
@@ -55,11 +58,9 @@ void TreeViewContextMenu::open()
     connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
 
     QAction* pasteAction = new QAction(KIcon("edit-paste"), i18n("Paste"), this);
-
-    QClipboard* clipboard = QApplication::clipboard();
-    const QMimeData* mimeData = clipboard->mimeData();
-    const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
-    pasteAction->setEnabled(sourceUrls.isEmpty());
+    const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+    const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
+    pasteAction->setEnabled(!pasteData.isEmpty());
     connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
 
     popup->addAction(cutAction);
@@ -68,7 +69,7 @@ void TreeViewContextMenu::open()
     popup->addSeparator();
 
     // insert 'Rename'
-    QAction* renameAction = new QAction(i18n("Rename"), this);
+    QAction* renameAction = new QAction(i18n("Rename..."), this);
     connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
     popup->addAction(renameAction);
 
@@ -81,8 +82,7 @@ void TreeViewContextMenu::open()
         QAction* moveToTrashAction = new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this);
         connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
         popup->addAction(moveToTrashAction);
-    }
-    else {
+    } else {
         showDeleteCommand = true;
     }
 
@@ -94,9 +94,9 @@ void TreeViewContextMenu::open()
 
     popup->addSeparator();
 
-    // insert 'Properties...' entry
-    QAction* propertiesAction = new QAction(i18n("Properties..."), this);
-    connect(this, SIGNAL(triggered()), this, SLOT(showProperties()));
+    // insert 'Properties' entry
+    QAction* propertiesAction = new QAction(i18n("Properties"), this);
+    connect(propertiesAction, SIGNAL(triggered()), this, SLOT(showProperties()));
     popup->addAction(propertiesAction);
 
     popup->exec(QCursor::pos());
@@ -131,30 +131,39 @@ void TreeViewContextMenu::paste()
     if (KonqMimeData::decodeIsCutSelection(mimeData)) {
         KonqOperations::copy(m_parent, KonqOperations::MOVE, source, dest);
         clipboard->clear();
-    }
-    else {
+    } else {
         KonqOperations::copy(m_parent, KonqOperations::COPY, source, dest);
     }
 }
 
 void TreeViewContextMenu::rename()
 {
-    // TODO
+    const KUrl& oldUrl = m_fileInfo->url();
+    RenameDialog dialog(oldUrl);
+    if (dialog.exec() == QDialog::Accepted) {
+        const QString& newName = dialog.newName();
+        if (!newName.isEmpty()) {
+            KUrl newUrl = oldUrl;
+            newUrl.setFileName(newName);
+            KonqOperations::rename(m_parent, oldUrl, newUrl);
+        }
+    }
 }
 
 void TreeViewContextMenu::moveToTrash()
 {
-    // TODO
+    KonqOperations::del(m_parent, KonqOperations::TRASH, m_fileInfo->url());
 }
 
 void TreeViewContextMenu::deleteItem()
 {
-    // TODO
+    KonqOperations::del(m_parent, KonqOperations::DEL, m_fileInfo->url());
 }
 
 void TreeViewContextMenu::showProperties()
 {
-    new KPropertiesDialog(m_fileInfo->url());
+    KPropertiesDialog dialog(m_fileInfo->url());
+    dialog.exec();
 }
 
 #include "treeviewcontextmenu.moc"