X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/d4fb129710d7fadf8e21f2cfd2588a794f774e41..5ce01c864f4ab9848a54ee982f6ac18e63f04773:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 22272fb74..af283cf00 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -27,38 +27,30 @@ #include "dolphinremoveaction.h" #include -#include -#include -#include +#include #include #include -#include -#include #include #include #include -#include +#include #include -#include -#include -#include #include -#include #include -#include #include -#include -#include +#include #include -#include #include +#include +#include +#include +#include +#include + #include #include -#include -#include -#include #include "views/dolphinview.h" #include "views/viewmodecontroller.h" @@ -66,8 +58,8 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const QPoint& pos, const KFileItem& fileInfo, - const KUrl& baseUrl) : - KMenu(parent), + const QUrl& baseUrl) : + QMenu(parent), m_pos(pos), m_mainWindow(parent), m_fileInfo(fileInfo), @@ -101,7 +93,7 @@ void DolphinContextMenu::setCustomActions(const QList& actions) DolphinContextMenu::Command DolphinContextMenu::open() { // get the context information - if (m_baseUrl.protocol() == QLatin1String("trash")) { + if (m_baseUrl.scheme() == QLatin1String("trash")) { m_context |= TrashContext; } @@ -132,7 +124,7 @@ void DolphinContextMenu::keyPressEvent(QKeyEvent *ev) if (m_removeAction && ev->key() == Qt::Key_Shift) { m_removeAction->update(); } - KMenu::keyPressEvent(ev); + QMenu::keyPressEvent(ev); } void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev) @@ -140,7 +132,7 @@ void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev) if (m_removeAction && ev->key() == Qt::Key_Shift) { m_removeAction->update(); } - KMenu::keyReleaseEvent(ev); + QMenu::keyReleaseEvent(ev); } void DolphinContextMenu::openTrashContextMenu() @@ -185,7 +177,7 @@ void DolphinContextMenu::openTrashItemContextMenu() addAction(propertiesAction); if (exec(m_pos) == restoreAction) { - KUrl::List selectedUrls; + QList selectedUrls; foreach (const KFileItem &item, m_selectedItems) { selectedUrls.append(item.url()); } @@ -200,6 +192,7 @@ void DolphinContextMenu::openItemContextMenu() { Q_ASSERT(!m_fileInfo.isNull()); + QAction* openParentAction = 0; QAction* openParentInNewWindowAction = 0; QAction* openParentInNewTabAction = 0; QAction* addToPlacesAction = 0; @@ -235,7 +228,13 @@ void DolphinContextMenu::openItemContextMenu() } addSeparator(); - } else if (m_baseUrl.protocol().contains("search")) { + } else if (m_baseUrl.scheme().contains("search") || m_baseUrl.scheme().contains("timeline")) { + openParentAction = new QAction(QIcon::fromTheme("document-open-folder"), + i18nc("@action:inmenu", + "Open Path"), + this); + addAction(openParentAction); + openParentInNewWindowAction = new QAction(QIcon::fromTheme("window-new"), i18nc("@action:inmenu", "Open Path in New Window"), @@ -259,7 +258,7 @@ void DolphinContextMenu::openItemContextMenu() } else { bool selectionHasOnlyDirs = true; foreach (const KFileItem& item, m_selectedItems) { - const KUrl& url = DolphinView::openItemAsFolderUrl(item); + const QUrl& url = DolphinView::openItemAsFolderUrl(item); if (url.isEmpty()) { selectionHasOnlyDirs = false; break; @@ -287,8 +286,9 @@ void DolphinContextMenu::openItemContextMenu() // insert 'Copy To' and 'Move To' sub menus if (GeneralSettings::showCopyMoveMenu()) { - m_copyToMenu.setItems(m_selectedItems); + m_copyToMenu.setUrls(m_selectedItems.urlList()); m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting()); + m_copyToMenu.setAutoErrorHandlingEnabled(true); m_copyToMenu.addActionsTo(this); } @@ -299,13 +299,16 @@ void DolphinContextMenu::openItemContextMenu() QAction* activatedAction = exec(m_pos); if (activatedAction) { if (activatedAction == addToPlacesAction) { - const KUrl selectedUrl(m_fileInfo.url()); + const QUrl selectedUrl(m_fileInfo.url()); if (selectedUrl.isValid()) { PlacesItemModel model; const QString text = selectedUrl.fileName(); PlacesItem* item = model.createPlacesItem(text, selectedUrl); model.appendItemToGroup(item); + model.saveBookmarks(); } + } else if (activatedAction == openParentAction) { + m_command = OpenParentFolder; } else if (activatedAction == openParentInNewWindowAction) { m_command = OpenParentFolderInNewWindow; } else if (activatedAction == openParentInNewTabAction) { @@ -368,6 +371,7 @@ void DolphinContextMenu::openViewportContextMenu() PlacesItem* item = model.createPlacesItem(container->placesText(), container->url()); model.appendItemToGroup(item); + model.saveBookmarks(); } } } @@ -389,7 +393,7 @@ void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& // Insert 'Move to Trash' and/or 'Delete' if (properties.supportsDeleting()) { - const bool showDeleteAction = (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false) || + const bool showDeleteAction = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) || !properties.isLocal()); const bool showMoveToTrashAction = (properties.isLocal() && properties.supportsMoving()); @@ -421,14 +425,14 @@ void DolphinContextMenu::addShowMenuBarAction() } } -bool DolphinContextMenu::placeExists(const KUrl& url) const +bool DolphinContextMenu::placeExists(const QUrl& url) const { PlacesItemModel model; const int count = model.count(); for (int i = 0; i < count; ++i) { - const KUrl placeUrl = model.placesItem(i)->url(); - if (placeUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) { + const QUrl placeUrl = model.placesItem(i)->url(); + if (placeUrl.matches(url, QUrl::StripTrailingSlash)) { return true; } } @@ -441,9 +445,11 @@ QAction* DolphinContextMenu::createPasteAction() QAction* action = 0; const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir(); if (isDir && (m_selectedItems.count() == 1)) { - const QPair pasteInfo = KonqOperations::pasteInfo(m_fileInfo.url()); - action = new QAction(QIcon::fromTheme("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this); - action->setEnabled(pasteInfo.first); + const QMimeData *mimeData = QApplication::clipboard()->mimeData(); + bool canPaste; + const QString text = KIO::pasteActionText(mimeData, &canPaste, m_fileInfo); + action = new QAction(QIcon::fromTheme("edit-paste"), text, this); + action->setEnabled(canPaste); connect(action, &QAction::triggered, m_mainWindow, &DolphinMainWindow::pasteIntoFolder); } else { action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); @@ -463,7 +469,7 @@ KFileItemListProperties& DolphinContextMenu::selectedItemsProperties() const KFileItem DolphinContextMenu::baseFileItem() { if (!m_baseFileItem) { - m_baseFileItem = new KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_baseUrl); + m_baseFileItem = new KFileItem(m_baseUrl); } return *m_baseFileItem; } @@ -507,13 +513,6 @@ void DolphinContextMenu::addFileItemPluginActions() continue; } - // Old API (kdelibs-4.6.0 only) - KFileItemActionPlugin* plugin = service->createInstance(); - if (plugin) { - plugin->setParent(this); - addActions(plugin->actions(props, m_mainWindow)); - } - // New API (kdelibs >= 4.6.1) KAbstractFileItemActionPlugin* abstractPlugin = service->createInstance(); if (abstractPlugin) { abstractPlugin->setParent(this); @@ -527,17 +526,13 @@ void DolphinContextMenu::addVersionControlPluginActions() const DolphinView* view = m_mainWindow->activeViewContainer()->view(); const QList versionControlActions = view->versionControlActions(m_selectedItems); if (!versionControlActions.isEmpty()) { - foreach (QAction* action, versionControlActions) { - addAction(action); - } + addActions(versionControlActions); addSeparator(); } } void DolphinContextMenu::addCustomActions() { - foreach (QAction* action, m_customActions) { - addAction(action); - } + addActions(m_customActions); }