]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/selectionmode/bottombarcontentscontainer.cpp
Apply 1 suggestion(s) to 1 file(s)
[dolphin.git] / src / selectionmode / bottombarcontentscontainer.cpp
index 04b52a60f1e4bdd40bd358e3dfc7ccf58c27ad73..0e3087a9c52f2b571a2af065a8d4a6ed4e81ee31 100644 (file)
@@ -1,6 +1,6 @@
 /*
     This file is part of the KDE project
-    SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@zohomail.eu>
+    SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@kde.org>
 
     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */
@@ -18,7 +18,6 @@
 #include <QHBoxLayout>
 #include <QLabel>
 #include <QMenu>
-#include <QPushButton>
 #include <QToolButton>
 #include <QVBoxLayout>
 
@@ -26,9 +25,9 @@
 
 using namespace SelectionMode;
 
-BottomBarContentsContainer::BottomBarContentsContainer(KActionCollection *actionCollection, QWidget *parent) :
-    QWidget{parent},
-    m_actionCollection{actionCollection}
+BottomBarContentsContainer::BottomBarContentsContainer(KActionCollection *actionCollection, QWidget *parent)
+    : QWidget{parent}
+    m_actionCollection{actionCollection}
 {
     // We will mostly interact with m_layout when changing the contents and not care about the other internal hierarchy.
     m_layout = new QHBoxLayout(this);
@@ -39,7 +38,9 @@ void BottomBarContentsContainer::resetContents(BottomBar::Contents contents)
     emptyBarContents();
 
     // A label is added in many of the methods below. We only know its size a bit later and if it should be hidden.
-    QTimer::singleShot(10, this, [this](){ updateExplanatoryLabelVisibility(); });
+    QTimer::singleShot(10, this, [this]() {
+        updateExplanatoryLabelVisibility();
+    });
 
     Q_CHECK_PTR(m_actionCollection);
     m_contents = contents;
@@ -69,8 +70,10 @@ void BottomBarContentsContainer::resetContents(BottomBar::Contents contents)
     }
 }
 
