X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/6baba131b2e112c37015412b701bc3ea01a86c04..5413025f0b26e9b195d1117bb483fbfe42e8c8c8:/src/dolphincontextmenu.h diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h index 2a678d9a2..9ebdb1a56 100644 --- a/src/dolphincontextmenu.h +++ b/src/dolphincontextmenu.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2006 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -20,19 +20,17 @@ #ifndef DOLPHINCONTEXTMENU_H #define DOLPHINCONTEXTMENU_H -#include -#include -#include -#include +#include +#include -#include -#include -#include +#include +#include -class KMenu; -class KFileItem; class QAction; class DolphinMainWindow; +class KFileItemActions; +class KFileItemListProperties; +class DolphinRemoveAction; /** * @brief Represents the context menu which appears when doing a right @@ -46,58 +44,51 @@ class DolphinMainWindow; * - 'Actions': Contains all actions which can be applied to the * given item. */ -class DolphinContextMenu : public QObject +class DolphinContextMenu : public QMenu { Q_OBJECT public: - enum ViewType + enum Command { - ItemsView, - SidebarView + None, + OpenParentFolder, + OpenParentFolderInNewWindow, + OpenParentFolderInNewTab }; /** * @parent Pointer to the main window the context menu * belongs to. + * @pos Position in screen coordinates. * @fileInfo Pointer to the file item the context menu * is applied. If 0 is passed, the context menu * is above the viewport. * @baseUrl Base URL of the viewport where the context menu * should be opened. - * @viewType On which view type is the context menu shown. */ DolphinContextMenu(DolphinMainWindow* parent, - KFileItem* fileInfo, - const KUrl& baseUrl, - ViewType viewType = ItemsView); + const QPoint& pos, + const KFileItem& fileInfo, + const QUrl& baseUrl); - virtual ~DolphinContextMenu(); + ~DolphinContextMenu() override; - /** Opens the context menu modal. */ - void open(); + void setCustomActions(const QList& actions); -private slots: - /** Cuts the item m_fileInfo. */ - void cut(); - - /** Copies the item m_fileInfo. */ - void copy(); - - /** Paste the clipboard to m_fileInfo. */ - void paste(); - - /** Renames the item m_fileInfo. */ - void rename(); - - /** Moves the item m_fileInfo to the trash. */ - void moveToTrash(); - - /** Deletes the item m_fileInfo. */ - void deleteItem(); + /** + * Opens the context menu model and returns the requested + * command, that should be triggered by the caller. If + * Command::None has been returned, either the context-menu + * had been closed without executing an action or an + * already available action from the main-window has been + * executed. + */ + Command open(); - /** Shows the properties of the item m_fileInfo. */ - void showProperties(); +protected: + void keyPressEvent(QKeyEvent *ev) override; + void keyReleaseEvent(QKeyEvent *ev) override; private: void openTrashContextMenu(); @@ -105,40 +96,45 @@ private: void openItemContextMenu(); void openViewportContextMenu(); - void insertDefaultItemActions(KMenu* popup); + void insertDefaultItemActions(const KFileItemListProperties&); + + /** + * Adds the "Show menubar" action to the menu if the + * menubar is hidden. + */ + void addShowMenuBarAction(); + + bool placeExists(const QUrl& url) const; + + QAction* createPasteAction(); + + KFileItemListProperties& selectedItemsProperties() const; + + /** + * Returns the file item for m_baseUrl. + */ + KFileItem baseFileItem(); /** - * Inserts the 'Open With...' submenu to \a popup. - * @param popup Menu where the 'Open With...' sub menu should - * be added. - * @param openWithVector Output parameter which contains all 'Open with...' - * services. - * @return Identifier of the first 'Open With...' entry. - * All succeeding identifiers have an increased value of 1 - * to the predecessor. + * Adds actions that have been installed as service-menu. + * (see http://techbase.kde.org/index.php?title=Development/Tutorials/Creating_Konqueror_Service_Menus) */ - QList insertOpenWithItems(KMenu* popup, - QVector& openWithVector); + void addServiceActions(KFileItemActions& fileItemActions); /** - * Inserts the 'Actions...' submenu to \a popup. - * @param popup Menu where the 'Actions...' sub menu should - * be added. - * @param openWithVector Output parameter which contains all 'Actions...' - * services. + * Adds actions that are provided by a KVersionControlPlugin. */ - QList insertActionItems(KMenu* popup, - QVector& actionsVector); + void addVersionControlPluginActions(); /** - * Returns true, if 'menu' contains already - * an entry with the name 'entryName'. + * Adds custom actions e.g. like the "[x] Expandable Folders"-action + * provided in the details view. */ - bool containsEntry(const KMenu* menu, - const QString& entryName) const; + void addCustomActions(); private: - struct Entry { + struct Entry + { int type; QString name; QString filePath; // empty for separator @@ -147,19 +143,31 @@ private: QString comment; }; - enum ContextType { + enum ContextType + { NoContext = 0, ItemContext = 1, TrashContext = 2 }; + QPoint m_pos; DolphinMainWindow* m_mainWindow; - KFileItem* m_fileInfo; - KUrl m_baseUrl; + + KFileItem m_fileInfo; + + QUrl m_baseUrl; + KFileItem* m_baseFileItem; /// File item for m_baseUrl + KFileItemList m_selectedItems; - KUrl::List m_selectedUrls; - ViewType m_viewType; + mutable KFileItemListProperties* m_selectedItemsProperties; + int m_context; + KFileCopyToMenu m_copyToMenu; + QList m_customActions; + + Command m_command; + + DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete' }; #endif