- // Parts of the following code have been taken
- // from the class KonqOperations located in
- // libqonq/konq_operations.h of Konqueror.
- // (Copyright (C) 2000 David Faure <faure@kde.org>)
-
- KMenu* actionsMenu = new KMenu(i18n("Actions"));
-
- QList<QAction*> serviceActions;
-
- QStringList dirs = KGlobal::dirs()->findDirs("data", "dolphin/servicemenus/");
-
- KMenu* menu = 0;
- for (QStringList::ConstIterator dirIt = dirs.begin(); dirIt != dirs.end(); ++dirIt) {
- QDir dir(*dirIt);
- QStringList filters;
- filters << "*.desktop";
- dir.setNameFilters(filters);
- QStringList entries = dir.entryList(QDir::Files);
-
- for (QStringList::ConstIterator entryIt = entries.begin(); entryIt != entries.end(); ++entryIt) {
- KSimpleConfig cfg(*dirIt + *entryIt, true);
- cfg.setDesktopGroup();
- if ((cfg.hasKey("Actions") || cfg.hasKey("X-KDE-GetActionMenu")) && cfg.hasKey("ServiceTypes")) {
- //const QStringList types = cfg.readListEntry("ServiceTypes");
- QStringList types;
- types = cfg.readEntry("ServiceTypes", types);
- for (QStringList::ConstIterator it = types.begin(); it != types.end(); ++it) {
- // check whether the mime type is equal or whether the
- // mimegroup (e. g. image/*) is supported
-
- bool insert = false;
- if ((*it) == "all/allfiles") {
- // The service type is valid for all files, but not for directories.
- // Check whether the selected items only consist of files...
- const KFileItemList list = m_dolphinView->selectedItems();
-
- QListIterator<KFileItem*> mimeIt(list);
- insert = true;
- while (insert && mimeIt.hasNext()) {
- KFileItem* item = mimeIt.next();
- insert = !item->isDir();
- }
- }
-
- if (!insert) {
- // Check whether the MIME types of all selected files match
- // to the mimetype of the service action. As soon as one MIME
- // type does not match, no service menu is shown at all.
- const KFileItemList list = m_dolphinView->selectedItems();
-
- QListIterator<KFileItem*> mimeIt(list);
- insert = true;
- while (insert && mimeIt.hasNext()) {
- KFileItem* item = mimeIt.next();
- const QString mimeType(item->mimetype());
- const QString mimeGroup(mimeType.left(mimeType.indexOf('/')));
-
- insert = (*it == mimeType) ||
- ((*it).right(1) == "*") &&
- ((*it).left((*it).indexOf('/')) == mimeGroup);
- }
- }
-
- if (insert) {
- menu = actionsMenu;
-
- const QString submenuName = cfg.readEntry( "X-KDE-Submenu" );
- if (!submenuName.isEmpty()) {
- menu = new KMenu(submenuName);
- actionsMenu->addMenu(menu);
- }
-
- Q3ValueList<KDEDesktopMimeType::Service> userServices =
- KDEDesktopMimeType::userDefinedServices(*dirIt + *entryIt, true);
-
- Q3ValueList<KDEDesktopMimeType::Service>::Iterator serviceIt;
- for (serviceIt = userServices.begin(); serviceIt != userServices.end(); ++serviceIt) {
- KDEDesktopMimeType::Service service = (*serviceIt);
- if (!service.m_strIcon.isEmpty()) {
- QAction* action = menu->addAction(SmallIcon(service.m_strIcon),
- service.m_strName);
- serviceActions << action;
- }
- else {
- QAction *action = menu->addAction(service.m_strName);
- serviceActions << action;
- }
- actionsVector.append(service);
- }
- }
- }
- }
+ const KActionCollection *collection = m_mainWindow->actionCollection();
+
+ // Insert 'Cut', 'Copy', 'Copy Location' and 'Paste'
+ addAction(collection->action(KStandardAction::name(KStandardAction::Cut)));
+ addAction(collection->action(KStandardAction::name(KStandardAction::Copy)));
+ if (ContextMenuSettings::showCopyLocation()) {
+ QAction *copyPathAction = collection->action(QStringLiteral("copy_location"));
+ copyPathAction->setEnabled(m_selectedItems.size() == 1);
+ addAction(copyPathAction);
+ }
+ QAction *pasteAction = createPasteAction();
+ if (pasteAction) {
+ addAction(pasteAction);
+ }
+
+ // Insert 'Duplicate Here'
+ if (ContextMenuSettings::showDuplicateHere()) {
+ addAction(m_mainWindow->actionCollection()->action(QStringLiteral("duplicate")));
+ }
+
+ // Insert 'Rename'
+ addAction(collection->action(KStandardAction::name(KStandardAction::RenameFile)));
+
+ // Insert 'Add to Places' entry if appropriate
+ if (ContextMenuSettings::showAddToPlaces() && m_selectedItems.count() == 1 && m_fileInfo.isDir() && !placeExists(m_fileInfo.url())) {
+ addAction(m_mainWindow->actionCollection()->action(QStringLiteral("add_to_places")));
+ }
+
+ addSeparator();
+
+ // Insert 'Move to Trash' and/or 'Delete'
+ const bool showDeleteAction = (KSharedConfig::openConfig()->group(QStringLiteral("KDE")).readEntry("ShowDeleteCommand", false) || !properties.isLocal());
+ const bool showMoveToTrashAction = (properties.isLocal() && properties.supportsMoving());
+
+ if (showDeleteAction && showMoveToTrashAction) {
+ delete m_removeAction;
+ m_removeAction = nullptr;
+ addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
+ addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
+ } else if (showDeleteAction && !showMoveToTrashAction) {
+ addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
+ } else {
+ if (!m_removeAction) {
+ m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());