mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 20:16:54 +03:00
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
This commit is contained in:
parent
6dfcd35580
commit
092c62f0e0
@ -559,6 +559,8 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt )
|
||||
action: @selector(reloadPage:) keyEquivalent: @""];
|
||||
[popupMenu addItemWithTitle: NSLocalizedString( @"Forward", @"Context menu" )
|
||||
action: @selector(goForward:) keyEquivalent: @""];
|
||||
[popupMenu addItemWithTitle: NSLocalizedString( @"View Source", @"Context menu" )
|
||||
action: @selector(viewSource:) keyEquivalent: @""];
|
||||
|
||||
[NSMenu popUpContextMenu: popupMenu withEvent: event forView: self];
|
||||
|
||||
|
@ -67,6 +67,8 @@ struct browser_window;
|
||||
- (IBAction) zoomOut: (id) sender;
|
||||
- (IBAction) zoomOriginal: (id) sender;
|
||||
|
||||
- (IBAction) viewSource: (id) sender;
|
||||
|
||||
- (void) buildBackMenu: (NSMenu *)menu;
|
||||
- (void) buildForwardMenu: (NSMenu *)menu;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -37,6 +37,7 @@
|
||||
#import "desktop/tree.h"
|
||||
#import "render/html.h"
|
||||
#import "utils/url.h"
|
||||
#import "utils/filename.h"
|
||||
#import "utils/log.h"
|
||||
#import "utils/messages.h"
|
||||
#import "utils/utils.h"
|
||||
@ -180,6 +181,9 @@ int main( int argc, char **argv )
|
||||
|
||||
netsurf_init(&argc, &argv, options, messages);
|
||||
|
||||
/* Initialise filename allocator */
|
||||
filename_initialise();
|
||||
|
||||
apple_image_init();
|
||||
|
||||
NSApplication *app = cocoa_prepare_app();
|
||||
|
Loading…
Reference in New Issue
Block a user