X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/1cdb64a12bf5e6f3b97d38992799ba6bfbb06ef5..ec9841397ff92b872df5c3853a232cedae82dfde:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 915f7e3e1..c9028862d 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -43,27 +44,35 @@ #include #include +#include +#include #include DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, KFileItem* fileInfo, const KUrl& baseUrl, - KFileItemList selectedItems) : + ViewType viewType) : m_mainWindow(parent), m_fileInfo(fileInfo), m_baseUrl(baseUrl), - m_selectedItems(selectedItems), + m_viewType(viewType), m_context(NoContext) { - // The context menu either accesses the URLs of the selected items - // or the items itself. To increase the performance the URLs are cached. - KFileItemList::const_iterator it = selectedItems.begin(); - const KFileItemList::const_iterator end = selectedItems.end(); - while (it != end) { - KFileItem* item = *it; - m_selectedUrls.append(item->url()); - ++it; + if (viewType == ItemsView) { + // The context menu either accesses the URLs of the selected items + // or the items itself. To increase the performance both lists are cached. + DolphinView* view = m_mainWindow->activeView(); + m_selectedUrls = view->selectedUrls(); + m_selectedItems = view->selectedItems(); } + else if (fileInfo != 0) { + m_selectedUrls.append(fileInfo->url()); + m_selectedItems.append(fileInfo); + } +} + +DolphinContextMenu::~DolphinContextMenu() +{ } void DolphinContextMenu::open() @@ -96,8 +105,58 @@ void DolphinContextMenu::open() } } -DolphinContextMenu::~DolphinContextMenu() +void DolphinContextMenu::cut() +{ + QMimeData* mimeData = new QMimeData(); + KUrl::List kdeUrls; + kdeUrls.append(m_fileInfo->url()); + KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), true); + QApplication::clipboard()->setMimeData(mimeData); +} + +void DolphinContextMenu::copy() +{ + QMimeData* mimeData = new QMimeData(); + KUrl::List kdeUrls; + kdeUrls.append(m_fileInfo->url()); + KonqMimeData::populateMimeData(mimeData, kdeUrls, KUrl::List(), false); + QApplication::clipboard()->setMimeData(mimeData); +} + +void DolphinContextMenu::paste() +{ + QClipboard* clipboard = QApplication::clipboard(); + const QMimeData* mimeData = clipboard->mimeData(); + + const KUrl::List source = KUrl::List::fromMimeData(mimeData); + const KUrl& dest = m_fileInfo->url(); + if (KonqMimeData::decodeIsCutSelection(mimeData)) { + KonqOperations::copy(m_mainWindow, KonqOperations::MOVE, source, dest); + clipboard->clear(); + } + else { + KonqOperations::copy(m_mainWindow, KonqOperations::COPY, source, dest); + } +} + +void DolphinContextMenu::rename() +{ + // TODO +} + +void DolphinContextMenu::moveToTrash() +{ + // TODO +} + +void DolphinContextMenu::deleteItem() { + // TODO +} + +void DolphinContextMenu::showProperties() +{ + new KPropertiesDialog(m_fileInfo->url()); } void DolphinContextMenu::openTrashContextMenu() @@ -159,10 +218,12 @@ void DolphinContextMenu::openItemContextMenu() KMenu* popup = new KMenu(m_mainWindow); insertDefaultItemActions(popup); + popup->addSeparator(); + // insert 'Bookmark this folder' entry if exactly one item is selected QAction* bookmarkAction = 0; if (m_fileInfo->isDir() && (m_selectedUrls.count() == 1)) { - bookmarkAction = popup->addAction(KIcon("bookmark-folder"), i18n("Bookmark this folder")); + bookmarkAction = popup->addAction(KIcon("bookmark-folder"), i18n("Bookmark folder")); } // Insert 'Open With...' sub menu @@ -175,7 +236,14 @@ void DolphinContextMenu::openItemContextMenu() popup->addSeparator(); // insert 'Properties...' entry - QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); + 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()); @@ -275,34 +343,62 @@ 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' - const KStandardAction::StandardAction actionNames[] = { - KStandardAction::Cut, - KStandardAction::Copy, - KStandardAction::Paste - }; - - const int count = sizeof(actionNames) / sizeof(KStandardAction::StandardAction); - for (int i = 0; i < count; ++i) { - QAction* action = m_mainWindow->actionCollection()->action(KStandardAction::stdName(actionNames[i])); - if (action != 0) { - popup->addAction(action); - } + 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(rename())); + } + else { + renameAction = collection->action("rename"); + } popup->addAction(renameAction); // insert 'Move to Trash' and (optionally) 'Delete' const KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::NoGlobals); const KConfigGroup kdeConfig(globalConfig, "KDE"); bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false); - const KUrl& url = m_mainWindow->activeView()->url(); + const KUrl& url = insertSidebarActions ? m_fileInfo->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 { + moveToTrashAction = collection->action("move_to_trash"); + } popup->addAction(moveToTrashAction); } else { @@ -310,7 +406,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 { + deleteAction = collection->action("delete"); + } popup->addAction(deleteAction); } } @@ -354,7 +457,7 @@ QList DolphinContextMenu::insertOpenWithItems(KMenu* popup, const QString appName((*it)->name()); if (!containsEntry(openWithMenu, appName)) { const KIcon icon((*it)->icon()); - QAction *action = openWithMenu->addAction(icon, appName); + QAction* action = openWithMenu->addAction(icon, appName); openWithVector.append(*it); openWithActions << action; } @@ -364,7 +467,6 @@ QList DolphinContextMenu::insertOpenWithItems(KMenu* popup, QAction* action = openWithMenu->addAction(i18n("&Other...")); openWithActions << action; - popup->addSeparator(); popup->addMenu(openWithMenu); } else { @@ -378,7 +480,6 @@ QList DolphinContextMenu::insertOpenWithItems(KMenu* popup, else { // At least one of the selected items has a different MIME type. In this case // just show a disabled "Open With..." entry. - popup->addSeparator(); QAction* action = popup->addAction(i18n("Open With...")); action->setEnabled(false); } @@ -537,3 +638,5 @@ bool DolphinContextMenu::containsEntry(const KMenu* menu, return false; } + +#include "dolphincontextmenu.moc"