diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 2475c68bcf..6ff20fe7f5 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -68,6 +68,10 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, } } +DolphinContextMenu::~DolphinContextMenu() +{ +} + void DolphinContextMenu::open() { // get the context information @@ -98,8 +102,39 @@ void DolphinContextMenu::open() } } -DolphinContextMenu::~DolphinContextMenu() +void DolphinContextMenu::cut() { + // TODO +} + +void DolphinContextMenu::copy() +{ + // TODO +} + +void DolphinContextMenu::paste() +{ + // TODO +} + +void DolphinContextMenu::rename() +{ + // TODO +} + +void DolphinContextMenu::moveToTrash() +{ + // TODO +} + +void DolphinContextMenu::deleteItem() +{ + // TODO +} + +void DolphinContextMenu::showProperties() +{ + new KPropertiesDialog(m_fileInfo->url()); } void DolphinContextMenu::openTrashContextMenu() @@ -159,9 +194,7 @@ void DolphinContextMenu::openItemContextMenu() Q_ASSERT(m_fileInfo != 0); KMenu* popup = new KMenu(m_mainWindow); - if (m_viewType == ItemsView) { - insertDefaultItemActions(popup); - } + insertDefaultItemActions(popup); popup->addSeparator(); @@ -180,11 +213,16 @@ void DolphinContextMenu::openItemContextMenu() const QList serviceActions = insertActionItems(popup, actionsVector); popup->addSeparator(); - if (m_viewType == ItemsView) { - // insert 'Properties...' entry - QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); - popup->addAction(propertiesAction); + // insert 'Properties...' entry + QAction* propertiesAction = 0; + if (m_viewType == SidebarView) { + propertiesAction = new QAction(i18n("Properties..."), this); + connect(this, SIGNAL(triggered()), this, SLOT(showProperties())); } + else { + propertiesAction = m_mainWindow->actionCollection()->action("properties"); + } + popup->addAction(propertiesAction); QAction* activatedAction = popup->exec(QCursor::pos()); @@ -283,18 +321,45 @@ void DolphinContextMenu::openViewportContextMenu() void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) { Q_ASSERT(popup != 0); + const KActionCollection* collection = m_mainWindow->actionCollection(); + const bool insertSidebarActions = (m_viewType == SidebarView); // insert 'Cut', 'Copy' and 'Paste' - QAction* cutAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Cut)); - QAction* copyAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Copy)); - QAction* pasteAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste)); + QAction* cutAction = 0; + QAction* copyAction = 0; + QAction* pasteAction = 0; + if (insertSidebarActions) { + cutAction = new QAction(KIcon("edit-cut"), i18n("Cut"), this); + connect(cutAction, SIGNAL(triggered()), this, SLOT(cut())); + + copyAction = new QAction(KIcon("edit-copy"), i18n("Copy"), this); + connect(copyAction, SIGNAL(triggered()), this, SLOT(copy())); + + const QAction* menuPasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste)); + pasteAction = new QAction(KIcon("edit-paste"), menuPasteAction->text(), this); + pasteAction->setEnabled(menuPasteAction->isEnabled()); + connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste())); + } + else { + cutAction = collection->action(KStandardAction::stdName(KStandardAction::Cut)); + copyAction = collection->action(KStandardAction::stdName(KStandardAction::Copy)); + pasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste)); + } + popup->addAction(cutAction); popup->addAction(copyAction); popup->addAction(pasteAction); popup->addSeparator(); // insert 'Rename' - QAction* renameAction = m_mainWindow->actionCollection()->action("rename"); + QAction* renameAction = 0; + if (insertSidebarActions) { + renameAction = new QAction(i18n("Rename"), this); + connect(renameAction, SIGNAL(triggered()), this, SLOT(paste())); + } + else { + collection->action("rename"); + } popup->addAction(renameAction); // insert 'Move to Trash' and (optionally) 'Delete' @@ -303,7 +368,14 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false); const KUrl& url = m_mainWindow->activeView()->url(); if (url.isLocalFile()) { - QAction* moveToTrashAction = m_mainWindow->actionCollection()->action("move_to_trash"); + QAction* moveToTrashAction = 0; + if (insertSidebarActions) { + moveToTrashAction = new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this); + connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash())); + } + else { + collection->action("move_to_trash"); + } popup->addAction(moveToTrashAction); } else { @@ -311,7 +383,14 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) } if (showDeleteCommand) { - QAction* deleteAction = m_mainWindow->actionCollection()->action("delete"); + QAction* deleteAction = 0; + if (insertSidebarActions) { + deleteAction = new QAction(KIcon("edit-delete"), i18n("Delete"), this); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem())); + } + else { + collection->action("delete"); + } popup->addAction(deleteAction); } } @@ -536,3 +615,5 @@ bool DolphinContextMenu::containsEntry(const KMenu* menu, return false; } + +#include "dolphincontextmenu.moc" diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h index 09288c6026..2a678d9a2b 100644 --- a/src/dolphincontextmenu.h +++ b/src/dolphincontextmenu.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -45,8 +46,10 @@ class DolphinMainWindow; * - 'Actions': Contains all actions which can be applied to the * given item. */ -class DolphinContextMenu +class DolphinContextMenu : public QObject { + Q_OBJECT + public: enum ViewType { @@ -74,6 +77,28 @@ public: /** Opens the context menu modal. */ void open(); +private slots: + /** Cuts the item m_fileInfo. */ + void cut(); + + /** Copies the item m_fileInfo. */ + void copy(); + + /** Paste the clipboard to m_fileInfo. */ + void paste(); + + /** Renames the item m_fileInfo. */ + void rename(); + + /** Moves the item m_fileInfo to the trash. */ + void moveToTrash(); + + /** Deletes the item m_fileInfo. */ + void deleteItem(); + + /** Shows the properties of the item m_fileInfo. */ + void showProperties(); + private: void openTrashContextMenu(); void openTrashItemContextMenu(); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 994f03b6e8..db9c740cc2 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -460,6 +460,11 @@ bool DolphinView::hasSelection() const return itemView()->selectionModel()->hasSelection(); } +void DolphinView::clearSelection() +{ + itemView()->selectionModel()->clear(); +} + KFileItemList DolphinView::selectedItems() const { const QAbstractItemView* view = itemView(); diff --git a/src/dolphinview.h b/src/dolphinview.h index 218411208f..fd47e1fae2 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -219,11 +219,11 @@ public: */ const QLinkedList urlHistory(int& index) const; - /** - * Returns true, if at least one item is selected. - */ + /** Returns true, if at least one item is selected. */ bool hasSelection() const; + void clearSelection(); + /** * Returns the selected items. The list is empty if no item has been * selected. @@ -250,7 +250,6 @@ public: */ void rename(const KUrl& source, const QString& newName); - /** Returns the status bar of the view. */ DolphinStatusBar* statusBar() const; /** diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp index b7c1f1f537..4dddeae5c7 100644 --- a/src/treeviewsidebarpage.cpp +++ b/src/treeviewsidebarpage.cpp @@ -121,6 +121,7 @@ void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event) KFileItem* item = m_dirModel->itemForIndex(index); #endif + mainWindow()->activeView()->clearSelection(); DolphinContextMenu contextMenu(mainWindow(), item, m_dirLister->url(),