summaryrefslogtreecommitdiff
path: root/cocoa/BrowserViewController.m
diff options
context:
space:
mode:
authorFran├žois Revel <mmu_man@netsurf-browser.org>2011-05-12 17:31:55 +0000
committerFran├žois Revel <mmu_man@netsurf-browser.org>2011-05-12 17:31:55 +0000
commit092c62f0e01ae489baa50fa66a2045b680e15f50 (patch)
tree2c67c97005cb4fdcacb0049e95bb7701c97e2b61 /cocoa/BrowserViewController.m
parent6dfcd3558064082c1f30ac880fa19b2995da6527 (diff)
downloadnetsurf-092c62f0e01ae489baa50fa66a2045b680e15f50.tar.gz
netsurf-092c62f0e01ae489baa50fa66a2045b680e15f50.tar.bz2
Add code to open the source file into Xcode. Currently called by the context menu because I didn't want to dig the .xib files, feel free to move it to the View main menu.
svn path=/trunk/netsurf/; revision=12387
Diffstat (limited to 'cocoa/BrowserViewController.m')
-rw-r--r--cocoa/BrowserViewController.m65
1 files changed, 64 insertions, 1 deletions
diff --git a/cocoa/BrowserViewController.m b/cocoa/BrowserViewController.m
index 387227de0..2ae354d71 100644
--- a/cocoa/BrowserViewController.m
+++ b/cocoa/BrowserViewController.m
@@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#import "cocoa/BrowserViewController.h"
#import "cocoa/BrowserView.h"
#import "cocoa/BrowserWindowController.h"
@@ -27,6 +26,9 @@
#import "desktop/options.h"
#import "desktop/selection.h"
+#import "utils/filename.h"
+#import "utils/url.h"
+
@implementation BrowserViewController
@@ -125,6 +127,67 @@
browser_window_stop( browser );
}
+- (IBAction) viewSource: (id) sender;
+{
+ struct hlcache_handle *content;
+ size_t size;
+ const char *source;
+ const char *path = NULL;
+
+ if (browser == NULL)
+ return;
+ content = browser->current_content;
+ if (content == NULL)
+ return;
+ source = content_get_source_data(content, &size);
+ if (source == NULL)
+ return;
+
+ /* try to load local files directly. */
+ char *scheme;
+ if (url_scheme(content_get_url(content), &scheme) != URL_FUNC_OK)
+ return;
+ if (strcmp(scheme, "file") == 0)
+ path = url_to_path(content_get_url(content));
+ free(scheme);
+
+ if (path == NULL) {
+ /* 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();
+ const char *extension = "txt";
+ fprintf(stderr, "filename '%p'\n", filename);
+ if (filename == NULL)
+ return;
+ lwc_string *str = content_get_mime_type(content);
+ if (str) {
+ NSString *mime = [NSString stringWithUTF8String:lwc_string_data(str)];
+ NSString *uti = (NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mime, NULL);
+ NSString *ext = (NSString *)UTTypeCopyPreferredTagWithClass((CFStringRef)uti, kUTTagClassFilenameExtension);
+ extension = [ext UTF8String];
+ lwc_string_unref(str);
+ }
+
+ NSURL *dataUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%s.%s", filename, extension]
+ relativeToURL:[NSURL fileURLWithPath:@TEMP_FILENAME_PREFIX]];
+
+
+ NSData *data = [NSData dataWithBytes:source length:size];
+ [data writeToURL:dataUrl atomically:NO];
+ path = [[dataUrl path] UTF8String];
+ }
+
+ if (path) {
+ NSString * p = [NSString stringWithUTF8String: path];
+ NSWorkspace * ws = [NSWorkspace sharedWorkspace];
+ [ws openFile:p withApplication:@"Xcode"];
+ }
+}
+
static inline bool compare_float( float a, float b )
{
const float epsilon = 0.00001;