Daniel Brötzmann pushed to branch newcontrol at gajim / gajim
Commits: 63822d4d by wurstsalat at 2022-07-09T12:51:55+02:00 Menus: Add 'Search…' back to single chat menu
- - - - - 1231e186 by wurstsalat at 2022-07-09T14:55:06+02:00 MessageActionsBox: Formatting, linting
- - - - - 22e95542 by wurstsalat at 2022-07-09T15:24:34+02:00 Fix quoting and mentioning
- - - - -
8 changed files:
- gajim/gtk/chat_stack.py - gajim/gtk/const.py - gajim/gtk/controls/base.py - gajim/gtk/conversation/rows/message.py - gajim/gtk/conversation/view.py - gajim/gtk/menus.py - gajim/gtk/message_actions_box.py - gajim/gtk/message_input.py
Changes:
===================================== gajim/gtk/chat_stack.py ===================================== @@ -167,6 +167,9 @@ def _update_chat_actions(self, contact: BareContact) -> None: online and contact.supports_video() and sys.platform != 'win32')
+ app.window.get_action('quote').set_enabled(online) + app.window.get_action('mention').set_enabled(online) + def _update_group_chat_actions(self, contact: GroupchatContact) -> None: is_visitor = False if contact.is_joined: @@ -175,6 +178,9 @@ def _update_group_chat_actions(self, contact: GroupchatContact) -> None: is_visitor = self_contact.role.is_visitor app.window.get_action('request-voice').set_enabled(is_visitor)
+ app.window.get_action('quote').set_enabled(contact.is_joined) + app.window.get_action('mention').set_enabled(contact.is_joined) + def _update_participant_actions(self, contact: GroupchatParticipant) -> None: pass
===================================== gajim/gtk/const.py ===================================== @@ -194,6 +194,8 @@ def __str__(self): ('input-strike', None, False), ('input-clear', None, False), ('show-emoji-chooser', None, False), + ('quote', 's', False), + ('mention', 's', False), ('send-file-httpupload', None, False), ('send-file-jingle', None, False), ('send-file', None, False),
===================================== gajim/gtk/controls/base.py ===================================== @@ -58,7 +58,6 @@ from gajim.common.preview_helpers import filename_from_uri from gajim.common.preview_helpers import guess_simple_file_type from gajim.common.storage.archive import ConversationRow -from gajim.common.structs import OutgoingMessage
from gajim.gui.conversation.view import ConversationView from gajim.gui.conversation.scrolled import ScrolledView @@ -166,8 +165,6 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None:
# Create ConversationView and connect signals self.conversation_view = ConversationView(self.account, self.contact) - self.conversation_view.connect('quote', self._on_quote) - self.conversation_view.connect('mention', self._on_mention) self.conversation_view.connect('scroll-to-end', self._on_scroll_to_end)
id_ = self.conversation_view.connect( @@ -409,22 +406,6 @@ def shutdown(self) -> None:
self.unregister_events()
- def insert_as_quote(self, text: str) -> None: - text = '> ' + text.replace('\n', '\n> ') + '\n' - message_buffer = self.msg_textview.get_buffer() - message_buffer.insert_at_cursor(text) - self.msg_textview.grab_focus() - - def _on_quote(self, _view: ConversationView, text: str) -> None: - self.insert_as_quote(text) - - def _on_mention(self, _view: ConversationView, name: str) -> None: - gc_refer_to_nick_char = app.settings.get('gc_refer_to_nick_char') - text = f'{name}{gc_refer_to_nick_char} ' - message_buffer = self.msg_textview.get_buffer() - message_buffer.insert_at_cursor(text) - GLib.idle_add(self.msg_textview.grab_focus) - def _on_scroll_to_end(self, _view: ConversationView) -> None: scroll_to_end(self._scrolled_view)
===================================== gajim/gtk/conversation/rows/message.py ===================================== @@ -24,7 +24,6 @@ from gi.repository import GdkPixbuf from gi.repository import GLib from gi.repository import Gtk -from gi.repository import GObject from gi.repository import Pango
import cairo @@ -60,20 +59,6 @@
class MessageRow(BaseRow): - - __gsignals__ = { - 'mention': ( - GObject.SignalFlags.RUN_LAST, - None, - (str,) - ), - 'quote': ( - GObject.SignalFlags.RUN_LAST, - None, - (str,) - ), - } - def __init__(self, account: str, contact: ChatContactT, @@ -269,7 +254,7 @@ def _on_avatar_clicked(self, name: str ) -> int: if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 1: - self.emit('mention', name) + app.window.activate_action('mention', GLib.Variant('s', name)) return Gdk.EVENT_STOP
@staticmethod @@ -331,7 +316,8 @@ def on_copy_message(self, _widget: Gtk.Widget) -> None: clip.set_text(f'{timestamp_formatted} - {self.name}: {text}', -1)
def on_quote_message(self, _widget: Gtk.Widget) -> None: - self.emit('quote', self._message_widget.get_text()) + app.window.activate_action( + 'quote', GLib.Variant('s', self._message_widget.get_text()))
def on_retract_message(self, _widget: Gtk.Widget) -> None: def _on_retract(reason: str) -> None:
===================================== gajim/gtk/conversation/view.py ===================================== @@ -68,16 +68,6 @@ class ConversationView(Gtk.ListBox):
__gsignals__ = { - 'quote': ( - GObject.SignalFlags.RUN_LAST | GObject.SignalFlags.ACTION, - None, - (str, ) - ), - 'mention': ( - GObject.SignalFlags.RUN_LAST | GObject.SignalFlags.ACTION, - None, - (str, ) - ), 'scroll-to-end': ( GObject.SignalFlags.RUN_LAST | GObject.SignalFlags.ACTION, None, @@ -268,8 +258,6 @@ def add_message(self, error=error, encryption_enabled=self.encryption_enabled, log_line_id=log_line_id) - message_row.connect('mention', self._on_mention) - message_row.connect('quote', self._on_quote)
if message_id is not None: self._message_id_row_map[message_id] = message_row @@ -513,12 +501,6 @@ def show_error(self, id_: str, error: StanzaError) -> None: message_row.set_error(to_user_string(error)) message_row.set_merged(False)
- def _on_quote(self, _message_row: MessageRow, text: str) -> None: - self.emit('quote', text) - - def _on_mention(self, _message_row: MessageRow, name: str) -> None: - self.emit('mention', name) - def _on_contact_setting_changed(self, value: Any, setting: str,
===================================== gajim/gtk/menus.py ===================================== @@ -85,6 +85,8 @@ def get_singlechat_menu(contact: types.BareContact) -> GajimMenu: menu.add_item(_('Start Voice Call…'), 'win.start-voice-call') menu.add_item(_('Start Video Call…'), 'win.start-video-call')
+ menu.add_item(_('Search…'), 'win.search-history', None) + if can_add_to_roster(contact): params = AccountJidParam(account=account, jid=contact.jid) menu.add_item(_('Add to Contact List…'), 'win.add-to-roster', params)
===================================== gajim/gtk/message_actions_box.py ===================================== @@ -37,7 +37,8 @@ from gajim.common import i18n from gajim.common.i18n import _ from gajim.common.const import Direction -from gajim.common.modules.contacts import GroupchatContact, GroupchatParticipant +from gajim.common.modules.contacts import GroupchatContact +from gajim.common.modules.contacts import GroupchatParticipant from gajim.common.types import ChatContactT from gajim.gui.security_label_selector import SecurityLabelSelector
@@ -46,16 +47,17 @@ from .dialogs import ErrorDialog from .dialogs import PastePreviewDialog from .emoji_chooser import emoji_chooser -from .menus import get_encryption_menu, get_private_chat_menu, get_self_contact_menu +from .menus import get_encryption_menu from .menus import get_format_menu from .menus import get_groupchat_menu +from .menus import get_private_chat_menu +from .menus import get_self_contact_menu from .menus import get_singlechat_menu from .message_input import MessageInputTextView
if app.is_installed('GSPELL'): from gi.repository import Gspell # pylint: disable=ungrouped-imports
- log = logging.getLogger('gajim.gui.messageactionsbox')
@@ -124,6 +126,8 @@ def _connect_actions(self) -> None: 'input-strike', 'input-clear', 'show-emoji-chooser', + 'quote', + 'mention', ]
for action in actions: @@ -145,7 +149,7 @@ def _connect_actions(self) -> None:
def _on_action(self, action: Gio.SimpleAction, - _param: Optional[GLib.Variant]) -> Optional[int]: + param: Optional[GLib.Variant]) -> Optional[int]:
if self._contact is None: return @@ -162,6 +166,14 @@ def _on_action(self, elif action_name == 'show-emoji-chooser': self._on_show_emoji_chooser()
+ elif action_name == 'quote': + assert param + self.msg_textview.insert_as_quote(param.get_string()) + + elif action_name == 'mention': + assert param + self.msg_textview.mention_participant(param.get_string()) + def switch_contact(self, contact: ChatContactT) -> None: self._contact = contact self._set_settings_menu(contact) @@ -305,9 +317,10 @@ def _on_clear(self) -> None: self.msg_textview.clear()
def _on_show_emoji_chooser(self) -> None: - if sys.platform == 'darwin': - self._ui.emoticons_button.get_popover().show() + popover = self._ui.emoticons_button.get_popover() + assert popover + popover.show() else: self.msg_textview.emit('insert-emoji')
@@ -359,6 +372,7 @@ def _get_spell_checker_language(self, if not lang: lang = i18n.LANG
+ assert isinstance(lang, str) lang = Gspell.language_lookup(lang) if lang is None: lang = Gspell.language_get_default()
===================================== gajim/gtk/message_input.py ===================================== @@ -367,10 +367,15 @@ def _on_populate_popup(self,
menu.show_all()
+ def mention_participant(self, name: str) -> None: + gc_refer_to_nick_char = app.settings.get('gc_refer_to_nick_char') + text = f'{name}{gc_refer_to_nick_char} ' + self.insert_text(text) + self.grab_focus() + def insert_as_quote(self, text: str) -> None: text = '> ' + text.replace('\n', '\n> ') + '\n' - message_buffer = self.get_buffer() - message_buffer.insert_at_cursor(text) + self.insert_text(text) self.grab_focus()
def _paste_clipboard_as_quote(self, _item: Gtk.MenuItem) -> None:
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/25088a135b0299352e33d625808ebced...