mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
On middle-click, open file with the second application for the file mime
FEATURE: 390631
This commit is contained in:
parent
ff852b97f1
commit
d27ee07de7
|
@ -31,6 +31,7 @@
|
||||||
#else
|
#else
|
||||||
#include <KIO/JobUiDelegate>
|
#include <KIO/JobUiDelegate>
|
||||||
#endif
|
#endif
|
||||||
|
#include <KApplicationTrader>
|
||||||
#include <KIO/OpenUrlJob>
|
#include <KIO/OpenUrlJob>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KMessageWidget>
|
#include <KMessageWidget>
|
||||||
|
@ -135,6 +136,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
|
||||||
connect(m_view, &DolphinView::writeStateChanged, this, &DolphinViewContainer::writeStateChanged);
|
connect(m_view, &DolphinView::writeStateChanged, this, &DolphinViewContainer::writeStateChanged);
|
||||||
connect(m_view, &DolphinView::requestItemInfo, this, &DolphinViewContainer::showItemInfo);
|
connect(m_view, &DolphinView::requestItemInfo, this, &DolphinViewContainer::showItemInfo);
|
||||||
connect(m_view, &DolphinView::itemActivated, this, &DolphinViewContainer::slotItemActivated);
|
connect(m_view, &DolphinView::itemActivated, this, &DolphinViewContainer::slotItemActivated);
|
||||||
|
connect(m_view, &DolphinView::fileMiddleClickActivated, this, &DolphinViewContainer::slotfileMiddleClickActivated);
|
||||||
connect(m_view, &DolphinView::itemsActivated, this, &DolphinViewContainer::slotItemsActivated);
|
connect(m_view, &DolphinView::itemsActivated, this, &DolphinViewContainer::slotItemsActivated);
|
||||||
connect(m_view, &DolphinView::redirection, this, &DolphinViewContainer::redirect);
|
connect(m_view, &DolphinView::redirection, this, &DolphinViewContainer::redirect);
|
||||||
connect(m_view, &DolphinView::directoryLoadingStarted, this, &DolphinViewContainer::slotDirectoryLoadingStarted);
|
connect(m_view, &DolphinView::directoryLoadingStarted, this, &DolphinViewContainer::slotDirectoryLoadingStarted);
|
||||||
|
@ -739,6 +741,26 @@ void DolphinViewContainer::slotItemActivated(const KFileItem &item)
|
||||||
job->start();
|
job->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DolphinViewContainer::slotfileMiddleClickActivated(const KFileItem &item)
|
||||||
|
{
|
||||||
|
KService::List services = KApplicationTrader::queryByMimeType(item.mimetype());
|
||||||
|
|
||||||
|
if (services.length() >= 2) {
|
||||||
|
auto service = services.at(1);
|
||||||
|
|
||||||
|
KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(service, this);
|
||||||
|
job->setUrls({item.url()});
|
||||||
|
|
||||||
|
#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
|
||||||
|
job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
|
||||||
|
#else
|
||||||
|
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
|
||||||
|
#endif
|
||||||
|
connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished);
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DolphinViewContainer::slotItemsActivated(const KFileItemList &items)
|
void DolphinViewContainer::slotItemsActivated(const KFileItemList &items)
|
||||||
{
|
{
|
||||||
Q_ASSERT(items.count() >= 2);
|
Q_ASSERT(items.count() >= 2);
|
||||||
|
|
|
@ -326,6 +326,11 @@ private Q_SLOTS:
|
||||||
*/
|
*/
|
||||||
void slotItemsActivated(const KFileItemList &items);
|
void slotItemsActivated(const KFileItemList &items);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles middle click of file. It opens the file passed using the second application associated with the file's mimetype.
|
||||||
|
*/
|
||||||
|
void slotfileMiddleClickActivated(const KFileItem &item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the information for the item \a item inside the statusbar. If the
|
* Shows the information for the item \a item inside the statusbar. If the
|
||||||
* item is null, the default statusbar information is shown.
|
* item is null, the default statusbar information is shown.
|
||||||
|
|
|
@ -1136,6 +1136,7 @@ void DolphinView::slotItemMiddleClicked(int index)
|
||||||
const KFileItem &item = m_model->fileItem(index);
|
const KFileItem &item = m_model->fileItem(index);
|
||||||
const QUrl &url = openItemAsFolderUrl(item);
|
const QUrl &url = openItemAsFolderUrl(item);
|
||||||
const auto modifiers = QGuiApplication::keyboardModifiers();
|
const auto modifiers = QGuiApplication::keyboardModifiers();
|
||||||
|
const QString &archiveProtocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype());
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
// keep in sync with KUrlNavigator::slotNavigatorButtonClicked
|
// keep in sync with KUrlNavigator::slotNavigatorButtonClicked
|
||||||
if (modifiers & Qt::ShiftModifier) {
|
if (modifiers & Qt::ShiftModifier) {
|
||||||
|
@ -1143,13 +1144,15 @@ void DolphinView::slotItemMiddleClicked(int index)
|
||||||
} else {
|
} else {
|
||||||
Q_EMIT tabRequested(url);
|
Q_EMIT tabRequested(url);
|
||||||
}
|
}
|
||||||
} else if (isTabsForFilesEnabled()) {
|
} else if (!archiveProtocol.isEmpty() && isTabsForFilesEnabled()) {
|
||||||
// keep in sync with KUrlNavigator::slotNavigatorButtonClicked
|
// keep in sync with KUrlNavigator::slotNavigatorButtonClicked
|
||||||
if (modifiers & Qt::ShiftModifier) {
|
if (modifiers & Qt::ShiftModifier) {
|
||||||
Q_EMIT activeTabRequested(item.url());
|
Q_EMIT activeTabRequested(item.url());
|
||||||
} else {
|
} else {
|
||||||
Q_EMIT tabRequested(item.url());
|
Q_EMIT tabRequested(item.url());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Q_EMIT fileMiddleClickActivated(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -452,6 +452,12 @@ Q_SIGNALS:
|
||||||
*/
|
*/
|
||||||
void itemActivated(const KFileItem &item);
|
void itemActivated(const KFileItem &item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is emitted when clicking on a file with the middle mouse button.
|
||||||
|
* @note: This will not be emitted for folders or file archives that will/can be opened like folders.
|
||||||
|
*/
|
||||||
|
void fileMiddleClickActivated(const KFileItem &item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is emitted when multiple items have been activated by e. g.
|
* Is emitted when multiple items have been activated by e. g.
|
||||||
* context menu open with.
|
* context menu open with.
|
||||||
|
|
Loading…
Reference in a new issue