X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/2a3035088bff8287fb92fd8dbd93aabe8aaa90d2..e8bc9f1072bfc43d7605315c8df69f37bfc71cc3:/src/dolphinpart.cpp diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 2f52447ec..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) { @@ -78,14 +72,22 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(slotErrorMessage(QString))); connect(m_view, SIGNAL(itemTriggered(KFileItem)), this, SLOT(slotItemTriggered(KFileItem))); - connect(m_view, SIGNAL(requestContextMenu(KFileItem, const KUrl&)), - this, SLOT(slotOpenContextMenu(KFileItem, const KUrl&))); + connect(m_view, SIGNAL(requestContextMenu(KFileItem,KUrl)), + this, SLOT(slotOpenContextMenu(KFileItem,KUrl))); connect(m_view, SIGNAL(selectionChanged(KFileItemList)), m_extension, SIGNAL(selectionInfo(KFileItemList))); + connect(m_view, SIGNAL(selectionChanged(KFileItemList)), + this, SLOT(slotSelectionChanged(KFileItemList))); connect(m_view, SIGNAL(requestItemInfo(KFileItem)), this, SLOT(slotRequestItemInfo(KFileItem))); - connect(m_view, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(slotUrlChanged(const KUrl&))); + connect(m_view, SIGNAL(urlChanged(KUrl)), + this, SLOT(slotUrlChanged(KUrl))); + connect(m_view, SIGNAL(modeChanged()), + this, SLOT(updateViewActions())); + + QClipboard* clipboard = QApplication::clipboard(); + connect(clipboard, SIGNAL(dataChanged()), + this, SLOT(updatePasteAction())); createActions(); updateViewActions(); @@ -103,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? } @@ -122,6 +120,38 @@ void DolphinPart::createActions() viewModeActions->addAction(DolphinView::detailsModeAction(actionCollection())); viewModeActions->addAction(DolphinView::columnsModeAction(actionCollection())); connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*))); + + KAction* renameAction = new KAction(i18nc("@action:inmenu", "Rename..."), this); + connect(renameAction, SIGNAL(triggered()), m_view, SLOT(renameSelectedItems())); + renameAction->setEnabled(false); + renameAction->setShortcut(Qt::Key_F2); + actionCollection()->addAction("rename", renameAction); +} + +void DolphinPart::slotSelectionChanged(const KFileItemList& selection) +{ + // Yes, DolphinMainWindow has very similar code :/ + const bool hasSelection = !selection.isEmpty(); + if (!hasSelection) { + stateChanged("has_no_selection"); + } else { + stateChanged("has_selection"); + + QAction* renameAction = actionCollection()->action("rename"); + Q_ASSERT(renameAction); + if (renameAction) { + 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() @@ -218,8 +248,18 @@ void DolphinPart::slotOpenContextMenu(const KFileItem& _item, const KUrl&) item = KFileItem( S_IFDIR, (mode_t)-1, url() ); } + KParts::BrowserExtension::ActionGroupMap actionGroups; + QList editActions; + editActions.append(actionCollection()->action("rename")); + actionGroups.insert("editactions", editActions); + KFileItemList items; items.append(item); - emit m_extension->popupMenu( QCursor::pos(), items, KParts::OpenUrlArguments(), KParts::BrowserArguments(), popupFlags ); + emit m_extension->popupMenu(QCursor::pos(), + items, + KParts::OpenUrlArguments(), + KParts::BrowserArguments(), + popupFlags, + actionGroups); } void DolphinPart::slotViewModeActionTriggered(QAction* action) @@ -238,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"