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:
Yann Leboulanger 2006-10-10 15:53:42 +00:00
parent f6ba23bf13
commit aae7e7e99c
5 changed files with 26 additions and 17 deletions

View File

@ -1517,7 +1517,7 @@ class ChatControl(ChatControlBase):
self.msg_textview.destroy()
def allow_shutdown(self):
def allow_shutdown(self, method):
if time.time() - gajim.last_message_time[self.account]\
[self.get_full_jid()] < 2:
# 2 seconds

View File

@ -1105,7 +1105,7 @@ class GroupchatControl(ChatControlBase):
reason = 'offline'
if len(message_array):
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)
return True
elif command == 'ban':
@ -1292,11 +1292,13 @@ class GroupchatControl(ChatControlBase):
self.handlers[i].disconnect(i)
del self.handlers[i]
def allow_shutdown(self):
model, iter = self.list_treeview.get_selection().get_selected()
if iter:
self.list_treeview.get_selection().unselect_all()
return False
def allow_shutdown(self, method):
'''If check_selection is True, '''
if method == self.parent_win.CLOSE_ESC:
model, iter = self.list_treeview.get_selection().get_selected()
if iter:
self.list_treeview.get_selection().unselect_all()
return False
retval = True
includes = gajim.config.get('confirm_close_muc_rooms').split(' ')
excludes = gajim.config.get('noconfirm_close_muc_rooms').split(' ')

View File

@ -57,7 +57,7 @@ class MessageControl:
or inactive (state is False)'''
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.
If a control is not in a suitable shutdown state this method
should return False'''

View File

@ -40,6 +40,13 @@ class MessageWindow:
# DND_TARGETS is the targets needed by drag_source_set and drag_dest_set
DND_TARGETS = [('GAJIM_TAB', 0, 81)]
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):
# A dictionary of dictionaries where _contacts[account][jid] == A MessageControl
@ -140,7 +147,7 @@ class MessageWindow:
def _on_window_delete(self, win, event):
# Make sure all controls are okay with being deleted
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 False
@ -199,7 +206,7 @@ class MessageWindow:
self.popup_menu(event)
elif event.button == 2: # middle click
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,
event_keymod):
@ -224,7 +231,7 @@ class MessageWindow:
def _on_close_button_clicked(self, button, control):
'''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):
'''redraw the window's title'''
@ -279,11 +286,11 @@ class MessageWindow:
ctrl_page = self.notebook.page_num(ctrl.widget)
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)
if force is True, do not ask any confirmation'''
# Shutdown the MessageControl
if not force and not ctrl.allow_shutdown():
if not force and not ctrl.allow_shutdown(mothod):
return
if reason is not None: # We are leaving gc with a status message
ctrl.shutdown(reason)
@ -499,9 +506,9 @@ class MessageWindow:
elif event.keyval == gtk.keysyms.Tab: # CTRL + TAB
self.move_to_next_unread_tab(True)
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
self.remove_tab(ctrl)
self.remove_tab(ctrl, self.CLOSE_CTRL_KEY)
# MOD1 (ALT) mask
elif event.state & gtk.gdk.MOD1_MASK:
@ -524,7 +531,7 @@ class MessageWindow:
# Close tab bindings
elif event.keyval == gtk.keysyms.Escape and \
gajim.config.get('escape_key_closes'): # Escape
self.remove_tab(ctrl)
self.remove_tab(ctrl, self.CLOSE_ESC)
else:
# If the active control has a message_textview pass the event to it
active_ctrl = self.get_active_control()

View File

@ -2138,7 +2138,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
account)
ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid,
account)
msg_win.remove_tab(ctrl)
msg_win.remove_tab(ctrl, msg_win.CLOSE_CLOSE_BUTTON)
else:
need_readd = True
if need_readd: