]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix "delete" and "move to trash" actions in dolphinpart; moved all logic for those...
authorDavid Faure <faure@kde.org>
Sat, 17 Nov 2007 00:08:54 +0000 (00:08 +0000)
committerDavid Faure <faure@kde.org>
Sat, 17 Nov 2007 00:08:54 +0000 (00:08 +0000)
Inside dolphin, the usual: moving code to DolphinView.
Pressing shift while clicking on "Move to Trash" in konq (dolphinpart) offers to delete, as in kde3 (this bit of logic might be good for dolphin itself too? see DolphinPart::slotTrashActivated)
CCMAIL: peter.penz@gmx.at

svn path=/trunk/KDE/kdebase/apps/; revision=737682

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinpart.cpp
src/dolphinpart.h
src/dolphinpart.rc
src/dolphinui.rc
src/dolphinview.cpp
src/dolphinview.h
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h

index c38cc5ea3b8f58b964dc7a444d0423d572687305..540fe5e4847ec8ada4bd9a31a3fd7b00278a4583 100644 (file)
@@ -52,7 +52,6 @@
 #include <kicon.h>
 #include <kiconloader.h>
 #include <kio/netaccess.h>
 #include <kicon.h>
 #include <kiconloader.h>
 #include <kio/netaccess.h>
-#include <kio/deletejob.h>
 #include <kinputdialog.h>
 #include <klocale.h>
 #include <kmenu.h>
 #include <kinputdialog.h>
 #include <klocale.h>
 #include <kmenu.h>
@@ -488,28 +487,13 @@ void DolphinMainWindow::rename()
 void DolphinMainWindow::moveToTrash()
 {
     clearStatusBar();
 void DolphinMainWindow::moveToTrash()
 {
     clearStatusBar();
-    const KUrl::List selectedUrls = m_activeViewContainer->view()->selectedUrls();
-    KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);
-    m_undoCommandTypes.append(KonqFileUndoManager::TRASH);
+    m_activeViewContainer->view()->trashSelectedItems();
 }
 
 void DolphinMainWindow::deleteItems()
 {
     clearStatusBar();
 }
 
 void DolphinMainWindow::deleteItems()
 {
     clearStatusBar();
-
-    const KUrl::List list = m_activeViewContainer->view()->selectedUrls();
-    const bool del = KonqOperations::askDeleteConfirmation(list,
-                     KonqOperations::DEL,
-                     KonqOperations::DEFAULT_CONFIRMATION,
-                     this);
-
-    if (del) {
-        KIO::Job* job = KIO::del(list);
-        connect(job, SIGNAL(result(KJob*)),
-                this, SLOT(slotHandleJobError(KJob*)));
-        connect(job, SIGNAL(result(KJob*)),
-                this, SLOT(slotDeleteFileFinished(KJob*)));
-    }
+    m_activeViewContainer->view()->deleteSelectedItems();
 }
 
 void DolphinMainWindow::properties()
 }
 
 void DolphinMainWindow::properties()
@@ -533,24 +517,6 @@ void DolphinMainWindow::slotHandlePlacesError(const QString &message)
     }
 }
 
     }
 }
 
