mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-21 17:30:15 +00:00
[Dolphin] Open Preferred Search Tool action
Summary: Added "Open Preferred Search Tool" action to Tools menu. It runs preferred (topmost) external search tool as configured in the "More Search Tools" menu. By default Ctrl+Shift+F shortcut is assigned to this action. FEATURE: 384798 FIXED-IN: 20.03.80 {F7134238} {F7134240} {F7134242} Reviewers: #dolphin, ngraham, elvisangelaccio Reviewed By: #dolphin, ngraham Subscribers: pkloc, kfm-devel, kde-doc-english Tags: #dolphin, #documentation Differential Revision: https://phabricator.kde.org/D22594
This commit is contained in:
parent
808339bff6
commit
537dc7864a
|
@ -2018,6 +2018,17 @@ for this action.</para></listitem>
|
||||||
<listitem><para><action>Opens &konsole; within the current folder.</action></para></listitem>
|
<listitem><para><action>Opens &konsole; within the current folder.</action></para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><menuchoice>
|
||||||
|
<shortcut>
|
||||||
|
<keycombo action="simul">&Ctrl;&Shift;<keycap>F</keycap></keycombo>
|
||||||
|
</shortcut>
|
||||||
|
<guimenu>Tools</guimenu>
|
||||||
|
<guimenuitem>Open Preferred Search Tool</guimenuitem>
|
||||||
|
</menuchoice></term>
|
||||||
|
<listitem><para><action>Opens preferred search tool in the current folder.</action></para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><menuchoice>
|
<term><menuchoice>
|
||||||
<guimenu>Tools</guimenu>
|
<guimenu>Tools</guimenu>
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#include <KJobWidgets>
|
#include <KJobWidgets>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KMessageBox>
|
#include <KMessageBox>
|
||||||
|
#include <KNS3/KMoreToolsMenuFactory>
|
||||||
#include <KProtocolInfo>
|
#include <KProtocolInfo>
|
||||||
#include <KProtocolManager>
|
#include <KProtocolManager>
|
||||||
#include <KRun>
|
#include <KRun>
|
||||||
|
@ -197,6 +198,8 @@ DolphinMainWindow::DolphinMainWindow() :
|
||||||
toolBar()->installEventFilter(middleClickEventFilter);
|
toolBar()->installEventFilter(middleClickEventFilter);
|
||||||
|
|
||||||
setupWhatsThis();
|
setupWhatsThis();
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, &DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
DolphinMainWindow::~DolphinMainWindow()
|
DolphinMainWindow::~DolphinMainWindow()
|
||||||
|
@ -933,23 +936,88 @@ void DolphinMainWindow::toggleShowMenuBar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinMainWindow::openTerminal()
|
QString DolphinMainWindow::activeContainerLocalPath()
|
||||||
{
|
{
|
||||||
QString dir(QDir::homePath());
|
|
||||||
|
|
||||||
// If the given directory is not local, it can still be the URL of an
|
|
||||||
// ioslave using UDS_LOCAL_PATH which to be converted first.
|
|
||||||
KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url());
|
KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url());
|
||||||
KJobWidgets::setWindow(statJob, this);
|
KJobWidgets::setWindow(statJob, this);
|
||||||
statJob->exec();
|
statJob->exec();
|
||||||
QUrl url = statJob->mostLocalUrl();
|
QUrl url = statJob->mostLocalUrl();
|
||||||
|
|
||||||
//If the URL is local after the above conversion, set the directory.
|
|
||||||
if (url.isLocalFile()) {
|
if (url.isLocalFile()) {
|
||||||
dir = url.toLocalFile();
|
return url.toLocalFile();
|
||||||
|
}
|
||||||
|
return QDir::homePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
KToolInvocation::invokeTerminal(QString(), dir);
|
QPointer<QAction> DolphinMainWindow::preferredSearchTool()
|
||||||
|
{
|
||||||
|
m_searchTools.clear();
|
||||||
|
KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
|
||||||
|
&m_searchTools, { "files-find" }, QUrl::fromLocalFile(activeContainerLocalPath())
|
||||||
|
);
|
||||||
|
QList<QAction*> actions = m_searchTools.actions();
|
||||||
|
if (actions.isEmpty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
QAction* action = actions.first();
|
||||||
|
if (action->isSeparator()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction()
|
||||||
|
{
|
||||||
|
QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
|
||||||
|
const QList<QWidget*> widgets = openPreferredSearchTool->associatedWidgets();
|
||||||
|
for (QWidget* widget : widgets) {
|
||||||
|
QMenu* menu = qobject_cast<QMenu*>(widget);
|
||||||
|
if (menu) {
|
||||||
|
connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the open_preferred_search_tool action *before* the Configure Shortcuts window is shown,
|
||||||
|
// since this action is then listed in that window and it should be up-to-date when it is displayed.
|
||||||
|
// This update is instantaneous if user made no changes to the search tools in the meantime.
|
||||||
|
// Maybe all KStandardActions should defer calls to their slots, so that we could simply connect() to trigger()?
|
||||||
|
connect(
|
||||||
|
actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings)), &QAction::hovered,
|
||||||
|
this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
|
||||||
|
);
|
||||||
|
|
||||||
|
updateOpenPreferredSearchToolAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DolphinMainWindow::updateOpenPreferredSearchToolAction()
|
||||||
|
{
|
||||||
|
QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
|
||||||
|
if (!openPreferredSearchTool) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QPointer<QAction> tool = preferredSearchTool();
|
||||||
|
if (tool) {
|
||||||
|
openPreferredSearchTool->setVisible(true);
|
||||||
|
openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text()));
|
||||||
|
openPreferredSearchTool->setIcon(tool->icon());
|
||||||
|
} else {
|
||||||
|
openPreferredSearchTool->setVisible(false);
|
||||||
|
// still visible in Shortcuts configuration window
|
||||||
|
openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
|
||||||
|
openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DolphinMainWindow::openPreferredSearchTool()
|
||||||
|
{
|
||||||
|
QPointer<QAction> tool = preferredSearchTool();
|
||||||
|
if (tool) {
|
||||||
|
tool->trigger();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DolphinMainWindow::openTerminal()
|
||||||
|
{
|
||||||
|
KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinMainWindow::editSettings()
|
void DolphinMainWindow::editSettings()
|
||||||
|
@ -1091,7 +1159,9 @@ void DolphinMainWindow::updateControlMenu()
|
||||||
|
|
||||||
// Add a curated assortment of items from the "Tools" menu
|
// Add a curated assortment of items from the "Tools" menu
|
||||||
addActionToMenu(ac->action(QStringLiteral("show_filter_bar")), menu);
|
addActionToMenu(ac->action(QStringLiteral("show_filter_bar")), menu);
|
||||||
|
addActionToMenu(ac->action(QStringLiteral("open_preferred_search_tool")), menu);
|
||||||
addActionToMenu(ac->action(QStringLiteral("open_terminal")), menu);
|
addActionToMenu(ac->action(QStringLiteral("open_terminal")), menu);
|
||||||
|
connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
|
|
||||||
|
@ -1465,6 +1535,15 @@ void DolphinMainWindow::setupActions()
|
||||||
compareFiles->setEnabled(false);
|
compareFiles->setEnabled(false);
|
||||||
connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
|
connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
|
||||||
|
|
||||||
|
QAction* openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
|
||||||
|
openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
|
||||||
|
openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis",
|
||||||
|
"<para>This opens a preferred search tool for the viewed location.</para>"
|
||||||
|
"<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
|
||||||
|
openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
|
||||||
|
actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL + Qt::SHIFT + Qt::Key_F);
|
||||||
|
connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
|
||||||
|
|
||||||
#ifdef HAVE_TERMINAL
|
#ifdef HAVE_TERMINAL
|
||||||
if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
|
if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
|
||||||
QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
|
QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
|
||||||
|
@ -2207,6 +2286,8 @@ bool DolphinMainWindow::event(QEvent *event)
|
||||||
QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
|
QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
|
||||||
QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
|
QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
|
||||||
return true;
|
return true;
|
||||||
|
} else if (event->type() == QEvent::WindowActivate) {
|
||||||
|
updateOpenPreferredSearchToolAction();
|
||||||
}
|
}
|
||||||
return KXmlGuiWindow::event(event);
|
return KXmlGuiWindow::event(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QMenu>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
@ -352,6 +353,15 @@ private slots:
|
||||||
*/
|
*/
|
||||||
void toggleShowMenuBar();
|
void toggleShowMenuBar();
|
||||||
|
|
||||||
|
/** Sets up updates for "Open Preferred Search Tool" action. */
|
||||||
|
void setupUpdateOpenPreferredSearchToolAction();
|
||||||
|
|
||||||
|
/** Updates "Open Preferred Search Tool" action. */
|
||||||
|
void updateOpenPreferredSearchToolAction();
|
||||||
|
|
||||||
|
/** Opens preferred search tool for the current location. */
|
||||||
|
void openPreferredSearchTool();
|
||||||
|
|
||||||
/** Opens a terminal window for the current location. */
|
/** Opens a terminal window for the current location. */
|
||||||
void openTerminal();
|
void openTerminal();
|
||||||
|
|
||||||
|
@ -597,6 +607,15 @@ private:
|
||||||
/** Adds "What's This?" texts to many widgets and StandardActions. */
|
/** Adds "What's This?" texts to many widgets and StandardActions. */
|
||||||
void setupWhatsThis();
|
void setupWhatsThis();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the KIO::StatJob::mostLocalUrl() for the active container URL
|
||||||
|
* if it's a local file. Otherwise returns the user's home path.
|
||||||
|
*/
|
||||||
|
QString activeContainerLocalPath();
|
||||||
|
|
||||||
|
/** Returns preferred search tool as configured in "More Search Tools" menu. */
|
||||||
|
QPointer<QAction> preferredSearchTool();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Implements a custom error handling for the undo manager. This
|
* Implements a custom error handling for the undo manager. This
|
||||||
|
@ -633,6 +652,9 @@ private:
|
||||||
|
|
||||||
KToolBarPopupAction* m_backAction;
|
KToolBarPopupAction* m_backAction;
|
||||||
KToolBarPopupAction* m_forwardAction;
|
KToolBarPopupAction* m_forwardAction;
|
||||||
|
|
||||||
|
QMenu m_searchTools;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
|
inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KMessageBox>
|
#include <KMessageBox>
|
||||||
#include <KMimeTypeEditor>
|
#include <KMimeTypeEditor>
|
||||||
|
#include <KNS3/KMoreToolsMenuFactory>
|
||||||
#include <KPluginFactory>
|
#include <KPluginFactory>
|
||||||
#include <KRun>
|
#include <KRun>
|
||||||
#include <KSharedConfig>
|
#include <KSharedConfig>
|
||||||
|
@ -553,8 +554,17 @@ void DolphinPart::slotOpenTerminal()
|
||||||
|
|
||||||
void DolphinPart::slotFindFile()
|
void DolphinPart::slotFindFile()
|
||||||
{
|
{
|
||||||
|
QMenu searchTools;
|
||||||
|
KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
|
||||||
|
&searchTools, { "files-find" }, QUrl::fromLocalFile(KParts::ReadOnlyPart::localFilePath())
|
||||||
|
);
|
||||||
|
QList<QAction*> actions = searchTools.actions();
|
||||||
|
if (!(actions.isEmpty())) {
|
||||||
|
actions.first()->trigger();
|
||||||
|
} else {
|
||||||
KRun::run(QStringLiteral("kfind"), {url()}, widget());
|
KRun::run(QStringLiteral("kfind"), {url()}, widget());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DolphinPart::updateNewMenu()
|
void DolphinPart::updateNewMenu()
|
||||||
{
|
{
|
||||||
|
|
|
@ -194,7 +194,7 @@ private Q_SLOTS:
|
||||||
void slotOpenTerminal();
|
void slotOpenTerminal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open KFind with the current path.
|
* Open preferred search tool in the current directory to find files.
|
||||||
*/
|
*/
|
||||||
void slotFindFile();
|
void slotFindFile();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
|
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
|
||||||
<kpartgui name="dolphin" version="27">
|
<kpartgui name="dolphin" version="28">
|
||||||
<MenuBar>
|
<MenuBar>
|
||||||
<Menu name="file">
|
<Menu name="file">
|
||||||
<Action name="new_menu" />
|
<Action name="new_menu" />
|
||||||
|
@ -54,6 +54,7 @@
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu name="tools">
|
<Menu name="tools">
|
||||||
<Action name="show_filter_bar" />
|
<Action name="show_filter_bar" />
|
||||||
|
<Action name="open_preferred_search_tool" />
|
||||||
<Action name="open_terminal" />
|
<Action name="open_terminal" />
|
||||||
<Action name="compare_files" />
|
<Action name="compare_files" />
|
||||||
<Action name="change_remote_encoding" />
|
<Action name="change_remote_encoding" />
|
||||||
|
|
Loading…
Reference in a new issue