#include "dolphincontextmenu.h"
#include "dolphinmainwindow.h"
+#include "dolphinnewmenu.h"
#include "dolphinsettings.h"
#include "dolphinview.h"
#include "dolphinviewcontainer.h"
#include "dolphin_generalsettings.h"
-#include "fileitemcapabilities.h"
#include <kactioncollection.h>
#include <kfileplacesmodel.h>
#include <kmimetypetrader.h>
#include <knewmenu.h>
#include <konqmimedata.h>
+#include <konq_fileitemcapabilities.h>
#include <konq_operations.h>
#include <konq_menuactions.h>
+#include <konq_popupmenuinformation.h>
#include <klocale.h>
#include <kpropertiesdialog.h>
#include <krun.h>
Q_ASSERT(!m_fileInfo.isNull());
KMenu* popup = new KMenu(m_mainWindow);
+ if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1)) {
+ // setup 'Create New' menu
+ DolphinNewMenu* newMenu = new DolphinNewMenu(popup, m_mainWindow);
+ newMenu->slotCheckUpToDate();
+ newMenu->setPopupFiles(m_fileInfo.url());
+ newMenu->setEnabled(capabilities().supportsWriting());
+
+ KMenu* menu = newMenu->menu();
+ menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
+ menu->setIcon(KIcon("document-new"));
+ popup->addMenu(newMenu->menu());
+ popup->addSeparator();
+
+ // insert 'Open in new window' and 'Open in new tab' entries
+ popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
+ popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
+ popup->addSeparator();
+ }
addShowMenubarAction(popup);
insertDefaultItemActions(popup);
i18nc("@action:inmenu Add selected folder to places", "Add to Places"));
}
- // Insert 'Open With...' sub menu
- QVector<KService::Ptr> openWithVector;
- const QList<QAction*> openWithActions = insertOpenWithItems(popup, openWithVector);
+ KonqPopupMenuInformation popupInfo;
+ popupInfo.setItems(m_selectedItems);
+ popupInfo.setParentWidget(m_mainWindow);
+ KonqMenuActions menuActions;
+ menuActions.setPopupMenuInfo(popupInfo);
+
+ // Insert 'Open With...' action or sub menu
+ menuActions.addOpenWithActionsTo(popup, "DesktopEntryName != 'dolphin'");
// Insert 'Actions' sub menu
- KonqMenuActions menuActions;
- menuActions.setItems(m_selectedItems);
if (menuActions.addActionsTo(popup)) {
popup->addSeparator();
}
// Insert 'Copy To' and 'Move To' sub menus
if (DolphinSettings::instance().generalSettings()->showCopyMoveMenu()) {
m_copyToMenu.setItems(m_selectedItems);
- m_copyToMenu.setReadOnly(!capabilities().supportsMoving());
+ m_copyToMenu.setReadOnly(!capabilities().supportsWriting());
m_copyToMenu.addActionsTo(popup);
popup->addSeparator();
}
DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
selectedUrl);
}
- } else if (openWithActions.contains(activatedAction)) {
- // one of the 'Open With' items has been selected
- if (openWithActions.last() == activatedAction) {
- // the item 'Other...' has been selected
- KRun::displayOpenWithDialog(m_selectedUrls, m_mainWindow);
- } else {
- int id = openWithActions.indexOf(activatedAction);
- KService::Ptr servicePtr = openWithVector[id];
- KRun::run(*servicePtr, m_selectedUrls, m_mainWindow);
- }
}
- openWithVector.clear();
popup->deleteLater();
}
QAction* columnsMode = m_mainWindow->actionCollection()->action("columns");
viewModeMenu->addAction(columnsMode);
- QAction* previewsMode = m_mainWindow->actionCollection()->action("previews");
- viewModeMenu->addAction(previewsMode);
-
popup->addMenu(viewModeMenu);
popup->addSeparator();
QAction* action = popup->exec(QCursor::pos());
if (action == propertiesAction) {
const KUrl& url = m_mainWindow->activeViewContainer()->url();
- KPropertiesDialog dialog(url, m_mainWindow);
- dialog.exec();
+
+ KPropertiesDialog* dialog = new KPropertiesDialog(url, m_mainWindow);
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ dialog->show();
} else if (action == addToPlacesAction) {
const KUrl& url = m_mainWindow->activeViewContainer()->url();
if (url.isValid()) {
popup->addAction(renameAction);
// insert 'Move to Trash' and (optionally) 'Delete'
- KConfigGroup kdeConfig(KGlobal::config(), "KDE");
- bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
+ KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
+ KConfigGroup configGroup(globalConfig, "KDE");
+ bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false);
+
const KUrl& url = m_mainWindow->activeViewContainer()->url();
if (url.isLocalFile()) {
QAction* moveToTrashAction = collection->action("move_to_trash");
}
}
-QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
- QVector<KService::Ptr>& openWithVector)
-{
- // Parts of the following code have been taken
- // from the class KonqOperations located in
- // libqonq/konq_operations.h of Konqueror.
- // (Copyright (C) 2000 David Faure <faure@kde.org>)
-
- // Prepare 'Open With' sub menu. Usually a sub menu is created, where all applications
- // are listed which are registered to open the item. As last entry "Other..." will be
- // attached which allows to select a custom application. If no applications are registered
- // no sub menu is created at all, only "Open With..." will be offered.
- bool insertOpenWithItems = true;
- const QString contextMimeType(m_fileInfo.mimetype());
-
- QListIterator<KFileItem> mimeIt(m_selectedItems);
- while (insertOpenWithItems && mimeIt.hasNext()) {
- KFileItem item = mimeIt.next();
- insertOpenWithItems = (contextMimeType == item.mimetype());
- }
-
- QList<QAction*> openWithActions;
- if (insertOpenWithItems) {
- // fill the 'Open with' sub menu with application types
- const KMimeType::Ptr mimePtr = KMimeType::findByUrl(m_fileInfo.url());
- KService::List offers = KMimeTypeTrader::self()->query(mimePtr->name(),
- "Application",
- "Type == 'Application'");
- if (offers.count() > 0) {
- KService::List::Iterator it;
- KMenu* openWithMenu = new KMenu(i18nc("@title:menu", "Open With"));
- for (it = offers.begin(); it != offers.end(); ++it) {
- // The offer list from the KTrader returns duplicate
- // application entries. Although this seems to be a configuration
- // problem outside the scope of Dolphin, duplicated entries just
- // will be skipped here.
- const QString appName((*it)->name());
- if (!containsEntry(openWithMenu, appName)) {
- const KIcon icon((*it)->icon());
- QAction* action = openWithMenu->addAction(icon, appName);
- openWithVector.append(*it);
- openWithActions << action;
- }
- }
-
- openWithMenu->addSeparator();
- QAction* action = openWithMenu->addAction(i18nc("@action:inmenu Open With", "&Other..."));
-
- openWithActions << action;
- popup->addMenu(openWithMenu);
- } else {
- // No applications are registered, hence just offer
- // a "Open With..." item instead of a sub menu containing
- // only one entry.
- QAction* action = popup->addAction(i18nc("@title:menu", "Open With..."));
- openWithActions << action;
- }
- } else {
- // At least one of the selected items has a different MIME type. In this case
- // just show a disabled "Open With..." entry.
- QAction* action = popup->addAction(i18nc("@title:menu", "Open With..."));
- action->setEnabled(false);
- }
-
- return openWithActions;
-}
-
-bool DolphinContextMenu::containsEntry(const KMenu* menu,
- const QString& entryName) const
-{
- Q_ASSERT(menu != 0);
-
- const QList<QAction*> list = menu->actions();
- const uint count = list.count();
- for (uint i = 0; i < count; ++i) {
- const QAction* action = list.at(i);
- if (action->text() == entryName) {
- return true;
- }
- }
-
- return false;
-}
-
void DolphinContextMenu::addShowMenubarAction(KMenu* menu)
{
KAction* showMenuBar = m_mainWindow->showMenuBarAction();
if (!m_mainWindow->menuBar()->isVisible()) {
- // TODO: it should not be necessary to uncheck the menu
- // bar action, but currently the action states don't get
- // updated if the menu is disabled
- showMenuBar->setChecked(false);
menu->addAction(showMenuBar);
menu->addSeparator();
}
QAction* DolphinContextMenu::createPasteAction()
{
QAction* action = 0;
- if ((m_selectedItems.count() == 1) && m_fileInfo.isDir()) {
+ 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);
return action;
}
-FileItemCapabilities& DolphinContextMenu::capabilities()
+KonqFileItemCapabilities& DolphinContextMenu::capabilities()
{
if (m_capabilities == 0) {
- m_capabilities = new FileItemCapabilities(m_selectedItems);
+ m_capabilities = new KonqFileItemCapabilities(m_selectedItems);
}
return *m_capabilities;
}