-void DolphinMainWindow::slotHandleJobError(KJob* job)
-{
-    if (job->error() != 0) {
-        DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
-        statusBar->setMessage(job->errorString(),
-                              DolphinStatusBar::Error);
-    }
-}
-
-void DolphinMainWindow::slotDeleteFileFinished(KJob* job)
-{
-    if (job->error() == 0) {
-        DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
-        statusBar->setMessage(i18nc("@info:status", "Delete operation completed."),
-                              DolphinStatusBar::OperationCompleted);
-    }
-}
-
 void DolphinMainWindow::slotUndoAvailable(bool available)
 {
     QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
 void DolphinMainWindow::slotUndoAvailable(bool available)
 {
     QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
@@ -1047,21 +1013,13 @@ void DolphinMainWindow::setupActions()
     newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
     connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
 
     newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
     connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
 
-    KAction* rename = actionCollection()->addAction("rename");
-    rename->setText(i18nc("@action:inmenu File", "Rename..."));
-    rename->setShortcut(Qt::Key_F2);
+    KAction* rename = DolphinView::createRenameAction(actionCollection());
     connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
 
     connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
 
-    KAction* moveToTrash = actionCollection()->addAction("move_to_trash");
-    moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
-    moveToTrash->setIcon(KIcon("user-trash"));
-    moveToTrash->setShortcut(QKeySequence::Delete);
+    KAction* moveToTrash = DolphinView::createMoveToTrashAction(actionCollection());
     connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
 
     connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
 
-    KAction* deleteAction = actionCollection()->addAction("delete");
-    deleteAction->setText(i18nc("@action:inmenu File", "Delete"));
-    deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
-    deleteAction->setIcon(KIcon("edit-delete"));
+    KAction* deleteAction = DolphinView::createDeleteAction(actionCollection());
     connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
 
     KAction* properties = actionCollection()->addAction("properties");
     connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
 
     KAction* properties = actionCollection()->addAction("properties");
index 1471b44e900e3da2c3e8d1c5c809d15bd0f84f41..2f91f95532dd62253a95d4c1f1a01fd1068da90c 100644 (file)
@@ -199,18 +199,6 @@ private slots:
      */
     void slotHandlePlacesError(const QString &message);
 
      */
     void slotHandlePlacesError(const QString &message);
 
-    /**
-     * Shows the error information of the job \a job
-     * in the status bar.
-     */
-    void slotHandleJobError(KJob* job);
-
-    /**
-     * Indicates in the status bar that the delete operation
-     * of the job \a job has been finished.
-     */
-    void slotDeleteFileFinished(KJob* job);
-
     /**
      * Updates the state of the 'Undo' menu action dependent
      * from the parameter \a available.
     /**
      * Updates the state of the 'Undo' menu action dependent
      * from the parameter \a available.
index a0871ce066c3dc2d740591f995ae398982b0f16e..113b840e7a168116cc1269c44d6199272f6df533 100644 (file)
@@ -91,8 +91,9 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi
 
     createActions();
     updateViewActions();
 
     createActions();
     updateViewActions();
+    slotSelectionChanged(KFileItemList()); // initially disable selection-dependent actions
 
 
-    // TODO provide these actions in the menu, merged with the existing view-mode-actions somehow
+    // TODO provide the viewmode actions in the menu, merged with the existing view-mode-actions somehow
     // [Q_PROPERTY introspection?]
 
     // TODO sort_by_* actions
     // [Q_PROPERTY introspection?]
 
     // TODO sort_by_* actions
@@ -104,8 +105,6 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi
     // (sort of spacial navigation)
 
     // TODO MMB-click should do something like KonqDirPart::mmbClicked
     // (sort of spacial navigation)
 
     // TODO MMB-click should do something like KonqDirPart::mmbClicked
-
-    // TODO updating the trash and del actions too - or removing special handling of those from konq?
 }
 
 DolphinPart::~DolphinPart()
 }
 
 DolphinPart::~DolphinPart()
@@ -121,11 +120,15 @@ void DolphinPart::createActions()
     viewModeActions->addAction(DolphinView::columnsModeAction(actionCollection()));
     connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*)));
 
     viewModeActions->addAction(DolphinView::columnsModeAction(actionCollection()));
     connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*)));
 
-    KAction* renameAction = new KAction(i18nc("@action:inmenu", "Rename..."), this);
+    KAction* renameAction = DolphinView::createRenameAction(actionCollection());
     connect(renameAction, SIGNAL(triggered()), m_view, SLOT(renameSelectedItems()));
     connect(renameAction, SIGNAL(triggered()), m_view, SLOT(renameSelectedItems()));
-    renameAction->setEnabled(false);
-    renameAction->setShortcut(Qt::Key_F2);
-    actionCollection()->addAction("rename", renameAction);
+
+    KAction* moveToTrashAction = DolphinView::createMoveToTrashAction(actionCollection());
+    connect(moveToTrashAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)),
+            this, SLOT(slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers)));
+
+    KAction* deleteAction = DolphinView::createDeleteAction(actionCollection());
+    connect(deleteAction, SIGNAL(triggered()), m_view, SLOT(deleteSelectedItems()));
 }
 
 void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
 }
 
 void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
@@ -136,13 +139,18 @@ void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
         stateChanged("has_no_selection");
     } else {
         stateChanged("has_selection");
         stateChanged("has_no_selection");
     } else {
         stateChanged("has_selection");
+    }
 
 
-        QAction* renameAction = actionCollection()->action("rename");
-        Q_ASSERT(renameAction);
-        if (renameAction) {
-            renameAction->setEnabled(true);
+    QStringList actions;
+    actions << "rename" << "move_to_trash" << "delete";
+    foreach(const QString& actionName, actions) {
+        QAction* action = actionCollection()->action(actionName);
+        Q_ASSERT(action);
+        if (action) {
+            action->setEnabled(hasSelection);
         }
     }
         }
     }
+
     emit m_extension->enableAction("cut", hasSelection);
     emit m_extension->enableAction("copy", hasSelection);
 }
     emit m_extension->enableAction("cut", hasSelection);
     emit m_extension->enableAction("copy", hasSelection);
 }
@@ -251,6 +259,8 @@ void DolphinPart::slotOpenContextMenu(const KFileItem& _item, const KUrl&)
     KParts::BrowserExtension::ActionGroupMap actionGroups;
     QList<QAction *> editActions;
     editActions.append(actionCollection()->action("rename"));
     KParts::BrowserExtension::ActionGroupMap actionGroups;
     QList<QAction *> editActions;
     editActions.append(actionCollection()->action("rename"));
+    editActions.append(actionCollection()->action("move_to_trash"));
+    editActions.append(actionCollection()->action("delete"));
     actionGroups.insert("editactions", editActions);
 
     KFileItemList items; items.append(item);
     actionGroups.insert("editactions", editActions);
 
     KFileItemList items; items.append(item);
@@ -295,4 +305,17 @@ void DolphinPartBrowserExtension::paste()
     m_part->view()->paste();
 }
 
     m_part->view()->paste();
 }
 
+////
+
+void DolphinPart::slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers modifiers)
+{
+    // Note: kde3's konq_mainwindow.cpp used to check
+    // reason == KAction::PopupMenuActivation && ...
+    // but this isn't supported anymore
+    if (modifiers & Qt::ShiftModifier)
+        m_view->deleteSelectedItems();
+    else
+        m_view->trashSelectedItems();
+}
+
 #include "dolphinpart.moc"
 #include "dolphinpart.moc"
index 114c21d3178ffb3725f1218441109f99da29a96a..5075702dba7fbee703bca56abcf98bf56348e151 100644 (file)
@@ -108,6 +108,11 @@ private Q_SLOTS:
      */
     void updatePasteAction();
 
      */
     void updatePasteAction();
 
+    /**
+     * Connected to the "move_to_trash" action; adds "shift means del" handling.
+     */
+    void slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers);
+
 private:
     void createActions();
 
 private:
     void createActions();
 
index f1d4652e55897a7e8747184a13f215e8ee2aeaaf..3344db227f8f913217c1ae88c16783c955c3d1f7 100644 (file)
@@ -1,9 +1,11 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphinpart" version="4" >
+<kpartgui name="dolphinpart" version="5" >
  <MenuBar>
   <Menu name="edit">
    <Action name="rename"/>
  <MenuBar>
   <Menu name="edit">
    <Action name="rename"/>
-   <!-- TODO trash, del -->
+   <Action name="move_to_trash" />
+   <Action name="delete"/>
+   <Separator />
    <Action name="select_all" />
    <Action name="invert_selection" />
   </Menu>
    <Action name="select_all" />
    <Action name="invert_selection" />
   </Menu>
index 80d720da8a6e9ad4453dbf525fd122196c0025c2..707dd7c432a6ca95207aeb1217c0de46dd34ab4c 100644 (file)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui version="2" name="dolphin" >
+<kpartgui version="3" name="dolphin" >
  <MenuBar>
   <Menu name="file">
    <Action name="create_new" />
  <MenuBar>
   <Menu name="file">
    <Action name="create_new" />
index 30b07ce4222422ae1e4d8c7c06db5ac0bd1c61d4..51e2a0a575ae6e2e8e3ef48c1c83531abb1b1935 100644 (file)
@@ -36,6 +36,7 @@
 #include <kfileitemdelegate.h>
 #include <klocale.h>
 #include <kiconeffect.h>
 #include <kfileitemdelegate.h>
 #include <klocale.h>
 #include <kiconeffect.h>
+#include <kio/deletejob.h>
 #include <kio/netaccess.h>
 #include <kio/previewjob.h>
 #include <kmimetyperesolver.h>
 #include <kio/netaccess.h>
 #include <kio/previewjob.h>
 #include <kmimetyperesolver.h>
@@ -1067,6 +1068,36 @@ void DolphinView::renameSelectedItems()
     }
 }
 
     }
 }
 
