Respect developer views appearance setting

This commit is contained in:
anthony 2021-03-18 19:43:37 +00:00
parent 9f15aa694f
commit 1ed107b4b9
3 changed files with 37 additions and 14 deletions

View File

@ -224,19 +224,36 @@ static NSMenuItem *menuItemForItem(id item) {
}
-(void)openDeveloperFileAtPath: (NSString*)path {
NSString *app;
NSString *app;
Website *website;
BrowserWindowController *current;
website = [[Website alloc] initWithName: @"" url: [NSString
stringWithFormat: @"file://%@", path]];
[website autorelease];
switch ([[Preferences defaultPreferences] developerViewLocation]) {
case ViewLocationTab:
case ViewLocationWindow:
case ViewLocationEditor:
app = [[NSWorkspace sharedWorkspace] getBestAppInRole: @"Viewer"
forExtension: @"txt"];
if (app == nil) {
NSLog(@"No app found to show content");
} else {
[[NSWorkspace sharedWorkspace] openFile: path withApplication: app];
current = [self activeBrowserWindow];
if (current != nil) {
[current newTab: [website url]];
break;
}
case ViewLocationWindow:
[self openWebsite: website];
break;
case ViewLocationEditor:
if (![[NSWorkspace sharedWorkspace] openFile: path]) {
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText: @"No Editor"];
[alert setInformativeText: @"Either no NSWorkspace provider"\
" exists,\nor no app can be found to open this file"\
" type (.txt). \nTry picking a different option for"\
" developer views \nin preferences > appearance."];
[alert addButtonWithTitle: @"Ok"];
[alert runModal];
[alert release];
}
break;
default:
break;
}

View File

@ -729,11 +729,13 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) {
}
-(NSString*)dumpContentType: (enum content_debug)type {
char *fname = tempnam("/tmp", "netsurf");
if (fname == NULL) {
char fname[100];
char *tmp = tmpnam(NULL);
if (tmp == NULL) {
NSLog(@"tmpnam error");
return nil;
}
snprintf(fname, 100, "%s.txt", tmp);
FILE *f = fopen(fname, "w+");
if (f == NULL) {
NSLog(@"fopen error");
@ -775,11 +777,13 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) {
NSLog(@"get source data failed");
return;
}
char *fname = tempnam("/tmp", "netsurf");
if (fname == NULL) {
char *tmp = tmpnam(NULL);
if (tmp == NULL) {
NSLog(@"tmpnam error");
return;
}
char fname[100];
snprintf(fname, 100, "%s.txt", tmp);
FILE *f = fopen(fname, "w+");
if (f == NULL) {
NSLog(@"fopen error");

View File

@ -30,6 +30,8 @@ static const char *gnustep_fetch_filetype(const char *unix_path) {
return "image/gif";
} else if (strncmp(ext, "png", 3) == 0) {
return "image/png";
} else if (strncmp(ext, "txt", 3) == 0) {
return "text/plain";
} else {
return "text/html";
}
@ -49,4 +51,4 @@ static const char *gnustep_fetch_get_resource_url(const char *path) {
struct gui_fetch_table gnustep_fetch_table = {
.filetype = gnustep_fetch_filetype,
.get_resource_url = gnustep_fetch_get_resource_url
};
};