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
#include <kicon.h>
#include <kiconloader.h>
#include <kio/netaccess.h>
-#include <kio/deletejob.h>
#include <kinputdialog.h>
#include <klocale.h>
#include <kmenu.h>
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()
}
}
-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));
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");
*/
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.
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
// (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()
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)
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);
}
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);
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"
*/
void updatePasteAction();
+ /**
+ * Connected to the "move_to_trash" action; adds "shift means del" handling.
+ */
+ void slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers);
+
private:
void createActions();
<!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>
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui version="2" name="dolphin" >
+<kpartgui version="3" name="dolphin" >
<MenuBar>
<Menu name="file">
<Action name="create_new" />
#include <kfileitemdelegate.h>
#include <klocale.h>
#include <kiconeffect.h>
+#include <kio/deletejob.h>
#include <kio/netaccess.h>
#include <kio/previewjob.h>
#include <kmimetyperesolver.h>
}
}
+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();
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 <QListView>
#include <QWidget>
+class KAction;
class KToggleAction;
class DolphinController;
class KDirLister;
*/
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
*/
*/
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.
*/
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,
*/
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);
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&)),
m_statusBar->setMessage(msg, DolphinStatusBar::Error);
}
+void DolphinViewContainer::showOperationCompletedMessage(const QString& msg)
+{
+ m_statusBar->setMessage(msg, DolphinStatusBar::OperationCompleted);
+}
+
void DolphinViewContainer::closeFilterBar()
{
m_filterBar->hide();
/** 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();
/**