Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: d7732dfa by Daniel Brötzmann at 2021-03-25T21:09:05+01:00 MessageInputTextView: Remove custom placeholder
- - - - - fadc7596 by Daniel Brötzmann at 2021-03-25T21:09:09+01:00 MessageInputTextView: Add focus borders
- - - - -
7 changed files:
- gajim/chat_control_base.py - gajim/common/modules/chatstates.py - gajim/data/style/default-dark.css - gajim/data/style/default.css - gajim/data/style/gajim.css - gajim/groupchat_control.py - gajim/gtk/message_input.py
Changes:
===================================== gajim/chat_control_base.py ===================================== @@ -203,8 +203,8 @@ def __init__(self, parent_win, widget_name, contact, acct, self._on_message_textview_key_press_event) self.msg_textview.connect('populate-popup', self.on_msg_textview_populate_popup) - self.msg_textview.connect('text-changed', - self._on_message_tv_buffer_changed) + self.msg_textview.get_buffer().connect( + 'changed', self._on_message_tv_buffer_changed)
# Send message button self.xml.send_message_button.set_action_name( @@ -217,6 +217,8 @@ def __init__(self, parent_win, widget_name, contact, acct, 'set_visible')
self.msg_scrolledwindow = ScrolledWindow() + self.msg_scrolledwindow.get_style_context().add_class( + 'message-input-border') self.msg_scrolledwindow.add(self.msg_textview)
self.xml.hbox.pack_start(self.msg_scrolledwindow, True, True, 0) @@ -742,7 +744,6 @@ def on_msg_textview_populate_popup(self, _textview, menu): menu.show_all()
def insert_as_quote(self, text: str) -> None: - self.msg_textview.remove_placeholder() text = '> ' + text.replace('\n', '\n> ') + '\n' message_buffer = self.msg_textview.get_buffer() message_buffer.insert_at_cursor(text) @@ -1060,7 +1061,7 @@ def _on_window_motion_notify(self, *args): con.get_module('Chatstate').set_mouse_activity( self.contact, self.msg_textview.has_text())
- def _on_message_tv_buffer_changed(self, textview, textbuffer): + def _on_message_tv_buffer_changed(self, textbuffer): has_text = self.msg_textview.has_text() if self.parent_win is not None: self.parent_win.window.lookup_action( @@ -1072,7 +1073,7 @@ def _on_message_tv_buffer_changed(self, textview, textbuffer):
con = app.connections[self.account] con.get_module('Chatstate').set_keyboard_activity(self.contact) - if not textview.has_text(): + if not has_text: con.get_module('Chatstate').set_chatstate_delayed(self.contact, Chatstate.ACTIVE) return @@ -1285,7 +1286,6 @@ def set_emoticon_popover(self): self._on_emoticon_button_clicked)
def _on_emoticon_button_clicked(self, _widget): - self.msg_textview.remove_placeholder() # Present GTK emoji chooser (not cross platform compatible) self.msg_textview.emit('insert-emoji') self.xml.emoticons_button.set_property('active', False)
===================================== gajim/common/modules/chatstates.py ===================================== @@ -237,8 +237,8 @@ def get_active_chatstate(self, contact: ContactT) -> Optional[str]: def block_chatstates(self, contact: ContactT, block: bool) -> None: # Block sending chatstates to a contact # Used for example if we cycle through the MUC nick list, which - # produces a lot of text-changed signals from the textview. This - # Would lead to sending ACTIVE -> COMPOSING -> ACTIVE ... + # produces a lot of buffer 'changed' signals from the input textview. + # This would lead to sending ACTIVE -> COMPOSING -> ACTIVE ... if block: self._blocked.append(contact.jid) else:
===================================== gajim/data/style/default-dark.css ===================================== @@ -41,9 +41,6 @@ .gajim-state-paused { color: rgb(20, 210, 160); } -.gajim-message-placeholder { - color: rgb(195, 195, 195); -} .gajim-msg-correcting text { background: rgb(100, 100, 50); }
===================================== gajim/data/style/default.css ===================================== @@ -41,9 +41,6 @@ .gajim-state-paused { color: rgb(20, 160, 120); } -.gajim-message-placeholder { - color: rgb(170, 170, 170); -} .gajim-msg-correcting text { background: rgb(240, 230, 170); }
===================================== gajim/data/style/gajim.css ===================================== @@ -30,6 +30,14 @@
.chatcontrol-separator {margin-bottom: 5px;}
+.message-input-border { + border: 2px solid transparent; +} +.message-input-focus { + border: 2px solid @theme_selected_bg_color; + border-radius: 4px; +} + .link-button { min-height: 0px; }
/* VCardWindow */
===================================== gajim/groupchat_control.py ===================================== @@ -1915,7 +1915,6 @@ def _start_private_message(self, nick): return ctrl
def append_nick_in_msg_textview(self, _widget, nick): - self.msg_textview.remove_placeholder() message_buffer = self.msg_textview.get_buffer() start_iter, end_iter = message_buffer.get_bounds() cursor_position = message_buffer.get_insert()
===================================== gajim/gtk/message_input.py ===================================== @@ -20,14 +20,11 @@ from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GLib -from gi.repository import GObject from gi.repository import Pango
from nbxmpp.modules.misc import build_xhtml_body
from gajim.common import app -from gajim.common.i18n import _ -from gajim.common.const import StyleAttr from gajim.common.regex import LINK_REGEX
from .util import scroll_to_end @@ -41,12 +38,7 @@ class MessageInputTextView(Gtk.TextView): Class for the message textview (where user writes new messages) for chat/groupchat windows """ - __gsignals__ = { - 'text-changed': (GObject.SignalFlags.RUN_LAST, None, (Gtk.TextBuffer,)) - } - UNDO_LIMIT = 20 - PLACEHOLDER = _('Write a message…')
def __init__(self): Gtk.TextView.__init__(self) @@ -70,8 +62,6 @@ def __init__(self): # needed to know if we undid something self.undo_pressed = False
- buffer_ = self.get_buffer() - buffer_.connect('changed', self._on_buffer_changed) self._last_text = ''
self.begin_tags = {} @@ -80,11 +70,7 @@ def __init__(self): self.fonts_tags = [] self.other_tags = {}
- color = app.css_config.get_value( - '.gajim-message-placeholder', StyleAttr.COLOR) - self.placeholder_tag = buffer_.create_tag('placeholder') - self.placeholder_tag.set_property('foreground', color) - + buffer_ = self.get_buffer() self.other_tags['bold'] = buffer_.create_tag('bold') self.other_tags['bold'].set_property('weight', Pango.Weight.BOLD) self.begin_tags['bold'] = '<strong>' @@ -105,10 +91,8 @@ def __init__(self): self.begin_tags['strike'] = strike self.end_tags['strike'] = '</span>'
- self.connect('paste-clipboard', self._paste_clipboard) self.connect_after('paste-clipboard', self._after_paste_clipboard) - self.connect('focus-in-event', self._on_grab_focus) - self.connect('grab-focus', self._on_grab_focus) + self.connect('focus-in-event', self._on_focus_in) self.connect('focus-out-event', self._on_focus_out) self.connect('destroy', self._on_destroy)
@@ -123,15 +107,15 @@ def _on_destroy(self, *args): None, Gdk.DragAction.DEFAULT)
- def _on_buffer_changed(self, *args): - text = self.get_text() - # Because of inserting and removing PLACEHOLDER text - # the signal becomes unreliable when determining if the user - # typed in new text. So we send our own signal depending on if - # there is real new text that is not the PLACEHOLDER - if text != self._last_text: - self.emit('text-changed', self.get_buffer()) - self._last_text = text + def _on_focus_in(self, _widget, _event): + scrolled = self.get_parent() + scrolled.get_style_context().add_class('message-input-focus') + return False + + def _on_focus_out(self, _widget, _event): + scrolled = self.get_parent() + scrolled.get_style_context().remove_class('message-input-focus') + return False
def insert_text(self, text): self.get_buffer().insert_at_cursor(text) @@ -148,50 +132,19 @@ def has_text(self): buf = self.get_buffer() start, end = buf.get_bounds() text = buf.get_text(start, end, True) - return text not in (self.PLACEHOLDER, '') + return text != ''
def get_text(self): - # gets the text if its not PLACEHOLDER buf = self.get_buffer() start, end = buf.get_bounds() text = self.get_buffer().get_text(start, end, True) - if text == self.PLACEHOLDER: - return '' return text
- def is_placeholder(self): - buf = self.get_buffer() - start, end = buf.get_bounds() - text = buf.get_text(start, end, True) - return text == self.PLACEHOLDER - - def remove_placeholder(self): - if self.is_placeholder(): - self.get_buffer().set_text('') - self.toggle_speller(True) - - def _on_grab_focus(self, *args): - self.remove_placeholder() - - def _on_focus_out(self, *args): - buf = self.get_buffer() - start, end = buf.get_bounds() - text = buf.get_text(start, end, True) - if text == '': - buf.insert_with_tags( - start, self.PLACEHOLDER, self.placeholder_tag) - self.toggle_speller(False) - def toggle_speller(self, activate): if app.is_installed('GSPELL') and app.settings.get('use_speller'): spell_view = Gspell.TextView.get_from_gtk_text_view(self) spell_view.set_inline_spell_checking(activate)
- @staticmethod - def _paste_clipboard(textview): - if textview.is_placeholder(): - textview.get_buffer().set_text('') - @staticmethod def _after_paste_clipboard(textview): buffer_ = textview.get_buffer() @@ -429,7 +382,6 @@ def replace_char_at_iter(self, iter_, new_char): buffer_.insert(iter_, new_char)
def insert_emoji(self, codepoint, pixbuf): - self.remove_placeholder() buffer_ = self.get_buffer() if buffer_.get_char_count(): # buffer contains text
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/e7a02bd196709a642f7149d6dabda18d...