Skip to content

Commit

Permalink
Separate the pill-style Toolbar from the pill-style HeaderBar
Browse files Browse the repository at this point in the history
The composer toolbar uses the former, while the main window header uses
the latter.

https://bugzilla.gnome.org/show_bug.cgi?id=730903
  • Loading branch information
rschroll committed Jun 4, 2014
1 parent 14a6fe0 commit 39ef136
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/client/components/main-toolbar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

// Draws the main toolbar.
public class MainToolbar : PillToolbar {
public class MainToolbar : PillHeaderbar {
private const string ICON_CLEAR_NAME = "edit-clear-symbolic";
private const string ICON_CLEAR_RTL_NAME = "edit-clear-rtl-symbolic";
private const string DEFAULT_SEARCH_TEXT = _("Search");
Expand Down
65 changes: 53 additions & 12 deletions src/client/components/pill-toolbar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@
*/

/**
* Class for creating a Nautilus-style "pill" toolbar. Use only as directed.
* Interface for creating a Nautilus-style "pill" toolbar. Use only as directed.
*
* Subclasses should inherit from some Gtk.Container and provide pack_start() and
* pack_end() methods with the correct signature. They also need to have action_group
* and size properties and call initialize() in their constructors.
*/
public class PillToolbar : Gtk.HeaderBar {
private Gtk.ActionGroup action_group;
private Gtk.SizeGroup size = new Gtk.SizeGroup(Gtk.SizeGroupMode.VERTICAL);
public interface PillBar : Gtk.Container {
protected abstract Gtk.ActionGroup action_group { get; set; }
protected abstract Gtk.SizeGroup size { get; set; }

public PillToolbar(Gtk.ActionGroup toolbar_action_group) {
public abstract void pack_start(Gtk.Widget widget);
public abstract void pack_end(Gtk.Widget widget);

protected virtual void initialize(Gtk.ActionGroup toolbar_action_group) {
action_group = toolbar_action_group;
size = new Gtk.SizeGroup(Gtk.SizeGroupMode.VERTICAL);
}

public void add_start(Gtk.Widget *widget) {
public virtual void add_start(Gtk.Widget widget) {
pack_start(widget);
size.add_widget(widget);
}

public void add_end(Gtk.Widget *widget) {
public virtual void add_end(Gtk.Widget widget) {
pack_end(widget);
size.add_widget(widget);
}

protected void setup_button(Gtk.Button b, string? icon_name, string action_name,
protected virtual void setup_button(Gtk.Button b, string? icon_name, string action_name,
bool show_label = false) {
b.related_action = action_group.get_action(action_name);
b.tooltip_text = b.related_action.tooltip;
Expand All @@ -45,7 +53,7 @@ public class PillToolbar : Gtk.HeaderBar {
/**
* Given an icon and action, creates a button that triggers the action.
*/
public Gtk.Button create_toolbar_button(string? icon_name, string action_name, bool show_label = false) {
public virtual Gtk.Button create_toolbar_button(string? icon_name, string action_name, bool show_label = false) {
Gtk.Button b = new Gtk.Button();
setup_button(b, icon_name, action_name, show_label);

Expand All @@ -55,7 +63,7 @@ public class PillToolbar : Gtk.HeaderBar {
/**
* Given an icon and action, creates a toggle button that triggers the action.
*/
public Gtk.Button create_toggle_button(string? icon_name, string action_name) {
public virtual Gtk.Button create_toggle_button(string? icon_name, string action_name) {
Gtk.ToggleButton b = new Gtk.ToggleButton();
setup_button(b, icon_name, action_name);

Expand All @@ -65,7 +73,7 @@ public class PillToolbar : Gtk.HeaderBar {
/**
* Given an icon, menu, and action, creates a button that triggers the menu and the action.
*/
public Gtk.MenuButton create_menu_button(string? icon_name, Gtk.Menu? menu, string action_name) {
public virtual Gtk.MenuButton create_menu_button(string? icon_name, Gtk.Menu? menu, string action_name) {
Gtk.MenuButton b = new Gtk.MenuButton();
setup_button(b, icon_name, action_name);
b.popup = menu;
Expand All @@ -78,7 +86,7 @@ public class PillToolbar : Gtk.HeaderBar {
* toolbar. Optionally adds spacers "before" and "after" the buttons (those terms depending
* on Gtk.TextDirection)
*/
public Gtk.Box create_pill_buttons(Gee.Collection<Gtk.Button> buttons,
public virtual Gtk.Box create_pill_buttons(Gee.Collection<Gtk.Button> buttons,
bool before_spacer = true, bool after_spacer = false) {
Gtk.Box box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
box.valign = Gtk.Align.CENTER;
Expand All @@ -96,3 +104,36 @@ public class PillToolbar : Gtk.HeaderBar {
}
}

/**
* A pill-style header bar.
*/
public class PillHeaderbar : Gtk.HeaderBar, PillBar {
protected Gtk.ActionGroup action_group { get; set; }
protected Gtk.SizeGroup size { get; set; }

public PillHeaderbar(Gtk.ActionGroup toolbar_action_group) {
initialize(toolbar_action_group);
}
}

/**
* A pill-style toolbar.
*/
public class PillToolbar : Gtk.Box, PillBar {
protected Gtk.ActionGroup action_group { get; set; }
protected Gtk.SizeGroup size { get; set; }

public PillToolbar(Gtk.ActionGroup toolbar_action_group) {
Object(orientation: Gtk.Orientation.HORIZONTAL, spacing: 6);
initialize(toolbar_action_group);
}

public new void pack_start(Gtk.Widget widget) {
base.pack_start(widget, false, false, 0);
}

public new void pack_end(Gtk.Widget widget) {
base.pack_end(widget, false, false, 0);
}
}

2 changes: 2 additions & 0 deletions ui/composer.glade
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@
<object class="GtkAlignment" id="toolbar area">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">6</property>
<property name="right_padding">6</property>
<child>
<placeholder/>
</child>
Expand Down

0 comments on commit 39ef136

Please sign in to comment.