#include "dolphinnewfilemenu.h"
#include "dolphinviewcontainer.h"
#include "dolphin_generalsettings.h"
+#include "dolphinremoveaction.h"
#include <KActionCollection>
#include <KDesktopFile>
#include <KFileItemListProperties>
#include <KGlobal>
#include <KIconLoader>
-#include <KIO/NetAccess>
+#include <KIO/RestoreJob>
+#include <KIO/EmptyTrashJob>
+#include <KIO/JobUiDelegate>
+#include <KJobUiDelegate>
+#include <KJobWidgets>
#include <KMenu>
#include <KMenuBar>
#include <KMessageBox>
#include <KMimeTypeTrader>
+#include <KMimeType>
#include <KNewFileMenu>
-#include <konqmimedata.h>
#include <konq_operations.h>
#include <KService>
#include <KLocale>
#include <KPropertiesDialog>
#include <KStandardAction>
-#include <KStandardDirs>
#include <KToolBar>
#include <panels/places/placesitem.h>
m_copyToMenu(parent),
m_customActions(),
m_command(None),
- m_shiftPressed(qApp->keyboardModifiers() & Qt::ShiftModifier),
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 QAction(this);
- connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemoveActionTriggered()));
}
DolphinContextMenu::~DolphinContextMenu()
void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
{
- if (ev->key() == Qt::Key_Shift) {
- m_shiftPressed = true;
- updateRemoveAction();
+ 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) {
- // not just "m_shiftPressed = false", the user could be playing with both Shift keys...
- m_shiftPressed = qApp->keyboardModifiers() & Qt::ShiftModifier;
- updateRemoveAction();
+ if (m_removeAction && ev->key() == Qt::Key_Shift) {
+ m_removeAction->update();
}
KMenu::keyReleaseEvent(ev);
}
-void DolphinContextMenu::slotRemoveActionTriggered()
-{
- const KActionCollection* collection = m_mainWindow->actionCollection();
- if (moveToTrash()) {
- collection->action("move_to_trash")->trigger();
- } else {
- collection->action("delete")->trigger();
- }
-}
-
void DolphinContextMenu::openTrashContextMenu()
{
Q_ASSERT(m_context & TrashContext);
- QAction* emptyTrashAction = new QAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), this);
+ QAction* emptyTrashAction = new QAction(QIcon::fromTheme("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), this);
KConfig trashConfig("trashrc", KConfig::SimpleConfig);
emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true));
addAction(emptyTrashAction);
addShowMenuBarAction();
if (exec(m_pos) == emptyTrashAction) {
- KonqOperations::emptyTrash(m_mainWindow);
+ KIO::JobUiDelegate uiDelegate;
+ uiDelegate.setWindow(m_mainWindow);
+ if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) {
+ KIO::Job* job = KIO::emptyTrash();
+ KJobWidgets::setWindow(job, m_mainWindow);
+ job->ui()->setAutoErrorHandlingEnabled(true);
+ }
}
}
selectedUrls.append(item.url());
}
- KonqOperations::restoreTrashedItems(selectedUrls, m_mainWindow);
+ KIO::RestoreJob *job = KIO::restoreFromTrash(selectedUrls);
+ KJobWidgets::setWindow(job, m_mainWindow);
+ job->uiDelegate()->setAutoErrorHandlingEnabled(true);
}
}
{
Q_ASSERT(!m_fileInfo.isNull());
+ QAction* openParentAction = 0;
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
- DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow);
+ DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow);
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
newFileMenu->checkUpToDate();
newFileMenu->setPopupFiles(m_fileInfo.url());
- newFileMenu->setEnabled(selectedItemsProperties().supportsWriting());
- connect(newFileMenu, SIGNAL(fileCreated(KUrl)), newFileMenu, SLOT(deleteLater()));
- connect(newFileMenu, SIGNAL(directoryCreated(KUrl)), newFileMenu, SLOT(deleteLater()));
+ newFileMenu->setEnabled(selectedItemsProps.supportsWriting());
+ connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
+ connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
- KMenu* menu = newFileMenu->menu();
+ QMenu* menu = newFileMenu->menu();
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
- menu->setIcon(KIcon("document-new"));
+ menu->setIcon(QIcon::fromTheme("document-new"));
addMenu(menu);
addSeparator();
// insert 'Add to Places' entry
if (!placeExists(m_fileInfo.url())) {
- addToPlacesAction = addAction(KIcon("bookmark-new"),
+ addToPlacesAction = addAction(QIcon::fromTheme("bookmark-new"),
i18nc("@action:inmenu Add selected folder to places",
"Add to Places"));
}
addSeparator();
- } else if (m_baseUrl.protocol().contains("search")) {
- openParentInNewWindowAction = new QAction(KIcon("window-new"),
+ } else if (m_baseUrl.protocol().contains("search") || m_baseUrl.protocol().contains("timeline")) {
+ openParentAction = new QAction(QIcon::fromTheme("document-open-folder"),
+ i18nc("@action:inmenu",
+ "Open Path"),
+ this);
+ addAction(openParentAction);
+
+ openParentInNewWindowAction = new QAction(QIcon::fromTheme("window-new"),
i18nc("@action:inmenu",
"Open Path in New Window"),
this);
addAction(openParentInNewWindowAction);
- openParentInNewTabAction = new QAction(KIcon("tab-new"),
+ openParentInNewTabAction = new QAction(QIcon::fromTheme("tab-new"),
i18nc("@action:inmenu",
"Open Path in New Tab"),
this);
addAction(openParentInNewTabAction);
+ addSeparator();
+ } else if (!DolphinView::openItemAsFolderUrl(m_fileInfo).isEmpty()) {
+ // insert 'Open in new window' and 'Open in new tab' entries
+ addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
+ addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
+
+ addSeparator();
+ }
+ } else {
+ bool selectionHasOnlyDirs = true;
+ foreach (const KFileItem& item, m_selectedItems) {
+ const KUrl& url = DolphinView::openItemAsFolderUrl(item);
+ if (url.isEmpty()) {
+ selectionHasOnlyDirs = false;
+ break;
+ }
+ }
+
+ if (selectionHasOnlyDirs) {
+ // insert 'Open in new tab' entry
+ addAction(m_mainWindow->actionCollection()->action("open_in_new_tabs"));
addSeparator();
}
}
- 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);
}
PlacesItem* item = model.createPlacesItem(text, selectedUrl);
model.appendItemToGroup(item);
}
+ } else if (activatedAction == openParentAction) {
+ m_command = OpenParentFolder;
} else if (activatedAction == openParentInNewWindowAction) {
m_command = OpenParentFolderInNewWindow;
} else if (activatedAction == openParentInNewTabAction) {
// Insert 'Add to Places' entry if exactly one item is selected
QAction* addToPlacesAction = 0;
if (!placeExists(m_mainWindow->activeViewContainer()->url())) {
- addToPlacesAction = addAction(KIcon("bookmark-new"),
+ addToPlacesAction = addAction(QIcon::fromTheme("bookmark-new"),
i18nc("@action:inmenu Add current folder to places", "Add to Places"));
}
}
}
-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);
- updateRemoveAction();
+ 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();
+ }
}
}
QAction* action = 0;
const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir();
if (isDir && (m_selectedItems.count() == 1)) {
- action = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this);
- const QMimeData* mimeData = QApplication::clipboard()->mimeData();
- const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
- action->setEnabled(!pasteData.isEmpty() && selectedItemsProperties().supportsWriting());
- connect(action, SIGNAL(triggered()), m_mainWindow, SLOT(pasteIntoFolder()));
+ const QPair<bool, QString> pasteInfo = KonqOperations::pasteInfo(m_fileInfo.url());
+ action = new QAction(QIcon::fromTheme("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this);
+ action->setEnabled(pasteInfo.first);
+ connect(action, &QAction::triggered, m_mainWindow, &DolphinMainWindow::pasteIntoFolder);
} else {
action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
}
const KConfig config("kservicemenurc", KConfig::NoGlobals);
const KConfigGroup showGroup = config.group("Show");
- foreach (const KSharedPtr<KService>& service, pluginServices) {
+ foreach (const KService::Ptr& service, pluginServices) {
if (!showGroup.readEntry(service->desktopEntryName(), true)) {
// The plugin has been disabled
continue;
}
}
-void DolphinContextMenu::updateRemoveAction()
-{
- const KActionCollection* collection = m_mainWindow->actionCollection();
-
- // Using m_removeAction->setText(action->text()) does not apply the &-shortcut.
- // This is only done until the original action has been shown at least once. To
- // bypass this issue, the text and &-shortcut is applied manually.
- const QAction* action = 0;
- if (moveToTrash()) {
- action = collection->action("move_to_trash");
- m_removeAction->setText(i18nc("@action:inmenu", "&Move to Trash"));
- } else {
- action = collection->action("delete");
- m_removeAction->setText(i18nc("@action:inmenu", "&Delete"));
- }
- m_removeAction->setIcon(action->icon());
- m_removeAction->setShortcuts(action->shortcuts());
-}
-
-bool DolphinContextMenu::moveToTrash() const
-{
- return !m_shiftPressed;
-}
-
-#include "dolphincontextmenu.moc"