+void DolphinView::trashSelectedItems()
+{
+    emit doingOperation(KonqFileUndoManager::TRASH);
+    KonqOperations::del(this, KonqOperations::TRASH, selectedUrls());
+}
+
+void DolphinView::deleteSelectedItems()
+{
+    const KUrl::List list = selectedUrls();
+    const bool del = KonqOperations::askDeleteConfirmation(list,
+                     KonqOperations::DEL,
+                     KonqOperations::DEFAULT_CONFIRMATION,
+                     this);
+
+    if (del) {
+        KIO::Job* job = KIO::del(list);
+        connect(job, SIGNAL(result(KJob*)),
+                this, SLOT(slotDeleteFileFinished(KJob*)));
+    }
+}
+
+void DolphinView::slotDeleteFileFinished(KJob* job)
+{
+    if (job->error() == 0) {
+        emit operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
+    } else {
+        emit errorMessage(job->errorString());
+    }
+}
+
 void DolphinView::cutSelectedItems()
 {
     QMimeData* mimeData = new QMimeData();
 void DolphinView::cutSelectedItems()
 {
     QMimeData* mimeData = new QMimeData();
@@ -1156,4 +1187,30 @@ QPair<bool, QString> DolphinView::pasteInfo() const
     return ret;
 }
 
     return ret;
 }
 
