X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f9bbbd82f43c40971f20a463ad63706ef6f91170..1859d6455daaa8163fd451e26ffd34cc86738464:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index b4d249d76..bedc835c2 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -20,43 +20,41 @@ #include "dolphincontextmenu.h" +#include "dolphin_generalsettings.h" #include "dolphinmainwindow.h" #include "dolphinnewfilemenu.h" -#include "dolphinviewcontainer.h" -#include "dolphin_generalsettings.h" #include "dolphinremoveaction.h" +#include "dolphinviewcontainer.h" +#include "panels/places/placesitem.h" +#include "panels/places/placesitemmodel.h" +#include "trash/dolphintrash.h" +#include "views/dolphinview.h" +#include "views/viewmodecontroller.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 "views/dolphinview.h" -#include "views/viewmodecontroller.h" - DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const QPoint& pos, const KFileItem& fileInfo, @@ -66,14 +64,14 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, m_mainWindow(parent), m_fileInfo(fileInfo), m_baseUrl(baseUrl), - m_baseFileItem(0), + m_baseFileItem(nullptr), m_selectedItems(), - m_selectedItemsProperties(0), + m_selectedItemsProperties(nullptr), m_context(NoContext), m_copyToMenu(parent), m_customActions(), m_command(None), - m_removeAction(0) + m_removeAction(nullptr) { // The context menu either accesses the URLs of the selected items // or the items itself. To increase the performance both lists are cached. @@ -84,7 +82,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, DolphinContextMenu::~DolphinContextMenu() { delete m_selectedItemsProperties; - m_selectedItemsProperties = 0; + m_selectedItemsProperties = nullptr; } void DolphinContextMenu::setCustomActions(const QList& actions) @@ -142,8 +140,7 @@ void DolphinContextMenu::openTrashContextMenu() Q_ASSERT(m_context & TrashContext); QAction* emptyTrashAction = new QAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"), this); - KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); - emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); + emptyTrashAction->setEnabled(!Trash::isEmpty()); addAction(emptyTrashAction); addCustomActions(); @@ -154,13 +151,7 @@ void DolphinContextMenu::openTrashContextMenu() addShowMenuBarAction(); if (exec(m_pos) == emptyTrashAction) { - KIO::JobUiDelegate uiDelegate; - uiDelegate.setWindow(m_mainWindow); - if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { - KIO::Job* job = KIO::emptyTrash(); - KJobWidgets::setWindow(job, m_mainWindow); - job->uiDelegate()->setAutoErrorHandlingEnabled(true); - } + Trash::empty(m_mainWindow); } } @@ -195,13 +186,17 @@ void DolphinContextMenu::openItemContextMenu() { Q_ASSERT(!m_fileInfo.isNull()); - QAction* openParentAction = 0; - QAction* openParentInNewWindowAction = 0; - QAction* openParentInNewTabAction = 0; - QAction* addToPlacesAction = 0; + QAction* openParentAction = nullptr; + QAction* openParentInNewWindowAction = nullptr; + QAction* openParentInNewTabAction = nullptr; + QAction* addToPlacesAction = nullptr; const KFileItemListProperties& selectedItemsProps = selectedItemsProperties(); if (m_selectedItems.count() == 1) { + if (m_fileInfo.isLink()) { + addAction(m_mainWindow->actionCollection()->action(QStringLiteral("show_target"))); + addSeparator(); + } if (m_fileInfo.isDir()) { // setup 'Create New' menu DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow); @@ -306,9 +301,7 @@ void DolphinContextMenu::openItemContextMenu() if (selectedUrl.isValid()) { PlacesItemModel model; const QString text = selectedUrl.fileName(); - PlacesItem* item = model.createPlacesItem(text, selectedUrl, KIO::iconNameForUrl(selectedUrl)); - model.appendItemToGroup(item); - model.saveBookmarks(); + model.createPlacesItem(text, selectedUrl, KIO::iconNameForUrl(selectedUrl)); } } else if (activatedAction == openParentAction) { m_command = OpenParentFolder; @@ -337,7 +330,7 @@ void DolphinContextMenu::openViewportContextMenu() addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_tab"))); // Insert 'Add to Places' entry if exactly one item is selected - QAction* addToPlacesAction = 0; + QAction* addToPlacesAction = nullptr; if (!placeExists(m_mainWindow->activeViewContainer()->url())) { addToPlacesAction = addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), i18nc("@action:inmenu Add current folder to places", "Add to Places")); @@ -369,13 +362,16 @@ void DolphinContextMenu::openViewportContextMenu() QAction* action = exec(m_pos); if (addToPlacesAction && (action == addToPlacesAction)) { const DolphinViewContainer* container = m_mainWindow->activeViewContainer(); - if (container->url().isValid()) { + const QUrl url = container->url(); + if (url.isValid()) { PlacesItemModel model; - PlacesItem* item = model.createPlacesItem(container->placesText(), - container->url(), - KIO::iconNameForUrl(container->url())); - model.appendItemToGroup(item); - model.saveBookmarks(); + QString icon; + if (container->isSearchModeEnabled()) { + icon = QStringLiteral("folder-saved-search-symbolic"); + } else { + icon = KIO::iconNameForUrl(url); + } + model.createPlacesItem(container->placesText(), url, icon); } } } @@ -403,7 +399,7 @@ void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& if (showDeleteAction && showMoveToTrashAction) { delete m_removeAction; - m_removeAction = 0; + 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) { @@ -430,6 +426,7 @@ void DolphinContextMenu::addShowMenuBarAction() bool DolphinContextMenu::placeExists(const QUrl& url) const { + Q_UNUSED(url) // Creating up a PlacesItemModel to find out if 'url' is one of the Places // can be expensive because the model asks Solid for the devices which are // available, which can take some time. @@ -440,7 +437,7 @@ bool DolphinContextMenu::placeExists(const QUrl& url) const QAction* DolphinContextMenu::createPasteAction() { - QAction* action = 0; + QAction* action = nullptr; const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir(); if (isDir && (m_selectedItems.count() == 1)) { const QMimeData *mimeData = QApplication::clipboard()->mimeData(); @@ -477,7 +474,7 @@ void DolphinContextMenu::addServiceActions(KFileItemActions& fileItemActions) fileItemActions.setParentWidget(m_mainWindow); // insert 'Open With...' action or sub menu - fileItemActions.addOpenWithActionsTo(this, QStringLiteral("DesktopEntryName != 'dolphin'")); + fileItemActions.addOpenWithActionsTo(this, QStringLiteral("DesktopEntryName != '%1'").arg(qApp->desktopFileName())); // insert 'Actions' sub menu fileItemActions.addServiceActionsTo(this);