Merge branch 'formatting-menu' into 'master'

Make the formatting menu declarative.

See merge request !10
This commit is contained in:
Philipp Hörist 2016-12-24 09:01:39 +01:00
commit c52046f565
4 changed files with 104 additions and 66 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkAdjustment" id="adjustment1">
@ -278,6 +278,85 @@
</child>
</object>
</child>
<child type="titlebar">
<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>
@ -525,11 +604,11 @@
<child>
<object class="GtkButton" id="authentication_button">
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="no_show_all">True</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="lock_image">
<property name="visible">True</property>
@ -584,13 +663,13 @@
<object class="GtkButton" id="emoticons_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<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="tooltip_markup" translatable="yes">Show a list of emoticons (Alt+M)</property>
<property name="tooltip_text" translatable="yes">Show a list of emoticons (Alt+M)</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="emoticons_button_image">
<property name="visible">True</property>
@ -608,14 +687,15 @@
</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>
<property name="receives_default">True</property>
<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="focus_on_click">False</property>
<property name="popup">formattings_menu</property>
<child>
<object class="GtkImage" id="image10">
<property name="visible">True</property>
@ -674,10 +754,10 @@
<object class="GtkButton" id="send_file_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
@ -739,13 +819,13 @@
<object class="GtkButton" id="convert_to_gc_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<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="tooltip_markup" translatable="yes">Invite contacts to the conversation (Ctrl+G)</property>
<property name="tooltip_text" translatable="yes">Invite contacts to the conversation (Ctrl+G)</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="convert_to_gc_button_image">
<property name="visible">True</property>
@ -766,13 +846,13 @@
<object class="GtkButton" id="contact_information_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<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="tooltip_markup" translatable="yes">Show the contact&amp;apos;s profile (Ctrl+I)</property>
<property name="tooltip_text" translatable="yes">Show the contact's profile (Ctrl+I)</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
@ -793,13 +873,13 @@
<object class="GtkButton" id="history_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<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="tooltip_markup" translatable="yes">Browse the chat history (Ctrl+H)</property>
<property name="tooltip_text" translatable="yes">Browse the chat history (Ctrl+H)</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="history_image">
<property name="visible">True</property>
@ -832,13 +912,13 @@
<object class="GtkButton" id="message_window_actions_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<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="tooltip_markup" translatable="yes">Show advanced functions (Alt+D)</property>
<property name="tooltip_text" translatable="yes">Show advanced functions (Alt+D)</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
@ -875,10 +955,10 @@
<object class="GtkVolumeButton" id="sound_hscale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<property name="orientation">vertical</property>
<property name="adjustment">adjustment1</property>
<property name="icons">audio-volume-muted
@ -908,10 +988,10 @@ audio-volume-medium</property>
<object class="GtkVolumeButton" id="mic_hscale">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<property name="orientation">vertical</property>
<property name="adjustment">adjustment2</property>
<property name="icons">audio-mic-volume-muted

View File

@ -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

View File

@ -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,

View File

@ -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)