2020-08-25 17:07:38 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
#ifndef DOLPHINCONTEXTMENU_H
|
|
|
|
#define DOLPHINCONTEXTMENU_H
|
|
|
|
|
2015-02-04 07:56:17 +00:00
|
|
|
#include <KFileCopyToMenu>
|
2018-03-04 13:38:16 +00:00
|
|
|
#include <KFileItem>
|
2021-04-18 06:37:45 +00:00
|
|
|
#include <KFileItemActions>
|
2007-01-21 21:20:37 +00:00
|
|
|
|
2018-03-04 13:38:16 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QUrl>
|
2010-09-17 19:47:01 +00:00
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
class QAction;
|
|
|
|
class DolphinMainWindow;
|
2009-04-01 23:34:33 +00:00
|
|
|
class KFileItemListProperties;
|
2013-02-09 20:56:51 +00:00
|
|
|
class DolphinRemoveAction;
|
2006-11-21 06:02:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Represents the context menu which appears when doing a right
|
2007-03-15 22:42:21 +00:00
|
|
|
* click on an item or the viewport of the file manager.
|
2006-11-21 06:02:05 +00:00
|
|
|
*
|
|
|
|
* Beside static menu entries (e. g. 'Paste' or 'Properties') two
|
|
|
|
* dynamic sub menus are shown when opening a context menu above
|
|
|
|
* an item:
|
|
|
|
* - 'Open With': Contains all applications which are registered to
|
|
|
|
* open items of the given MIME type.
|
|
|
|
* - 'Actions': Contains all actions which can be applied to the
|
|
|
|
* given item.
|
|
|
|
*/
|
2014-10-10 21:36:36 +00:00
|
|
|
class DolphinContextMenu : public QMenu
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2007-03-17 20:42:26 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
public:
|
|
|
|
/**
|
2007-03-15 22:42:21 +00:00
|
|
|
* @parent Pointer to the main window the context menu
|
|
|
|
* belongs to.
|
|
|
|
* @fileInfo Pointer to the file item the context menu
|
|
|
|
* is applied. If 0 is passed, the context menu
|
|
|
|
* is above the viewport.
|
2022-04-02 17:00:58 +00:00
|
|
|
* @selectedItems The selected items for which the context menu
|
|
|
|
* is opened. This list generally includes \a fileInfo.
|
2007-03-15 22:42:21 +00:00
|
|
|
* @baseUrl Base URL of the viewport where the context menu
|
|
|
|
* should be opened.
|
2006-11-21 06:02:05 +00:00
|
|
|
*/
|
2007-03-15 22:42:21 +00:00
|
|
|
DolphinContextMenu(DolphinMainWindow* parent,
|
2007-08-13 21:57:20 +00:00
|
|
|
const KFileItem& fileInfo,
|
2022-04-02 17:00:58 +00:00
|
|
|
const KFileItemList &selectedItems,
|
2021-04-18 06:37:45 +00:00
|
|
|
const QUrl& baseUrl,
|
|
|
|
KFileItemActions *fileItemActions);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2017-11-20 22:25:06 +00:00
|
|
|
~DolphinContextMenu() override;
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
protected:
|
2021-06-18 13:12:54 +00:00
|
|
|
bool eventFilter(QObject* object, QEvent* event) override;
|
2010-09-20 19:52:40 +00:00
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
private:
|
2011-03-27 17:27:27 +00:00
|
|
|
/**
|
2022-04-02 17:00:58 +00:00
|
|
|
* Adds all the actions and menus to this menu based on all given information.
|
|
|
|
* This method calls the other helper methods for adding actions
|
|
|
|
* based on the context given in the constructor.
|
2011-03-27 17:27:27 +00:00
|
|
|
*/
|
2022-04-02 17:00:58 +00:00
|
|
|
void addAllActions();
|
|
|
|
|
|
|
|
void addTrashContextMenu();
|
|
|
|
void addTrashItemContextMenu();
|
|
|
|
void addItemContextMenu();
|
|
|
|
void addViewportContextMenu();
|
|
|
|
|
|
|
|
void insertDefaultItemActions(const KFileItemListProperties&);
|
2011-03-27 17:27:27 +00:00
|
|
|
|
2014-10-21 19:18:43 +00:00
|
|
|
bool placeExists(const QUrl& url) const;
|
2009-11-12 20:22:22 +00:00
|
|
|
|
2008-03-29 07:44:03 +00:00
|
|
|
QAction* createPasteAction();
|
|
|
|
|
2012-01-14 19:02:11 +00:00
|
|
|
KFileItemListProperties& selectedItemsProperties() const;
|
2010-10-25 13:45:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the file item for m_baseUrl.
|
|
|
|
*/
|
|
|
|
KFileItem baseFileItem();
|
|
|
|
|
|
|
|
/**
|
Move "Open" actions to the top of the context menu for files
Summary:
This patch moves the "Open", "Open With", and "Open in" items to the top of the context menu to reap the following benefits:
- Move the "Open" and "Open With" items closer to the top since they're commonly used items, and right now they're buried in the middle of the menu
- Group related functionality
- Consistency with other common platforms (macOS Finder and Windows Explorer both have these items at the top of the context menu)
For folders, the "Open With" entries are moved higher, but not all the way to the top, since the "open in New tab/folder" entries are more useful.
Test Plan:
Tested all menu items in the context menu for files, folders, and links; all still work.
Context menu for single file:
{F5806809}
Context menu for multiple files:
{F5806810}
Context menu for single folder:
{F5806811}
Context menu for multiple folders:
{F5806812}
Context menu for symlink to folder:
{F5806815}
Reviewers: #dolphin, #vdg, elvisangelaccio, abetts
Reviewed By: #dolphin, #vdg, elvisangelaccio, abetts
Subscribers: markg, abetts, elvisangelaccio
Differential Revision: https://phabricator.kde.org/D11884
2018-04-02 14:05:47 +00:00
|
|
|
* Adds "Open With" actions
|
2010-10-25 13:45:34 +00:00
|
|
|
*/
|
2021-04-18 06:37:45 +00:00
|
|
|
void addOpenWithActions();
|
2010-10-25 13:45:34 +00:00
|
|
|
|
2020-11-22 21:19:21 +00:00
|
|
|
/**
|
|
|
|
* Add services, custom actions, plugins and version control items to the menu
|
|
|
|
*/
|
2021-04-18 06:37:45 +00:00
|
|
|
void addAdditionalActions(const KFileItemListProperties &props);
|
2020-11-22 21:19:21 +00:00
|
|
|
|
2022-04-02 17:00:58 +00:00
|
|
|
private:
|
2007-04-09 19:12:54 +00:00
|
|
|
struct Entry
|
|
|
|
{
|
2006-11-21 06:02:05 +00:00
|
|
|
int type;
|
|
|
|
QString name;
|
|
|
|
QString filePath; // empty for separator
|
|
|
|
QString templatePath; // same as filePath for template
|
|
|
|
QString icon;
|
|
|
|
QString comment;
|
|
|
|
};
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2007-04-09 19:12:54 +00:00
|
|
|
enum ContextType
|
|
|
|
{
|
2007-03-15 21:24:41 +00:00
|
|
|
NoContext = 0,
|
|
|
|
ItemContext = 1,
|
2019-11-29 16:59:21 +00:00
|
|
|
TrashContext = 2,
|
|
|
|
TimelineContext = 4,
|
|
|
|
SearchContext = 8,
|
2007-03-15 21:24:41 +00:00
|
|
|
};
|
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
DolphinMainWindow* m_mainWindow;
|
2010-10-25 13:45:34 +00:00
|
|
|
|
2007-08-13 21:57:20 +00:00
|
|
|
KFileItem m_fileInfo;
|
2010-10-25 13:45:34 +00:00
|
|
|
|
2014-10-21 19:18:43 +00:00
|
|
|
QUrl m_baseUrl;
|
2010-10-25 13:45:34 +00:00
|
|
|
KFileItem* m_baseFileItem; /// File item for m_baseUrl
|
|
|
|
|
2007-10-02 19:03:03 +00:00
|
|
|
KFileItemList m_selectedItems;
|
2012-01-14 19:02:11 +00:00
|
|
|
mutable KFileItemListProperties* m_selectedItemsProperties;
|
2010-10-25 13:45:34 +00:00
|
|
|
|
2007-03-15 21:24:41 +00:00
|
|
|
int m_context;
|
2015-02-04 07:56:17 +00:00
|
|
|
KFileCopyToMenu m_copyToMenu;
|
2010-09-22 20:24:49 +00:00
|
|
|
|
2013-02-09 20:56:51 +00:00
|
|
|
DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
|
2021-04-18 06:37:45 +00:00
|
|
|
void addDirectoryItemContextMenu();
|
|
|
|
KFileItemActions *m_fileItemActions;
|
2019-11-29 16:59:21 +00:00
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|