Commit c52046f5 authored by Philipp Hörist's avatar Philipp Hörist

Merge branch 'formatting-menu' into 'master'

Make the formatting menu declarative.

See merge request !10
parents 8212bc25 c1c2a516
This diff is collapsed.
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment