Commit 9039b57d authored by john's avatar john

Issue#45 repaired

parent cb01fafe
......@@ -2608,7 +2608,6 @@ public class GearyController : Geary.BaseObject {
});
foreach (ConversationMessage msg_view in view) {
msg_view.link_activated.connect(on_link_activated);
msg_view.internal_link_activated.connect(on_internal_link_activated);
msg_view.save_image.connect((url, alt_text, buf) => {
on_save_image_extended(view, url, alt_text, buf);
});
......@@ -3064,10 +3063,6 @@ public class GearyController : Geary.BaseObject {
}
}
private void on_internal_link_activated(string uri, uint y) {
}
private void on_save_image_extended(ConversationEmail view,
string url,
string? alt_text,
......
......@@ -420,6 +420,9 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
/** Fired when the view source action is activated. */
public signal void view_source();
/** Fired when a internal link is activated */
public signal void internal_link_activated(string link, uint y);
/** Fired when the user selects text in a message. */
internal signal void body_selection_changed(bool has_selection);
......@@ -687,6 +690,13 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
update_email_state();
}
/**
* Get the summary's height of the primary message
*/
public uint get_summary_height() {
return this.primary_message.get_summary_height();
}
/**
* Returns user-selected body HTML from a message, if any.
*/
......@@ -754,6 +764,9 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
private void connect_message_view_signals(ConversationMessage view) {
view.flag_remote_images.connect(on_flag_remote_images);
view.remember_remote_images.connect(on_remember_remote_images);
view.internal_link_activated.connect((link, y) => {
internal_link_activated(link, y);
});
view.web_view.internal_resource_loaded.connect(on_resource_loaded);
view.web_view.content_loaded.connect(on_content_loaded);
view.web_view.selection_changed.connect((has_selection) => {
......
......@@ -229,7 +229,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
}
// Base class for list rows it the list box
// Base class for list rows in the list box
internal abstract class ConversationRow : Gtk.ListBoxRow, Geary.BaseInterface {
......@@ -327,10 +327,15 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
public ConversationEmail view { get; private set; }
/** Fired when a internal link is activated */
public signal void internal_link_activated(EmailRow view, uint y);
public EmailRow(ConversationEmail view) {
base(view.email);
this.view = view;
add(view);
connect_email_signals(view);
}
public override async void expand()
......@@ -358,6 +363,13 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
}
}
private void connect_email_signals(ConversationEmail email) {
email.internal_link_activated.connect((link, y) => {
stdout.printf("Reached ConversationEmail\n");
internal_link_activated(this, y);
});
}
}
......@@ -930,6 +942,8 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
}
email_added(view);
row.internal_link_activated.connect(on_internal_link_activated);
return row;
}
......@@ -955,6 +969,26 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
get_adjustment().set_value(y);
}
private void scroll_to_anchor(EmailRow row, uint anchor_y) {
Gtk.Allocation? alloc = null;
row.get_allocation(out alloc);
Gtk.Adjustment adj = get_adjustment();
uint page_size = (uint) adj.get_page_size();
uint summary_height = row.view.get_summary_height();
uint y = 0;
uint necessary_y_offset = summary_height + anchor_y;
if (necessary_y_offset <= page_size) {
//The anchor can be seen with in the page, just scroll to the row.
scroll_to(row);
} else {
//The anchor require further scrolling
y = alloc.y + necessary_y_offset;
adj.set_value(y);
}
}
/**
* Finds any currently visible messages, marks them as being read.
*/
......@@ -1154,4 +1188,8 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
}
}
private void on_internal_link_activated(EmailRow row, uint y) {
scroll_to_anchor(row, y);
}
}
......@@ -360,7 +360,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
});
add_action(ACTION_OPEN_LINK, true, VariantType.STRING)
.activate.connect((param) => {
link_activated(param.get_string());
on_link_activated(param.get_string());
});
add_action(ACTION_SAVE_IMAGE, true, new VariantType("(sms)"))
.activate.connect(on_save_image);
......@@ -448,13 +448,7 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
}
this.web_view.context_menu.connect(on_context_menu);
this.web_view.deceptive_link_clicked.connect(on_deceptive_link_clicked);
this.web_view.link_activated.connect((link) => {
if (link.contains(INTERNAL_ANCHOR_PREFIX)) {
on_internal_link_activated(link);
} else {
link_activated(link);
}
});
this.web_view.link_activated.connect(on_link_activated);
this.web_view.mouse_target_changed.connect(on_mouse_target_changed);
this.web_view.notify["is-loading"].connect(on_is_loading_notify);
this.web_view.resource_load_started.connect(on_resource_load_started);
......@@ -609,6 +603,11 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
this.progress_pulse.reset();
}
/** Get the height of the summary part */
public uint get_summary_height() {
return summary.get_allocated_height();
}
/**
* Starts loading the avatar for the message's sender.
*/
......@@ -1166,16 +1165,18 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
});
}
private void on_internal_link_activated(string link) {
//internal link handling
debug("Internal Link Handling Not Implentmented Yet");
long start = INTERNAL_ANCHOR_PREFIX.length;
long end = link.length;
this.web_view.get_anchor_target_y.begin(link.substring(start, end - start), (obj, res) => {
uint y = this.web_view.get_anchor_target_y.end(res);
stdout.printf("The y is %u\n", y);
internal_link_activated(link, y);
});
private void on_link_activated(string link) {
if (link.contains(INTERNAL_ANCHOR_PREFIX)) {
long start = INTERNAL_ANCHOR_PREFIX.length;
long end = link.length;
this.web_view.get_anchor_target_y.begin(link.substring(start, end - start), (obj, res) => {
uint y = this.web_view.get_anchor_target_y.end(res);
stdout.printf("The y is %u\n", y);
internal_link_activated(link, y);
});
} else {
link_activated(link);
}
}
}
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