Re-add "Open Terminal Here" feature

This is equivalent to the "Open Terminal Here" feature that existed until Version 20.12.  

If the user has selected folders, replace "Open Terminal" in the context menu with "Open Terminal Here".  
When more than 5 folders are selected, a modal window will ask the user if they are sure they want to
open all 6 or more terminal windows.

In Detail View, users can also select a file, 
which will open a terminal at the location of that file.

BUG: 452637
FIXED-IN: 22.08
This commit is contained in:
oioi 555 2022-05-02 20:25:24 +00:00 committed by Nate Graham
parent e148329393
commit 9b5f56980b
7 changed files with 63 additions and 8 deletions

View file

@ -445,8 +445,8 @@ void DolphinContextMenu::addAdditionalActions(const KFileItemListProperties &pro
addSeparator();
QList<QAction *> additionalActions;
if (props.isDirectory() && props.isLocal() && ContextMenuSettings::showOpenTerminal()) {
additionalActions << m_mainWindow->actionCollection()->action(QStringLiteral("open_terminal"));
if (props.isLocal() && ContextMenuSettings::showOpenTerminal()) {
additionalActions << m_mainWindow->actionCollection()->action(QStringLiteral("open_terminal_here"));
}
m_fileItemActions->addActionsTo(this, KFileItemActions::MenuActionSource::All, additionalActions);

View file

@ -1087,8 +1087,45 @@ void DolphinMainWindow::openPreferredSearchTool()
void DolphinMainWindow::openTerminal()
{
const QUrl url = m_activeViewContainer->url();
openTerminalJob(m_activeViewContainer->url());
}
void DolphinMainWindow::openTerminalHere()
{
QList<QUrl> urls = {};
for (const KFileItem& item : m_activeViewContainer->view()->selectedItems()) {
QUrl url = item.url();
if (item.isFile()) {
url.setPath(QFileInfo(url.path()).absolutePath());
}
if (!urls.contains(url)) {
urls << url;
}
}
// No items are selected. Open a terminal window for the current location.
if (urls.count() == 0) {
openTerminal();
return;
}
if (urls.count() > 5) {
QString question = i18np("Are you sure you want to open 1 terminal window?",
"Are you sure you want to open %1 terminal windows?", urls.count());
const int answer = KMessageBox::warningYesNo(this, question);
if (answer != KMessageBox::Yes) {
return;
}
}
for (const QUrl& url : urls) {
openTerminalJob(url);
}
}
void DolphinMainWindow::openTerminalJob(const QUrl& url)
{
if (url.isLocalFile()) {
auto job = new KTerminalLauncherJob(QString());
job->setWorkingDirectory(url.toLocalFile());
@ -1721,6 +1758,16 @@ void DolphinMainWindow::setupActions()
actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT | Qt::Key_F4);
connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
QAction* openTerminalHere = actionCollection()->addAction(QStringLiteral("open_terminal_here"));
// i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
openTerminalHere->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
openTerminalHere->setWhatsThis(xi18nc("@info:whatsthis",
"<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
"<para>To learn more about terminals use the help in the terminal application.</para>"));
openTerminalHere->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
actionCollection()->setDefaultShortcut(openTerminalHere, Qt::SHIFT | Qt::ALT | Qt::Key_F4);
connect(openTerminalHere, &QAction::triggered, this, &DolphinMainWindow::openTerminalHere);
#ifdef HAVE_TERMINAL
QAction* focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));

View file

@ -399,6 +399,12 @@ private Q_SLOTS:
/** Opens a terminal window for the current location. */
void openTerminal();
/** Opens terminal windows for the selected items' locations. */
void openTerminalHere();
/** Opens a terminal window for the URL. */
void openTerminalJob(const QUrl& url);
/** Focus a Terminal Panel. */
void focusTerminalPanel();

View file

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="dolphinpart" version="15" translationDomain="dolphin">
<gui name="dolphinpart" version="16" translationDomain="dolphin">
<MenuBar>
<Menu name="edit"><text>&amp;Edit</text>
<Action name="new_menu"/>
@ -40,6 +40,7 @@
</Menu>
<Menu name="tools"><text context="@title:menu">Tools</text>
<Action name="open_terminal"/>
<Action name="open_terminal_here"/>
<Action name="focus_terminal_panel"/>
<Action name="find_file" />
<Action name="show_filter_bar" />

View file

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="dolphin" version="35">
<gui name="dolphin" version="36">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
@ -69,6 +69,7 @@
<Menu name="tools">
<Action name="open_preferred_search_tool" />
<Action name="open_terminal" />
<Action name="open_terminal_here" />
<Action name="focus_terminal_panel"/>
<Action name="compare_files" />
<Action name="change_remote_encoding" />

View file

@ -127,7 +127,7 @@ bool ContextMenuSettingsPage::entryVisible(const QString& id)
return ContextMenuSettings::showCopyLocation();
} else if (id == "duplicate") {
return ContextMenuSettings::showDuplicateHere();
} else if (id == "open_terminal") {
} else if (id == "open_terminal_here") {
return ContextMenuSettings::showOpenTerminal();
}
return false;
@ -149,7 +149,7 @@ void ContextMenuSettingsPage::setEntryVisible(const QString& id, bool visible)
ContextMenuSettings::setShowCopyLocation(visible);
} else if (id == "duplicate") {
ContextMenuSettings::setShowDuplicateHere(visible);
} else if (id == "open_terminal") {
} else if (id == "open_terminal_here") {
ContextMenuSettings::setShowOpenTerminal(visible);
}
}

View file

@ -86,7 +86,7 @@ DolphinSettingsDialog::DolphinSettingsDialog(const QUrl& url, QWidget* parent, K
QStringLiteral("open_in_new_window"),
QStringLiteral("copy_location"),
QStringLiteral("duplicate"),
QStringLiteral("open_terminal"),
QStringLiteral("open_terminal_here")
});
KPageWidgetItem* contextMenuSettingsFrame = addPage(contextMenuSettingsPage,
i18nc("@title:group", "Context Menu"));