diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-04-27 16:23:50 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-04-27 16:24:11 -0400 |
commit | e8f16292d1774ea137145485a63c373df6cb0743 (patch) | |
tree | a48ce933b225113627c74c54904fea76975d6cfc /src/components/channeltabswitcherhandy.cpp | |
parent | db28abaa44813e58503f42fa83dab3f4173505d2 (diff) | |
download | abaddon-portaudio-e8f16292d1774ea137145485a63c373df6cb0743.tar.gz abaddon-portaudio-e8f16292d1774ea137145485a63c373df6cb0743.zip |
add back/forward history to tabs
also lots of reformatting in .cmake because clion is weird and did that for some reason
Diffstat (limited to 'src/components/channeltabswitcherhandy.cpp')
-rw-r--r-- | src/components/channeltabswitcherhandy.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/components/channeltabswitcherhandy.cpp b/src/components/channeltabswitcherhandy.cpp index bb28272..9abceed 100644 --- a/src/components/channeltabswitcherhandy.cpp +++ b/src/components/channeltabswitcherhandy.cpp @@ -57,6 +57,7 @@ void ChannelTabSwitcherHandy::AddChannelTab(Snowflake id) { CheckUnread(id); CheckPageIcon(page, *channel); + AppendPageHistory(page, id); } void ChannelTabSwitcherHandy::ReplaceActiveTab(Snowflake id) { @@ -78,6 +79,7 @@ void ChannelTabSwitcherHandy::ReplaceActiveTab(Snowflake id) { CheckUnread(id); CheckPageIcon(page, *channel); + AppendPageHistory(page, id); } } @@ -103,6 +105,14 @@ void ChannelTabSwitcherHandy::UseTabsState(const TabsState &state) { } } +void ChannelTabSwitcherHandy::GoBackOnCurrent() { + AdvanceOnCurrent(-1); +} + +void ChannelTabSwitcherHandy::GoForwardOnCurrent() { + AdvanceOnCurrent(1); +} + void ChannelTabSwitcherHandy::CheckUnread(Snowflake id) { if (auto it = m_pages.find(id); it != m_pages.end()) { hdy_tab_page_set_needs_attention(it->second, Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id) > -1); @@ -143,6 +153,41 @@ void ChannelTabSwitcherHandy::CheckPageIcon(HdyTabPage *page, const ChannelData hdy_tab_page_set_icon(page, nullptr); } +void ChannelTabSwitcherHandy::AppendPageHistory(HdyTabPage *page, Snowflake channel) { + auto it = m_page_history.find(page); + if (it == m_page_history.end()) { + m_page_history[page] = PageHistory { { channel }, 0 }; + return; + } + + // drop everything beyond current position + it->second.Visited.resize(++it->second.CurrentVisitedIndex); + it->second.Visited.push_back(channel); +} + +void ChannelTabSwitcherHandy::AdvanceOnCurrent(size_t by) { + auto *current = hdy_tab_view_get_selected_page(m_tab_view); + if (current == nullptr) return; + auto history = m_page_history.find(current); + if (history == m_page_history.end()) return; + if (by + history->second.CurrentVisitedIndex < 0 || by + history->second.CurrentVisitedIndex >= history->second.Visited.size()) return; + + history->second.CurrentVisitedIndex += by; + const auto to_id = history->second.Visited.at(history->second.CurrentVisitedIndex); + + // temporarily point current index to the end so that it doesnt fuck up the history + // remove it immediately after cuz the emit will call ReplaceActiveTab + const auto real = history->second.CurrentVisitedIndex; + history->second.CurrentVisitedIndex = history->second.Visited.size() - 1; + m_signal_channel_switched_to.emit(to_id); + // iterator might not be valid + history = m_page_history.find(current); + if (history != m_page_history.end()) { + history->second.Visited.pop_back(); + } + history->second.CurrentVisitedIndex = real; +} + ChannelTabSwitcherHandy::type_signal_channel_switched_to ChannelTabSwitcherHandy::signal_channel_switched_to() { return m_signal_channel_switched_to; } |