#include "dolphinview.h"
+#include "dolphin_compactmodesettings.h"
#include "dolphin_detailsmodesettings.h"
+#include "dolphin_iconsmodesettings.h"
#include "dolphin_generalsettings.h"
#include "dolphinitemlistview.h"
#include "dolphinnewfilemenuobserver.h"
#include "kitemviews/kitemlistcontroller.h"
#include "kitemviews/kitemlistheader.h"
#include "kitemviews/kitemlistselectionmanager.h"
+#include "kitemviews/private/kitemlistroleeditor.h"
#include "versioncontrol/versioncontrolobserver.h"
#include "viewproperties.h"
#include "views/tooltips/tooltipmanager.h"
#include <KProtocolManager>
#include <QAbstractItemView>
+#include <QActionGroup>
#include <QApplication>
#include <QClipboard>
#include <QDropEvent>
m_markFirstNewlySelectedItemAsCurrent(false),
m_versionControlObserver(nullptr),
m_twoClicksRenamingTimer(nullptr),
- m_placeholderLabel(nullptr)
+ m_placeholderLabel(nullptr),
+ m_showLoadingPlaceholderTimer(nullptr)
{
m_topLayout = new QVBoxLayout(this);
m_topLayout->setSpacing(0);
connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); });
connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); });
+ m_showLoadingPlaceholderTimer = new QTimer(this);
+ m_showLoadingPlaceholderTimer->setInterval(500);
+ m_showLoadingPlaceholderTimer->setSingleShot(true);
+ connect(m_showLoadingPlaceholderTimer, &QTimer::timeout, this, &DolphinView::showLoadingPlaceholder);
+
// Show some placeholder text for empty folders
// This is made using a heavily-modified QLabel rather than a KTitleWidget
// because KTitleWidget can't be told to turn off mouse-selectable text
connect(m_model, &KFileItemModel::errorMessage, this, &DolphinView::errorMessage);
connect(m_model, &KFileItemModel::directoryRedirection, this, &DolphinView::slotDirectoryRedirection);
connect(m_model, &KFileItemModel::urlIsFileError, this, &DolphinView::urlIsFileError);
+ connect(m_model, &KFileItemModel::fileItemsChanged, this, &DolphinView::fileItemsChanged);
connect(this, &DolphinView::itemCountChanged,
this, &DolphinView::updatePlaceholderLabel);
if (items.count() == 1 && GeneralSettings::renameInline()) {
const int index = m_model->index(items.first());
- m_view->editRole(index, "text");
- hideToolTip();
+ QMetaObject::Connection * const connection = new QMetaObject::Connection;
+ *connection = connect(m_view, &KItemListView::scrollingStopped, this, [=](){
+ QObject::disconnect(*connection);
+ delete connection;
+
+ m_view->editRole(index, "text");
+
+ hideToolTip();
+
+ connect(m_view, &DolphinItemListView::roleEditingFinished,
+ this, &DolphinView::slotRoleEditingFinished);
+ });
+ m_view->scrollToItem(index);
- connect(m_view, &DolphinItemListView::roleEditingFinished,
- this, &DolphinView::slotRoleEditingFinished);
} else {
KIO::RenameFileDialog* dialog = new KIO::RenameFileDialog(items, this);
connect(dialog, &KIO::RenameFileDialog::renamingFinished,
void DolphinView::resetZoomLevel()
{
- ViewModeSettings::ViewMode mode;
-
+ // TODO : Switch to using ViewModeSettings after MR #256 is merged
+ int defaultIconSize = KIconLoader::SizeSmall;
switch (m_mode) {
- case IconsView: mode = ViewModeSettings::IconsMode; break;
- case CompactView: mode = ViewModeSettings::CompactMode; break;
- case DetailsView: mode = ViewModeSettings::DetailsMode; break;
+ case IconsView:
+ IconsModeSettings::self()->useDefaults(true);
+ defaultIconSize = IconsModeSettings::iconSize();
+ IconsModeSettings::self()->useDefaults(false);
+ break;
+ case DetailsView:
+ DetailsModeSettings::self()->useDefaults(true);
+ defaultIconSize = DetailsModeSettings::iconSize();
+ DetailsModeSettings::self()->useDefaults(false);
+ break;
+ case CompactView:
+ CompactModeSettings::self()->useDefaults(true);
+ defaultIconSize = CompactModeSettings::iconSize();
+ CompactModeSettings::self()->useDefaults(false);
+ break;
+ default:
+ Q_ASSERT(false);
+ break;
}
- const ViewModeSettings settings(mode);
- const QSize iconSize = QSize(settings.iconSize(), settings.iconSize());
- setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(iconSize));
+
+ setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(QSize(defaultIconSize, defaultIconSize)));
}
void DolphinView::observeCreatedItem(const QUrl& url)
disconnect(m_view, &DolphinItemListView::roleEditingFinished,
this, &DolphinView::slotRoleEditingFinished);
- if (index < 0 || index >= m_model->count()) {
+ const KFileItemList items = selectedItems();
+ if (items.count() != 1) {
return;
}
if (role == "text") {
- const KFileItem oldItem = m_model->fileItem(index);
- const QString newName = value.toString();
+ const KFileItem oldItem = items.first();
+ const EditResult retVal = value.value<EditResult>();
+ const QString newName = retVal.newName;
if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1Char('.') && newName != QLatin1String("..")) {
const QUrl oldUrl = oldItem.url();
#endif
const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
- if (!newNameExistsAlready) {
+ if (!newNameExistsAlready && m_model->index(oldUrl) == index) {
// Only change the data in the model if no item with the new name
// is in the model yet. If there is an item with the new name
// already, calling KIO::CopyJob will open a dialog
// asking for a new name, and KFileItemModel will update the
// data when the dir lister signals that the file name has changed.
QHash<QByteArray, QVariant> data;
- data.insert(role, value);
+ data.insert(role, retVal.newName);
m_model->setData(index, data);
}
connect(job, &KJob::result, this, &DolphinView::slotRenamingResult);
}
}
+ if (retVal.direction != EditDone) {
+ const short indexShift = retVal.direction == EditNext ? 1 : -1;
+ m_container->controller()->selectionManager()->setSelected(index, 1, KItemListSelectionManager::Deselect);
+ m_container->controller()->selectionManager()->setSelected(index + indexShift, 1,
+ KItemListSelectionManager::Select);
+ renameSelectedItems();
+ }
}
}
Q_EMIT goUpRequested();
}
+void DolphinView::showLoadingPlaceholder()
+{
+ m_placeholderLabel->setText(i18n("Loading..."));
+ m_placeholderLabel->setVisible(true);
+}
+
void DolphinView::updatePlaceholderLabel()
{
- if (m_loading || itemsCount() > 0) {
+ m_showLoadingPlaceholderTimer->stop();
+ if (itemsCount() > 0) {
+ m_placeholderLabel->setVisible(false);
+ return;
+ }
+
+ if (m_loading) {
m_placeholderLabel->setVisible(false);
+ m_showLoadingPlaceholderTimer->start();
return;
}
m_placeholderLabel->setText(i18n("No items matching the filter"));
} else if (m_url.scheme() == QLatin1String("baloosearch") || m_url.scheme() == QLatin1String("filenamesearch")) {
m_placeholderLabel->setText(i18n("No items matching the search"));
- } else if (m_url.scheme() == QLatin1String("trash")) {
+ } else if (m_url.scheme() == QLatin1String("trash") && m_url.path() == QLatin1String("/")) {
m_placeholderLabel->setText(i18n("Trash is empty"));
} else if (m_url.scheme() == QLatin1String("tags")) {
m_placeholderLabel->setText(i18n("No tags"));
m_placeholderLabel->setText(i18n("No shared folders found"));
} else if (m_url.scheme() == QLatin1String("network")) {
m_placeholderLabel->setText(i18n("No relevant network resources found"));
- } else if (m_url.scheme() == QLatin1String("mtp")) {
+ } else if (m_url.scheme() == QLatin1String("mtp") && m_url.path() == QLatin1String("/")) {
m_placeholderLabel->setText(i18n("No MTP-compatible devices found"));
} else if (m_url.scheme() == QLatin1String("bluetooth")) {
m_placeholderLabel->setText(i18n("No Bluetooth devices found"));