X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/1cdb64a12bf5e6f3b97d38992799ba6bfbb06ef5..85bc196887fbed01187e3830cd28c2500cb01cb2:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 915f7e3e1..fff3b5ac3 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -43,27 +44,27 @@ #include #include +#include +#include #include DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, KFileItem* fileInfo, - const KUrl& baseUrl, - KFileItemList selectedItems) : + const KUrl& baseUrl) : m_mainWindow(parent), m_fileInfo(fileInfo), m_baseUrl(baseUrl), - m_selectedItems(selectedItems), 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; - } + // 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(); +} + +DolphinContextMenu::~DolphinContextMenu() +{ } void DolphinContextMenu::open() @@ -96,9 +97,6 @@ void DolphinContextMenu::open() } } -DolphinContextMenu::~DolphinContextMenu() -{ -} void DolphinContextMenu::openTrashContextMenu() { @@ -106,7 +104,7 @@ void DolphinContextMenu::openTrashContextMenu() KMenu* popup = new KMenu(m_mainWindow); - QAction* emptyTrashAction = new QAction(KIcon("user-trash"), i18n("Emtpy Trash"), popup); + QAction* emptyTrashAction = new QAction(KIcon("emptytrash"), i18n("Emtpy Trash"), popup); KConfig trashConfig("trashrc", KConfig::OnlyLocal); emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); popup->addAction(emptyTrashAction); @@ -159,10 +157,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 @@ -170,7 +170,7 @@ void DolphinContextMenu::openItemContextMenu() const QList openWithActions = insertOpenWithItems(popup, openWithVector); // Insert 'Actions' sub menu - QVector actionsVector; + QVector actionsVector; const QList serviceActions = insertActionItems(popup, actionsVector); popup->addSeparator(); @@ -196,7 +196,7 @@ void DolphinContextMenu::openItemContextMenu() else if (serviceActions.contains(activatedAction)) { // one of the 'Actions' items has been selected int id = serviceActions.indexOf(activatedAction); - KDEDesktopMimeType::executeService(m_selectedUrls, actionsVector[id]); + KDesktopFileActions::executeService(m_selectedUrls, actionsVector[id]); } else if (openWithActions.contains(activatedAction)) { // one of the 'Open With' items has been selected @@ -275,25 +275,20 @@ void DolphinContextMenu::openViewportContextMenu() void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) { Q_ASSERT(popup != 0); + const KActionCollection* collection = m_mainWindow->actionCollection(); // 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 = collection->action(KStandardAction::stdName(KStandardAction::Cut)); + QAction* copyAction = collection->action(KStandardAction::stdName(KStandardAction::Copy)); + QAction* 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 = collection->action("rename"); popup->addAction(renameAction); // insert 'Move to Trash' and (optionally) 'Delete' @@ -302,7 +297,7 @@ 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 = collection->action("move_to_trash"); popup->addAction(moveToTrashAction); } else { @@ -310,7 +305,7 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) } if (showDeleteCommand) { - QAction* deleteAction = m_mainWindow->actionCollection()->action("delete"); + QAction* deleteAction = collection->action("delete"); popup->addAction(deleteAction); } } @@ -354,7 +349,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 +359,6 @@ QList DolphinContextMenu::insertOpenWithItems(KMenu* popup, QAction* action = openWithMenu->addAction(i18n("&Other...")); openWithActions << action; - popup->addSeparator(); popup->addMenu(openWithMenu); } else { @@ -378,7 +372,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); } @@ -387,7 +380,7 @@ QList DolphinContextMenu::insertOpenWithItems(KMenu* popup, } QList DolphinContextMenu::insertActionItems(KMenu* popup, - QVector& actionsVector) + QVector& actionsVector) { // Parts of the following code have been taken // from the class KonqOperations located in @@ -456,12 +449,12 @@ QList DolphinContextMenu::insertActionItems(KMenu* popup, actionsMenu->addMenu(menu); } - Q3ValueList userServices = - KDEDesktopMimeType::userDefinedServices(*dirIt + *entryIt, true); + Q3ValueList userServices = + KDesktopFileActions::userDefinedServices(*dirIt + *entryIt, true); - Q3ValueList::Iterator serviceIt; + Q3ValueList::Iterator serviceIt; for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) { - KDEDesktopMimeType::Service service = (*serviceIt); + KDesktopFileActions::Service service = (*serviceIt); if (!service.m_strIcon.isEmpty()) { QAction* action = menu->addAction(SmallIcon(service.m_strIcon), service.m_strName); @@ -537,3 +530,5 @@ bool DolphinContextMenu::containsEntry(const KMenu* menu, return false; } + +#include "dolphincontextmenu.moc"