From 54ccbc94edd7cae429129dea5467557aa4039f4e Mon Sep 17 00:00:00 2001 From: François Revel Date: Fri, 3 Oct 2008 03:42:10 +0000 Subject: Add support for editting page source. svn path=/trunk/netsurf/; revision=5479 --- beos/beos_gui.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++++ beos/beos_gui.h | 2 ++ beos/beos_scaffolding.cpp | 5 +++ 3 files changed, 97 insertions(+) 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(); @@ -821,6 +825,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. */ diff --git a/beos/beos_gui.h b/beos/beos_gui.h index 6226df7a8..8e49b8665 100644 --- a/beos/beos_gui.h +++ b/beos/beos_gui.h @@ -57,3 +57,5 @@ extern BFilePanel *wndOpenFile; void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui); void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold); +void nsbeos_gui_view_source(struct content *content); + diff --git a/beos/beos_scaffolding.cpp b/beos/beos_scaffolding.cpp index dadab0c33..a3eea6109 100644 --- a/beos/beos_scaffolding.cpp +++ b/beos/beos_scaffolding.cpp @@ -538,7 +538,12 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m break; } case BROWSER_VIEW_SOURCE: + { + if (!bw || !bw->current_content) + break; + nsbeos_gui_view_source(bw->current_content); break; + } case BROWSER_OBJECT: break; case BROWSER_OBJECT_INFO: -- cgit v1.2.3