diff --git a/model/entrymodel.cpp b/model/entrymodel.cpp index 4ba0459..c54237f 100644 --- a/model/entrymodel.cpp +++ b/model/entrymodel.cpp @@ -453,10 +453,9 @@ bool EntryModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int co return push(make_unique(this, sourceParent, sourceRow, count, destinationParent, destinationChild)); } #endif - // check validation of specified arguments - if (!sourceParent.isValid() || !destinationParent.isValid() || sourceRow < 0 || count <= 0 - || entry(sourceParent)->type() != EntryType::Node // source and destination parent entries - || entry(destinationParent)->type() != EntryType::Node) { // need to be node entries + // check validation of specified arguments: source and destination parent entries need to be node entries + if (!sourceParent.isValid() || !destinationParent.isValid() || sourceRow < 0 || count <= 0 || entry(sourceParent)->type() != EntryType::Node // + || entry(destinationParent)->type() != EntryType::Node) { return false; } // determine the source parent entry and dest parent entry as node entries @@ -470,11 +469,12 @@ bool EntryModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int co } // do not move a row to one of its own children! -> check before for (int index = 0; index < count; ++index) { - Entry *toMove = srcParentEntry->children()[static_cast(sourceRow + index)]; - if (toMove->type() == EntryType::Node) { - if (destParentEntry->isIndirectChildOf(static_cast(toMove))) { - return false; - } + Entry *const toMove = srcParentEntry->children()[static_cast(sourceRow + index)]; + if (toMove->type() != EntryType::Node) { + continue; + } + if (toMove == destParentEntry || destParentEntry->isIndirectChildOf(static_cast(toMove))) { + return false; } } // actually perform the move operation diff --git a/model/entrymodel.h b/model/entrymodel.h index c5210ce..3182886 100644 --- a/model/entrymodel.h +++ b/model/entrymodel.h @@ -54,7 +54,7 @@ public: QModelIndex parent(const QModelIndex &child) const; bool hasChildren(const QModelIndex &parent) const; Q_INVOKABLE bool isNode(const QModelIndex &parent) const; - QVariant data(const QModelIndex &index, int role) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QMap itemData(const QModelIndex &index) const; bool setData(const QModelIndex &index, const QVariant &value, int role); bool setItemData(const QModelIndex &index, const QMap &roles); diff --git a/qml/EntriesPage.qml b/qml/EntriesPage.qml index 0b221f7..ede955a 100644 --- a/qml/EntriesPage.qml +++ b/qml/EntriesPage.qml @@ -22,7 +22,16 @@ Kirigami.ScrollablePage { iconName: "edit-paste" text: qsTr("Paste account") enabled: nativeInterface.canPaste - onTriggered: nativeInterface.pasteEntries(rootIndex) + onTriggered: { + var pastedEntries = nativeInterface.pasteEntries(rootIndex) + if (pastedEntries.length < 1) { + showPassiveNotification( + qsTr("Unable to paste the entries here")) + return + } + var joinedEntryNames = pastedEntries.join(", ") + showPassiveNotification(qsTr("Pasted ") + joinedEntryNames) + } } right: Kirigami.Action { iconName: "folder-add" diff --git a/quickgui/controller.cpp b/quickgui/controller.cpp index 21d5d73..2652d0b 100644 --- a/quickgui/controller.cpp +++ b/quickgui/controller.cpp @@ -113,28 +113,29 @@ void Controller::save() } } -bool Controller::pasteEntries(const QModelIndex &destinationParent, int row) +QStringList Controller::pasteEntries(const QModelIndex &destinationParent, int row) { if (m_cutEntries.isEmpty() || !m_entryModel.isNode(destinationParent)) { - return false; + return QStringList(); } if (row < 0) { row = m_entryModel.rowCount(destinationParent); } - bool result = true; + + QStringList successfullyMovedEntries; + successfullyMovedEntries.reserve(m_cutEntries.size()); for (const QPersistentModelIndex &cutIndex : m_cutEntries) { if (m_entryModel.moveRows(cutIndex.parent(), cutIndex.row(), 1, destinationParent, row)) { + successfullyMovedEntries << m_entryModel.data(m_entryModel.index(row, 0, destinationParent)).toString(); ++row; - } else { - result = false; } } // clear the cut entries m_cutEntries.clear(); emit cutEntriesChanged(m_cutEntries); - return true; + return successfullyMovedEntries; } void Controller::resetFileStatus() diff --git a/quickgui/controller.h b/quickgui/controller.h index 990f401..962621b 100644 --- a/quickgui/controller.h +++ b/quickgui/controller.h @@ -44,7 +44,7 @@ public: void setCutEntries(const QList &cutEntries); QString currentAccountName() const; Q_INVOKABLE void cutEntry(const QModelIndex &entryIndex); - Q_INVOKABLE bool pasteEntries(const QModelIndex &destinationParent, int row = -1); + Q_INVOKABLE QStringList pasteEntries(const QModelIndex &destinationParent, int row = -1); bool canPaste() const; public slots: