Refactoring to reduce size of openItemContextMenu and add the ContextType TimelineOrSearchContext

Reviewers: #dolphin, elvisangelaccio

Reviewed By: #dolphin, elvisangelaccio

Subscribers: kfm-devel

Tags: #dolphin

Differential Revision: https://phabricator.kde.org/D25615
This commit is contained in:
Méven Car 2019-11-29 17:59:21 +01:00
parent 89d53b98c7
commit 8b0c12a59c
2 changed files with 46 additions and 27 deletions

View file

@ -94,8 +94,13 @@ void DolphinContextMenu::setCustomActions(const QList<QAction*>& actions)
DolphinContextMenu::Command DolphinContextMenu::open()
{
// get the context information
if (m_baseUrl.scheme() == QLatin1String("trash")) {
const auto scheme = m_baseUrl.scheme();
if (scheme == QLatin1String("trash")) {
m_context |= TrashContext;
} else if (scheme == QLatin1String("search")) {
m_context |= SearchContext;
} else if (scheme == QLatin1String("timeline")) {
m_context |= TimelineContext;
}
if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) {
@ -183,22 +188,12 @@ void DolphinContextMenu::openTrashItemContextMenu()
}
}
void DolphinContextMenu::openItemContextMenu()
void DolphinContextMenu::addDirectoryItemContextMenu(KFileItemActions &fileItemActions)
{
Q_ASSERT(!m_fileInfo.isNull());
// insert 'Open in new window' and 'Open in new tab' entries
QAction* openParentAction = nullptr;
QAction* openParentInNewWindowAction = nullptr;
QAction* openParentInNewTabAction = nullptr;
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
KFileItemActions fileItemActions;
fileItemActions.setParentWidget(m_mainWindow);
fileItemActions.setItemListProperties(selectedItemsProps);
if (m_selectedItems.count() == 1) {
if (m_fileInfo.isDir()) {
// insert 'Open in new window' and 'Open in new tab' entries
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window")));
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab")));
@ -221,7 +216,26 @@ void DolphinContextMenu::openItemContextMenu()
addMenu(menu);
addSeparator();
} else if (m_baseUrl.scheme().contains(QLatin1String("search")) || m_baseUrl.scheme().contains(QLatin1String("timeline"))) {
}
void DolphinContextMenu::openItemContextMenu()
{
Q_ASSERT(!m_fileInfo.isNull());
QAction* openParentAction = nullptr;
QAction* openParentInNewWindowAction = nullptr;
QAction* openParentInNewTabAction = nullptr;
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
KFileItemActions fileItemActions;
fileItemActions.setParentWidget(m_mainWindow);
fileItemActions.setItemListProperties(selectedItemsProps);
if (m_selectedItems.count() == 1) {
// single files
if (m_fileInfo.isDir()) {
addDirectoryItemContextMenu(fileItemActions);
} else if (m_context & TimelineContext || m_context & SearchContext) {
addOpenWithActions(fileItemActions);
openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")),
@ -252,8 +266,9 @@ void DolphinContextMenu::openItemContextMenu()
addSeparator();
}
} else {
// multiple files
bool selectionHasOnlyDirs = true;
foreach (const KFileItem& item, m_selectedItems) {
for (const auto &item : qAsConst(m_selectedItems)) {
const QUrl& url = DolphinView::openItemAsFolderUrl(item);
if (url.isEmpty()) {
selectionHasOnlyDirs = false;

View file

@ -146,7 +146,9 @@ private:
{
NoContext = 0,
ItemContext = 1,
TrashContext = 2
TrashContext = 2,
TimelineContext = 4,
SearchContext = 8,
};
QPoint m_pos;
@ -167,6 +169,8 @@ private:
Command m_command;
DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
void addDirectoryItemContextMenu(KFileItemActions &fileItemActions);
};
#endif