mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-28 03:21:56 +00:00
Let's keep it simple: only offer a basic context menu for the treeview sidebar.
svn path=/trunk/KDE/kdebase/apps/; revision=642982
This commit is contained in:
parent
1cdb64a12b
commit
9ed13b31b4
|
@ -48,21 +48,23 @@
|
||||||
DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
|
DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
|
||||||
KFileItem* fileInfo,
|
KFileItem* fileInfo,
|
||||||
const KUrl& baseUrl,
|
const KUrl& baseUrl,
|
||||||
KFileItemList selectedItems) :
|
ViewType viewType) :
|
||||||
m_mainWindow(parent),
|
m_mainWindow(parent),
|
||||||
m_fileInfo(fileInfo),
|
m_fileInfo(fileInfo),
|
||||||
m_baseUrl(baseUrl),
|
m_baseUrl(baseUrl),
|
||||||
m_selectedItems(selectedItems),
|
m_viewType(viewType),
|
||||||
m_context(NoContext)
|
m_context(NoContext)
|
||||||
{
|
{
|
||||||
// The context menu either accesses the URLs of the selected items
|
if (viewType == ItemsView) {
|
||||||
// or the items itself. To increase the performance the URLs are cached.
|
// The context menu either accesses the URLs of the selected items
|
||||||
KFileItemList::const_iterator it = selectedItems.begin();
|
// or the items itself. To increase the performance both lists are cached.
|
||||||
const KFileItemList::const_iterator end = selectedItems.end();
|
DolphinView* view = m_mainWindow->activeView();
|
||||||
while (it != end) {
|
m_selectedUrls = view->selectedUrls();
|
||||||
KFileItem* item = *it;
|
m_selectedItems = view->selectedItems();
|
||||||
m_selectedUrls.append(item->url());
|
}
|
||||||
++it;
|
else if (fileInfo != 0) {
|
||||||
|
m_selectedUrls.append(fileInfo->url());
|
||||||
|
m_selectedItems.append(fileInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,12 +159,16 @@ void DolphinContextMenu::openItemContextMenu()
|
||||||
Q_ASSERT(m_fileInfo != 0);
|
Q_ASSERT(m_fileInfo != 0);
|
||||||
|
|
||||||
KMenu* popup = new KMenu(m_mainWindow);
|
KMenu* popup = new KMenu(m_mainWindow);
|
||||||
insertDefaultItemActions(popup);
|
if (m_viewType == ItemsView) {
|
||||||
|
insertDefaultItemActions(popup);
|
||||||
|
}
|
||||||
|
|
||||||
|
popup->addSeparator();
|
||||||
|
|
||||||
// insert 'Bookmark this folder' entry if exactly one item is selected
|
// insert 'Bookmark this folder' entry if exactly one item is selected
|
||||||
QAction* bookmarkAction = 0;
|
QAction* bookmarkAction = 0;
|
||||||
if (m_fileInfo->isDir() && (m_selectedUrls.count() == 1)) {
|
if (m_fileInfo->isDir() && (m_selectedUrls.count() == 1)) {
|
||||||
bookmarkAction = popup->addAction(KIcon("bookmark-folder"), i18n("Bookmark this folder"));
|
bookmarkAction = popup->addAction(KIcon("bookmark-folder"), i18n("Bookmark folder"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert 'Open With...' sub menu
|
// Insert 'Open With...' sub menu
|
||||||
|
@ -174,9 +180,11 @@ void DolphinContextMenu::openItemContextMenu()
|
||||||
const QList<QAction*> serviceActions = insertActionItems(popup, actionsVector);
|
const QList<QAction*> serviceActions = insertActionItems(popup, actionsVector);
|
||||||
popup->addSeparator();
|
popup->addSeparator();
|
||||||
|
|
||||||
// insert 'Properties...' entry
|
if (m_viewType == ItemsView) {
|
||||||
QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
|
// insert 'Properties...' entry
|
||||||
popup->addAction(propertiesAction);
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
|
||||||
|
popup->addAction(propertiesAction);
|
||||||
|
}
|
||||||
|
|
||||||
QAction* activatedAction = popup->exec(QCursor::pos());
|
QAction* activatedAction = popup->exec(QCursor::pos());
|
||||||
|
|
||||||
|
@ -277,19 +285,12 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
|
||||||
Q_ASSERT(popup != 0);
|
Q_ASSERT(popup != 0);
|
||||||
|
|
||||||
// insert 'Cut', 'Copy' and 'Paste'
|
// insert 'Cut', 'Copy' and 'Paste'
|
||||||
const KStandardAction::StandardAction actionNames[] = {
|
QAction* cutAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Cut));
|
||||||
KStandardAction::Cut,
|
QAction* copyAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Copy));
|
||||||
KStandardAction::Copy,
|
QAction* pasteAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
|
||||||
KStandardAction::Paste
|
popup->addAction(cutAction);
|
||||||
};
|
popup->addAction(copyAction);
|
||||||
|
popup->addAction(pasteAction);
|
||||||
const int count = sizeof(actionNames) / sizeof(KStandardAction::StandardAction);
|
|
||||||
for (int i = 0; i < count; ++i) {
|
|
||||||
QAction* action = m_mainWindow->actionCollection()->action(KStandardAction::stdName(actionNames[i]));
|
|
||||||
if (action != 0) {
|
|
||||||
popup->addAction(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
popup->addSeparator();
|
popup->addSeparator();
|
||||||
|
|
||||||
// insert 'Rename'
|
// insert 'Rename'
|
||||||
|
@ -354,7 +355,7 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
|
||||||
const QString appName((*it)->name());
|
const QString appName((*it)->name());
|
||||||
if (!containsEntry(openWithMenu, appName)) {
|
if (!containsEntry(openWithMenu, appName)) {
|
||||||
const KIcon icon((*it)->icon());
|
const KIcon icon((*it)->icon());
|
||||||
QAction *action = openWithMenu->addAction(icon, appName);
|
QAction* action = openWithMenu->addAction(icon, appName);
|
||||||
openWithVector.append(*it);
|
openWithVector.append(*it);
|
||||||
openWithActions << action;
|
openWithActions << action;
|
||||||
}
|
}
|
||||||
|
@ -364,7 +365,6 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
|
||||||
QAction* action = openWithMenu->addAction(i18n("&Other..."));
|
QAction* action = openWithMenu->addAction(i18n("&Other..."));
|
||||||
|
|
||||||
openWithActions << action;
|
openWithActions << action;
|
||||||
popup->addSeparator();
|
|
||||||
popup->addMenu(openWithMenu);
|
popup->addMenu(openWithMenu);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -378,7 +378,6 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
|
||||||
else {
|
else {
|
||||||
// At least one of the selected items has a different MIME type. In this case
|
// At least one of the selected items has a different MIME type. In this case
|
||||||
// just show a disabled "Open With..." entry.
|
// just show a disabled "Open With..." entry.
|
||||||
popup->addSeparator();
|
|
||||||
QAction* action = popup->addAction(i18n("Open With..."));
|
QAction* action = popup->addAction(i18n("Open With..."));
|
||||||
action->setEnabled(false);
|
action->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,12 @@ class DolphinMainWindow;
|
||||||
class DolphinContextMenu
|
class DolphinContextMenu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum ViewType
|
||||||
|
{
|
||||||
|
ItemsView,
|
||||||
|
SidebarView
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parent Pointer to the main window the context menu
|
* @parent Pointer to the main window the context menu
|
||||||
* belongs to.
|
* belongs to.
|
||||||
|
@ -56,13 +62,12 @@ public:
|
||||||
* is above the viewport.
|
* is above the viewport.
|
||||||
* @baseUrl Base URL of the viewport where the context menu
|
* @baseUrl Base URL of the viewport where the context menu
|
||||||
* should be opened.
|
* should be opened.
|
||||||
* @selectedItems Selected items where the actions of the context menu
|
* @viewType On which view type is the context menu shown.
|
||||||
* are applied.
|
|
||||||
*/
|
*/
|
||||||
DolphinContextMenu(DolphinMainWindow* parent,
|
DolphinContextMenu(DolphinMainWindow* parent,
|
||||||
KFileItem* fileInfo,
|
KFileItem* fileInfo,
|
||||||
const KUrl& baseUrl,
|
const KUrl& baseUrl,
|
||||||
KFileItemList selectedItems);
|
ViewType viewType = ItemsView);
|
||||||
|
|
||||||
virtual ~DolphinContextMenu();
|
virtual ~DolphinContextMenu();
|
||||||
|
|
||||||
|
@ -128,6 +133,7 @@ private:
|
||||||
KUrl m_baseUrl;
|
KUrl m_baseUrl;
|
||||||
KFileItemList m_selectedItems;
|
KFileItemList m_selectedItems;
|
||||||
KUrl::List m_selectedUrls;
|
KUrl::List m_selectedUrls;
|
||||||
|
ViewType m_viewType;
|
||||||
int m_context;
|
int m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -973,10 +973,7 @@ void DolphinView::openContextMenu(const QPoint& pos)
|
||||||
item = fileItem(index);
|
item = fileItem(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
DolphinContextMenu contextMenu(m_mainWindow,
|
DolphinContextMenu contextMenu(m_mainWindow, item, url());
|
||||||
item,
|
|
||||||
url(),
|
|
||||||
selectedItems());
|
|
||||||
contextMenu.open();
|
contextMenu.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,12 +108,6 @@ void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
|
||||||
{
|
{
|
||||||
SidebarPage::contextMenuEvent(event);
|
SidebarPage::contextMenuEvent(event);
|
||||||
|
|
||||||
// TODO: temporary deactivate the following code, as the wrong
|
|
||||||
// selection of cut/copy/paste actions is very confusing:
|
|
||||||
return;
|
|
||||||
|
|
||||||
KFileItem* item = 0;
|
|
||||||
|
|
||||||
const QModelIndex index = m_treeView->indexAt(event->pos());
|
const QModelIndex index = m_treeView->indexAt(event->pos());
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
// only open a context menu above a directory item
|
// only open a context menu above a directory item
|
||||||
|
@ -122,35 +116,15 @@ void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
|
||||||
|
|
||||||
#if defined(USE_PROXY_MODEL)
|
#if defined(USE_PROXY_MODEL)
|
||||||
const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
|
const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
|
||||||
item = m_dirModel->itemForIndex(dirModelIndex);
|
KFileItem* item = m_dirModel->itemForIndex(dirModelIndex);
|
||||||
#else
|
#else
|
||||||
item = m_dirModel->itemForIndex(index);
|
KFileItem* item = m_dirModel->itemForIndex(index);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_PROXY_MODEL)
|
|
||||||
const QItemSelection selection = m_proxyModel->mapSelectionToSource(
|
|
||||||
m_treeView->selectionModel()->selection());
|
|
||||||
#else
|
|
||||||
const QItemSelection selection = m_treeView->selectionModel()->selection();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
KFileItemList selectedItems;
|
|
||||||
|
|
||||||
const QModelIndexList indexList = selection.indexes();
|
|
||||||
QModelIndexList::const_iterator end = indexList.end();
|
|
||||||
for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
|
|
||||||
Q_ASSERT((*it).isValid());
|
|
||||||
|
|
||||||
KFileItem* item = m_dirModel->itemForIndex(*it);
|
|
||||||
if (item != 0) {
|
|
||||||
selectedItems.append(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DolphinContextMenu contextMenu(mainWindow(),
|
DolphinContextMenu contextMenu(mainWindow(),
|
||||||
item,
|
item,
|
||||||
m_dirLister->url(),
|
m_dirLister->url(),
|
||||||
selectedItems);
|
DolphinContextMenu::SidebarView);
|
||||||
contextMenu.open();
|
contextMenu.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue