┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Graham <[email protected]>2019-09-01 15:01:57 -0600
committerNate Graham <[email protected]>2019-09-01 15:04:45 -0600
commit7cad80b292ef4ff89db5d6da924e75db4624d711 (patch)
treec44436bcbdf964909e8341beac2a45cd02991e2c
parent3a7586907ed834fb3c09d47e047da305a25374a2 (diff)
Add "Add to Places" action to file menu
Summary: It's recommended that actions available in context menus be available in the main menu as well for discoverability's sake. This patch does so for the "Add to Places" action. The action is moved over to the main window, and accessed in the context menu via the actionCollection it lives in. BUG: 390757 FIXED-IN: 19.08.0 Test Plan: - Action still works - Action still appears in context menu when relevant - Action in the File menu only becomes enabled when only a single directory is selected or nothing is selected {F7143876} {F7143877} {F7143878} {F7143879} Reviewers: #dolphin, elvisangelaccio Reviewed By: #dolphin, elvisangelaccio Subscribers: elvisangelaccio, kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D22149
-rw-r--r--src/dolphincontextmenu.cpp36
-rw-r--r--src/dolphinmainwindow.cpp56
-rw-r--r--src/dolphinmainwindow.h7
-rw-r--r--src/dolphinui.rc4
4 files changed, 64 insertions, 39 deletions
diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp
index 1dfbe054d..7e6a45171 100644
--- a/src/dolphincontextmenu.cpp
+++ b/src/dolphincontextmenu.cpp
@@ -1,4 +1,4 @@
-/***************************************************************************
+ /***************************************************************************
* Copyright (C) 2006 by Peter Penz ([email protected]) and *
* Cvetoslav Ludmiloff *
* *
@@ -192,7 +192,6 @@ void DolphinContextMenu::openItemContextMenu()
QAction* openParentAction = nullptr;
QAction* openParentInNewWindowAction = nullptr;
QAction* openParentInNewTabAction = nullptr;
- QAction* addToPlacesAction = nullptr;
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
KFileItemActions fileItemActions;
@@ -210,9 +209,7 @@ void DolphinContextMenu::openItemContextMenu()
// insert 'Add to Places' entry
if (!placeExists(m_fileInfo.url())) {
- addToPlacesAction = addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")),
- i18nc("@action:inmenu Add selected folder to places",
- "Add to Places"));
+ addAction(m_mainWindow->actionCollection()->action(QStringLiteral("add_to_places")));
}
addSeparator();
@@ -314,14 +311,7 @@ void DolphinContextMenu::openItemContextMenu()
QAction* activatedAction = exec(m_pos);
if (activatedAction) {
- if (activatedAction == addToPlacesAction) {
- const QUrl selectedUrl(m_fileInfo.url());
- if (selectedUrl.isValid()) {
- PlacesItemModel model;
- const QString text = selectedUrl.fileName();
- model.createPlacesItem(text, selectedUrl, KIO::iconNameForUrl(selectedUrl));
- }
- } else if (activatedAction == openParentAction) {
+ if (activatedAction == openParentAction) {
m_command = OpenParentFolder;
} else if (activatedAction == openParentInNewWindowAction) {
m_command = OpenParentFolderInNewWindow;
@@ -365,10 +355,8 @@ void DolphinContextMenu::openViewportContextMenu()
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_tab")));
// Insert 'Add to Places' entry if exactly one item is selected
- 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"));
+ addAction(m_mainWindow->actionCollection()->action(QStringLiteral("add_to_places")));
}
addSeparator();
@@ -395,22 +383,6 @@ void DolphinContextMenu::openViewportContextMenu()
addAction(propertiesAction);
addShowMenuBarAction();
-
- QAction* action = exec(m_pos);
- if (addToPlacesAction && (action == addToPlacesAction)) {
- const DolphinViewContainer* container = m_mainWindow->activeViewContainer();
- const QUrl url = container->url();
- if (url.isValid()) {
- PlacesItemModel model;
- QString icon;
- if (container->isSearchModeEnabled()) {
- icon = QStringLiteral("folder-saved-search-symbolic");
- } else {
- icon = KIO::iconNameForUrl(url);
- }
- model.createPlacesItem(container->placesText(), url, icon);
- }
- }
}
void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties)
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 9368a9028..54098352e 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -32,6 +32,7 @@
#include "dolphintabpage.h"
#include "middleclickactioneventfilter.h"
#include "panels/folders/folderspanel.h"
+#include "panels/places/placesitemmodel.h"
#include "panels/places/placespanel.h"
#include "panels/information/informationpanel.h"
#include "panels/terminal/terminalpanel.h"
@@ -272,7 +273,7 @@ void DolphinMainWindow::changeUrl(const QUrl &url)
}
m_activeViewContainer->setUrl(url);
- updateEditActions();
+ updateFileAndEditActions();
updatePasteAction();
updateViewActions();
updateGoActions();
@@ -301,7 +302,7 @@ void DolphinMainWindow::slotEditableStateChanged(bool editable)
void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
{
- updateEditActions();
+ updateFileAndEditActions();
const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount();
@@ -352,6 +353,32 @@ void DolphinMainWindow::openNewActivatedTab()
m_tabWidget->openNewActivatedTab();
}
+void DolphinMainWindow::addToPlaces()
+{
+ QUrl url;
+ QString name;
+
+ // If nothing is selected, act on the current dir
+ if (m_activeViewContainer->view()->selectedItems().count() == 0) {
+ url = m_activeViewContainer->url();
+ name = m_activeViewContainer->placesText();
+ } else {
+ const auto dirToAdd = m_activeViewContainer->view()->selectedItems().first();
+ url = dirToAdd.url();
+ name = dirToAdd.name();
+ }
+ if (url.isValid()) {
+ PlacesItemModel model;
+ QString icon;
+ if (m_activeViewContainer->isSearchModeEnabled()) {
+ icon = QStringLiteral("folder-saved-search-symbolic");
+ } else {
+ icon = KIO::iconNameForUrl(url);
+ }
+ model.createPlacesItem(name, url, icon);
+ }
+}
+
void DolphinMainWindow::openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement)
{
m_tabWidget->openNewTab(url, QUrl(), tabPlacement);
@@ -1109,7 +1136,7 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
m_actionHandler->setCurrentView(viewContainer->view());
updateHistory();
- updateEditActions();
+ updateFileAndEditActions();
updatePasteAction();
updateViewActions();
updateGoActions();
@@ -1182,6 +1209,12 @@ void DolphinMainWindow::setupActions()
actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N});
connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
+ QAction* addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places"));
+ addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
+ addToPlaces->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder"
+ "to the Places panel."));
+ connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces);
+
QAction* closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
closeTab->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
@@ -1681,15 +1714,20 @@ void DolphinMainWindow::setupDockWidgets()
});
}
-void DolphinMainWindow::updateEditActions()
+
+void DolphinMainWindow::updateFileAndEditActions()
{
const KFileItemList list = m_activeViewContainer->view()->selectedItems();
+ const KActionCollection* col = actionCollection();
+ QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places"));
+
if (list.isEmpty()) {
stateChanged(QStringLiteral("has_no_selection"));
+
+ addToPlacesAction->setText(i18nc("@action:inmenu Add current folder to places", "Add '%1' to Places", m_activeViewContainer->placesText()));
} else {
stateChanged(QStringLiteral("has_selection"));
- KActionCollection* col = actionCollection();
QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
@@ -1697,6 +1735,14 @@ void DolphinMainWindow::updateEditActions()
QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
QAction* showTarget = col->action(QStringLiteral("show_target"));
+ if (list.length() == 1 && list.first().isDir()) {
+ addToPlacesAction->setEnabled(true);
+ addToPlacesAction->setText(i18nc("@action:inmenu Add current folder to places", "Add '%1' to Places", list.first().name()));
+ } else {
+ addToPlacesAction->setEnabled(false);
+ addToPlacesAction->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
+ }
+
KFileItemListProperties capabilities(list);
const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h
index 8453bfb36..253fc74d4 100644
--- a/src/dolphinmainwindow.h
+++ b/src/dolphinmainwindow.h
@@ -385,6 +385,11 @@ private slots:
void openNewActivatedTab();
/**
+ * Adds the current URL as an entry to the Places panel
+ */
+ void addToPlaces();
+
+ /**
* Opens a new tab in the background showing the URL \a url.
*/
void openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement);
@@ -515,7 +520,7 @@ private:
*/
void setupDockWidgets();
- void updateEditActions();
+ void updateFileAndEditActions();
void updateViewActions();
void updateGoActions();
diff --git a/src/dolphinui.rc b/src/dolphinui.rc
index 69663c471..754670a7e 100644
--- a/src/dolphinui.rc
+++ b/src/dolphinui.rc
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphin" version="24">
+<kpartgui name="dolphin" version="25">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
@@ -8,6 +8,8 @@
<Action name="file_close" />
<Action name="undo_close_tab" />
<Separator/>
+ <Action name="add_to_places" />
+ <Separator/>
<Action name="renamefile" />
<Action name="movetotrash" />
<Action name="deletefile" />