Philipp Hörist pushed to branch master at gajim / gajim
Commits: ef1866a9 by Philipp Hörist at 2019-08-15T07:19:49Z ChatControlBase: Add text auto-copy option
- On selecting the text is copied to the clipboard - If the option is diabled CTRL + SHIFT + C can be used
- - - - -
6 changed files:
- gajim/chat_control_base.py - gajim/common/config.py - gajim/data/gui/preferences_window.ui - gajim/gtk/htmltextview.py - gajim/gtk/preferences.py - gajim/message_window.py
Changes:
===================================== gajim/chat_control_base.py ===================================== @@ -396,6 +396,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): self.emoticons_button.get_popover().show() return Gdk.EVENT_STOP
+ if action == 'copy-text': + self.conv_textview.tv.emit('copy-clipboard') + return Gdk.EVENT_PROPAGATE
def add_actions(self):
===================================== gajim/common/config.py ===================================== @@ -295,6 +295,7 @@ 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')], }, {}) # type: Tuple[Dict[str, List[Any]], Dict[Any, Any]]
__options_per_key = {
===================================== gajim/data/gui/preferences_window.ui ===================================== @@ -565,6 +565,60 @@ <property name="border_width">18</property> <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="orientation">vertical</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, selecting Text will 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> + </child> <child> <object class="GtkFrame"> <property name="visible">True</property> @@ -799,7 +853,7 @@ <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">0</property> + <property name="position">1</property> </packing> </child> <child> @@ -893,7 +947,7 @@ <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> </object>
===================================== gajim/gtk/htmltextview.py ===================================== @@ -831,10 +831,26 @@ 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.config.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)
===================================== gajim/gtk/preferences.py ===================================== @@ -123,6 +123,12 @@ class Preferences(Gtk.ApplicationWindow): self._ui.sort_by_show_in_muc_checkbutton.set_active(st)
### Chat tab ### + ## General Settings + + # Enable auto copy + st = app.config.get('auto_copy') + self._ui.auto_copy.set_active(st) + ## Chat Settings # Use speller if app.is_installed('GSPELL'): @@ -539,6 +545,9 @@ class Preferences(Gtk.ApplicationWindow): ctrl.draw_roster()
### 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.config.set('use_speller', active)
===================================== gajim/message_window.py ===================================== @@ -182,6 +182,7 @@ class MessageWindow: ('switch-tab-7', ['<Alt>7', '<Alt>KP_7']), ('switch-tab-8', ['<Alt>8', '<Alt>KP_8']), ('switch-tab-9', ['<Alt>9', '<Alt>KP_9']), + ('copy-text', ['<Control><Shift>c']), ]
disabled_for_emacs = (
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/ef1866a9e7fb6742f1ac5a2eb75673c3b79...