-void BottomBarContentsContainer::updateForNewWidth()
+void BottomBarContentsContainer::adaptToNewBarWidth(int newBarWidth)
 {
+    m_barWidth = newBarWidth;
+
     if (m_contents == BottomBar::GeneralContents) {
         Q_ASSERT(m_overflowButton);
         if (unusedSpace() < 0) {
@@ -94,7 +97,7 @@ void BottomBarContentsContainer::updateForNewWidth()
                 }
             }
         } else {
-            // We have some unusedSpace(). Let's check if we can maybe add more of the contextual action's widgets.
+            // We have some unusedSpace(). Let's check if we can maybe add more of the contextual actions' widgets.
             for (auto i = m_generalBarActions.begin(); i != m_generalBarActions.end(); ++i) {
                 if (i->isWidgetVisible()) {
                     continue;
@@ -130,6 +133,7 @@ void BottomBarContentsContainer::slotSelectionChanged(const KFileItemList &selec
         auto contextActions = contextActionsFor(selection, baseUrl);
         m_generalBarActions.clear();
         if (contextActions.empty()) {
+            // We have nothing to show
             Q_ASSERT(qobject_cast<BottomBar *>(parentWidget()->parentWidget()->parentWidget()));
             if (isVisibleTo(parentWidget()->parentWidget()->parentWidget()->parentWidget())) { // is the bar visible
                 Q_EMIT barVisibilityChangeRequested(false);
@@ -153,27 +157,29 @@ void BottomBarContentsContainer::addCopyContents()
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process to copy files by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Copying"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel Copying"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *copyButton = new QPushButton(this);
     // We claim to have PasteContents already so triggering the copy action next won't instantly hide the bottom bar.
-    connect(copyButton, &QAbstractButton::clicked, [this]() {
+    connect(copyButton, &QAbstractButton::clicked, this, [this]() {
         if (GeneralSettings::showPasteBarAfterCopying()) {
-            m_contents = BottomBar::Contents::PasteContents;
+            m_contents = BottomBar::Contents::PasteContents; // prevents hiding
         }
     });
     // Connect the copy action as a second step.
     m_mainAction = ActionWithWidget(m_actionCollection->action(KStandardAction::name(KStandardAction::Copy)), copyButton);
     // Finally connect the lambda that actually changes the contents to the PasteContents.
-    connect(copyButton, &QAbstractButton::clicked, [this]() {
+    connect(copyButton, &QAbstractButton::clicked, this, [this]() {
         if (GeneralSettings::showPasteBarAfterCopying()) {
             resetContents(BottomBar::Contents::PasteContents); // resetContents() needs to be connected last because
                 // it instantly deletes the button and then the other slots won't be called.
         }
-        Q_EMIT leaveSelectionModeRequested();
+        Q_EMIT selectionModeLeavingRequested();
     });
     updateMainActionButton(KFileItemList());
     m_layout->addWidget(copyButton);
@@ -186,9 +192,11 @@ void BottomBarContentsContainer::addCopyLocationContents()
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process to copy the location of files by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Copying"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel Copying"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *copyLocationButton = new QPushButton(this);
@@ -199,15 +207,19 @@ void BottomBarContentsContainer::addCopyLocationContents()
 
 void BottomBarContentsContainer::addCopyToOtherViewContents()
 {
+    // clang-format off
     // i18n: "Copy over" refers to copying to the other split view area that is currently visible to the user.
     m_explanatoryLabel = new QLabel(i18nc("@info explaining the next step in a process", "Select the files and folders that should be copied over."), this);
+    // clang-format on
     m_explanatoryLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process to copy the location of files by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Copying"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel Copying"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *copyToOtherViewButton = new QPushButton(this);
@@ -223,27 +235,29 @@ void BottomBarContentsContainer::addCutContents()
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process to cut files by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Cutting"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel Cutting"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *cutButton = new QPushButton(this);
     // We claim to have PasteContents already so triggering the cut action next won't instantly hide the bottom bar.
-    connect(cutButton, &QAbstractButton::clicked, [this]() {
+    connect(cutButton, &QAbstractButton::clicked, this, [this]() {
         if (GeneralSettings::showPasteBarAfterCopying()) {
-            m_contents = BottomBar::Contents::PasteContents;
+            m_contents = BottomBar::Contents::PasteContents; // prevents hiding
         }
     });
     // Connect the cut action as a second step.
     m_mainAction = ActionWithWidget(m_actionCollection->action(KStandardAction::name(KStandardAction::Cut)), cutButton);
     // Finally connect the lambda that actually changes the contents to the PasteContents.
-    connect(cutButton, &QAbstractButton::clicked, [this](){
+    connect(cutButton, &QAbstractButton::clicked, this, [this]() {
         if (GeneralSettings::showPasteBarAfterCopying()) {
             resetContents(BottomBar::Contents::PasteContents); // resetContents() needs to be connected last because
                 // it instantly deletes the button and then the other slots won't be called.
         }
-        Q_EMIT leaveSelectionModeRequested();
+        Q_EMIT selectionModeLeavingRequested();
     });
     updateMainActionButton(KFileItemList());
     m_layout->addWidget(cutButton);
@@ -251,14 +265,17 @@ void BottomBarContentsContainer::addCutContents()
 
 void BottomBarContentsContainer::addDeleteContents()
 {
-    m_explanatoryLabel = new QLabel(i18nc("@info explaining the next step in a process", "Select the files and folders that should be permanently deleted."), this);
+    m_explanatoryLabel =
+        new QLabel(i18nc("@info explaining the next step in a process", "Select the files and folders that should be permanently deleted."), this);
     m_explanatoryLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process to delete files by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *deleteButton = new QPushButton(this);
@@ -274,9 +291,11 @@ void BottomBarContentsContainer::addDuplicateContents()
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process to duplicate files by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Duplicating"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel Duplicating"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *duplicateButton = new QPushButton(this);
@@ -288,15 +307,12 @@ void BottomBarContentsContainer::addDuplicateContents()
 void BottomBarContentsContainer::addGeneralContents()
 {
     if (!m_overflowButton) {
-        m_overflowButton = new QToolButton{this};
-        // i18n: This button appears in a bar if there isn't enough horizontal space to fit all the other buttons.
-        // The small icon-only button opens a menu that contains the actions that didn't fit on the bar.
-        // Since this is an icon-only button this text will only appear as a tooltip and as accessibility text.
-        m_overflowButton->setToolTip(i18nc("@action", "More"));
-        m_overflowButton->setAccessibleName(m_overflowButton->toolTip());
-        m_overflowButton->setIcon(QIcon::fromTheme(QStringLiteral("view-more-horizontal-symbolic")));
+        // clang-format off
+        // i18n: This button appears in a bar if there isn't enough horizontal space to fit all the other buttons so please keep it short.
+        // The small button opens a menu that contains the actions that didn't fit on the bar.
+        m_overflowButton = new QPushButton{QIcon::fromTheme(QStringLiteral("view-more-symbolic")), i18nc("@action keep short", "More"), this};
+        // clang-format on
         m_overflowButton->setMenu(new QMenu{m_overflowButton});
-        m_overflowButton->setPopupMode(QToolButton::ToolButtonPopupMode::InstantPopup);
         m_overflowButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding); // Makes sure it has the same height as the labeled buttons.
         m_layout->addWidget(m_overflowButton);
     } else {
@@ -338,15 +354,19 @@ void BottomBarContentsContainer::addGeneralContents()
 
 void BottomBarContentsContainer::addMoveToOtherViewContents()
 {
+    // clang-format off
     // i18n: "Move over" refers to moving to the other split view area that is currently visible to the user.
     m_explanatoryLabel = new QLabel(i18nc("@info explaining the next step in a process", "Select the files and folders that should be moved over."), this);
+    // clang-format on
     m_explanatoryLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process to copy the location of files by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort Moving"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel Moving"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *moveToOtherViewButton = new QPushButton(this);
@@ -357,14 +377,17 @@ void BottomBarContentsContainer::addMoveToOtherViewContents()
 
 void BottomBarContentsContainer::addMoveToTrashContents()
 {
-    m_explanatoryLabel = new QLabel(i18nc("@info explaining the next step in a process", "Select the files and folders that should be moved to the Trash."), this);
+    m_explanatoryLabel =
+        new QLabel(i18nc("@info explaining the next step in a process", "Select the files and folders that should be moved to the Trash."), this);
     m_explanatoryLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process of moving files to the trash by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Abort"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *moveToTrashButton = new QPushButton(this);
@@ -376,9 +399,10 @@ void BottomBarContentsContainer::addMoveToTrashContents()
 void BottomBarContentsContainer::addPasteContents()
 {
     m_explanatoryLabel = new QLabel(xi18n("<para>The selected files and folders were added to the Clipboard. "
-            "Now the <emphasis>Paste</emphasis> action can be used to transfer them from the Clipboard "
-            "to any other location. They can even be transferred to other applications by using their "
-            "respective <emphasis>Paste</emphasis> actions.</para>"), this);
+                                          "Now the <emphasis>Paste</emphasis> action can be used to transfer them from the Clipboard "
+                                          "to any other location. They can even be transferred to other applications by using their "
+                                          "respective <emphasis>Paste</emphasis> actions.</para>"),
+                                    this);
     m_explanatoryLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
@@ -390,7 +414,7 @@ void BottomBarContentsContainer::addPasteContents()
      * So we first have to claim that we have different contents before requesting to leave selection mode. */
     auto actuallyLeaveSelectionMode = [this]() {
         m_contents = BottomBar::Contents::CopyLocationContents;
-        Q_EMIT leaveSelectionModeRequested();
+        Q_EMIT barVisibilityChangeRequested(false);
     };
 
     auto *pasteButton = new QPushButton(this);
@@ -400,9 +424,9 @@ void BottomBarContentsContainer::addPasteContents()
     vBoxLayout->addWidget(pasteButton);
 
     auto *dismissButton = new QToolButton(this);
-    dismissButton->setText(i18nc("@action Dismisses a bar explaining how to use the Paste action", "Dismiss this Reminder"));
+    dismissButton->setText(i18nc("@action Dismisses a bar explaining how to use the Paste action", "Dismiss This Reminder"));
     connect(dismissButton, &QAbstractButton::clicked, this, actuallyLeaveSelectionMode);
-    auto *dontRemindAgainAction = new QAction(i18nc("@action Dismisses an explanatory area and never shows it again", "Don't remind me again"), this);
+    auto *dontRemindAgainAction = new QAction(i18nc("@action Dismisses an explanatory area and never shows it again", "Don't Remind Me Again"), this);
     connect(dontRemindAgainAction, &QAction::triggered, this, []() {
         GeneralSettings::setShowPasteBarAfterCopying(false);
     });
@@ -418,14 +442,18 @@ void BottomBarContentsContainer::addPasteContents()
 
 void BottomBarContentsContainer::addRenameContents()
 {
-    m_explanatoryLabel = new QLabel(i18nc("@info explains the next step in a process", "Select the file or folder that should be renamed.\nBulk renaming is possible when multiple items are selected."), this);
+    m_explanatoryLabel = new QLabel(i18nc("@info explains the next step in a process",
+                                          "Select the file or folder that should be renamed.\nBulk renaming is possible when multiple items are selected."),
+                                    this);
     m_explanatoryLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
     m_explanatoryLabel->setWordWrap(true);
     m_layout->addWidget(m_explanatoryLabel);
 
+    // clang-format off
     // i18n: Aborts the current step-by-step process to delete files by leaving the selection mode.
-    auto *cancelButton = new QPushButton(i18nc("@action:button", "Stop Renaming"), this);
-    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::leaveSelectionModeRequested);
+    auto *cancelButton = new QPushButton(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18nc("@action:button", "Cancel Renaming"), this);
+    // clang-format on
+    connect(cancelButton, &QAbstractButton::clicked, this, &BottomBarContentsContainer::selectionModeLeavingRequested);
     m_layout->addWidget(cancelButton);
 
     auto *renameButton = new QPushButton(this);
@@ -442,20 +470,22 @@ void BottomBarContentsContainer::emptyBarContents()
             QLayoutItem *grandChild;
             while ((grandChild = childLayout->takeAt(0)) != nullptr) {
                 delete grandChild->widget(); // delete the widget
-                delete grandChild;   // delete the layout item
+                delete grandChild; // delete the layout item
             }
         }
         delete child->widget(); // delete the widget
-        delete child;   // delete the layout item
+        delete child; // delete the layout item
     }
 }
 
-std::vector<QAction *> BottomBarContentsContainer::contextActionsFor(const KFileItemList& selectedItems, const QUrl& baseUrl)
+std::vector<QAction *> BottomBarContentsContainer::contextActionsFor(const KFileItemList &selectedItems, const QUrl &baseUrl)
 {
     if (selectedItems.isEmpty()) {
         // There are no contextual actions to show for these items.
         // We might even want to hide this bar in this case. To make this clear, we reset m_internalContextMenu.
-        m_internalContextMenu.release()->deleteLater();
+        if (m_internalContextMenu) {
+            m_internalContextMenu.release()->deleteLater();
+        }
         return std::vector<QAction *>{};
     }
 
@@ -486,7 +516,8 @@ std::vector<QAction *> BottomBarContentsContainer::contextActionsFor(const KFile
 
     // KHamburgerMenu would only be visible if there is no menu available anywhere on the user interface. This might be useful for recovery from
     // such a situation in theory but a bar with context dependent actions doesn't really seem like the right place for it.
-    Q_ASSERT(internalContextMenuActions.first()->icon().name() == m_actionCollection->action(KStandardAction::name(KStandardAction::HamburgerMenu))->icon().name());
+    Q_ASSERT(internalContextMenuActions.first()->icon().name()
+             == m_actionCollection->action(KStandardAction::name(KStandardAction::HamburgerMenu))->icon().name());
     internalContextMenuActions.removeFirst();
 
     for (auto it = internalContextMenuActions.constBegin(); it != internalContextMenuActions.constEnd(); ++it) {
@@ -500,6 +531,21 @@ std::vector<QAction *> BottomBarContentsContainer::contextActionsFor(const KFile
             }
         }
     }
+
+    auto separator = new QAction(m_internalContextMenu.get());
+    separator->setSeparator(true);
+    contextActions.emplace_back(separator);
+
+    // Add "Invert Selection" and "Select All" at the very end for better usability while in selection mode.
+    // Design-wise this decision is slightly questionable because the other actions in the bar apply to the selected items while
+    // the "select" actions apply to the view instead but we decided that there are more benefits than drawbacks to this.
+    auto invertSelectionAction = m_actionCollection->action(QStringLiteral("invert_selection"));
+    Q_ASSERT(invertSelectionAction && !internalContextMenuActions.contains(invertSelectionAction));
+    contextActions.emplace_back(invertSelectionAction);
+    auto selectAllAction = m_actionCollection->action(KStandardAction::name(KStandardAction::SelectAll));
+    Q_ASSERT(selectAllAction && !internalContextMenuActions.contains(selectAllAction));
+    contextActions.emplace_back(selectAllAction);
+
     return contextActions;
 }
 
@@ -516,10 +562,8 @@ int BottomBarContentsContainer::unusedSpace() const
         }
         sumOfPreferredWidths += m_layout->itemAt(i)->sizeHint().width() + m_layout->spacing();
     }
-    Q_ASSERT(qobject_cast<BottomBar *>(parentWidget()->parentWidget()->parentWidget()));
-    const int totalBarWidth = parentWidget()->parentWidget()->parentWidget()->width();
-    return totalBarWidth - sumOfPreferredWidths - 20; // We consider all space used when there are only 20 pixels left
-                                                      // so there is some room to breath and not too much wonkyness while resizing.
+    return m_barWidth - sumOfPreferredWidths - 20; // We consider all space used when there are only 20 pixels left
+                                                   // so there is some room to breath and not too much wonkyness while resizing.
 }
 
 void BottomBarContentsContainer::updateExplanatoryLabelVisibility()
@@ -534,8 +578,8 @@ void BottomBarContentsContainer::updateExplanatoryLabelVisibility()
         m_explanatoryLabel->setVisible(unusedSpace() > m_explanatoryLabel->sizeHint().width() + 20);
     }
 }
-
-void BottomBarContentsContainer::updateMainActionButton(const KFileItemList& selection)
+// clang-format off
+void BottomBarContentsContainer::updateMainActionButton(const KFileItemList& selectedItems)
 {
     if (!m_mainAction.widget()) {
         return;
@@ -543,45 +587,69 @@ void BottomBarContentsContainer::updateMainActionButton(const KFileItemList& sel
     Q_ASSERT(qobject_cast<QAbstractButton *>(m_mainAction.widget()));
 
     // Users are nudged towards selecting items by having the button disabled when nothing is selected.
-    m_mainAction.widget()->setEnabled(selection.count() > 0 && m_mainAction.action()->isEnabled());
+    m_mainAction.widget()->setEnabled(selectedItems.count() > 0 && m_mainAction.action()->isEnabled());
     QFontMetrics fontMetrics = m_mainAction.widget()->fontMetrics();
 
     QString buttonText;
     switch (m_contents) {
     case BottomBar::CopyContents:
-        buttonText = i18ncp("@action A more elaborate and clearly worded version of the Copy action",
-                            "Copy %2 to the Clipboard", "Copy %2 to the Clipboard", selection.count(),
-                            fileItemListToString(selection, fontMetrics.averageCharWidth() * 20, fontMetrics));
+        // i18n: A more elaborate and clearly worded version of the Copy action
+        // %2 is a textual representation of the currently selected files or folders. This can be the name of
+        // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
+        // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
+        // and a fallback will be used.
+        buttonText = i18ncp("@action", "Copy %2 to the Clipboard", "Copy %2 to the Clipboard", selectedItems.count(), fileItemListToString(selectedItems, fontMetrics.averageCharWidth() * 20, fontMetrics));
+        // All these long lines can not be broken up with line breaks becaue the i18n call should be completely
+        // in the line following the "i18n:" comment without any line breaks within the i18n call
+        // or the comment might not be correctly extracted. See: https://commits.kde.org/kxmlgui/a31135046e1b3335b5d7bbbe6aa9a883ce3284c1
         break;
     case BottomBar::CopyLocationContents:
-        buttonText = i18ncp("@action A more elaborate and clearly worded version of the Copy Location action",
-                            "Copy the Location of %2 to the Clipboard", "Copy the Location of %2 to the Clipboard", selection.count(),
-                            fileItemListToString(selection, fontMetrics.averageCharWidth() * 20, fontMetrics));
+        // i18n: A more elaborate and clearly worded version of the Copy Location action
+        // %2 is a textual representation of the currently selected files or folders. This can be the name of
+        // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
+        // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
+        // and a fallback will be used.
+        buttonText = i18ncp("@action", "Copy the Location of %2 to the Clipboard", "Copy the Location of %2 to the Clipboard", selectedItems.count(), fileItemListToString(selectedItems, fontMetrics.averageCharWidth() * 20, fontMetrics));
         break;
     case BottomBar::CutContents:
-        buttonText = i18ncp("@action A more elaborate and clearly worded version of the Cut action",
-                            "Cut %2 to the Clipboard", "Cut %2 to the Clipboard", selection.count(),
-                            fileItemListToString(selection, fontMetrics.averageCharWidth() * 20, fontMetrics));
+        // i18n: A more elaborate and clearly worded version of the Cut action
+        // %2 is a textual representation of the currently selected files or folders. This can be the name of
+        // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
+        // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
+        // and a fallback will be used.
+        buttonText = i18ncp("@action", "Cut %2 to the Clipboard", "Cut %2 to the Clipboard", selectedItems.count(), fileItemListToString(selectedItems, fontMetrics.averageCharWidth() * 20, fontMetrics));
         break;
     case BottomBar::DeleteContents:
-        buttonText = i18ncp("@action A more elaborate and clearly worded version of the Delete action",
-                            "Permanently Delete %2", "Permanently Delete %2", selection.count(),
-                            fileItemListToString(selection, fontMetrics.averageCharWidth() * 20, fontMetrics));
+        // i18n: A more elaborate and clearly worded version of the Delete action
+        // %2 is a textual representation of the currently selected files or folders. This can be the name of
+        // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
+        // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
+        // and a fallback will be used.
+        buttonText = i18ncp("@action", "Permanently Delete %2", "Permanently Delete %2", selectedItems.count(), fileItemListToString(selectedItems, fontMetrics.averageCharWidth() * 20, fontMetrics));
         break;
     case BottomBar::DuplicateContents:
-        buttonText = i18ncp("@action A more elaborate and clearly worded version of the Duplicate action",
-                            "Duplicate %2", "Duplicate %2", selection.count(),
-                            fileItemListToString(selection, fontMetrics.averageCharWidth() * 20, fontMetrics));
+        // i18n: A more elaborate and clearly worded version of the Duplicate action
+        // %2 is a textual representation of the currently selected files or folders. This can be the name of
+        // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
+        // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
+        // and a fallback will be used.
+        buttonText = i18ncp("@action", "Duplicate %2", "Duplicate %2", selectedItems.count(), fileItemListToString(selectedItems, fontMetrics.averageCharWidth() * 20, fontMetrics));
         break;
     case BottomBar::MoveToTrashContents:
-        buttonText = i18ncp("@action A more elaborate and clearly worded version of the Trash action",
-                            "Move %2 to the Trash", "Move %2 to the Trash", selection.count(),
-                            fileItemListToString(selection, fontMetrics.averageCharWidth() * 20, fontMetrics));
+        // i18n: A more elaborate and clearly worded version of the Trash action
+        // %2 is a textual representation of the currently selected files or folders. This can be the name of
+        // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
+        // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
+        // and a fallback will be used.
+        buttonText = i18ncp("@action", "Move %2 to the Trash", "Move %2 to the Trash", selectedItems.count(), fileItemListToString(selectedItems, fontMetrics.averageCharWidth() * 20, fontMetrics));
         break;
     case BottomBar::RenameContents:
-        buttonText = i18ncp("@action A more elaborate and clearly worded version of the Rename action",
-                            "Rename %2", "Rename %2", selection.count(),
-                            fileItemListToString(selection, fontMetrics.averageCharWidth() * 20, fontMetrics));
+        // i18n: A more elaborate and clearly worded version of the Rename action
+        // %2 is a textual representation of the currently selected files or folders. This can be the name of
+        // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
+        // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
+        // and a fallback will be used.
+        buttonText = i18ncp("@action", "Rename %2", "Rename %2", selectedItems.count(), fileItemListToString(selectedItems, fontMetrics.averageCharWidth() * 20, fontMetrics));
         break;
     default:
         return;
@@ -593,3 +661,6 @@ void BottomBarContentsContainer::updateMainActionButton(const KFileItemList& sel
         updateExplanatoryLabelVisibility();
     }
 }
+// clang-format on
+
+#include "moc_bottombarcontentscontainer.cpp"