Reenable and update code for editing draft messages.

Use a Gtk.InfoBar for displaying the draft button.

* src/client/conversation-viewer/conversation-message.vala: Add draft
  infobar template child, edit_draft signal. Remove unused draft-related
  code.
  (ConversationMessage::ConversationMessage): Add new is_draft ctor
  param, when true show the draft infobar.
  (ConversationMessage::on_draft_response): New handler for when the edit
  draft button on the infobar is clicked.

* src/client/conversation-viewer/conversation-viewer.vala: Remove
  edit_draft signal, make a lame attemppt to work out if a message is a
  draft and pass that through to ConversationMessage.

* src/client/application/geary-controller.vala: Hook up on_edit_draft
  handler to added conversation messages.

* ui/conversation-message.ui: Added draft infobar.
This commit is contained in:
Michael James Gratton 2016-04-18 11:55:03 +10:00
parent b5270e3740
commit ea8a9c992c
4 changed files with 123 additions and 36 deletions

View file

@ -213,8 +213,6 @@ public class GearyController : Geary.BaseObject {
main_window.conversation_viewer.mark_messages.connect(on_conversation_viewer_mark_messages);
main_window.conversation_viewer.save_attachments.connect(on_save_attachments);
main_window.conversation_viewer.save_buffer_to_file.connect(on_save_buffer_to_file);
main_window.conversation_viewer.edit_draft.connect(on_edit_draft);
new_messages_monitor = new NewMessagesMonitor(should_notify_new_messages);
main_window.folder_list.set_new_messages_monitor(new_messages_monitor);
@ -294,8 +292,6 @@ public class GearyController : Geary.BaseObject {
main_window.conversation_viewer.mark_messages.disconnect(on_conversation_viewer_mark_messages);
main_window.conversation_viewer.save_attachments.disconnect(on_save_attachments);
main_window.conversation_viewer.save_buffer_to_file.disconnect(on_save_buffer_to_file);
main_window.conversation_viewer.edit_draft.disconnect(on_edit_draft);
// hide window while shutting down, as this can take a few seconds under certain conditions
main_window.hide();
@ -1495,10 +1491,6 @@ public class GearyController : Geary.BaseObject {
on_edit_draft(activated.get_latest_recv_email(Geary.App.Conversation.Location.IN_FOLDER));
}
private void on_edit_draft(Geary.Email draft) {
create_compose_widget(ComposerWidget.ComposeType.NEW_MESSAGE, draft, null, null, true);
}
private void on_special_folder_type_changed(Geary.Folder folder, Geary.SpecialFolderType old_type,
Geary.SpecialFolderType new_type) {
main_window.folder_list.remove_folder(folder);
@ -2589,11 +2581,13 @@ public class GearyController : Geary.BaseObject {
private void on_message_added(ConversationMessage message) {
message.link_activated.connect(on_link_activated);
message.attachment_activated.connect(on_attachment_activated);
message.edit_draft.connect(on_edit_draft);
}
private void on_message_removed(ConversationMessage message) {
message.link_activated.disconnect(on_link_activated);
message.attachment_activated.disconnect(on_attachment_activated);
message.edit_draft.disconnect(on_edit_draft);
}
private void on_link_activated(string link) {
@ -2604,6 +2598,10 @@ public class GearyController : Geary.BaseObject {
}
}
private void on_edit_draft(Geary.Email draft) {
create_compose_widget(ComposerWidget.ComposeType.NEW_MESSAGE, draft, null, null, true);
}
// Disables all single-message buttons and enables all multi-message buttons.
public void enable_multiple_message_buttons() {
update_tooltips();

View file

@ -121,6 +121,9 @@ public class ConversationMessage : Gtk.Box {
// The folder containing the message
private Geary.Folder containing_folder = null; // XXX weak??
[GtkChild]
private Gtk.InfoBar draft_infobar;
// Contains the current mouse-over'ed link URL, if any
private string? hover_url = null;
@ -136,8 +139,13 @@ public class ConversationMessage : Gtk.Box {
// Fired on attachment activation
public signal void attachment_activated(Geary.Attachment attachment);
// Fired the edit draft button is clicked.
public signal void edit_draft(Geary.Email message);
public ConversationMessage(Geary.Email email, Geary.Folder containing_folder) {
public ConversationMessage(Geary.Email email,
Geary.Folder containing_folder,
bool is_draft) {
this.email = email;
this.containing_folder = containing_folder;
@ -226,19 +234,10 @@ public class ConversationMessage : Gtk.Box {
// debug("Error adding attached message: %s", error.message);
// }
// }
// // Edit draft button for drafts folder.
// if (in_drafts_folder() && is_in_folder) {
// WebKit.DOM.HTMLElement draft_edit_container = Util.DOM.select(div_message, ".draft_edit");
// WebKit.DOM.HTMLElement draft_edit_button =
// Util.DOM.select(div_message, ".draft_edit_button");
// try {
// draft_edit_container.set_attribute("style", "display:block");
// draft_edit_button.set_inner_html(_("Edit Draft"));
// } catch (Error e) {
// warning("Error setting draft button: %s", e.message);
// }
// }
if (is_draft) {
draft_infobar.show();
}
update_message_state(false);
}
@ -1105,10 +1104,6 @@ public class ConversationMessage : Gtk.Box {
}
}
// private bool in_drafts_folder() {
// return containing_folder.special_folder_type == Geary.SpecialFolderType.DRAFTS;
// }
private static bool is_content_type_supported_inline(Geary.Mime.ContentType content_type) {
foreach (string mime_type in INLINE_MIME_TYPES) {
try {
@ -1118,7 +1113,7 @@ public class ConversationMessage : Gtk.Box {
debug("Unable to compare MIME type %s: %s", mime_type, err.message);
}
}
return false;
}
@ -1348,10 +1343,9 @@ public class ConversationMessage : Gtk.Box {
body_box.trigger_tooltip_query();
}
[GtkCallback]
private void on_remote_images_response(Gtk.InfoBar info_bar,
int response_id) {
private void on_remote_images_response(Gtk.InfoBar info_bar, int response_id) {
switch (response_id) {
case 1:
show_images(true);
@ -1362,10 +1356,17 @@ public class ConversationMessage : Gtk.Box {
default:
break; // pass
}
remote_images_infobar.hide();
}
[GtkCallback]
private void on_draft_response(Gtk.InfoBar info_bar, int response_id) {
if (response_id == 1) {
edit_draft(email);
}
}
// private void on_copy_text() {
// web_view.copy_clipboard();
// }

View file

@ -80,9 +80,6 @@ public class ConversationViewer : Gtk.Stack {
// Fired when the user wants to save an image buffer to disk
public signal void save_buffer_to_file(string? filename, Geary.Memory.Buffer buffer);
// Fired when the user clicks the edit draft button.
public signal void edit_draft(Geary.Email message);
// Fired when the viewer has been cleared.
public signal void cleared();
@ -636,8 +633,16 @@ public class ConversationViewer : Gtk.Stack {
}
messages.add(email);
// XXX Should be able to edit draft messages from any
// conversation. This test should be more like "is in drafts
// folder"
bool is_draft = (
current_folder.special_folder_type == Geary.SpecialFolderType.DRAFTS &&
is_in_folder
);
ConversationMessage message =
new ConversationMessage(email, current_folder);
new ConversationMessage(email, current_folder, is_draft);
message.body_box.button_release_event.connect_after((event) => {
// Consume all non-consumed clicks so the row is not
// inadvertently activated after clicking on the

View file

@ -609,6 +609,89 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkInfoBar" id="draft_infobar">
<property name="app_paintable">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="message_type">warning</property>
<signal name="response" handler="on_draft_response" swapped="no"/>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="spacing">6</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button3">
<property name="label" translatable="yes">Edit Draft</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="content_area">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Draft message</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">This message has not yet been sent.</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<action-widgets>
<action-widget response="1">button3</action-widget>
</action-widgets>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>