From c1c2a5162c4bb3aff8687517960143b6d48ff5c9 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 23 Dec 2016 19:01:32 +0100 Subject: [PATCH] Replace formatting button with declarative menu. This prevents Gajim from having to regenerate the menu everytime it is clicked on. --- data/gui/chat_control.ui | 79 +++++++++++++++++++++++++++++++++++++++- src/chat_control.py | 61 +++++-------------------------- src/message_control.py | 1 + src/message_textview.py | 4 +- 4 files changed, 90 insertions(+), 55 deletions(-) diff --git a/data/gui/chat_control.ui b/data/gui/chat_control.ui index d7cb93c92..5d5b97145 100644 --- a/data/gui/chat_control.ui +++ b/data/gui/chat_control.ui @@ -282,6 +282,82 @@ + + True + False + + + bold + True + False + Bold + + + + + + italic + True + False + Italic + + + + + + underline + True + False + Underline + + + + + + strike + True + False + Strike + + + + + + True + False + + + + + True + False + Color + + + + + + True + False + Font + + + + + + True + False + + + + + True + False + Clear formatting + + + + True False @@ -611,7 +687,7 @@ - + True True False @@ -619,6 +695,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK True none + formattings_menu True diff --git a/src/chat_control.py b/src/chat_control.py index 691f5d958..61ae054d1 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -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 diff --git a/src/message_control.py b/src/message_control.py index f2e35c029..cf0597603 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -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, diff --git a/src/message_textview.py b/src/message_textview.py index eb253da97..83900df6e 100644 --- a/src/message_textview.py +++ b/src/message_textview.py @@ -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)