allow shutdown func now get the method we used to close the tab. So that we check if a row is selected in gc control only if we close tab by pressing Esc key. fixes #2528
This commit is contained in:
parent
f6ba23bf13
commit
aae7e7e99c
5 changed files with 26 additions and 17 deletions
|
@ -1517,7 +1517,7 @@ class ChatControl(ChatControlBase):
|
||||||
self.msg_textview.destroy()
|
self.msg_textview.destroy()
|
||||||
|
|
||||||
|
|
||||||
def allow_shutdown(self):
|
def allow_shutdown(self, method):
|
||||||
if time.time() - gajim.last_message_time[self.account]\
|
if time.time() - gajim.last_message_time[self.account]\
|
||||||
[self.get_full_jid()] < 2:
|
[self.get_full_jid()] < 2:
|
||||||
# 2 seconds
|
# 2 seconds
|
||||||
|
|
|
@ -1105,7 +1105,7 @@ class GroupchatControl(ChatControlBase):
|
||||||
reason = 'offline'
|
reason = 'offline'
|
||||||
if len(message_array):
|
if len(message_array):
|
||||||
reason = message_array.pop(0)
|
reason = message_array.pop(0)
|
||||||
self.parent_win.remove_tab(self, reason, force = True)
|
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND, reason)
|
||||||
self.clear(self.msg_textview)
|
self.clear(self.msg_textview)
|
||||||
return True
|
return True
|
||||||
elif command == 'ban':
|
elif command == 'ban':
|
||||||
|
@ -1292,11 +1292,13 @@ class GroupchatControl(ChatControlBase):
|
||||||
self.handlers[i].disconnect(i)
|
self.handlers[i].disconnect(i)
|
||||||
del self.handlers[i]
|
del self.handlers[i]
|
||||||
|
|
||||||
def allow_shutdown(self):
|
def allow_shutdown(self, method):
|
||||||
model, iter = self.list_treeview.get_selection().get_selected()
|
'''If check_selection is True, '''
|
||||||
if iter:
|
if method == self.parent_win.CLOSE_ESC:
|
||||||
self.list_treeview.get_selection().unselect_all()
|
model, iter = self.list_treeview.get_selection().get_selected()
|
||||||
return False
|
if iter:
|
||||||
|
self.list_treeview.get_selection().unselect_all()
|
||||||
|
return False
|
||||||
retval = True
|
retval = True
|
||||||
includes = gajim.config.get('confirm_close_muc_rooms').split(' ')
|
includes = gajim.config.get('confirm_close_muc_rooms').split(' ')
|
||||||
excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ')
|
excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ')
|
||||||
|
|
|
@ -57,7 +57,7 @@ class MessageControl:
|
||||||
or inactive (state is False)'''
|
or inactive (state is False)'''
|
||||||
pass # Derived types MUST implement this method
|
pass # Derived types MUST implement this method
|
||||||
|
|
||||||
def allow_shutdown(self):
|
def allow_shutdown(self, method):
|
||||||
'''Called to check is a control is allowed to shutdown.
|
'''Called to check is a control is allowed to shutdown.
|
||||||
If a control is not in a suitable shutdown state this method
|
If a control is not in a suitable shutdown state this method
|
||||||
should return False'''
|
should return False'''
|
||||||
|
|
|
@ -40,6 +40,13 @@ class MessageWindow:
|
||||||
# DND_TARGETS is the targets needed by drag_source_set and drag_dest_set
|
# DND_TARGETS is the targets needed by drag_source_set and drag_dest_set
|
||||||
DND_TARGETS = [('GAJIM_TAB', 0, 81)]
|
DND_TARGETS = [('GAJIM_TAB', 0, 81)]
|
||||||
hid = 0 # drag_data_received handler id
|
hid = 0 # drag_data_received handler id
|
||||||
|
(
|
||||||
|
CLOSE_TAB_MIDDLE_CLICK,
|
||||||
|
CLOSE_ESC,
|
||||||
|
CLOSE_CLOSE_BUTTON,
|
||||||
|
CLOSE_COMMAND,
|
||||||
|
CLOSE_CTRL_KEY
|
||||||
|
) = range(5)
|
||||||
|
|
||||||
def __init__(self, acct, type):
|
def __init__(self, acct, type):
|
||||||
# A dictionary of dictionaries where _contacts[account][jid] == A MessageControl
|
# A dictionary of dictionaries where _contacts[account][jid] == A MessageControl
|
||||||
|
@ -140,7 +147,7 @@ class MessageWindow:
|
||||||
def _on_window_delete(self, win, event):
|
def _on_window_delete(self, win, event):
|
||||||
# Make sure all controls are okay with being deleted
|
# Make sure all controls are okay with being deleted
|
||||||
for ctrl in self.controls():
|
for ctrl in self.controls():
|
||||||
if not ctrl.allow_shutdown():
|
if not ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON):
|
||||||
return True # halt the delete
|
return True # halt the delete
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -199,7 +206,7 @@ class MessageWindow:
|
||||||
self.popup_menu(event)
|
self.popup_menu(event)
|
||||||
elif event.button == 2: # middle click
|
elif event.button == 2: # middle click
|
||||||
ctrl = self._widget_to_control(child)
|
ctrl = self._widget_to_control(child)
|
||||||
self.remove_tab(ctrl)
|
self.remove_tab(ctrl, self.CLOSE_TAB_MIDDLE_CLICK)
|
||||||
|
|
||||||
def _on_message_textview_mykeypress_event(self, widget, event_keyval,
|
def _on_message_textview_mykeypress_event(self, widget, event_keyval,
|
||||||
event_keymod):
|
event_keymod):
|
||||||
|
@ -224,7 +231,7 @@ class MessageWindow:
|
||||||
|
|
||||||
def _on_close_button_clicked(self, button, control):
|
def _on_close_button_clicked(self, button, control):
|
||||||
'''When close button is pressed: close a tab'''
|
'''When close button is pressed: close a tab'''
|
||||||
self.remove_tab(control)
|
self.remove_tab(control, self.CLOSE_CLOSE_BUTTON)
|
||||||
|
|
||||||
def show_title(self, urgent = True, control = None):
|
def show_title(self, urgent = True, control = None):
|
||||||
'''redraw the window's title'''
|
'''redraw the window's title'''
|
||||||
|
@ -279,11 +286,11 @@ class MessageWindow:
|
||||||
ctrl_page = self.notebook.page_num(ctrl.widget)
|
ctrl_page = self.notebook.page_num(ctrl.widget)
|
||||||
self.notebook.set_current_page(ctrl_page)
|
self.notebook.set_current_page(ctrl_page)
|
||||||
|
|
||||||
def remove_tab(self, ctrl, reason = None, force = False):
|
def remove_tab(self, ctrl, mothod, reason = None, force = False):
|
||||||
'''reason is only for gc (offline status message)
|
'''reason is only for gc (offline status message)
|
||||||
if force is True, do not ask any confirmation'''
|
if force is True, do not ask any confirmation'''
|
||||||
# Shutdown the MessageControl
|
# Shutdown the MessageControl
|
||||||
if not force and not ctrl.allow_shutdown():
|
if not force and not ctrl.allow_shutdown(mothod):
|
||||||
return
|
return
|
||||||
if reason is not None: # We are leaving gc with a status message
|
if reason is not None: # We are leaving gc with a status message
|
||||||
ctrl.shutdown(reason)
|
ctrl.shutdown(reason)
|
||||||
|
@ -499,9 +506,9 @@ class MessageWindow:
|
||||||
elif event.keyval == gtk.keysyms.Tab: # CTRL + TAB
|
elif event.keyval == gtk.keysyms.Tab: # CTRL + TAB
|
||||||
self.move_to_next_unread_tab(True)
|
self.move_to_next_unread_tab(True)
|
||||||
elif event.keyval == gtk.keysyms.F4: # CTRL + F4
|
elif event.keyval == gtk.keysyms.F4: # CTRL + F4
|
||||||
self.remove_tab(ctrl)
|
self.remove_tab(ctrl, self.CLOSE_CTRL_KEY)
|
||||||
elif event.keyval == gtk.keysyms.w: # CTRL + W
|
elif event.keyval == gtk.keysyms.w: # CTRL + W
|
||||||
self.remove_tab(ctrl)
|
self.remove_tab(ctrl, self.CLOSE_CTRL_KEY)
|
||||||
|
|
||||||
# MOD1 (ALT) mask
|
# MOD1 (ALT) mask
|
||||||
elif event.state & gtk.gdk.MOD1_MASK:
|
elif event.state & gtk.gdk.MOD1_MASK:
|
||||||
|
@ -524,7 +531,7 @@ class MessageWindow:
|
||||||
# Close tab bindings
|
# Close tab bindings
|
||||||
elif event.keyval == gtk.keysyms.Escape and \
|
elif event.keyval == gtk.keysyms.Escape and \
|
||||||
gajim.config.get('escape_key_closes'): # Escape
|
gajim.config.get('escape_key_closes'): # Escape
|
||||||
self.remove_tab(ctrl)
|
self.remove_tab(ctrl, self.CLOSE_ESC)
|
||||||
else:
|
else:
|
||||||
# If the active control has a message_textview pass the event to it
|
# If the active control has a message_textview pass the event to it
|
||||||
active_ctrl = self.get_active_control()
|
active_ctrl = self.get_active_control()
|
||||||
|
|
|
@ -2138,7 +2138,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
|
||||||
account)
|
account)
|
||||||
ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid,
|
ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid,
|
||||||
account)
|
account)
|
||||||
msg_win.remove_tab(ctrl)
|
msg_win.remove_tab(ctrl, msg_win.CLOSE_CLOSE_BUTTON)
|
||||||
else:
|
else:
|
||||||
need_readd = True
|
need_readd = True
|
||||||
if need_readd:
|
if need_readd:
|
||||||
|
|
Loading…
Add table
Reference in a new issue