Skip to content

Commit

Permalink
Add View Source item to page menu (#54)
Browse files Browse the repository at this point in the history
Fixes: #34
  • Loading branch information
kalikiana committed Sep 11, 2018
1 parent 498ec50 commit 2443a32
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/browser.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace Midori {
{ "fullscreen", fullscreen_activated },
{ "show-downloads", show_downloads_activated },
{ "find", find_activated },
{ "view-source", view_source_activated },
{ "print", print_activated },
{ "show-inspector", show_inspector_activated },
{ "clear-private-data", clear_private_data_activated },
Expand Down Expand Up @@ -105,6 +106,7 @@ namespace Midori {
application.set_accels_for_action ("win.fullscreen", { "F11" });
application.set_accels_for_action ("win.show-downloads", { "<Primary><Shift>j" });
application.set_accels_for_action ("win.find", { "<Primary>f", "slash" });
application.set_accels_for_action ("win.view-source", { "<Primary>u", "<Primary><Alt>u" });
application.set_accels_for_action ("win.print", { "<Primary>p" });
application.set_accels_for_action ("win.show-inspector", { "<Primary><Shift>i" });
application.set_accels_for_action ("win.goto", { "<Primary>l", "F7" });
Expand Down Expand Up @@ -405,6 +407,30 @@ namespace Midori {
tab.get_find_controller ().search (search_entry.text, options, int.MAX);
}

void view_source_activated () {
view_source.begin (tab);
}

async void view_source (Tab tab) {
string uri = tab.display_uri;
try {
var file = File.new_for_uri (uri);
if (!uri.has_prefix ("file:///")) {
FileIOStream stream;
file = File.new_tmp ("sourceXXXXXX", out stream);
var data = yield tab.get_main_resource ().get_data (null);
yield stream.output_stream.write_async (data);
yield stream.close_async ();
}
var files = new List<File> ();
files.append (file);
var info = AppInfo.get_default_for_type ("text/plain", false);
info.launch (files, get_display ().get_app_launch_context ());
} catch (Error error) {
critical ("Failed to open %s in editor: %s", uri, error.message);
}
}

void print_activated () {
tab.print (new WebKit.PrintOperation (tab));
}
Expand Down
5 changes: 5 additions & 0 deletions ui/menus.ui
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<attribute name="label" translatable="yes">_Find in Page</attribute>
<attribute name="accel">&lt;Primary&gt;f</attribute>
</item>
<item>
<attribute name="action">win.view-source</attribute>
<attribute name="label" translatable="yes">View So_urce</attribute>
<attribute name="accel">&lt;Primary&gt;&lt;Alt&gt;u</attribute>
</item>
<item>
<attribute name="action">win.print</attribute>
<attribute name="label" translatable="yes">_Print…</attribute>
Expand Down

0 comments on commit 2443a32

Please sign in to comment.