Commit c1865ba8 authored by Derek Christ's avatar Derek Christ Committed by Nate Graham
Browse files

Fix bug 434513: Item not selected after creating it

Fix bug 434513 where a newly created item is not selected right after
creating it like in Dolphin.
Also, when items are moved around on the desktop, they don't lose their
selection when they are dropped anymore.

BUG: 434513
parent 08b145aa
......@@ -1209,6 +1209,12 @@ FocusScope {
previewPlugins: plasmoid.configuration.previewPlugins
appletInterface: plasmoid
onSelectionChanged: {
if (usedByContainment) {
gridView.currentIndex = positioner.firstSelectedItem();
}
}
onListingCompleted: {
if (!gridView.model && plasmoid.expanded) {
gridView.model = positioner;
......@@ -1236,6 +1242,7 @@ FocusScope {
var row = -1;
var from = -1;
var to = -1;
let noItemMoved = true;
for (var i = 0; i < urls.length; i++) {
from = positioner.indexForUrl(urls[i]);
......@@ -1276,13 +1283,21 @@ FocusScope {
}
}
if (!noItemMoved) {
// Do not clear the selection when the items were moved
// right to the place where they were. Otherwise the
// call of Positioner::move() will not reselect them.
// Also, this should only be called after filling the
// moves list.
dir.clearSelection();
}
if (moves.length) {
positioner.move(moves);
gridView.forceLayout();
}
previouslySelectedItemIndex = -1;
dir.clearSelection();
}
}
......
......@@ -233,6 +233,7 @@ FolderModel::FolderModel(QObject *parent)
});
m_selectionModel = new QItemSelectionModel(this, this);
connect(m_selectionModel, &QItemSelectionModel::selectionChanged, this, &FolderModel::changeSelection);
connect(m_selectionModel, &QItemSelectionModel::selectionChanged, this, &FolderModel::selectionChanged);
setSourceModel(m_dirModel);
......@@ -1311,7 +1312,7 @@ void FolderModel::dropCwd(QObject *dropEvent)
}
}
void FolderModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void FolderModel::changeSelection(const QItemSelection &selected, const QItemSelection &deselected)
{
QModelIndexList indices = selected.indexes();
indices.append(deselected.indexes());
......
......@@ -268,6 +268,7 @@ Q_SIGNALS:
void requestRename() const;
void move(int x, int y, QList<QUrl> urls);
void popupMenuAboutToShow(KIO::DropJob *dropJob, QMimeData *mimeData, int x, int y);
void selectionChanged() const;
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
......@@ -279,7 +280,7 @@ private Q_SLOTS:
void dirListFailed(const QString &error);
void statResult(KJob *job);
void evictFromIsDirCache(const KFileItemList &items);
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void changeSelection(const QItemSelection &selected, const QItemSelection &deselected);
void pasteTo();
void moveSelectedToTrash();
void emptyTrashBin();
......
......@@ -134,6 +134,23 @@ int Positioner::map(int row) const
return row;
}
int Positioner::firstSelectedItem() const
{
int index = -1;
int min = std::numeric_limits<int>::max();
for (int i = 0; i < m_folderModel->rowCount(); i++) {
if (m_sourceToProxy.value(i) < min) {
if (m_folderModel->data(m_folderModel->index(i, 0), FolderModel::SelectedRole).toBool()) {
min = m_sourceToProxy.value(i);
index = min;
}
}
}
return index;
}
int Positioner::nearestItem(int currentIndex, Qt::ArrowType direction)
{
if (!m_enabled || currentIndex >= rowCount()) {
......@@ -355,7 +372,7 @@ void Positioner::move(const QVariantList &moves)
QVector<int> fromIndices;
QVector<int> toIndices;
QVector<int> sourceRows;
QVariantList sourceRows;
for (int i = 0; i < moves.count(); ++i) {
const int isFrom = (i % 2 == 0);
......@@ -377,7 +394,7 @@ void Positioner::move(const QVariantList &moves)
for (int i = 0; i < fromIndices.count(); ++i) {
const int from = fromIndices[i];
int to = toIndices[i];
const int sourceRow = sourceRows[i];
const int sourceRow = sourceRows[i].toInt();
if (sourceRow == -1 || from == to) {
continue;
......@@ -433,6 +450,8 @@ void Positioner::move(const QVariantList &moves)
endRemoveRows();
}
m_folderModel->updateSelection(sourceRows, true);
m_updatePositionsTimer->start();
}
......
......@@ -43,6 +43,7 @@ public:
Q_INVOKABLE int map(int row) const;
Q_INVOKABLE int nearestItem(int currentIndex, Qt::ArrowType direction);
Q_INVOKABLE int firstSelectedItem() const;
Q_INVOKABLE bool isBlank(int row) const;
Q_INVOKABLE int indexForUrl(const QUrl &url) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment