improve selection handling, particularly when multiple/all articles are selected

This commit is contained in:
Martin Rotter 2021-10-13 08:01:14 +02:00
parent 6a3b0edba8
commit ef4f99bb77
3 changed files with 26 additions and 18 deletions

View File

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url> <url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="4.0.3" date="2021-10-08"/> <release version="4.0.3" date="2021-10-13"/>
</releases> </releases>
<content_rating type="oars-1.0"> <content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute> <content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -410,7 +410,7 @@ void MessagesView::selectionChanged(const QItemSelection& selected, const QItemS
<< current_index << "', source '" << current_index << "', source '"
<< mapped_current_index << "'."; << mapped_current_index << "'.";
if (mapped_current_index.isValid() && selected_rows.count() > 0) { if (mapped_current_index.isValid() && selected_rows.count() == 1) {
Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()); Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row());
// Set this message as read only if current item // Set this message as read only if current item
@ -509,19 +509,18 @@ void MessagesView::markSelectedMessagesUnread() {
} }
void MessagesView::setSelectedMessagesReadStatus(RootItem::ReadStatus read) { void MessagesView::setSelectedMessagesReadStatus(RootItem::ReadStatus read) {
QModelIndex current_index = selectionModel()->currentIndex(); const QModelIndexList selected_indexes = selectionModel()->selectedRows();
if (!current_index.isValid()) { if (selected_indexes.isEmpty()) {
return; return;
} }
QModelIndexList selected_indexes = selectionModel()->selectedRows();
const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes); const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->setBatchMessagesRead(mapped_indexes, read); m_sourceModel->setBatchMessagesRead(mapped_indexes, read);
current_index = m_proxyModel->index(current_index.row(), current_index.column()); QModelIndex current_index = selectionModel()->currentIndex();
if (current_index.isValid()) { if (current_index.isValid() && selected_indexes.size() == 1) {
emit currentMessageChanged(m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()), m_sourceModel->loadedItem()); emit currentMessageChanged(m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()), m_sourceModel->loadedItem());
} }
else { else {
@ -530,19 +529,20 @@ void MessagesView::setSelectedMessagesReadStatus(RootItem::ReadStatus read) {
} }
void MessagesView::deleteSelectedMessages() { void MessagesView::deleteSelectedMessages() {
QModelIndex current_index = selectionModel()->currentIndex(); const QModelIndexList selected_indexes = selectionModel()->selectedRows();
if (!current_index.isValid()) { if (selected_indexes.isEmpty()) {
return; return;
} }
const QModelIndexList selected_indexes = selectionModel()->selectedRows();
const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes); const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->setBatchMessagesDeleted(mapped_indexes); m_sourceModel->setBatchMessagesDeleted(mapped_indexes);
current_index = moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier); QModelIndex current_index = currentIndex().isValid()
? moveCursor(QAbstractItemView::CursorAction::MoveDown, Qt::KeyboardModifier::NoModifier)
: currentIndex();
if (current_index.isValid()) { if (current_index.isValid() && selected_indexes.size() == 1) {
setCurrentIndex(current_index); setCurrentIndex(current_index);
} }
else { else {
@ -572,19 +572,18 @@ void MessagesView::restoreSelectedMessages() {
} }
void MessagesView::switchSelectedMessagesImportance() { void MessagesView::switchSelectedMessagesImportance() {
QModelIndex current_index = selectionModel()->currentIndex(); const QModelIndexList selected_indexes = selectionModel()->selectedRows();
if (!current_index.isValid()) { if (selected_indexes.isEmpty()) {
return; return;
} }
QModelIndexList selected_indexes = selectionModel()->selectedRows();
const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes); const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->switchBatchMessageImportance(mapped_indexes); m_sourceModel->switchBatchMessageImportance(mapped_indexes);
current_index = m_proxyModel->index(current_index.row(), current_index.column()); QModelIndex current_index = selectionModel()->currentIndex();
if (current_index.isValid()) { if (current_index.isValid() && selected_indexes.size() == 1) {
emit currentMessageChanged(m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()), m_sourceModel->loadedItem()); emit currentMessageChanged(m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()), m_sourceModel->loadedItem());
} }
else { else {

View File

@ -194,7 +194,16 @@ void Application::loadDynamicShortcuts() {
void Application::showPolls() const { void Application::showPolls() const {
if(isFirstRunCurrentVersion()) { if(isFirstRunCurrentVersion()) {
qApp->showGuiMessage(Notification::Event::NewAppVersionAvailable,
tr("RSS Guard has Discord server!"),
tr("You can visit it now! Click me!"),
QSystemTrayIcon::MessageIcon::Information,
true,
{},
tr("Go to Discord!"),
[this]() {
web()->openUrlInExternalBrowser(QSL("https://discord.gg/7xbVMPPNqH")); web()->openUrlInExternalBrowser(QSL("https://discord.gg/7xbVMPPNqH"));
});
} }
} }