Do not show "Move To Trash" action in context menu for remote URLs.

BUG: 261762
REVIEW: 111206
FIXED-IN: 4.11
This commit is contained in:
Dawit Alemayehu 2013-06-24 01:11:16 -04:00
parent 60fb908ccb
commit e688a52e3c
3 changed files with 52 additions and 49 deletions

View file

@ -74,14 +74,13 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
m_context(NoContext),
m_copyToMenu(parent),
m_customActions(),
m_command(None)
m_command(None),
m_removeAction(0)
{
// The context menu either accesses the URLs of the selected items
// or the items itself. To increase the performance both lists are cached.
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
m_selectedItems = view->selectedItems();
m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
}
DolphinContextMenu::~DolphinContextMenu()
@ -126,7 +125,7 @@ DolphinContextMenu::Command DolphinContextMenu::open()
void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
{
if (ev->key() == Qt::Key_Shift) {
if (m_removeAction && ev->key() == Qt::Key_Shift) {
m_removeAction->update();
}
KMenu::keyPressEvent(ev);
@ -134,7 +133,7 @@ void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev)
{
if (ev->key() == Qt::Key_Shift) {
if (m_removeAction && ev->key() == Qt::Key_Shift) {
m_removeAction->update();
}
KMenu::keyReleaseEvent(ev);
@ -192,6 +191,8 @@ void DolphinContextMenu::openItemContextMenu()
QAction* openParentInNewWindowAction = 0;
QAction* openParentInNewTabAction = 0;
QAction* addToPlacesAction = 0;
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
if (m_selectedItems.count() == 1) {
if (m_fileInfo.isDir()) {
// setup 'Create New' menu
@ -200,7 +201,7 @@ void DolphinContextMenu::openItemContextMenu()
newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
newFileMenu->checkUpToDate();
newFileMenu->setPopupFiles(m_fileInfo.url());
newFileMenu->setEnabled(selectedItemsProperties().supportsWriting());
newFileMenu->setEnabled(selectedItemsProps.supportsWriting());
connect(newFileMenu, SIGNAL(fileCreated(KUrl)), newFileMenu, SLOT(deleteLater()));
connect(newFileMenu, SIGNAL(directoryCreated(KUrl)), newFileMenu, SLOT(deleteLater()));
@ -260,12 +261,12 @@ void DolphinContextMenu::openItemContextMenu()
}
}
insertDefaultItemActions();
insertDefaultItemActions(selectedItemsProps);
addSeparator();
KFileItemActions fileItemActions;
fileItemActions.setItemListProperties(selectedItemsProperties());
fileItemActions.setItemListProperties(selectedItemsProps);
addServiceActions(fileItemActions);
addFileItemPluginActions();
@ -275,7 +276,7 @@ void DolphinContextMenu::openItemContextMenu()
// insert 'Copy To' and 'Move To' sub menus
if (GeneralSettings::showCopyMoveMenu()) {
m_copyToMenu.setItems(m_selectedItems);
m_copyToMenu.setReadOnly(!selectedItemsProperties().supportsWriting());
m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting());
m_copyToMenu.addActionsTo(this);
}
@ -359,7 +360,7 @@ void DolphinContextMenu::openViewportContextMenu()
}
}
void DolphinContextMenu::insertDefaultItemActions()
void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties)
{
const KActionCollection* collection = m_mainWindow->actionCollection();
@ -375,12 +376,26 @@ void DolphinContextMenu::insertDefaultItemActions()
addAction(renameAction);
// Insert 'Move to Trash' and/or 'Delete'
if (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false)) {
addAction(collection->action("move_to_trash"));
addAction(collection->action("delete"));
} else {
addAction(m_removeAction);
m_removeAction->update();
if (properties.supportsDeleting()) {
const bool showDeleteAction = (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false) ||
!properties.isLocal());
const bool showMoveToTrashAction = (properties.isLocal() &&
properties.supportsMoving());
if (showDeleteAction && showMoveToTrashAction) {
delete m_removeAction;
m_removeAction = 0;
addAction(m_mainWindow->actionCollection()->action("move_to_trash"));
addAction(m_mainWindow->actionCollection()->action("delete"));
} else if (showDeleteAction && !showMoveToTrashAction) {
addAction(m_mainWindow->actionCollection()->action("delete"));
} else {
if (!m_removeAction) {
m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
}
addAction(m_removeAction);
m_removeAction->update();
}
}
}

View file

@ -101,7 +101,7 @@ private:
void openItemContextMenu();
void openViewportContextMenu();
void insertDefaultItemActions();
void insertDefaultItemActions(const KFileItemListProperties&);
/**
* Adds the "Show menubar" action to the menu if the

View file

@ -426,10 +426,27 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos,
editActions += customActions;
if (!_item.isNull()) { // only for context menu on one or more items
bool supportsDeleting = capabilities.supportsDeleting();
bool supportsMoving = capabilities.supportsMoving();
const bool supportsMoving = capabilities.supportsMoving();
if (!supportsDeleting) {
if (capabilities.supportsDeleting()) {
const bool showDeleteAction = (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false) ||
!item.isLocalFile());
const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
if (showDeleteAction && showMoveToTrashAction) {
delete m_removeAction;
m_removeAction = 0;
editActions.append(actionCollection()->action("move_to_trash"));
editActions.append(actionCollection()->action("delete"));
} else if (showDeleteAction && !showMoveToTrashAction) {
editActions.append(actionCollection()->action("delete"));
} else {
if (!m_removeAction)
m_removeAction = new DolphinRemoveAction(this, actionCollection());
editActions.append(m_removeAction);
m_removeAction->update();
}
} else {
popupFlags |= KParts::BrowserExtension::NoDeletion;
}
@ -437,35 +454,6 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos,
editActions.append(actionCollection()->action("rename"));
}
bool addTrash = capabilities.isLocal() && supportsMoving;
bool addDel = false;
if (supportsDeleting) {
if ( !item.isLocalFile() )
addDel = true;
else if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
addTrash = false;
addDel = true;
}
else {
KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
KConfigGroup configGroup(globalConfig, "KDE");
addDel = configGroup.readEntry("ShowDeleteCommand", false);
}
}
if (!addTrash || !addDel) {
if (!m_removeAction) {
m_removeAction = new DolphinRemoveAction(this, actionCollection());
}
editActions.append(m_removeAction);
m_removeAction->update();
} else {
delete m_removeAction;
m_removeAction = 0;
editActions.append(actionCollection()->action("move_to_trash"));
editActions.append(actionCollection()->action("delete"));
}
// Normally KonqPopupMenu only shows the "Create new" submenu in the current view
// since otherwise the created file would not be visible.
// But in treeview mode we should allow it.