- let the "details view" show the "[x] Expandable Folders" action in the context menu
CCMAIL: faure@kde.org
svn path=/trunk/KDE/kdebase/apps/; revision=924867
m_fileInfo(fileInfo),
m_baseUrl(baseUrl),
m_context(NoContext),
- m_copyToMenu(parent)
+ m_copyToMenu(parent),
+ m_customActions()
{
// The context menu either accesses the URLs of the selected items
// or the items itself. To increase the performance both lists are cached.
m_capabilities = 0;
}
+void DolphinContextMenu::setCustomActions(const QList<QAction*>& actions)
+{
+ m_customActions = actions;
+}
+
void DolphinContextMenu::open()
{
// get the context information
QAction* addToPlacesAction = popup->addAction(KIcon("bookmark-new"),
i18nc("@action:inmenu Add current folder to places", "Add to Places"));
+ addCustomActions(popup);
+
QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
popup->addAction(propertiesAction);
KonqMenuActions menuActions;
menuActions.setPopupMenuInfo(popupInfo);
- // Insert 'Open With...' action or sub menu
+ // insert 'Open With...' action or sub menu
menuActions.addOpenWithActionsTo(popup, "DesktopEntryName != 'dolphin'");
- // Insert 'Actions' sub menu
+ // insert 'Actions' sub menu
if (menuActions.addActionsTo(popup)) {
popup->addSeparator();
}
- // Insert 'Copy To' and 'Move To' sub menus
+ // insert 'Copy To' and 'Move To' sub menus
if (DolphinSettings::instance().generalSettings()->showCopyMoveMenu()) {
m_copyToMenu.setItems(m_selectedItems);
m_copyToMenu.setReadOnly(!capabilities().supportsWriting());
QAction* addToPlacesAction = popup->addAction(KIcon("bookmark-new"),
i18nc("@action:inmenu Add current folder to places", "Add to Places"));
- popup->addSeparator();
+
+ addCustomActions(popup);
QAction* propertiesAction = popup->addAction(i18nc("@action:inmenu", "Properties"));
return *m_capabilities;
}
+void DolphinContextMenu::addCustomActions(KMenu* menu)
+{
+ foreach (QAction* action, m_customActions) {
+ menu->addAction(action);
+ }
+}
+
#include "dolphincontextmenu.moc"
virtual ~DolphinContextMenu();
+ void setCustomActions(const QList<QAction*>& actions);
+
/** Opens the context menu model. */
void open();
private:
KonqFileItemCapabilities& capabilities();
+ void addCustomActions(KMenu* menu);
private:
struct Entry
KUrl::List m_selectedUrls;
int m_context;
KonqCopyToMenu m_copyToMenu;
+ QList<QAction*> m_customActions;
};
#endif
}
}
-void DolphinController::triggerContextMenuRequest(const QPoint& pos)
+void DolphinController::triggerContextMenuRequest(const QPoint& pos,
+ const QList<QAction*>& customActions)
{
emit activated();
- emit requestContextMenu(pos);
+ emit requestContextMenu(pos, customActions);
}
void DolphinController::requestActivation()
* should be invoked by the view implementation when a context
* menu should be opened. The abstract Dolphin view itself
* takes care itself to get the selected items depending from
- * \a pos.
+ * \a pos. It is possible to define a custom list of actions for
+ * the context menu by \a customActions.
*/
- void triggerContextMenuRequest(const QPoint& pos);
+ void triggerContextMenuRequest(const QPoint& pos,
+ const QList<QAction*>& customActions = QList<QAction*>());
/**
* Requests an activation of the view and emits the signal
/**
* Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
* The abstract Dolphin view connects to this signal and will open the context menu.
- * @param pos Position relative to the view widget where the
- * context menu should be opened. It is recommended
- * to get the corresponding model index from
- * this position.
- */
- void requestContextMenu(const QPoint& pos);
+ * @param pos Position relative to the view widget where the
+ * context menu should be opened. It is recommended
+ * to get the corresponding model index from
+ * this position.
+ * @param customActions List of actions that is added to the context menu when
+ * the menu is opened above the viewport.
+ */
+ void requestContextMenu(const QPoint& pos, QList<QAction*> customActions);
/**
* Is emitted if the view has been activated by e. g. a mouse click.
m_controller(controller),
m_selectionManager(0),
m_autoScroller(0),
+ m_expandableFoldersAction(0),
m_font(),
m_decorationSize(),
m_band()
this, SLOT(slotGlobalSettingsChanged(int)));
m_useDefaultIndexAt = false;
+
+ m_expandableFoldersAction = new QAction(i18nc("@option:check", "Expandable Folders"), this);
+ m_expandableFoldersAction->setCheckable(true);
+ connect(m_expandableFoldersAction, SIGNAL(toggled(bool)),
+ this, SLOT(setFoldersExpandable(bool)));
}
DolphinDetailsView::~DolphinDetailsView()
void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
{
QTreeView::contextMenuEvent(event);
- m_controller->triggerContextMenuRequest(event->pos());
+
+ DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
+ m_expandableFoldersAction->setChecked(settings->expandableFolders());
+ m_controller->triggerContextMenuRequest(event->pos(),
+ QList<QAction*>() << m_expandableFoldersAction);
}
void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
}
popup.addSeparator();
- // add a checkbox item for the "Expandable Folders" setting
- DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
- QAction* expandableFoldersAction = popup.addAction(i18nc("@option:check", "Expandable Folders"));
- expandableFoldersAction->setCheckable(true);
- expandableFoldersAction->setChecked(settings->expandableFolders());
-
QAction* activatedAction = popup.exec(header()->mapToGlobal(pos));
- if (activatedAction == expandableFoldersAction) {
- const bool expand = expandableFoldersAction->isChecked();
- if (!expand) {
- // collapse all expanded folders, as QTreeView::setItemsExpandable(false)
- // does not do this task
- const int rowCount = model()->rowCount();
- for (int row = 0; row < rowCount; ++row) {
- setExpanded(model()->index(row, 0), false);
- }
- }
- settings->setExpandableFolders(expand);
- setRootIsDecorated(expand);
- setItemsExpandable(expand);
- } else if (activatedAction != 0) {
+ if (activatedAction != 0) {
const bool show = activatedAction->isChecked();
const int columnIndex = activatedAction->data().toInt();
m_band.ignoreOldInfo = false;
}
+void DolphinDetailsView::setFoldersExpandable(bool expandable)
+{
+ if (!expandable) {
+ // collapse all expanded folders, as QTreeView::setItemsExpandable(false)
+ // does not do this task
+ const int rowCount = model()->rowCount();
+ for (int row = 0; row < rowCount; ++row) {
+ setExpanded(model()->index(row, 0), false);
+ }
+ }
+ DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
+ settings->setExpandableFolders(expandable);
+ setRootIsDecorated(expandable);
+ setItemsExpandable(expandable);
+}
+
void DolphinDetailsView::updateDecorationSize(bool showPreview)
{
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
*/
void updateElasticBandSelection();
+ /**
+ * If \a expandable is true, the details view acts as tree view.
+ * The current expandable state is remembered in the settings.
+ */
+ void setFoldersExpandable(bool expandable);
+
private:
/**
* Updates the size of the decoration dependent on the
DolphinController* m_controller;
SelectionManager* m_selectionManager;
DolphinViewAutoScroller* m_autoScroller;
+ QAction* m_expandableFoldersAction;
QFont m_font;
QSize m_decorationSize;
this, SLOT(slotItemTriggered(KFileItem)));
connect(m_view, SIGNAL(tabRequested(KUrl)),
this, SLOT(createNewWindow(KUrl)));
- connect(m_view, SIGNAL(requestContextMenu(KFileItem,KUrl)),
- this, SLOT(slotOpenContextMenu(KFileItem,KUrl)));
+ connect(m_view, SIGNAL(requestContextMenu(KFileItem,KUrl,QList<QAction*>)),
+ this, SLOT(slotOpenContextMenu(KFileItem,KUrl,QList<QAction*>)));
connect(m_view, SIGNAL(selectionChanged(KFileItemList)),
m_extension, SIGNAL(selectionInfo(KFileItemList)));
connect(m_view, SIGNAL(selectionChanged(KFileItemList)),
emit m_extension->createNewWindow(url, args);
}
-void DolphinPart::slotOpenContextMenu(const KFileItem& _item, const KUrl&)
+void DolphinPart::slotOpenContextMenu(const KFileItem& _item,
+ const KUrl&,
+ const QList<QAction*>& customActions)
{
+ Q_UNUSED(customActions); // TODO: should be added to the context menu
+
KParts::BrowserExtension::PopupFlags popupFlags = KParts::BrowserExtension::DefaultPopupItems
| KParts::BrowserExtension::ShowProperties
| KParts::BrowserExtension::ShowUrlOperations;
void createNewWindow(const KUrl& url);
/**
* Opens the context menu on the current mouse position.
- * @item File item context. If item is 0, the context menu
- * should be applied to \a url.
- * @url URL which contains \a item.
- */
- void slotOpenContextMenu(const KFileItem& item, const KUrl& url);
+ * @item File item context. If item is null, the context menu
+ * should be applied to \a url.
+ * @url URL which contains \a item.
+ * @customActions Actions that should be added to the context menu,
+ * if the file item is null.
+ */
+ void slotOpenContextMenu(const KFileItem& item,
+ const KUrl& url,
+ const QList<QAction*>& customActions);
/**
* Asks the host to open the URL \a url if the current view has
connect(m_controller, SIGNAL(requestUrlChange(const KUrl&)),
this, SLOT(slotRequestUrlChange(const KUrl&)));
- connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
- this, SLOT(openContextMenu(const QPoint&)));
+ connect(m_controller, SIGNAL(requestContextMenu(const QPoint&, const QList<QAction*>&)),
+ this, SLOT(openContextMenu(const QPoint&, const QList<QAction*>&)));
connect(m_controller, SIGNAL(urlsDropped(const KFileItem&, const KUrl&, QDropEvent*)),
this, SLOT(dropUrls(const KFileItem&, const KUrl&, QDropEvent*)));
connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
emit selectionChanged(DolphinView::selectedItems());
}
-void DolphinView::openContextMenu(const QPoint& pos)
+void DolphinView::openContextMenu(const QPoint& pos,
+ const QList<QAction*>& customActions)
{
KFileItem item;
if (isColumnViewActive()) {
}
m_isContextMenuOpen = true; // TODO: workaround for Qt-issue 207192
- emit requestContextMenu(item, url());
+ emit requestContextMenu(item, url(), customActions);
m_isContextMenuOpen = false;
}
/**
* Is emitted if a context menu is requested for the item \a item,
- * which is part of \a url. If the item is 0, the context menu
- * for the URL should be shown.
+ * which is part of \a url. If the item is null, the context menu
+ * for the URL should be shown and the custom actions \a customActions
+ * will be added.
*/
- void requestContextMenu(const KFileItem& item, const KUrl& url);
+ void requestContextMenu(const KFileItem& item,
+ const KUrl& url,
+ const QList<QAction*>& customActions);
/**
* Is emitted if an information message with the content \a msg
* is used to check whether the context menu is related to an
* item or to the viewport.
*/
- void openContextMenu(const QPoint& pos);
+ void openContextMenu(const QPoint& pos, const QList<QAction*>& customActions);
/**
* Drops dragged URLs to the destination path \a destPath. If
void restoreCurrentItem();
/**
- * If \a view can be positively identified as not being the source for the
- * current drag operation, deleteLater() it immediately. Else stores
+ * If \a view can be positively identified as not being the source for the
+ * current drag operation, deleteLater() it immediately. Else stores
* it for later deletion.
*/
void deleteWhenNotDragSource(QAbstractItemView* view);
m_proxyModel);
connect(m_view, SIGNAL(urlChanged(const KUrl&)),
m_urlNavigator, SLOT(setUrl(const KUrl&)));
- connect(m_view, SIGNAL(requestContextMenu(KFileItem, const KUrl&)),
- this, SLOT(openContextMenu(KFileItem, const KUrl&)));
+ connect(m_view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
+ this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
connect(m_view, SIGNAL(contentsMoved(int, int)),
this, SLOT(saveContentsPos(int, int)));
connect(m_view, SIGNAL(requestItemInfo(KFileItem)),
}
void DolphinViewContainer::openContextMenu(const KFileItem& item,
- const KUrl& url)
+ const KUrl& url,
+ const QList<QAction*>& customActions)
{
DolphinContextMenu contextMenu(m_mainWindow, item, url);
+ contextMenu.setCustomActions(customActions);
contextMenu.open();
}
/**
* Opens the context menu on the current mouse position.
- * @item File item context. If item is 0, the context menu
- * should be applied to \a url.
- * @url URL which contains \a item.
+ * @item File item context. If item is null, the context menu
+ * should be applied to \a url.
+ * @url URL which contains \a item.
+ * @customActions Actions that should be added to the context menu,
+ * if the file item is null.
*/
- void openContextMenu(const KFileItem& item, const KUrl& url);
+ void openContextMenu(const KFileItem& item,
+ const KUrl& url,
+ const QList<QAction*>& customActions);
/**
* Saves the position of the contents to the