Philipp Hörist pushed to branch master at gajim / gajim
Commits: aad2e1d2 by Philipp Hörist at 2020-01-26T20:46:49+01:00 ChatControlBase: Add focus() method
This method is called by the MessageWindow on the currently active control, when it gains focus.
This allows the controls to decide by themself what should be focused inside the control.
For example the GroupchatControl could have the change nickname page open and would want to focus the nickname entry
- - - - -
5 changed files:
- gajim/chat_control.py - gajim/chat_control_base.py - gajim/groupchat_control.py - gajim/gtk/dataform.py - gajim/message_window.py
Changes:
===================================== gajim/chat_control.py ===================================== @@ -340,6 +340,9 @@ class ChatControl(ChatControlBase): win.lookup_action( 'information-' + self.control_id).set_enabled(online)
+ def focus(self): + self.msg_textview.grab_focus() + def delegate_action(self, action): res = super().delegate_action(action) if res == Gdk.EVENT_STOP:
===================================== gajim/chat_control_base.py ===================================== @@ -332,6 +332,9 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper): """ on_response_yes(self)
+ def focus(self): + raise NotImplementedError + def get_nb_unread(self): jid = self.contact.jid if self.resource:
===================================== gajim/groupchat_control.py ===================================== @@ -1899,6 +1899,23 @@ class GroupchatControl(ChatControlBase):
return Gdk.EVENT_PROPAGATE
+ def focus(self): + page_name = self._get_current_page() + if page_name == 'groupchat': + self.msg_textview.grab_focus() + elif page_name == 'password': + self.xml.password_entry.grab_focus_without_selecting() + elif page_name == 'nickname': + self.xml.nickname_entry.grab_focus_without_selecting() + elif page_name == 'rename': + self.xml.name_entry.grab_focus_without_selecting() + elif page_name == 'subject': + self.xml.subject_textview.grab_focus() + elif page_name == 'captcha': + self._captcha_request.focus_first_entry() + elif page_name == 'destroy': + self.xml.destroy_reason_entry.grab_focus_without_selecting() + def _start_private_message(self, nick): gc_c = app.contacts.get_gc_contact(self.account, self.room_jid, nick) nick_jid = gc_c.get_full_jid()
===================================== gajim/gtk/dataform.py ===================================== @@ -69,7 +69,7 @@ class DataFormWidget(Gtk.ScrolledWindow): def focus_first_entry(self): for widget in self._form_grid.get_children(): if isinstance(widget, Gtk.Entry): - widget.grab_focus() + widget.grab_focus_without_selecting() break
===================================== gajim/message_window.py ===================================== @@ -451,7 +451,7 @@ class MessageWindow(EventHelper): # whether the tab is the active one. self.show_title() if self.get_num_controls() == 1: - GLib.timeout_add(500, control.msg_textview.grab_focus) + GLib.timeout_add(500, control.focus)
def on_tab_eventbox_button_press_event(self, widget, event, child): if event.button == 3: # right click @@ -463,7 +463,7 @@ class MessageWindow(EventHelper): self.remove_tab(ctrl, self.CLOSE_TAB_MIDDLE_CLICK) else: ctrl = self._widget_to_control(child) - GLib.idle_add(ctrl.msg_textview.grab_focus) + GLib.idle_add(ctrl.focus)
def _on_close_button_clicked(self, button, control): """ @@ -549,7 +549,7 @@ class MessageWindow(EventHelper): ctrl_page = self.notebook.page_num(ctrl.widget) self.notebook.set_current_page(ctrl_page) self.window.present() - GLib.idle_add(ctrl.msg_textview.grab_focus) + GLib.idle_add(ctrl.focus)
def remove_tab(self, ctrl, method, reason=None, force=False): """ @@ -825,7 +825,7 @@ class MessageWindow(EventHelper):
control = self.get_active_control() if isinstance(control, ChatControlBase): - control.msg_textview.grab_focus() + control.focus()
def get_tab_at_xy(self, x, y): """
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/aad2e1d2132a3f64c39a83a8af7f1385e0e...