Replace formatting button with declarative menu.
This prevents Gajim from having to regenerate the menu everytime it is clicked on.
This commit is contained in:
parent
db2b6e5ee5
commit
c1c2a5162c
|
@ -282,6 +282,82 @@
|
|||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkMenu" id="formattings_menu">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkCheckMenuItem" id="bold">
|
||||
<property name="name">bold</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Bold</property>
|
||||
<signal name="activate" handler="on_formatting_menuitem_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckMenuItem" id="italic">
|
||||
<property name="name">italic</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Italic</property>
|
||||
<signal name="activate" handler="on_formatting_menuitem_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckMenuItem" id="underline">
|
||||
<property name="name">underline</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Underline</property>
|
||||
<signal name="activate" handler="on_formatting_menuitem_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckMenuItem" id="strike">
|
||||
<property name="name">strike</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Strike</property>
|
||||
<signal name="activate" handler="on_formatting_menuitem_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="color">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Color</property>
|
||||
<signal name="activate" handler="on_color_menuitem_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="font">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Font</property>
|
||||
<signal name="activate" handler="on_font_menuitem_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="clear_formatting">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Clear formatting</property>
|
||||
<signal name="activate" handler="on_clear_formatting_menuitem_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="image4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -611,7 +687,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="formattings_button">
|
||||
<object class="GtkMenuButton" id="formattings_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
|
@ -619,6 +695,7 @@
|
|||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="has_tooltip">True</property>
|
||||
<property name="relief">none</property>
|
||||
<property name="popup">formattings_menu</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image10">
|
||||
<property name="visible">True</property>
|
||||
|
|
|
@ -373,10 +373,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
widget.set_sensitive(False)
|
||||
self.handlers[id_] = widget
|
||||
|
||||
widget = self.xml.get_object('formattings_button')
|
||||
id_ = widget.connect('clicked', self.on_formattings_button_clicked)
|
||||
self.handlers[id_] = widget
|
||||
|
||||
# the following vars are used to keep history of user's messages
|
||||
self.sent_history = []
|
||||
self.sent_history_pos = 0
|
||||
|
@ -979,64 +975,25 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|||
gajim.interface.emoticon_menuitem_clicked = self.append_emoticon
|
||||
gajim.interface.popup_emoticons_under_button(widget, self.parent_win)
|
||||
|
||||
def on_formattings_button_clicked(self, widget):
|
||||
"""
|
||||
Popup formattings menu
|
||||
"""
|
||||
menu = Gtk.Menu()
|
||||
|
||||
menuitems = ((_('Bold'), 'bold'),
|
||||
(_('Italic'), 'italic'),
|
||||
(_('Underline'), 'underline'),
|
||||
(_('Strike'), 'strike'))
|
||||
|
||||
active_tags = self.msg_textview.get_active_tags()
|
||||
|
||||
for menuitem in menuitems:
|
||||
item = Gtk.CheckMenuItem.new_with_label(menuitem[0])
|
||||
if menuitem[1] in active_tags:
|
||||
item.set_active(True)
|
||||
else:
|
||||
item.set_active(False)
|
||||
item.connect('activate', self.msg_textview.set_tag,
|
||||
menuitem[1])
|
||||
menu.append(item)
|
||||
|
||||
item = Gtk.SeparatorMenuItem.new() # separator
|
||||
menu.append(item)
|
||||
|
||||
item = Gtk.MenuItem.new_with_label(_('Color'))
|
||||
item.connect('activate', self.on_color_menuitem_activale)
|
||||
menu.append(item)
|
||||
|
||||
item = Gtk.MenuItem.new_with_label(_('Font'))
|
||||
item.connect('activate', self.on_font_menuitem_activale)
|
||||
menu.append(item)
|
||||
|
||||
item = Gtk.SeparatorMenuItem.new() # separator
|
||||
menu.append(item)
|
||||
|
||||
item = Gtk.MenuItem.new_with_label(_('Clear formating'))
|
||||
item.connect('activate', self.msg_textview.clear_tags)
|
||||
menu.append(item)
|
||||
|
||||
menu.show_all()
|
||||
menu.attach_to_widget(widget, None)
|
||||
gtkgui_helpers.popup_emoticons_under_button(menu, widget,
|
||||
self.parent_win)
|
||||
|
||||
def on_color_menuitem_activale(self, widget):
|
||||
def on_color_menuitem_activate(self, widget):
|
||||
color_dialog = Gtk.ColorChooserDialog(None, self.parent_win.window)
|
||||
color_dialog.set_use_alpha(False)
|
||||
color_dialog.connect('response', self.msg_textview.color_set)
|
||||
color_dialog.show_all()
|
||||
|
||||
def on_font_menuitem_activale(self, widget):
|
||||
def on_font_menuitem_activate(self, widget):
|
||||
font_dialog = Gtk.FontChooserDialog(None, self.parent_win.window)
|
||||
start, finish = self.msg_textview.get_active_iters()
|
||||
font_dialog.connect('response', self.msg_textview.font_set, start, finish)
|
||||
font_dialog.show_all()
|
||||
|
||||
def on_formatting_menuitem_activate(self, widget):
|
||||
tag = widget.get_name()
|
||||
self.msg_textview.set_tag(tag)
|
||||
|
||||
def on_clear_formatting_menuitem_activate(self, widget):
|
||||
self.msg_textview.clear_tags()
|
||||
|
||||
def on_actions_button_clicked(self, widget):
|
||||
"""
|
||||
Popup action menu
|
||||
|
|
|
@ -64,6 +64,7 @@ class MessageControl(object):
|
|||
gajim.last_message_time[self.account][self.get_full_jid()] = 0
|
||||
|
||||
self.xml = gtkgui_helpers.get_gtk_builder('%s.ui' % widget_name)
|
||||
self.xml.connect_signals(self)
|
||||
self.widget = self.xml.get_object('%s_hbox' % widget_name)
|
||||
|
||||
gajim.ged.register_event_handler('message-outgoing', ged.OUT_GUI1,
|
||||
|
|
|
@ -122,7 +122,7 @@ class MessageTextView(Gtk.TextView):
|
|||
start, finish = _buffer.get_bounds()
|
||||
return (start, finish)
|
||||
|
||||
def set_tag(self, widget, tag):
|
||||
def set_tag(self, tag):
|
||||
_buffer = self.get_buffer()
|
||||
start, finish = self.get_active_iters()
|
||||
if start.has_tag(self.other_tags[tag]):
|
||||
|
@ -134,7 +134,7 @@ class MessageTextView(Gtk.TextView):
|
|||
_buffer.remove_tag_by_name('underline', start, finish)
|
||||
_buffer.apply_tag_by_name(tag, start, finish)
|
||||
|
||||
def clear_tags(self, widget):
|
||||
def clear_tags(self):
|
||||
_buffer = self.get_buffer()
|
||||
start, finish = self.get_active_iters()
|
||||
_buffer.remove_all_tags(start, finish)
|
||||
|
|
Loading…
Reference in New Issue