+KAction* DolphinView::createRenameAction(KActionCollection* collection)
+{
+    KAction* rename = collection->addAction("rename");
+    rename->setText(i18nc("@action:inmenu File", "Rename..."));
+    rename->setShortcut(Qt::Key_F2);
+    return rename;
+}
+
+KAction* DolphinView::createMoveToTrashAction(KActionCollection* collection)
+{
+    KAction* moveToTrash = collection->addAction("move_to_trash");
+    moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
+    moveToTrash->setIcon(KIcon("user-trash"));
+    moveToTrash->setShortcut(QKeySequence::Delete);
+    return moveToTrash;
+}
+
+KAction* DolphinView::createDeleteAction(KActionCollection* collection)
+{
+    KAction* deleteAction = collection->addAction("delete");
+    deleteAction->setIcon(KIcon("edit-delete"));
+    deleteAction->setText(i18nc("@action:inmenu File", "Delete"));
+    deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
+    return deleteAction;
+}
+
 #include "dolphinview.moc"
 #include "dolphinview.moc"
index c20ea10d2ca30f30a33b9d69d3d98fa0838885ba..f550fa51356dd1368e24e8009a6cb860baec80c4 100644 (file)
@@ -38,6 +38,7 @@
 #include <QListView>
 #include <QWidget>
 
 #include <QListView>
 #include <QWidget>
 
+class KAction;
 class KToggleAction;
 class DolphinController;
 class KDirLister;
 class KToggleAction;
 class DolphinController;
 class KDirLister;
@@ -339,6 +340,24 @@ public:
      */
     static KToggleAction* columnsModeAction(KActionCollection* collection);
 
      */
     static KToggleAction* columnsModeAction(KActionCollection* collection);
 
+    /**
+     * Creates the rename action.
+     * This code is here to share it between the mainwindow and the part
+     */
+    static KAction* createRenameAction(KActionCollection* collection);
+
+    /**
+     * Creates the "move to trash" action.
+     * This code is here to share it between the mainwindow and the part
+     */
+    static KAction* createMoveToTrashAction(KActionCollection* collection);
+
+    /**
+     * Creates the delete action.
+     * This code is here to share it between the mainwindow and the part
+     */
+    static KAction* createDeleteAction(KActionCollection* collection);
+
     /**
      * Returns the action name corresponding to the current view mode
      */
     /**
      * Returns the action name corresponding to the current view mode
      */
