do not show Clear menuitem in TextView in History Window

This commit is contained in:
Nikos Kouremenos 2006-10-07 13:23:20 +00:00
parent 799a372d18
commit 607f473cc8
2 changed files with 32 additions and 15 deletions

View file

@ -36,8 +36,12 @@ from htmltextview import HtmlTextView
class ConversationTextview: class ConversationTextview:
'''Class for the conversation textview (where user reads already said messages) '''Class for the conversation textview (where user reads already said messages)
for chat/groupchat windows''' for chat/groupchat windows'''
def __init__(self, account): def __init__(self, account, used_in_history_window = False):
# no need to inherit TextView, use it as property is safer '''if used_in_history_window is True, then we do not show
Clear menuitem in context menu'''
self.used_in_history_window = used_in_history_window
# no need to inherit TextView, use it as atrribute is safer
self.tv = HtmlTextView() self.tv = HtmlTextView()
self.tv.html_hyperlink_handler = self.html_hyperlink_handler self.tv.html_hyperlink_handler = self.html_hyperlink_handler
@ -52,11 +56,13 @@ class ConversationTextview:
self.handlers = {} self.handlers = {}
# connect signals # connect signals
id = self.tv.connect('motion_notify_event', self.on_textview_motion_notify_event) id = self.tv.connect('motion_notify_event',
self.on_textview_motion_notify_event)
self.handlers[id] = self.tv self.handlers[id] = self.tv
id = self.tv.connect('populate_popup', self.on_textview_populate_popup) id = self.tv.connect('populate_popup', self.on_textview_populate_popup)
self.handlers[id] = self.tv self.handlers[id] = self.tv
id = self.tv.connect('button_press_event', self.on_textview_button_press_event) id = self.tv.connect('button_press_event',
self.on_textview_button_press_event)
self.handlers[id] = self.tv self.handlers[id] = self.tv
self.account = account self.account = account
@ -145,7 +151,7 @@ class ConversationTextview:
self.handlers[i].disconnect(i) self.handlers[i].disconnect(i)
del self.handlers del self.handlers
self.tv.destroy() self.tv.destroy()
#TODO #FIXME:
# self.line_tooltip.destroy() # self.line_tooltip.destroy()
def update_tags(self): def update_tags(self):
@ -311,18 +317,28 @@ class ConversationTextview:
def on_textview_populate_popup(self, textview, menu): def on_textview_populate_popup(self, textview, menu):
'''we override the default context menu and we prepend Clear '''we override the default context menu and we prepend Clear
(only if used_in_history_window is False)
and if we have sth selected we show a submenu with actions on the phrase and if we have sth selected we show a submenu with actions on the phrase
(see on_conversation_textview_button_press_event)''' (see on_conversation_textview_button_press_event)'''
item = gtk.SeparatorMenuItem()
menu.prepend(item) separator_menuitem_was_added = False
item = gtk.ImageMenuItem(gtk.STOCK_CLEAR) if not self.used_in_history_window:
menu.prepend(item) item = gtk.SeparatorMenuItem()
id = item.connect('activate', self.clear) menu.prepend(item)
self.handlers[id] = item separator_menuitem_was_added = True
item = gtk.ImageMenuItem(gtk.STOCK_CLEAR)
menu.prepend(item)
id = item.connect('activate', self.clear)
self.handlers[id] = item
if self.selected_phrase: if self.selected_phrase:
if len(self.selected_phrase) > 25: if not separator_menuitem_was_added:
self.selected_phrase = helpers.reduce_chars_newlines( item = gtk.SeparatorMenuItem()
self.selected_phrase, 25) menu.prepend(item)
self.selected_phrase = helpers.reduce_chars_newlines(
self.selected_phrase, 25)
item = gtk.MenuItem(_('_Actions for "%s"') % self.selected_phrase) item = gtk.MenuItem(_('_Actions for "%s"') % self.selected_phrase)
menu.prepend(item) menu.prepend(item)
submenu = gtk.Menu() submenu = gtk.Menu()

View file

@ -59,7 +59,8 @@ class HistoryWindow:
self.calendar = xml.get_widget('calendar') self.calendar = xml.get_widget('calendar')
scrolledwindow = xml.get_widget('scrolledwindow') scrolledwindow = xml.get_widget('scrolledwindow')
self.history_textview = conversation_textview.ConversationTextview(account) self.history_textview = conversation_textview.ConversationTextview(
account, used_in_history_window = True)
scrolledwindow.add(self.history_textview.tv) scrolledwindow.add(self.history_textview.tv)
self.history_buffer = self.history_textview.tv.get_buffer() self.history_buffer = self.history_textview.tv.get_buffer()
self.history_buffer.create_tag('highlight', background = 'yellow') self.history_buffer.create_tag('highlight', background = 'yellow')