Better behavior when manipulating batch messages with dynamic SQL selection.

This commit is contained in:
Martin Rotter 2016-09-16 08:09:38 +02:00
parent b46dce2e49
commit 674e089f93
2 changed files with 42 additions and 25 deletions

View File

@ -642,8 +642,8 @@ void FormMain::createConnections() {
SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(deleteSelectedMessages()));
connect(m_ui->m_actionMarkSelectedMessagesAsRead,
SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(markSelectedMessagesRead()));
connect(m_ui->m_actionMarkSelectedMessagesAsUnread,
SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(markSelectedMessagesUnread()));
connect(m_ui->m_actionMarkSelectedMessagesAsUnread, &QAction::triggered,
tabWidget()->feedMessageViewer()->messagesView(), &MessagesView::markSelectedMessagesUnread);
connect(m_ui->m_actionOpenSelectedSourceArticlesExternally,
SIGNAL(triggered()), tabWidget()->feedMessageViewer()->messagesView(), SLOT(openSelectedSourceMessagesExternally()));
connect(m_ui->m_actionOpenSelectedMessagesInternally,

View File

@ -82,6 +82,10 @@ void MessagesView::reloadSelections(bool mark_current_index_read) {
// Now, we must find the same previously focused message.
if (selected_message.m_id > 0) {
if (m_proxyModel->rowCount() == 0) {
current_index = QModelIndex();
}
else {
for (int i = 0; i < m_proxyModel->rowCount(); i++) {
QModelIndex msg_idx = m_proxyModel->index(i, MSG_DB_TITLE_INDEX);
Message msg = m_sourceModel->messageAt(m_proxyModel->mapToSource(msg_idx).row());
@ -96,6 +100,7 @@ void MessagesView::reloadSelections(bool mark_current_index_read) {
}
}
}
}
if (current_index.isValid()) {
if (!mark_current_index_read) {
@ -340,6 +345,7 @@ void MessagesView::setSelectedMessagesReadStatus(RootItem::ReadStatus read) {
selected_indexes = m_proxyModel->mapListFromSource(mapped_indexes, true);
current_index = m_proxyModel->mapFromSource(m_sourceModel->index(mapped_current_index.row(), mapped_current_index.column()));
if (current_index.isValid()) {
if (read == RootItem::Unread) {
// User selected to mark some messages as unread, if one
// of them will be marked as current, then it will be read again.
@ -351,6 +357,10 @@ void MessagesView::setSelectedMessagesReadStatus(RootItem::ReadStatus read) {
reselectIndexes(selected_indexes);
m_batchUnreadSwitch = false;
}
else {
emit currentMessageRemoved();
}
}
void MessagesView::deleteSelectedMessages() {
const QModelIndex current_index = selectionModel()->currentIndex();
@ -425,12 +435,19 @@ void MessagesView::switchSelectedMessagesImportance() {
current_index = m_proxyModel->mapFromSource(m_sourceModel->index(mapped_current_index.row(),
mapped_current_index.column()));
if (current_index.isValid()) {
m_batchUnreadSwitch = true;
setCurrentIndex(current_index);
scrollTo(current_index);
reselectIndexes(selected_indexes);
setCurrentIndex(current_index);
reselectIndexes(QModelIndexList() << selected_indexes);
m_batchUnreadSwitch = false;
}
else {
// Messages were probably removed from the model, nothing can
// be selected and no message can be displayed.
emit currentMessageRemoved();
}
}
void MessagesView::reselectIndexes(const QModelIndexList &indexes) {
if (indexes.size() < RESELECT_MESSAGE_THRESSHOLD) {