Allow to cut, copy, paste, ... the currently selected item from a sidebar by the DolphinContextMenu (currently only used by the tree view).

svn path=/trunk/KDE/kdebase/apps/; revision=643572
This commit is contained in:
Peter Penz 2007-03-17 20:42:26 +00:00
parent 9b9c12ec69
commit 6baba131b2
5 changed files with 130 additions and 19 deletions

View file

@ -68,6 +68,10 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
} }
} }
DolphinContextMenu::~DolphinContextMenu()
{
}
void DolphinContextMenu::open() void DolphinContextMenu::open()
{ {
// get the context information // 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() void DolphinContextMenu::openTrashContextMenu()
@ -159,9 +194,7 @@ void DolphinContextMenu::openItemContextMenu()
Q_ASSERT(m_fileInfo != 0); Q_ASSERT(m_fileInfo != 0);
KMenu* popup = new KMenu(m_mainWindow); KMenu* popup = new KMenu(m_mainWindow);
if (m_viewType == ItemsView) { insertDefaultItemActions(popup);
insertDefaultItemActions(popup);
}
popup->addSeparator(); popup->addSeparator();
@ -180,11 +213,16 @@ void DolphinContextMenu::openItemContextMenu()
const QList<QAction*> serviceActions = insertActionItems(popup, actionsVector); const QList<QAction*> serviceActions = insertActionItems(popup, actionsVector);
popup->addSeparator(); popup->addSeparator();
if (m_viewType == ItemsView) { // insert 'Properties...' entry
// insert 'Properties...' entry QAction* propertiesAction = 0;
QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); if (m_viewType == SidebarView) {
popup->addAction(propertiesAction); 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()); QAction* activatedAction = popup->exec(QCursor::pos());
@ -283,18 +321,45 @@ void DolphinContextMenu::openViewportContextMenu()
void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
{ {
Q_ASSERT(popup != 0); Q_ASSERT(popup != 0);
const KActionCollection* collection = m_mainWindow->actionCollection();
const bool insertSidebarActions = (m_viewType == SidebarView);
// insert 'Cut', 'Copy' and 'Paste' // insert 'Cut', 'Copy' and 'Paste'
QAction* cutAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Cut)); QAction* cutAction = 0;
QAction* copyAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Copy)); QAction* copyAction = 0;
QAction* pasteAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste)); 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(cutAction);
popup->addAction(copyAction); popup->addAction(copyAction);
popup->addAction(pasteAction); popup->addAction(pasteAction);
popup->addSeparator(); popup->addSeparator();
// insert 'Rename' // 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); popup->addAction(renameAction);
// insert 'Move to Trash' and (optionally) 'Delete' // insert 'Move to Trash' and (optionally) 'Delete'
@ -303,7 +368,14 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false); bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
const KUrl& url = m_mainWindow->activeView()->url(); const KUrl& url = m_mainWindow->activeView()->url();
if (url.isLocalFile()) { 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); popup->addAction(moveToTrashAction);
} }
else { else {
@ -311,7 +383,14 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
} }
if (showDeleteCommand) { 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); popup->addAction(deleteAction);
} }
} }
@ -536,3 +615,5 @@ bool DolphinContextMenu::containsEntry(const KMenu* menu,
return false; return false;
} }
#include "dolphincontextmenu.moc"

View file

@ -25,6 +25,7 @@
#include <kservice.h> #include <kservice.h>
#include <kurl.h> #include <kurl.h>
#include <QObject>
#include <QString> #include <QString>
#include <QVector> #include <QVector>
@ -45,8 +46,10 @@ class DolphinMainWindow;
* - 'Actions': Contains all actions which can be applied to the * - 'Actions': Contains all actions which can be applied to the
* given item. * given item.
*/ */
class DolphinContextMenu class DolphinContextMenu : public QObject
{ {
Q_OBJECT
public: public:
enum ViewType enum ViewType
{ {
@ -74,6 +77,28 @@ public:
/** Opens the context menu modal. */ /** Opens the context menu modal. */
void open(); 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: private:
void openTrashContextMenu(); void openTrashContextMenu();
void openTrashItemContextMenu(); void openTrashItemContextMenu();

View file

@ -460,6 +460,11 @@ bool DolphinView::hasSelection() const
return itemView()->selectionModel()->hasSelection(); return itemView()->selectionModel()->hasSelection();
} }
void DolphinView::clearSelection()
{
itemView()->selectionModel()->clear();
}
KFileItemList DolphinView::selectedItems() const KFileItemList DolphinView::selectedItems() const
{ {
const QAbstractItemView* view = itemView(); const QAbstractItemView* view = itemView();

View file

@ -219,11 +219,11 @@ public:
*/ */
const QLinkedList<UrlNavigator::HistoryElem> urlHistory(int& index) const; const QLinkedList<UrlNavigator::HistoryElem> 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; bool hasSelection() const;
void clearSelection();
/** /**
* Returns the selected items. The list is empty if no item has been * Returns the selected items. The list is empty if no item has been
* selected. * selected.
@ -250,7 +250,6 @@ public:
*/ */
void rename(const KUrl& source, const QString& newName); void rename(const KUrl& source, const QString& newName);
/** Returns the status bar of the view. */
DolphinStatusBar* statusBar() const; DolphinStatusBar* statusBar() const;
/** /**

View file

@ -121,6 +121,7 @@ void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
KFileItem* item = m_dirModel->itemForIndex(index); KFileItem* item = m_dirModel->itemForIndex(index);
#endif #endif
mainWindow()->activeView()->clearSelection();
DolphinContextMenu contextMenu(mainWindow(), DolphinContextMenu contextMenu(mainWindow(),
item, item,
m_dirLister->url(), m_dirLister->url(),