summaryrefslogtreecommitdiff
path: root/beos
diff options
context:
space:
mode:
authorFrançois Revel <mmu_man@netsurf-browser.org>2008-10-03 03:42:10 +0000
committerFrançois Revel <mmu_man@netsurf-browser.org>2008-10-03 03:42:10 +0000
commit54ccbc94edd7cae429129dea5467557aa4039f4e (patch)
tree1fa1f8e31d20a55a5f9126a6be80bbf4eca17c9c /beos
parent209c72b0113b5235a49af7a16e2aecb8e9f9c8ef (diff)
downloadnetsurf-54ccbc94edd7cae429129dea5467557aa4039f4e.tar.gz
netsurf-54ccbc94edd7cae429129dea5467557aa4039f4e.tar.bz2
Add support for editting page source.
svn path=/trunk/netsurf/; revision=5479
Diffstat (limited to 'beos')
-rw-r--r--beos/beos_gui.cpp90
-rw-r--r--beos/beos_gui.h2
-rw-r--r--beos/beos_scaffolding.cpp5
3 files changed, 97 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.
*/
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: