diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dolphinmainwindow.cpp | 52 | ||||
| -rw-r--r-- | src/dolphinmainwindow.h | 12 | ||||
| -rw-r--r-- | src/dolphinpart.cpp | 45 | ||||
| -rw-r--r-- | src/dolphinpart.h | 5 | ||||
| -rw-r--r-- | src/dolphinpart.rc | 6 | ||||
| -rw-r--r-- | src/dolphinui.rc | 2 | ||||
| -rw-r--r-- | src/dolphinview.cpp | 57 | ||||
| -rw-r--r-- | src/dolphinview.h | 41 | ||||
| -rw-r--r-- | src/dolphinviewcontainer.cpp | 7 | ||||
| -rw-r--r-- | src/dolphinviewcontainer.h | 3 |
10 files changed, 157 insertions, 73 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index c38cc5ea3..540fe5e48 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -52,7 +52,6 @@ #include <kicon.h> #include <kiconloader.h> #include <kio/netaccess.h> -#include <kio/deletejob.h> #include <kinputdialog.h> #include <klocale.h> #include <kmenu.h> @@ -488,28 +487,13 @@ void DolphinMainWindow::rename() 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(); - - 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() @@ -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)); @@ -1047,21 +1013,13 @@ void DolphinMainWindow::setupActions() 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())); - 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())); - 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"); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 1471b44e9..2f91f9553 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -200,18 +200,6 @@ private slots: 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. */ diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index a0871ce06..113b840e7 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -91,8 +91,9 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi 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 @@ -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 - - // TODO updating the trash and del actions too - or removing special handling of those from konq? } DolphinPart::~DolphinPart() @@ -121,11 +120,15 @@ void DolphinPart::createActions() 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())); - 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) @@ -136,13 +139,18 @@ void DolphinPart::slotSelectionChanged(const KFileItemList& 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); } @@ -251,6 +259,8 @@ void DolphinPart::slotOpenContextMenu(const KFileItem& _item, const KUrl&) 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); @@ -295,4 +305,17 @@ void DolphinPartBrowserExtension::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" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 114c21d31..5075702db 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -108,6 +108,11 @@ private Q_SLOTS: */ void updatePasteAction(); + /** + * Connected to the "move_to_trash" action; adds "shift means del" handling. + */ + void slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers); + private: void createActions(); diff --git a/src/dolphinpart.rc b/src/dolphinpart.rc index f1d4652e5..3344db227 100644 --- a/src/dolphinpart.rc +++ b/src/dolphinpart.rc @@ -1,9 +1,11 @@ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> -<kpartgui name="dolphinpart" version="4" > +<kpartgui name="dolphinpart" version="5" > <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> diff --git a/src/dolphinui.rc b/src/dolphinui.rc index 80d720da8..707dd7c43 100644 --- a/src/dolphinui.rc +++ b/src/dolphinui.rc @@ -1,5 +1,5 @@ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> -<kpartgui version="2" name="dolphin" > +<kpartgui version="3" name="dolphin" > <MenuBar> <Menu name="file"> <Action name="create_new" /> diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 30b07ce42..51e2a0a57 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -36,6 +36,7 @@ #include <kfileitemdelegate.h> #include <klocale.h> #include <kiconeffect.h> +#include <kio/deletejob.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(); @@ -1156,4 +1187,30 @@ QPair<bool, QString> DolphinView::pasteInfo() const 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" diff --git a/src/dolphinview.h b/src/dolphinview.h index c20ea10d2..f550fa513 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -38,6 +38,7 @@ #include <QListView> #include <QWidget> +class KAction; class KToggleAction; class DolphinController; class KDirLister; @@ -340,6 +341,24 @@ public: 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 */ QString currentViewModeActionName() const; @@ -373,6 +392,16 @@ public slots: 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. */ @@ -464,6 +493,12 @@ signals: 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, * it is assured that the view contains already the correct root @@ -573,6 +608,12 @@ private slots: */ 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); diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 7e28a30fe..26b4920e9 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -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&))); + 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&)), @@ -250,6 +252,11 @@ void DolphinViewContainer::showErrorMessage(const QString& msg) m_statusBar->setMessage(msg, DolphinStatusBar::Error); } +void DolphinViewContainer::showOperationCompletedMessage(const QString& msg) +{ + m_statusBar->setMessage(msg, DolphinStatusBar::OperationCompleted); +} + void DolphinViewContainer::closeFilterBar() { m_filterBar->hide(); diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index 5e252dcda..ac7fe315b 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -161,6 +161,9 @@ private slots: /** 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(); /** |
