Daniel Brötzmann pushed to branch mainwindow at gajim / gajim
Commits:
-
76ff8ab1
by wurstsalat at 2021-09-05T12:47:35+02:00
4 changed files:
Changes:
| ... | ... | @@ -181,6 +181,57 @@ def select_chat(self, account, jid): |
| 181 | 181 |
row = self._chats[(account, jid)]
|
| 182 | 182 |
self.select_row(row)
|
| 183 | 183 |
|
| 184 |
+ def select_next_chat(self, forwards):
|
|
| 185 |
+ # Selects the next chat, but prioritizes chats with unread messages.
|
|
| 186 |
+ # Direction is forwards (True) or backwards (False)
|
|
| 187 |
+ row = self.get_selected_chat()
|
|
| 188 |
+ if row is None:
|
|
| 189 |
+ row = self.get_row_at_index(0)
|
|
| 190 |
+ if row is not None:
|
|
| 191 |
+ self.select_chat(row.account, row.jid)
|
|
| 192 |
+ return
|
|
| 193 |
+ |
|
| 194 |
+ index = row.get_index()
|
|
| 195 |
+ current = index
|
|
| 196 |
+ unread_found = False
|
|
| 197 |
+ # Loop until finding a chat with unread count or completing a cycle
|
|
| 198 |
+ while True:
|
|
| 199 |
+ if forwards:
|
|
| 200 |
+ index += 1
|
|
| 201 |
+ if index >= len(self.get_children()):
|
|
| 202 |
+ index = 0
|
|
| 203 |
+ else:
|
|
| 204 |
+ index -= 1
|
|
| 205 |
+ if index < 0:
|
|
| 206 |
+ index = len(self.get_children()) - 1
|
|
| 207 |
+ |
|
| 208 |
+ row = self.get_row_at_index(index)
|
|
| 209 |
+ if row.unread_count > 0:
|
|
| 210 |
+ unread_found = True
|
|
| 211 |
+ break
|
|
| 212 |
+ if index == current:
|
|
| 213 |
+ break
|
|
| 214 |
+ |
|
| 215 |
+ if unread_found:
|
|
| 216 |
+ self.select_chat(row.account, row.jid)
|
|
| 217 |
+ return
|
|
| 218 |
+ |
|
| 219 |
+ index = row.get_index()
|
|
| 220 |
+ if forwards:
|
|
| 221 |
+ next_row = self.get_row_at_index(index + 1)
|
|
| 222 |
+ else:
|
|
| 223 |
+ next_row = self.get_row_at_index(index - 1)
|
|
| 224 |
+ if next_row is None:
|
|
| 225 |
+ if forwards:
|
|
| 226 |
+ next_row = self.get_row_at_index(0)
|
|
| 227 |
+ else:
|
|
| 228 |
+ last = len(self.get_children()) - 1
|
|
| 229 |
+ next_row = self.get_row_at_index(last)
|
|
| 230 |
+ self.select_chat(next_row.account, next_row.jid)
|
|
| 231 |
+ return
|
|
| 232 |
+ |
|
| 233 |
+ self.select_chat(next_row.account, next_row.jid)
|
|
| 234 |
+ |
|
| 184 | 235 |
def toggle_chat_pinned(self, account, jid):
|
| 185 | 236 |
row = self._chats[(account, jid)]
|
| 186 | 237 |
row.toggle_pinned()
|
| ... | ... | @@ -14,6 +14,7 @@ |
| 14 | 14 |
|
| 15 | 15 |
import logging
|
| 16 | 16 |
|
| 17 |
+from gi.repository import GLib
|
|
| 17 | 18 |
from gi.repository import Gtk
|
| 18 | 19 |
|
| 19 | 20 |
from gajim.common import ged
|
| ... | ... | @@ -94,6 +95,8 @@ def remove_chat(self, account, jid): |
| 94 | 95 |
|
| 95 | 96 |
def show_chat(self, account, jid):
|
| 96 | 97 |
self.set_visible_child_name(f'{account}:{jid}')
|
| 98 |
+ control = self.get_control(account, jid)
|
|
| 99 |
+ GLib.idle_add(control.focus)
|
|
| 97 | 100 |
|
| 98 | 101 |
def clear(self):
|
| 99 | 102 |
self.set_visible_child_name('empty')
|
| ... | ... | @@ -831,8 +831,7 @@ def _on_message_textview_key_press_event(self, textview, event): |
| 831 | 831 |
if event.get_state() & Gdk.ModifierType.SHIFT_MASK:
|
| 832 | 832 |
if (event.get_state() & Gdk.ModifierType.CONTROL_MASK and
|
| 833 | 833 |
event.keyval == Gdk.KEY_ISO_Left_Tab):
|
| 834 |
- # TODO:
|
|
| 835 |
- self.parent_win.move_to_next_unread_tab(False)
|
|
| 834 |
+ app.window.select_next_chat(False)
|
|
| 836 | 835 |
return True
|
| 837 | 836 |
|
| 838 | 837 |
if event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_Page_Up):
|
| ... | ... | @@ -841,8 +840,7 @@ def _on_message_textview_key_press_event(self, textview, event): |
| 841 | 840 |
|
| 842 | 841 |
if event.get_state() & Gdk.ModifierType.CONTROL_MASK:
|
| 843 | 842 |
if event.keyval == Gdk.KEY_Tab:
|
| 844 |
- # TODO
|
|
| 845 |
- self.parent_win.move_to_next_unread_tab(True)
|
|
| 843 |
+ app.window.select_next_chat(True)
|
|
| 846 | 844 |
return True
|
| 847 | 845 |
|
| 848 | 846 |
message_buffer = self.msg_textview.get_buffer()
|
| ... | ... | @@ -339,6 +339,12 @@ def select_chat(self, account, jid): |
| 339 | 339 |
self._main_stack.show_chat_page()
|
| 340 | 340 |
self._chat_page.select_chat(account, jid)
|
| 341 | 341 |
|
| 342 |
+ def select_next_chat(self, forwards):
|
|
| 343 |
+ chat_list_stack = self._chat_page.get_chat_list_stack()
|
|
| 344 |
+ chat_list = chat_list_stack.get_current_chat_list()
|
|
| 345 |
+ if chat_list is not None:
|
|
| 346 |
+ chat_list.select_next_chat(forwards)
|
|
| 347 |
+ |
|
| 342 | 348 |
@staticmethod
|
| 343 | 349 |
def _add_to_roster(_action, param):
|
| 344 | 350 |
_workspace, account, jid = param.unpack()
|