Commit 8bb4f5fb authored by Robert Schroll's avatar Robert Schroll Committed by Charles Lindsay

Add formatting menu in composer; fix #6436

N.B. The actions for the menu need to be set through the UIManager, not
through the ActionGroup.  Otherwise you get warnings about
gtk_accel_label_set_accel_closure.
parent 7de9b2d9
......@@ -33,8 +33,7 @@ public class ComposerWindow : Gtk.Window {
private const string ACTION_JUSTIFY_RIGHT = "justifyright";
private const string ACTION_JUSTIFY_CENTER = "justifycenter";
private const string ACTION_JUSTIFY_FULL = "justifyfull";
private const string ACTION_FONT = "font";
private const string ACTION_FONT_SIZE = "fontsize";
private const string ACTION_MENU = "menu";
private const string ACTION_COLOR = "color";
private const string ACTION_INSERT_LINK = "insertlink";
private const string ACTION_COMPOSE_AS_HTML = "compose as html";
......@@ -140,8 +139,7 @@ public class ComposerWindow : Gtk.Window {
private Gtk.Entry subject_entry;
private Gtk.Button discard_button;
private Gtk.Button send_button;
private Gtk.ToggleToolButton font_button;
private Gtk.ToggleToolButton font_size_button;
private Gtk.ToggleToolButton menu_button;
private Gtk.Label message_overlay_label;
private WebKit.DOM.Element? prev_selected_link = null;
private Gtk.Box attachments_box;
......@@ -152,14 +150,14 @@ public class ComposerWindow : Gtk.Window {
private Gtk.Widget hidden_on_attachment_drag_over_child;
private Gtk.Widget visible_on_attachment_drag_over_child;
private Gtk.Menu menu_html;
private Gtk.Menu menu_plain;
private Gtk.RadioMenuItem font_small;
private Gtk.RadioMenuItem font_medium;
private Gtk.RadioMenuItem font_large;
private Gtk.Menu font_size_menu;
private Gtk.RadioMenuItem font_sans;
private Gtk.RadioMenuItem font_serif;
private Gtk.RadioMenuItem font_monospace;
private Gtk.Menu font_menu;
private Gtk.ActionGroup actions;
private string? hover_url = null;
......@@ -272,8 +270,7 @@ public class ComposerWindow : Gtk.Window {
actions.get_action(ACTION_JUSTIFY_CENTER).activate.connect(on_formatting_action);
actions.get_action(ACTION_JUSTIFY_FULL).activate.connect(on_formatting_action);
actions.get_action(ACTION_FONT).activate.connect(on_select_font);
actions.get_action(ACTION_FONT_SIZE).activate.connect(on_select_font_size);
actions.get_action(ACTION_MENU).activate.connect(on_open_menu);
actions.get_action(ACTION_COLOR).activate.connect(on_select_color);
actions.get_action(ACTION_INSERT_LINK).activate.connect(on_insert_link);
......@@ -358,38 +355,52 @@ public class ComposerWindow : Gtk.Window {
GearyApplication.instance.config.spell_check_changed.connect(on_spell_check_changed);
font_button = builder.get_object("font button") as Gtk.ToggleToolButton;
font_size_button = builder.get_object("font size button") as Gtk.ToggleToolButton;
menu_button = builder.get_object("menu button") as Gtk.ToggleToolButton;
// Build menu
menu_html = new Gtk.Menu();
menu_html.deactivate.connect(on_deactivate_menu);
menu_html.attach_to_widget(menu_button, null);
// Build font menu.
font_menu = new Gtk.Menu();
font_menu.deactivate.connect(on_deactivate_font_menu);
font_menu.attach_to_widget(font_button, null);
font_sans = new Gtk.RadioMenuItem.with_label(new SList<Gtk.RadioMenuItem>(),
_("Sans Serif"));
font_sans.activate.connect(on_font_sans);
font_menu.append(font_sans);
menu_html.append(font_sans);
font_serif = new Gtk.RadioMenuItem.with_label_from_widget(font_sans, _("Serif"));
font_serif.activate.connect(on_font_serif);
font_menu.append(font_serif);
menu_html.append(font_serif);
font_monospace = new Gtk.RadioMenuItem.with_label_from_widget(font_sans,
_("Fixed width"));
font_monospace.activate.connect(on_font_monospace);
font_menu.append(font_monospace);
menu_html.append(font_monospace);
menu_html.append(new Gtk.SeparatorMenuItem());
// Build font size menu.
font_size_menu = new Gtk.Menu();
font_size_menu.deactivate.connect(on_deactivate_font_size_menu);
font_size_menu.attach_to_widget(font_size_button, null);
font_small = new Gtk.RadioMenuItem.with_label(new SList<Gtk.RadioMenuItem>(), _("Small"));
font_small.activate.connect(on_font_size_small);
font_size_menu.append(font_small);
menu_html.append(font_small);
font_medium = new Gtk.RadioMenuItem.with_label_from_widget(font_small, _("Medium"));
font_medium.activate.connect(on_font_size_medium);
font_size_menu.append(font_medium);
menu_html.append(font_medium);
font_large = new Gtk.RadioMenuItem.with_label_from_widget(font_small, _("Large"));
font_large.activate.connect(on_font_size_large);
font_size_menu.append(font_large);
menu_html.append(font_large);
menu_html.append(new Gtk.SeparatorMenuItem());
Gtk.MenuItem color_item = new Gtk.MenuItem();
color_item.related_action = ui.get_action("ui/color");
menu_html.append(color_item);
menu_html.append(new Gtk.SeparatorMenuItem());
Gtk.MenuItem html_item = new Gtk.CheckMenuItem();
html_item.related_action = ui.get_action("ui/htmlcompose");
menu_html.append(html_item);
menu_plain = new Gtk.Menu();
menu_plain.deactivate.connect(on_deactivate_menu);
menu_plain.attach_to_widget(menu_button, null);
Gtk.MenuItem html_item2 = new Gtk.CheckMenuItem();
html_item2.related_action = ui.get_action("ui/htmlcompose");
menu_plain.append(html_item2);
WebKit.WebSettings s = new WebKit.WebSettings();
s.enable_spell_checking = GearyApplication.instance.config.spell_check;
......@@ -970,8 +981,8 @@ public class ComposerWindow : Gtk.Window {
private void toggle_toolbar_buttons(bool show) {
string[] buttons = {"bold button", "italic button", "underline button",
"strikethrough button", "toolbar separator 1", "toolbar separator 2", "font button",
"font size button", "color button", "link button", "remove format button"};
"strikethrough button", "toolbar separator 1", "toolbar separator 2",
"link button", "remove format button"};
foreach (string button in buttons) {
Gtk.Widget widget = (Gtk.Widget) builder.get_object(button);
if (show)
......@@ -981,28 +992,21 @@ public class ComposerWindow : Gtk.Window {
}
}
private void on_select_font() {
if (!font_button.active)
return;
font_menu.show_all();
font_menu.popup(null, null, GtkUtil.menu_popup_relative, 0, 0);
}
private void on_deactivate_font_menu() {
font_button.active = false;
}
private void on_select_font_size() {
if (!font_size_button.active)
private void on_open_menu() {
if (!menu_button.active)
return;
font_size_menu.show_all();
font_size_menu.popup(null, null, GtkUtil.menu_popup_relative, 0, 0);
if (compose_as_html) {
menu_html.show_all();
menu_html.popup(null, null, GtkUtil.menu_popup_relative, 0, 0);
} else {
menu_plain.show_all();
menu_plain.popup(null, null, GtkUtil.menu_popup_relative, 0, 0);
}
}
private void on_deactivate_font_size_menu() {
font_size_button.active = false;
private void on_deactivate_menu() {
menu_button.active = false;
}
private void on_font_sans() {
......@@ -1276,11 +1280,6 @@ public class ComposerWindow : Gtk.Window {
select_all_item.activate.connect(on_select_all);
context_menu.append(select_all_item);
// HTML or plain text
Gtk.CheckMenuItem html_item = new Gtk.CheckMenuItem();
html_item.related_action = actions.get_action(ACTION_COMPOSE_AS_HTML);
context_menu.append(html_item);
context_menu.show_all();
update_actions();
......
......@@ -71,15 +71,9 @@
<accelerator key="r" modifiers="GDK_CONTROL_MASK"/>
</child>
<child>
<object class="GtkAction" id="font">
<property name="label" translatable="yes">Font</property>
<property name="stock_id">gtk-select-font</property>
</object>
<accelerator key="d" modifiers="GDK_CONTROL_MASK"/>
</child>
<child>
<object class="GtkAction" id="composemenu">
<property name="stock_id">gtk-properties</property>
<object class="GtkAction" id="menu">
<property name="label" translatable="yes">Menu</property>
<property name="stock_id">gtk-go-down</property>
</object>
</child>
<child>
......@@ -138,15 +132,10 @@
</object>
<accelerator key="k" modifiers="GDK_CONTROL_MASK"/>
</child>
<child>
<object class="GtkAction" id="fontsize">
<property name="label" translatable="yes">Font size</property>
<property name="icon_name">font</property>
</object>
</child>
<child>
<object class="GtkToggleAction" id="compose as html">
<property name="label" translatable="yes">Rich Text</property>
<property name="icon_name">text-html</property>
</object>
</child>
<child>
......@@ -154,6 +143,11 @@
<accelerator key="w" modifiers="GDK_CONTROL_MASK"/>
</child>
</object>
<object class="GtkArrow" id="menu arrow">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="arrow_type">down</property>
</object>
<object class="GtkBox" id="composer">
<property name="visible">True</property>
<property name="can_focus">False</property>
......@@ -531,26 +525,12 @@
</packing>
</child>
<child>
<object class="GtkToggleToolButton" id="font button">
<property name="related_action">font</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes" comments="Opens font drop-down menu">Fonts</property>
<property name="label" translatable="yes">Fonts</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToggleToolButton" id="font size button">
<property name="related_action">fontsize</property>
<object class="GtkToolButton" id="link button">
<property name="related_action">insertlink</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes" comments="Opens font size drop-down menu">Font size</property>
<property name="label" translatable="yes">Font size</property>
<property name="tooltip_text" translatable="yes" comments="Add an HTML link">Link (Ctrl+L)</property>
<property name="label" translatable="yes">Link</property>
<property name="use_underline">True</property>
</object>
<packing>
......@@ -559,12 +539,12 @@
</packing>
</child>
<child>
<object class="GtkToolButton" id="color button">
<property name="related_action">color</property>
<object class="GtkToolButton" id="remove format button">
<property name="related_action">removeformat</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes" comments="Opens font color dialog">Color (Ctrl+R)</property>
<property name="label" translatable="yes">Color</property>
<property name="tooltip_text" translatable="yes" comments="Resets formatting to the default style">Remove formatting (Ctrl+Space)</property>
<property name="label" translatable="yes">Remove formatting</property>
<property name="use_underline">True</property>
</object>
<packing>
......@@ -573,27 +553,29 @@
</packing>
</child>
<child>
<object class="GtkToolButton" id="link button">
<property name="related_action">insertlink</property>
<object class="GtkToolItem" id="filler">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes" comments="Add an HTML link">Link (Ctrl+L)</property>
<property name="label" translatable="yes">Link</property>
<property name="use_underline">True</property>
<property name="use_action_appearance">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
<property name="expand">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="remove format button">
<property name="related_action">removeformat</property>
<object class="GtkToggleToolButton" id="menu button">
<property name="related_action">menu</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes" comments="Resets formatting to the default style">Remove formatting (Ctrl+Space)</property>
<property name="label" translatable="yes">Remove formatting</property>
<property name="tooltip_text" translatable="yes" comments="Various options for formatting text">Formatting Menu</property>
<property name="label" translatable="yes">Menu</property>
<property name="use_underline">True</property>
<property name="icon_widget">menu arrow</property>
</object>
<packing>
<property name="expand">False</property>
......
......@@ -14,7 +14,7 @@
<accelerator action="strikethrough" />
<accelerator action="removeformat" />
<accelerator action="compose as html" />
<accelerator action="compose as html" name="htmlcompose" />
<accelerator action="indent" />
<accelerator action="outdent" />
......@@ -24,8 +24,7 @@
<accelerator action="justifycenter" />
<accelerator action="justifyfull" />
<accelerator action="font" />
<accelerator action="color" />
<accelerator action="color" name="color" />
<accelerator action="insertlink" />
<accelerator action="close" />
......
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