X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/fc1503986032918ad84d420209c948b45c8bb375..e9b697bdf6b8de3a40ac2d4689a9b20a6d7cf550:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index e17987fdd..8d014fc2c 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -21,11 +21,14 @@ #include "dolphincontextmenu.h" #include "dolphinmainwindow.h" -#include "dolphinsettings.h" +#include "dolphinnewmenu.h" +#include "settings/dolphinsettings.h" #include "dolphinview.h" #include "dolphinviewcontainer.h" +#include "dolphin_generalsettings.h" #include +#include #include #include #include @@ -37,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -53,9 +57,12 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const KFileItem& fileInfo, const KUrl& baseUrl) : m_mainWindow(parent), + m_capabilities(0), m_fileInfo(fileInfo), m_baseUrl(baseUrl), - m_context(NoContext) + m_context(NoContext), + m_copyToMenu(parent), + m_customActions() { // The context menu either accesses the URLs of the selected items // or the items itself. To increase the performance both lists are cached. @@ -66,6 +73,13 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, DolphinContextMenu::~DolphinContextMenu() { + delete m_capabilities; + m_capabilities = 0; +} + +void DolphinContextMenu::setCustomActions(const QList& actions) +{ + m_customActions = actions; } void DolphinContextMenu::open() @@ -95,25 +109,6 @@ void DolphinContextMenu::open() } } -void DolphinContextMenu::pasteIntoFolder() -{ - // TODO: this method should go into DolphinView (see DolphinContextMenu::createPasteAction()) - Q_ASSERT(m_selectedItems.count() == 1); - Q_ASSERT(m_fileInfo.isDir()); - - QClipboard* clipboard = QApplication::clipboard(); - const QMimeData* mimeData = clipboard->mimeData(); - - const KUrl::List source = KUrl::List::fromMimeData(mimeData); - const KUrl& dest = m_fileInfo.url(); - if (KonqMimeData::decodeIsCutSelection(mimeData)) { - KonqOperations::copy(m_mainWindow, KonqOperations::MOVE, source, dest); - clipboard->clear(); - } else { - KonqOperations::copy(m_mainWindow, KonqOperations::COPY, source, dest); - } -} - void DolphinContextMenu::openTrashContextMenu() { Q_ASSERT(m_context & TrashContext); @@ -130,12 +125,14 @@ void DolphinContextMenu::openTrashContextMenu() QAction* addToPlacesAction = popup->addAction(KIcon("bookmark-new"), i18nc("@action:inmenu Add current folder to places", "Add to Places")); + addCustomActions(popup); + QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); popup->addAction(propertiesAction); QAction *action = popup->exec(QCursor::pos()); if (action == emptyTrashAction) { - const QString text(i18nc("@info", "Do you really want to empty the Trash? All items will get deleted.")); + const QString text(i18nc("@info", "Do you really want to empty the Trash? All items will be deleted.")); const bool del = KMessageBox::warningContinueCancel(m_mainWindow, text, QString(), @@ -185,6 +182,24 @@ void DolphinContextMenu::openItemContextMenu() 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); @@ -197,15 +212,25 @@ void DolphinContextMenu::openItemContextMenu() i18nc("@action:inmenu Add selected folder to places", "Add to Places")); } - // Insert 'Open With...' sub menu - QVector openWithVector; - const QList openWithActions = insertOpenWithItems(popup, openWithVector); - - // Insert 'Actions' sub menu KonqMenuActions menuActions; - menuActions.setItems(m_selectedItems); - if (menuActions.addActionsTo(popup)) + menuActions.setParentWidget(m_mainWindow); + menuActions.setItemListProperties(m_selectedItems); + + // insert 'Open With...' action or sub menu + menuActions.addOpenWithActionsTo(popup, "DesktopEntryName != 'dolphin'"); + + // insert 'Actions' sub menu + 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().supportsWriting()); + m_copyToMenu.addActionsTo(popup); + popup->addSeparator(); + } // insert 'Properties...' entry QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); @@ -219,19 +244,8 @@ void DolphinContextMenu::openItemContextMenu() 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(); } @@ -263,24 +277,24 @@ void DolphinContextMenu::openViewportContextMenu() 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* addToPlacesAction = popup->addAction(KIcon("bookmark-new"), i18nc("@action:inmenu Add current folder to places", "Add to Places")); - popup->addSeparator(); - QAction* propertiesAction = popup->addAction(i18nc("@action:inmenu", "Properties")); + addCustomActions(popup); + QAction* propertiesAction = popup->addAction(i18nc("@action:inmenu", "Properties")); + propertiesAction->setIcon(KIcon("document-properties")); 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()) { @@ -311,8 +325,10 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) 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"); @@ -327,98 +343,10 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup) } } -QList DolphinContextMenu::insertOpenWithItems(KMenu* popup, - QVector& 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 ) - - // 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 mimeIt(m_selectedItems); - while (insertOpenWithItems && mimeIt.hasNext()) { - KFileItem item = mimeIt.next(); - insertOpenWithItems = (contextMimeType == item.mimetype()); - } - - QList 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 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(); } @@ -435,14 +363,14 @@ QString DolphinContextMenu::placesName(const KUrl& url) const QAction* DolphinContextMenu::createPasteAction() { - // TODO: move this method as QAction* action pasteAction() into DolphinMainWindow 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); - action->setEnabled(!pasteData.isEmpty()); - connect(action, SIGNAL(triggered()), this, SLOT(pasteIntoFolder())); + action->setEnabled(!pasteData.isEmpty() && capabilities().supportsWriting()); + connect(action, SIGNAL(triggered()), m_mainWindow, SLOT(pasteIntoFolder())); } else { action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); } @@ -450,4 +378,19 @@ QAction* DolphinContextMenu::createPasteAction() return action; } +KFileItemListProperties& DolphinContextMenu::capabilities() +{ + if (m_capabilities == 0) { + m_capabilities = new KFileItemListProperties(m_selectedItems); + } + return *m_capabilities; +} + +void DolphinContextMenu::addCustomActions(KMenu* menu) +{ + foreach (QAction* action, m_customActions) { + menu->addAction(action); + } +} + #include "dolphincontextmenu.moc"