@@ -372,6 +391,16 @@ public slots:
      */
     void renameSelectedItems();
 
      */
     void renameSelectedItems();
 
+    /**
+     * Moves all selected items to the trash.
+     */
+    void trashSelectedItems();
+
+    /**
+     * Deletes all selected items.
+     */
+    void deleteSelectedItems();
+
     /**
      * Copies all selected items to the clipboard and marks
      * the items as cutted.
     /**
      * Copies all selected items to the clipboard and marks
      * the items as cutted.
@@ -463,6 +492,12 @@ signals:
      */
     void errorMessage(const QString& msg);
 
      */
     void errorMessage(const QString& msg);
 
+    /**
+     * Is emitted if an "operation completed" message with the content \a msg
+     * should be shown.
+     */
+    void operationCompletedMessage(const QString& msg);
+
     /**
      * Is emitted after DolphinView::setUrl() has been invoked and
      * the path \a url is currently loaded. If this signal is emitted,
     /**
      * Is emitted after DolphinView::setUrl() has been invoked and
      * the path \a url is currently loaded. If this signal is emitted,
@@ -573,6 +608,12 @@ private slots:
      */
     void clearHoverInformation();
 
      */
     void clearHoverInformation();
 
+    /**
+     * Indicates in the status bar that the delete operation
+     * of the job \a job has been finished.
+     */
+    void slotDeleteFileFinished(KJob* job);
+
 private:
     void loadDirectory(const KUrl& url, bool reload = false);
 
 private:
     void loadDirectory(const KUrl& url, bool reload = false);
 
index 7e28a30fe3fe570925f9690af1e9cacfcb5609fd..26b4920e9b1b9919cf85e2daae045675a7b33fb3 100644 (file)
@@ -129,6 +129,8 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
             this, SLOT(showErrorMessage(const QString&)));
     connect(m_view, SIGNAL(infoMessage(const QString&)),
             this, SLOT(showInfoMessage(const QString&)));
             this, SLOT(showErrorMessage(const QString&)));
     connect(m_view, SIGNAL(infoMessage(const QString&)),
             this, SLOT(showInfoMessage(const QString&)));
+    connect(m_view, SIGNAL(operationCompletedMessage(const QString&)),
+            this, SLOT(showOperationCompletedMessage(const QString&)));
     connect(m_view, SIGNAL(itemTriggered(KFileItem)),
             this, SLOT(slotItemTriggered(KFileItem)));
     connect(m_view, SIGNAL(startedPathLoading(const KUrl&)),
     connect(m_view, SIGNAL(itemTriggered(KFileItem)),
             this, SLOT(slotItemTriggered(KFileItem)));
     connect(m_view, SIGNAL(startedPathLoading(const KUrl&)),
@@ -250,6 +252,11 @@ void DolphinViewContainer::showErrorMessage(const QString& msg)
     m_statusBar->setMessage(msg, DolphinStatusBar::Error);
 }
 
     m_statusBar->setMessage(msg, DolphinStatusBar::Error);
 }
 
+void DolphinViewContainer::showOperationCompletedMessage(const QString& msg)
+{
+    m_statusBar->setMessage(msg, DolphinStatusBar::OperationCompleted);
+}
+
 void DolphinViewContainer::closeFilterBar()
 {
     m_filterBar->hide();
 void DolphinViewContainer::closeFilterBar()
 {
     m_filterBar->hide();
index 5e252dcdad75ad13e2e929d39481087a22a0122b..ac7fe315baa3115eed924e73b7dc9e3d1aef3d48 100644 (file)
@@ -161,6 +161,9 @@ private slots:
     /** Shows the error message \a msg inside the statusbar. */
     void showErrorMessage(const QString& msg);
 
     /** Shows the error message \a msg inside the statusbar. */
     void showErrorMessage(const QString& msg);
 
+    /** Shows the "operation completed" message \a msg inside the statusbar. */
+    void showOperationCompletedMessage(const QString& msg);
+
     void closeFilterBar();
 
     /**
     void closeFilterBar();
 
     /**