Philipp Hörist pushed to branch master at gajim / gajim
Commits: a8fcde47 by lovetox at 2020-08-29T07:21:32+02:00 Remove unused code
- - - - - cd9150b8 by lovetox at 2020-08-29T20:55:22+02:00 ChatControlBase: Remove auto copy workaround
We are now able to copy text with CTRL/META + c in the ConversationTextView and the MessageInput
- - - - -
9 changed files:
- gajim/application.py - gajim/chat_control_base.py - gajim/common/config.py - gajim/common/setting_values.py - gajim/conversation_textview.py - gajim/data/gui/preferences_window.ui - gajim/gtk/htmltextview.py - gajim/gtk/preferences.py - gajim/message_window.py
Changes:
===================================== gajim/application.py ===================================== @@ -558,7 +558,6 @@ class GajimApplication(Gtk.Application): 'win.switch-tab-7': ['<Alt>7', '<Alt>KP_7'], 'win.switch-tab-8': ['<Alt>8', '<Alt>KP_8'], 'win.switch-tab-9': ['<Alt>9', '<Alt>KP_9'], - 'win.copy-text': ['<Control><Shift>c'], }
for action, accels in shortcuts.items():
===================================== gajim/chat_control_base.py ===================================== @@ -82,6 +82,14 @@ if app.is_installed('GSPELL'): from gi.repository import Gspell # pylint: disable=ungrouped-imports
+if sys.platform == 'darwin': + COPY_MODIFIER = Gdk.ModifierType.META_MASK + COPY_MODIFIER_KEYS = (Gdk.KEY_Meta_L, Gdk.KEY_Meta_R) +else: + COPY_MODIFIER = Gdk.ModifierType.CONTROL_MASK + COPY_MODIFIER_KEYS = (Gdk.KEY_Control_L, Gdk.KEY_Control_R) + + ################################################################################ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper): """ @@ -187,9 +195,8 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper): id_ = self.conv_textview.connect('quote', self.on_quote) self.handlers[id_] = self.conv_textview.tv
- id_ = self.conv_textview.tv.connect('grab-focus', - self._on_html_textview_grab_focus) - self.handlers[id_] = self.conv_textview.tv + self.conv_textview.tv.connect('key-press-event', + self._on_conv_textview_key_press_event)
self.conv_scrolledwindow = self.xml.conversation_scrolledwindow self.conv_scrolledwindow.add(self.conv_textview.tv) @@ -279,6 +286,27 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper): # to properly use the super, because of the old code. CommandTools.__init__(self)
+ def _on_conv_textview_key_press_event(self, textview, event): + if event.keyval in COPY_MODIFIER_KEYS: + # Don’t route modifier keys for copy action to the Message Input + # otherwise pressing CTRL/META + c (the next event after that) + # will not reach the textview (because the Message Input would get + # focused). + return Gdk.EVENT_PROPAGATE + + if event.get_state() & COPY_MODIFIER: + # Don’t reroute the event if it is META + c and the + # textview has a selection + if event.keyval == Gdk.KEY_c: + if textview.get_buffer().props.has_selection: + return Gdk.EVENT_PROPAGATE + + # Focus the Messsage Input and resend the event + textview.unselect() + self.msg_textview.grab_focus() + self.msg_textview.get_toplevel().propagate_key_event(event) + return Gdk.EVENT_STOP + @property def type(self): return self._type @@ -511,10 +539,6 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper): self.msg_textview.emit('insert-emoji') return Gdk.EVENT_STOP
- if action == 'copy-text': - self.conv_textview.tv.emit('copy-clipboard') - return Gdk.EVENT_STOP - return Gdk.EVENT_PROPAGATE
def add_actions(self): @@ -643,13 +667,6 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper): gspell_lang = checker.get_language() self.contact.settings.set('speller_language', gspell_lang.get_code())
- def _on_html_textview_grab_focus(self, textview): - # Abort signal so the textview does not get focused - # Focus the MessageInputTextView instead - GObject.signal_stop_emission_by_name(textview, 'grab-focus') - self.msg_textview.grab_focus() - return Gdk.EVENT_STOP - def on_banner_label_populate_popup(self, _label, menu): """ Override the default context menu and add our own menuitems
===================================== gajim/common/config.py ===================================== @@ -240,7 +240,6 @@ class Config: 'muclumbus_api_jid': [opt_str, 'rodrigo.de.mucobedo@dreckshal.de'], 'muclumbus_api_http_uri': [opt_str, 'https://search.jabbercat.org/api/1.0/search'], 'muclumbus_api_pref': [opt_str, 'http', _('API Preferences. Possible values: 'http', 'iq'')], - 'auto_copy': [opt_bool, True, _('Selecting text will copy it to the clipboard')], 'command_system_execute': [opt_bool, False, _('If enabled, Gajim will execute commands (/show, /sh, /execute, /exec).')], 'groupchat_roster_width': [opt_int, 210, _('Width of group chat roster in pixel')], 'dev_force_bookmark_2': [opt_bool, False, _('Force Bookmark 2 usage')],
===================================== gajim/common/setting_values.py ===================================== @@ -176,7 +176,6 @@ APP_SETTINGS = { 'muclumbus_api_jid': 'rodrigo.de.mucobedo@dreckshal.de', 'muclumbus_api_http_uri': 'https://search.jabbercat.org/api/1.0/search', 'muclumbus_api_pref': 'http', - 'auto_copy': True, 'command_system_execute': False, 'groupchat_roster_width': 210, 'dev_force_bookmark_2': False,
===================================== gajim/conversation_textview.py ===================================== @@ -74,96 +74,6 @@ TRUST_SYMBOL_DATA = { }
-def is_selection_modified(mark): - name = mark.get_name() - return name in ('selection_bound', 'insert') - -def has_focus(widget): - return widget.get_state_flags() & Gtk.StateFlags.FOCUSED == \ - Gtk.StateFlags.FOCUSED - -class TextViewImage(Gtk.Image): - - def __init__(self, anchor, text): - super(TextViewImage, self).__init__() - self.anchor = anchor - self._selected = False - self._disconnect_funcs = [] - self.connect('parent-set', self.on_parent_set) - self.set_tooltip_markup(text) - self.anchor.plaintext = text - - def _get_selected(self): - parent = self.get_parent() - if not parent or not self.anchor: - return False - buffer_ = parent.get_buffer() - position = buffer_.get_iter_at_child_anchor(self.anchor) - bounds = buffer_.get_selection_bounds() - return bounds and position.in_range(*bounds) - - def get_state(self): - parent = self.get_parent() - if not parent: - return Gtk.StateType.NORMAL - if self._selected: - if has_focus(parent): - return Gtk.StateType.SELECTED - return Gtk.StateType.ACTIVE - return Gtk.StateType.NORMAL - - def _update_selected(self): - selected = self._get_selected() - if self._selected != selected: - self._selected = selected - self.queue_draw() - - def _do_connect(self, widget, signal, callback): - id_ = widget.connect(signal, callback) - def disconnect(): - widget.disconnect(id_) - self._disconnect_funcs.append(disconnect) - - def _disconnect_signals(self): - for func in self._disconnect_funcs: - func() - self._disconnect_funcs = [] - - def on_parent_set(self, widget, old_parent): - parent = self.get_parent() - if not parent: - self._disconnect_signals() - return - if isinstance(parent, Gtk.EventBox): - parent = parent.get_parent() - if not parent: - self._disconnect_signals() - return - - self._do_connect(parent, 'style-set', self.do_queue_draw) - self._do_connect(parent, 'focus-in-event', self.do_queue_draw) - self._do_connect(parent, 'focus-out-event', self.do_queue_draw) - - textbuf = parent.get_buffer() - self._do_connect(textbuf, 'mark-set', self.on_mark_set) - self._do_connect(textbuf, 'mark-deleted', self.on_mark_deleted) - - def do_queue_draw(self, *args): - self.queue_draw() - return False - - def on_mark_set(self, buf, iterat, mark): - self.on_mark_modified(mark) - return False - - def on_mark_deleted(self, buf, mark): - self.on_mark_modified(mark) - return False - - def on_mark_modified(self, mark): - if is_selection_modified(mark): - self._update_selected() - class ConversationTextview(GObject.GObject): """ Class for the conversation textview (where user reads already said messages)
===================================== gajim/data/gui/preferences_window.ui ===================================== @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.36.0 --> +<!-- Generated with glade 3.22.2 --> <interface> <requires lib="gtk+" version="3.22"/> <object class="GtkAdjustment" id="adjustment_status_auto_away"> @@ -534,60 +534,7 @@ <property name="orientation">vertical</property> <property name="spacing">6</property> <child> - <object class="GtkFrame"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label_xalign">0</property> - <property name="shadow_type">none</property> - <child> - <object class="GtkAlignment"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkBox"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="margin_top">6</property> - <property name="orientation">vertical</property> - <property name="spacing">6</property> - <child> - <object class="GtkCheckButton" id="auto_copy"> - <property name="label" translatable="yes">Enable auto copy</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="tooltip_text" translatable="yes">If enabled, selected text will automatically be copied to the clipboard, otherwise you can copy text with CTRL + SHIFT + C</property> - <property name="halign">start</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <signal name="toggled" handler="on_auto_copy_toggled" swapped="no"/> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - </object> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">General</property> - <style> - <class name="bold"/> - <class name="margin-top6"/> - </style> - </object> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> + <placeholder/> </child> <child> <object class="GtkFrame">
===================================== gajim/gtk/htmltextview.py ===================================== @@ -713,26 +713,10 @@ class HtmlTextView(Gtk.TextView): self.plugin_modified = False self._cursor_changed = False
- self.connect('button-release-event', self._on_button_release) if standalone: self.connect('query-tooltip', self._query_tooltip) self.create_tags()
- @staticmethod - def _on_button_release(textview, event): - if event.button == 1: - # Left Mouse button - - if not app.settings.get('auto_copy'): - return Gdk.EVENT_PROPAGATE - - if not textview.get_buffer().get_has_selection(): - return Gdk.EVENT_PROPAGATE - selected = textview.get_selected_text() - clipboard = textview.get_clipboard(Gdk.SELECTION_CLIPBOARD) - clipboard.set_text(selected, -1) - return Gdk.EVENT_PROPAGATE - def create_tags(self): color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR)
@@ -887,3 +871,8 @@ class HtmlTextView(Gtk.TextView): self.add_child_at_anchor(emoji, anchor) buffer_.delete_mark(start_mark) buffer_.delete_mark(end_mark) + + def unselect(self): + buffer_ = self.get_buffer() + insert_iter = buffer_.get_iter_at_mark(buffer_.get_insert()) + buffer_.select_range(insert_iter, insert_iter)
===================================== gajim/gtk/preferences.py ===================================== @@ -119,11 +119,6 @@ class Preferences(Gtk.ApplicationWindow): self._ui.sort_by_show_in_muc_checkbutton.set_active(st)
### Chat tab ### - ## General Settings - - # Enable auto copy - st = app.settings.get('auto_copy') - self._ui.auto_copy.set_active(st)
## Chat Settings # Use speller @@ -492,9 +487,6 @@ class Preferences(Gtk.ApplicationWindow): ctrl.roster.invalidate_sort()
### Chat tab ### - def on_auto_copy_toggled(self, widget): - self.on_checkbutton_toggled(widget, 'auto_copy') - def on_speller_checkbutton_toggled(self, widget): active = widget.get_active() app.settings.set('use_speller', active)
===================================== gajim/message_window.py ===================================== @@ -193,7 +193,6 @@ class MessageWindow(EventHelper): 'switch-tab-7', 'switch-tab-8', 'switch-tab-9', - 'copy-text', ]
disabled_for_emacs = (
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/55c7ed44fc7bb70e27ee07a586585e16...