diff --git a/src/Widgets/FormatBar.vala b/src/Widgets/FormatBar.vala index 8286caefc..3616d5924 100644 --- a/src/Widgets/FormatBar.vala +++ b/src/Widgets/FormatBar.vala @@ -21,13 +21,14 @@ public class Code.FormatBar : Gtk.Box { public bool tab_style_set_by_editor_config { get; set; default = false; } public bool tab_width_set_by_editor_config { get; set; default = false; } - private FormatButton line_menubutton; - private FormatButton lang_menubutton; - private FormatButton tab_menubutton; + private FormatBox line_formatbox; + private FormatBox lang_formatbox; + private FormatBox tab_formatbox; private Granite.SwitchModelButton space_tab_modelbutton; private Gtk.Entry goto_entry; private Gtk.InfoBar editorconfig_infobar; private Gtk.ListBox lang_selection_listbox; + private Gtk.MenuButton line_menubutton; private Gtk.SourceLanguageManager manager; private Gtk.SpinButton width_spinbutton; private LangEntry normal_entry; @@ -81,8 +82,10 @@ public class Code.FormatBar : Gtk.Box { child = box }; - tab_menubutton = new FormatButton () { - icon = new ThemedIcon ("format-indent-more-symbolic"), + tab_formatbox = new FormatBox ("format-indent-more-symbolic"); + + var tab_menubutton = new Gtk.MenuButton () { + child = tab_formatbox, popover = tab_popover }; @@ -137,8 +140,10 @@ public class Code.FormatBar : Gtk.Box { child = popover_content }; - lang_menubutton = new FormatButton () { - icon = new ThemedIcon ("application-x-class-file-symbolic"), + lang_formatbox = new FormatBox ("application-x-class-file-symbolic"); + + var lang_menubutton = new Gtk.MenuButton () { + child = lang_formatbox, popover = lang_popover, tooltip_text = _("Document language") }; @@ -164,8 +169,10 @@ public class Code.FormatBar : Gtk.Box { child = line_box }; - line_menubutton = new FormatButton () { - icon = new ThemedIcon ("view-continuous-symbolic"), + line_formatbox = new FormatBox ("view-continuous-symbolic"); + + line_menubutton = new Gtk.MenuButton () { + child = line_formatbox, popover = line_popover }; line_menubutton.tooltip_markup = Granite.markup_accel_tooltip ( @@ -231,7 +238,7 @@ public class Code.FormatBar : Gtk.Box { private void select_language (LangEntry lang, bool update_source_view = true) { lang_selection_listbox.select_row (lang); - lang_menubutton.text = lang.lang_name; + lang_formatbox.text = lang.lang_name; if (update_source_view) { lang.active = true; doc.source_view.language = lang.lang_id != null ? manager.get_language (lang.lang_id) : null; @@ -259,7 +266,7 @@ public class Code.FormatBar : Gtk.Box { Gtk.TextIter iter; buffer.get_iter_at_offset (out iter, position); var line = iter.get_line () + 1; - line_menubutton.text = "%d.%d".printf (line, iter.get_line_offset () + 1); + line_formatbox.text = "%d.%d".printf (line, iter.get_line_offset () + 1); goto_entry.text = "%d.%d".printf (line, iter.get_line_offset () + 1); } @@ -285,9 +292,9 @@ public class Code.FormatBar : Gtk.Box { public void set_tab_width (int indent_width) { width_spinbutton.@value = indent_width; if (space_tab_modelbutton.active) { - tab_menubutton.text = ngettext ("%d Space", "%d Spaces", indent_width).printf (indent_width); + tab_formatbox.text = ngettext ("%d Space", "%d Spaces", indent_width).printf (indent_width); } else { - tab_menubutton.text = ngettext ("%d Tab", "%d Tabs", indent_width).printf (indent_width); + tab_formatbox.text = ngettext ("%d Tab", "%d Tabs", indent_width).printf (indent_width); } if (doc != null) { @@ -311,41 +318,32 @@ public class Code.FormatBar : Gtk.Box { } } - private class FormatButton : Gtk.MenuButton { + private class FormatBox : Gtk.Box { public unowned string text { set { label_widget.label = "%s".printf (value); } } - public unowned GLib.Icon? icon { - owned get { - return img.gicon; - } - set { - img.gicon = value; - } - } - private Gtk.Image img; + public string icon_name { get; construct; } + private Gtk.Label label_widget; + public FormatBox (string icon_name) { + Object (icon_name: icon_name); + } + construct { - img = new Gtk.Image () { - icon_size = Gtk.IconSize.SMALL_TOOLBAR - }; + var img = new Gtk.Image.from_icon_name (icon_name, SMALL_TOOLBAR); label_widget = new Gtk.Label (null) { - ellipsize = Pango.EllipsizeMode.END, + ellipsize = END, use_markup = true }; - var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { - halign = Gtk.Align.CENTER - }; - box.add (img); - box.add (label_widget); - - add (box); + halign = CENTER; + add (img); + add (label_widget); } }