From f8302197daca5667aa3d4963528ce09e344eb27f Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 15 Nov 2007 20:04:05 +0000 Subject: Implement cut/copy/paste in dolphinpart. Had to move more code to DolphinView, to use it from the part. svn path=/trunk/KDE/kdebase/apps/; revision=737203 --- src/dolphinpart.cpp | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'src/dolphinpart.cpp') diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index f278edddf..a0871ce06 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -18,29 +18,23 @@ */ #include "dolphinpart.h" -#include -#include -#include #include "dolphinsortfilterproxymodel.h" #include "dolphinview.h" #include "dolphinmodel.h" +#include #include #include -#include #include +#include + +#include #include +#include typedef KParts::GenericFactory DolphinPartFactory; K_EXPORT_COMPONENT_FACTORY(dolphinpart, DolphinPartFactory) -class DolphinPartBrowserExtension : public KParts::BrowserExtension -{ -public: - DolphinPartBrowserExtension( KParts::ReadOnlyPart* part ) - : KParts::BrowserExtension( part ) {} -}; - DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringList& args) : KParts::ReadOnlyPart(parent) { @@ -91,6 +85,10 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi connect(m_view, SIGNAL(modeChanged()), this, SLOT(updateViewActions())); + QClipboard* clipboard = QApplication::clipboard(); + connect(clipboard, SIGNAL(dataChanged()), + this, SLOT(updatePasteAction())); + createActions(); updateViewActions(); @@ -107,10 +105,6 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi // TODO MMB-click should do something like KonqDirPart::mmbClicked - // TODO updating the paste action - // if (paste) emit m_extension->setActionText( "paste", actionText ); - // emit m_extension->enableAction( "paste", paste ); - // TODO updating the trash and del actions too - or removing special handling of those from konq? } @@ -137,7 +131,8 @@ void DolphinPart::createActions() void DolphinPart::slotSelectionChanged(const KFileItemList& selection) { // Yes, DolphinMainWindow has very similar code :/ - if (selection.isEmpty()) { + const bool hasSelection = !selection.isEmpty(); + if (!hasSelection) { stateChanged("has_no_selection"); } else { stateChanged("has_selection"); @@ -148,6 +143,15 @@ void DolphinPart::slotSelectionChanged(const KFileItemList& selection) renameAction->setEnabled(true); } } + emit m_extension->enableAction("cut", hasSelection); + emit m_extension->enableAction("copy", hasSelection); +} + +void DolphinPart::updatePasteAction() +{ + QPair pasteInfo = m_view->pasteInfo(); + emit m_extension->enableAction( "paste", pasteInfo.first ); + emit m_extension->setActionText( "paste", pasteInfo.second ); } void DolphinPart::updateViewActions() @@ -274,4 +278,21 @@ void DolphinPart::slotUrlChanged(const KUrl& url) } } +//// + +void DolphinPartBrowserExtension::cut() +{ + m_part->view()->cutSelectedItems(); +} + +void DolphinPartBrowserExtension::copy() +{ + m_part->view()->copySelectedItems(); +} + +void DolphinPartBrowserExtension::paste() +{ + m_part->view()->paste(); +} + #include "dolphinpart.moc" -- cgit v1.3