]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Re-add "Open Terminal Here" feature
authoroioi 555 <oioi555x@gmail.com>
Mon, 2 May 2022 20:25:24 +0000 (20:25 +0000)
committerNate Graham <nate@kde.org>
Mon, 2 May 2022 20:25:24 +0000 (20:25 +0000)
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

src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinpart.rc
src/dolphinui.rc
src/settings/contextmenu/contextmenusettingspage.cpp
src/settings/dolphinsettingsdialog.cpp

index 65d84106067b2b7123ac80d09d7e23e65297fc27..2568f503f13b5246e0ed1d7f08a2d1e5b87b346b 100644 (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);
 
index 589c2c185b5fc1cbc9fb76eacb8bef3e0749619d..3e9d463d252d67f5cccb94784ded2efa945945f3 100644 (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"));
index 17327f2de9f3bbafd6027b9b89b99f34eef19e24..6e775c5cc3e71d38f4ac3c058b5f569fa9959c30 100644 (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();
 
index a65cf685ee448ed3d8f2414b656016ce887c4d26..d13f4aaed7a1b69b0bfbb5c048f74e3518f01f61 100644 (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" />
index 1b7f2e8b10573b6d718d21eae56f40cec0f9e12f..b6afe2abb1b1ee265fce1485651ccd0bb98dbd29 100644 (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" />
index cec1f96491d4c6039fc03e7ac0dc845c2b34896a..97bb39ff099d05153947b7aef40da10f0a297883 100644 (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);
     }
 }
index d699ef894bc342b236a478133557fcda80a7508b..bd4c5fb02dead78dc608fd97cbfba29f6b3260bf 100644 (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"));