diff options
author | François Revel <mmu_man@netsurf-browser.org> | 2008-10-03 03:42:10 +0000 |
---|---|---|
committer | François Revel <mmu_man@netsurf-browser.org> | 2008-10-03 03:42:10 +0000 |
commit | 54ccbc94edd7cae429129dea5467557aa4039f4e (patch) | |
tree | 1fa1f8e31d20a55a5f9126a6be80bbf4eca17c9c /beos/beos_gui.cpp | |
parent | 209c72b0113b5235a49af7a16e2aecb8e9f9c8ef (diff) | |
download | netsurf-54ccbc94edd7cae429129dea5467557aa4039f4e.tar.gz netsurf-54ccbc94edd7cae429129dea5467557aa4039f4e.tar.bz2 |
Add support for editting page source.
svn path=/trunk/netsurf/; revision=5479
Diffstat (limited to 'beos/beos_gui.cpp')
-rw-r--r-- | beos/beos_gui.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp index 3e9e50b99..119c3946c 100644 --- a/beos/beos_gui.cpp +++ b/beos/beos_gui.cpp @@ -56,6 +56,7 @@ extern "C" { #include "render/box.h" #include "render/form.h" #include "render/html.h" +#include "utils/filename.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/url.h" @@ -384,6 +385,9 @@ void gui_init(int argc, char** argv) check_homedir(); + // make sure the cache dir exists + create_directory(TEMP_FILENAME_PREFIX, 0600); + //nsbeos_completion_init(); @@ -822,6 +826,92 @@ void gui_window_save_as_link(struct gui_window *g, struct content *c) } /** + * Send the source of a content to a text editor. + */ + +void nsbeos_gui_view_source(struct content *content) +{ + char *temp_name; + bool done = false; + BPath path; + status_t err; + + if (!content || !content->source_data) { + warn_user("MiscError", "No document source"); + return; + } + + /* try to load local files directly. */ + temp_name = url_to_path(content->url); + if (temp_name) { + path.SetTo(temp_name); + BEntry entry; + if (entry.SetTo(path.Path()) >= B_OK + && entry.Exists() && entry.IsFile()) + done = true; + } + if (!done) { + /* We cannot release the requested filename until after it + * has finished being used. As we can't easily find out when + * this is, we simply don't bother releasing it and simply + * allow it to be re-used next time NetSurf is started. The + * memory overhead from doing this is under 1 byte per + * filename. */ + const char *filename = filename_request(); + if (!filename) { + warn_user("NoMemory", 0); + return; + } + path.SetTo(TEMP_FILENAME_PREFIX); + path.Append(filename); + BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); + err = file.InitCheck(); + if (err < B_OK) { + warn_user("IOError", strerror(err)); + return; + } + err = file.Write(content->source_data, content->source_size); + if (err < B_OK) { + warn_user("IOError", strerror(err)); + return; + } + const char *mime = content_mime(content->type); + file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0LL, + mime, strlen(mime) + 1); + + } + + entry_ref ref; + if (get_ref_for_path(path.Path(), &ref) < B_OK) + return; + + BMessage m(B_REFS_RECEIVED); + m.AddRef("refs", &ref); + + // apps to try + const char *editorSigs[] = { + "application/x-vnd.beunited.pe", + "application/x-vnd.XEmacs", + "application/x-vnd.Haiku-STEE", + "application/x-vnd.Be-STEE", + "application/x-vnd.yT-STEE", + NULL + }; + int i; + for (i = 0; editorSigs[i]; i++) { + team_id team = -1; + BMessenger msgr(editorSigs[i], team); + if (msgr.SendMessage(&m) >= B_OK) + break; + if (be_roster->Launch(editorSigs[i], (BMessage *)NULL, &team) >= B_OK) { + snooze(1000); + if (msgr.SendMessage(&m) >= B_OK) + break; + } + } +} + +/** * Broadcast an URL that we can't handle. */ |