]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Fix dismiss button in selection mode paste bar
[dolphin.git] / src / views / dolphinview.cpp
index 0566dbf842b955f4d4a9d82534088d202c0c33f3..4e5f4c7863a2023555f60b71270ad123db2252bc 100644 (file)
@@ -40,7 +40,6 @@
 #include <KIO/JobUiDelegate>
 #include <KIO/Paste>
 #include <KIO/PasteJob>
-#include <KIO/PreviewJob>
 #include <KIO/RenameFileDialog>
 #include <KJobWidgets>
 #include <KLocalizedString>
@@ -48,6 +47,8 @@
 #include <KProtocolManager>
 #include <KUrlMimeData>
 
+#include <kwidgetsaddons_version.h>
+
 #include <QAbstractItemView>
 #include <QActionGroup>
 #include <QApplication>
@@ -111,7 +112,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
 
     m_model = new KFileItemModel(this);
     m_view = new DolphinItemListView();
-    m_view->setEnabledSelectionToggles(GeneralSettings::showSelectionToggle());
+    m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting);
     m_view->setVisibleRoles({"text"});
     applyModeToView();
 
@@ -173,7 +174,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
     connect(controller, &KItemListController::increaseZoom, this, &DolphinView::slotIncreaseZoom);
     connect(controller, &KItemListController::decreaseZoom, this, &DolphinView::slotDecreaseZoom);
     connect(controller, &KItemListController::swipeUp, this, &DolphinView::slotSwipeUp);
-    connect(controller, &KItemListController::selectionModeRequested, this, &DolphinView::selectionModeRequested);
+    connect(controller, &KItemListController::selectionModeChangeRequested, this, &DolphinView::selectionModeChangeRequested);
 
     connect(m_model, &KFileItemModel::directoryLoadingStarted,       this, &DolphinView::slotDirectoryLoadingStarted);
     connect(m_model, &KFileItemModel::directoryLoadingCompleted,     this, &DolphinView::slotDirectoryLoadingCompleted);
@@ -235,6 +236,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
 
 DolphinView::~DolphinView()
 {
+    disconnect(m_container->controller(), &KItemListController::modelChanged, this, &DolphinView::slotModelChanged);
 }
 
 QUrl DolphinView::url() const
@@ -283,17 +285,19 @@ DolphinView::Mode DolphinView::viewMode() const
     return m_mode;
 }
 
-void DolphinView::setSelectionMode(const bool enabled)
+void DolphinView::setSelectionModeEnabled(const bool enabled)
 {
     if (enabled) {
         m_proxyStyle = std::make_unique<SelectionMode::SingleClickSelectionProxyStyle>();
         setStyle(m_proxyStyle.get());
         m_view->setStyle(m_proxyStyle.get());
+        m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::False);
     } else {
         setStyle(QApplication::style());
         m_view->setStyle(QApplication::style());
+        m_view->setEnabledSelectionToggles(DolphinItemListView::SelectionTogglesEnabled::FollowSetting);
     }
-    m_container->controller()->setSelectionMode(enabled);
+    m_container->controller()->setSelectionModeEnabled(enabled);
 }
 
 bool DolphinView::selectionMode() const
@@ -1015,11 +1019,19 @@ void DolphinView::slotItemsActivated(const KItemSet &indexes)
 
     if (indexes.count() > 5) {
         QString question = i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes.count());
+#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
+        const int answer = KMessageBox::warningTwoActions(this, question, {},
+#else
         const int answer = KMessageBox::warningYesNo(this, question, {},
+#endif
                                                      KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes.count()),
                                                               QStringLiteral("document-open")),
                                                      KStandardGuiItem::cancel());
+#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
+        if (answer != KMessageBox::PrimaryAction) {
+#else
         if (answer != KMessageBox::Yes) {
+#endif
             return;
         }
     }
@@ -1365,7 +1377,7 @@ void DolphinView::slotItemCreated(const QUrl& url)
 
 void DolphinView::slotJobResult(KJob *job)
 {
-    if (job->error()) {
+    if (job->error() && job->error() != KIO::ERR_USER_CANCELED) {
         Q_EMIT errorMessage(job->errorString());
     }
     if (!m_selectedUrls.isEmpty()) {
@@ -1488,6 +1500,16 @@ bool DolphinView::itemsExpandable() const
     return m_mode == DetailsView;
 }
 
+bool DolphinView::isExpanded(const KFileItem& item) const
+{
+    Q_ASSERT(item.isDir());
+    Q_ASSERT(items().contains(item));
+    if (!itemsExpandable()) {
+        return false;
+    }
+    return m_model->isExpanded(m_model->index(item));
+}
+
 void DolphinView::restoreState(QDataStream& stream)
 {
     // Read the version number of the view state and check if the version is supported.
@@ -1867,7 +1889,11 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
                 KGuiItem yesGuiItem(KStandardGuiItem::yes());
                 yesGuiItem.setText(i18nc("@action:button", "Rename and Hide"));
 
+#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
+                const auto code = KMessageBox::questionTwoActions(this,
+#else
                 const auto code = KMessageBox::questionYesNo(this,
+#endif
                                                              oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
                                                                                      "Do you still want to rename it?")
                                                                               : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
@@ -1878,7 +1904,11 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
                                                              QStringLiteral("ConfirmHide")
                                                             );
 
+#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
+                if (code == KMessageBox::SecondaryAction) {
+#else
                 if (code == KMessageBox::No) {
+#endif
                    return;
                 }
             }