Use two different buttons in ConversationMessage to show starred state.

Having two buttons means we don't need to change the image and handler
when clicked, just manage their visbility.

* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage): Add both a star and unstar template child,
  update their state as the message's state changes.

* ui/conversation-message.ui: Rename flag button to "star", add new
  unstar button.
This commit is contained in:
Michael James Gratton 2016-04-16 15:43:54 +10:00
parent 26574d873d
commit 9e9e007974
2 changed files with 53 additions and 18 deletions

View file

@ -82,7 +82,9 @@ public class ConversationMessage : Gtk.Box {
[GtkChild]
private Gtk.Image attachment_icon;
[GtkChild]
private Gtk.Button flag_button;
private Gtk.Button star_button;
[GtkChild]
private Gtk.Button unstar_button;
[GtkChild]
private Gtk.MenuButton message_menubutton;
@ -251,7 +253,8 @@ public class ConversationMessage : Gtk.Box {
header_revealer.set_reveal_child(true);
header_revealer.set_transition_type(revealer);
flag_button.set_sensitive(true);
star_button.set_sensitive(true);
unstar_button.set_sensitive(true);
message_menubutton.set_sensitive(true);
// XXX this is pretty gross
@ -268,7 +271,8 @@ public class ConversationMessage : Gtk.Box {
avatar_image.set_pixel_size(24); // XXX constant
preview_revealer.set_reveal_child(true);
header_revealer.set_reveal_child(false);
flag_button.set_sensitive(false);
star_button.set_sensitive(false);
unstar_button.set_sensitive(false);
message_menubutton.set_sensitive(false);
body_revealer.set_reveal_child(false);
}
@ -369,8 +373,24 @@ public class ConversationMessage : Gtk.Box {
}
public void update_flags(Geary.Email email) {
toggle_class("read");
toggle_class("starred");
Geary.EmailFlags flags = email.email_flags;
Gtk.StyleContext style = get_style_context();
if (flags.is_unread()) {
style.add_class("geary_unread");
} else {
style.remove_class("geary_unread");
}
if (flags.is_flagged()) {
style.add_class("geary_starred");
star_button.hide();
unstar_button.show();
} else {
style.remove_class("geary_starred");
star_button.show();
unstar_button.hide();
}
//if (email.email_flags.is_outbox_sent()) {
// email_warning.set_inner_html(
@ -1073,16 +1093,6 @@ public class ConversationMessage : Gtk.Box {
// return containing_folder.special_folder_type == Geary.SpecialFolderType.DRAFTS;
// }
private void toggle_class(string cls) {
Gtk.StyleContext context = get_style_context();
if (context.has_class(cls)) {
context.add_class(cls);
} else {
context.remove_class(cls);
}
}
private static bool is_content_type_supported_inline(Geary.Mime.ContentType content_type) {
foreach (string mime_type in INLINE_MIME_TYPES) {
try {

View file

@ -406,13 +406,14 @@
</packing>
</child>
<child>
<object class="GtkButton" id="flag_button">
<object class="GtkButton" id="star_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Toggle this message's flag</property>
<property name="tooltip_text" translatable="yes">Mark this message as starred</property>
<property name="valign">start</property>
<property name="action_name">win.message_star</property>
<property name="relief">none</property>
<child>
<object class="GtkImage">
@ -428,6 +429,30 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="unstar_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Mark this message as not starred</property>
<property name="valign">start</property>
<property name="action_name">win.message_unstar</property>
<property name="relief">none</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">starred-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="message_menubutton">
<property name="visible">True</property>
@ -448,7 +473,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
</object>