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
-/***************************************************************************
+ /***************************************************************************
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
* Cvetoslav Ludmiloff *
* *
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and *
* Cvetoslav Ludmiloff *
* *
QAction* openParentAction = nullptr;
QAction* openParentInNewWindowAction = nullptr;
QAction* openParentInNewTabAction = nullptr;
QAction* openParentAction = nullptr;
QAction* openParentInNewWindowAction = nullptr;
QAction* openParentInNewTabAction = nullptr;
- QAction* addToPlacesAction = nullptr;
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
KFileItemActions fileItemActions;
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
KFileItemActions fileItemActions;
// insert 'Add to Places' entry
if (!placeExists(m_fileInfo.url())) {
// 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")));
QAction* activatedAction = exec(m_pos);
if (activatedAction) {
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;
m_command = OpenParentFolder;
} else if (activatedAction == openParentInNewWindowAction) {
m_command = OpenParentFolderInNewWindow;
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_tab")));
// Insert 'Add to Places' entry if exactly one item is selected
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())) {
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")));
addAction(propertiesAction);
addShowMenuBarAction();
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)
}
void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties)
#include "dolphintabpage.h"
#include "middleclickactioneventfilter.h"
#include "panels/folders/folderspanel.h"
#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"
#include "panels/places/placespanel.h"
#include "panels/information/informationpanel.h"
#include "panels/terminal/terminalpanel.h"
}
m_activeViewContainer->setUrl(url);
}
m_activeViewContainer->setUrl(url);
+ updateFileAndEditActions();
updatePasteAction();
updateViewActions();
updateGoActions();
updatePasteAction();
updateViewActions();
updateGoActions();
void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
{
void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
{
+ updateFileAndEditActions();
const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount();
const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount();
m_tabWidget->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);
void DolphinMainWindow::openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement)
{
m_tabWidget->openNewTab(url, QUrl(), tabPlacement);
m_actionHandler->setCurrentView(viewContainer->view());
updateHistory();
m_actionHandler->setCurrentView(viewContainer->view());
updateHistory();
+ updateFileAndEditActions();
updatePasteAction();
updateViewActions();
updateGoActions();
updatePasteAction();
updateViewActions();
updateGoActions();
actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N});
connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
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 "
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 "
-void DolphinMainWindow::updateEditActions()
+
+void DolphinMainWindow::updateFileAndEditActions()
{
const KFileItemList list = m_activeViewContainer->view()->selectedItems();
{
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"));
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"));
} 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));
QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
QAction* showTarget = col->action(QStringLiteral("show_target"));
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();
KFileItemListProperties capabilities(list);
const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
*/
void openNewActivatedTab();
*/
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.
*/
/**
* Opens a new tab in the background showing the URL \a url.
*/
*/
void setupDockWidgets();
*/
void setupDockWidgets();
- void updateEditActions();
+ void updateFileAndEditActions();
void updateViewActions();
void updateGoActions();
void updateViewActions();
void updateGoActions();
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphin" version="24">
+<kpartgui name="dolphin" version="25">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
<Action name="file_close" />
<Action name="undo_close_tab" />
<Separator/>
<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" />
<Action name="renamefile" />
<Action name="movetotrash" />
<Action name="deletefile" />