groups - nicks auto complete
This commit is contained in:
parent
0ee8a0ec21
commit
c0a34d3e14
@ -386,6 +386,22 @@ class ContactsManager(ToxSave):
|
||||
num = self._contacts.index(contact)
|
||||
self._delete_contact(num)
|
||||
|
||||
def get_gc_peer_name(self, name):
|
||||
group = self.get_curr_contact()
|
||||
|
||||
names = sorted(group.get_peers_names())
|
||||
if name in names: # return next nick
|
||||
index = names.index(name)
|
||||
index = (index + 1) % len(names)
|
||||
|
||||
return names[index]
|
||||
|
||||
suggested_names = list(filter(lambda x: x.startswith(name), names))
|
||||
if not len(suggested_names):
|
||||
return '\t'
|
||||
|
||||
return suggested_names[0]
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Friend requests
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -98,6 +98,11 @@ class GroupChat(contact.Contact, ToxSave):
|
||||
def remove_all_peers_except_self(self):
|
||||
self._peers = self._peers[:1]
|
||||
|
||||
def get_peers_names(self):
|
||||
peers_names = map(lambda p: p.name, self._peers)
|
||||
|
||||
return list(peers_names)
|
||||
|
||||
def get_peers(self):
|
||||
return self._peers[:]
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from ui.contact_items import *
|
||||
from ui.widgets import MultilineEdit, ComboBox
|
||||
from ui.widgets import MultilineEdit
|
||||
from ui.main_screen_widgets import *
|
||||
import utils.util as util
|
||||
import utils.ui as util_ui
|
||||
@ -37,7 +37,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
self._toxes = toxes
|
||||
self._messenger = messenger
|
||||
self._contacts_manager.active_contact_changed.add_callback(self._new_contact_selected)
|
||||
self.messageEdit.set_messenger(messenger)
|
||||
self.messageEdit.set_dependencies(messenger, contacts_manager)
|
||||
|
||||
self.update_gc_invites_button_state()
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
from ui.widgets import RubberBandWindow, create_menu, QRightClickButton, CenteredWidget, LineEdit
|
||||
import urllib
|
||||
import re
|
||||
import utils.util as util
|
||||
import utils.ui as util_ui
|
||||
from stickers.stickers import load_stickers
|
||||
@ -11,14 +12,15 @@ class MessageArea(QtWidgets.QPlainTextEdit):
|
||||
|
||||
def __init__(self, parent, form):
|
||||
super().__init__(parent)
|
||||
self._messenger = None
|
||||
self._messenger = self._contacts_manager = None
|
||||
self.parent = form
|
||||
self.setAcceptDrops(True)
|
||||
self._timer = QtCore.QTimer(self)
|
||||
self._timer.timeout.connect(lambda: self._messenger.send_typing(False))
|
||||
|
||||
def set_messenger(self, messenger):
|
||||
def set_dependencies(self, messenger, contacts_manager):
|
||||
self._messenger = messenger
|
||||
self._contacts_manager = contacts_manager
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.matches(QtGui.QKeySequence.Paste):
|
||||
@ -39,10 +41,17 @@ class MessageArea(QtWidgets.QPlainTextEdit):
|
||||
self._messenger.send_message()
|
||||
elif event.key() == QtCore.Qt.Key_Up and not self.toPlainText():
|
||||
self.appendPlainText(self._messenger.get_last_message())
|
||||
elif event.key() == QtCore.Qt.Key_Tab and not self._messenger.is_active_a_friend():
|
||||
elif event.key() == QtCore.Qt.Key_Tab and self._contacts_manager.is_active_a_group():
|
||||
text = self.toPlainText()
|
||||
pos = self.textCursor().position()
|
||||
self.insertPlainText(self._messenger.get_gc_peer_name(text[:pos]))
|
||||
text_cursor = self.textCursor()
|
||||
pos = text_cursor.position()
|
||||
current_word = re.split("\s+", text[:pos])[-1]
|
||||
start_index = text.rindex(current_word, 0, pos)
|
||||
peer_name = self._contacts_manager.get_gc_peer_name(current_word)
|
||||
self.setPlainText(text[:start_index] + peer_name + text[pos:])
|
||||
new_pos = start_index + len(peer_name)
|
||||
text_cursor.setPosition(new_pos, QtGui.QTextCursor.MoveAnchor)
|
||||
self.setTextCursor(text_cursor)
|
||||
else:
|
||||
self._messenger.send_typing(True)
|
||||
if self._timer.isActive():
|
||||
|
Loading…
Reference in New Issue
Block a user