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()
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);
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);
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
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()));
}
}
- insertDefaultItemActions();
+ insertDefaultItemActions(selectedItemsProps);
addSeparator();
KFileItemActions fileItemActions;
- fileItemActions.setItemListProperties(selectedItemsProperties());
+ fileItemActions.setItemListProperties(selectedItemsProps);
addServiceActions(fileItemActions);
addFileItemPluginActions();
// 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);
}
}
}
-void DolphinContextMenu::insertDefaultItemActions()
+void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties)
{
const KActionCollection* collection = m_mainWindow->actionCollection();
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();
+ }
}
}
editActions += customActions;
if (!_item.isNull()) { // only for context menu on one or more items
- bool supportsDeleting = capabilities.supportsDeleting();
- bool supportsMoving = capabilities.supportsMoving();
-
- if (!supportsDeleting) {
+ const bool supportsMoving = capabilities.supportsMoving();
+
+ 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;
}
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.