Scenarios can now be opened in the editor by double-clicking them.
- Character editor also supports dropping saved games on the app icon
This commit is contained in:
@@ -6,39 +6,55 @@
|
||||
//
|
||||
//
|
||||
|
||||
#include "universe.h" // Include before Cocoa because the Cocoa header defines things that cause compilation errors in here
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <string>
|
||||
#include "fileio.hpp"
|
||||
#include "pc.menus.h"
|
||||
#include "pc.fileio.h"
|
||||
|
||||
extern bool verify_restore_quit(std::string dlog);
|
||||
extern bool All_Done;
|
||||
extern bool All_Done, party_in_scen, scen_items_loaded;
|
||||
extern cUniverse univ;
|
||||
extern fs::path file_in_mem;
|
||||
|
||||
typedef NSAppleEventDescriptor AEDescr;
|
||||
|
||||
@interface AppleEventHandler : NSObject
|
||||
-(void)handleOpenDoc:(AEDescr*)theAppleEvent withReply: (AEDescr*)reply;
|
||||
-(void)handleQuit:(AEDescr*)theAppleEvent withReply: (AEDescr*)reply;
|
||||
@interface AppleEventHandler : NSObject<NSApplicationDelegate>
|
||||
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file;
|
||||
-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender;
|
||||
@end
|
||||
|
||||
void set_up_apple_events(); // Suppress "no prototype" warning
|
||||
void set_up_apple_events() {
|
||||
AppleEventHandler* aeHandler = [[AppleEventHandler alloc] init];
|
||||
NSAppleEventManager* AEmgr = [NSAppleEventManager sharedAppleEventManager];
|
||||
[AEmgr setEventHandler: aeHandler andSelector: @selector(handleOpenDoc:withReply:)
|
||||
forEventClass: kCoreEventClass andEventID: kAEOpenDocuments];
|
||||
[AEmgr setEventHandler: aeHandler andSelector: @selector(handleQuit:withReply:)
|
||||
forEventClass: kCoreEventClass andEventID: kAEQuitApplication];
|
||||
[[NSApplication sharedApplication] setDelegate: aeHandler];
|
||||
}
|
||||
|
||||
@implementation AppleEventHandler
|
||||
-(void)handleOpenDoc:(AEDescr*)theAppleEvent withReply: (AEDescr*)reply {
|
||||
(void) theAppleEvent; // Suppress "unused parameter" warning
|
||||
(void) reply;
|
||||
// TODO: Handle this
|
||||
-(BOOL)application:(NSApplication*) app openFile:(NSString*) file {
|
||||
(void) app; // Suppress "unused parameter" warning
|
||||
|
||||
unsigned long len = [file length], sz = len + 1;
|
||||
auto msg = std::shared_ptr<unichar>(new unichar[sz], std::default_delete<unichar[]>());
|
||||
std::fill(msg.get(), msg.get() + sz, 0);
|
||||
[file getCharacters: msg.get() range: (NSRange){0, len}];
|
||||
std::string fileName;
|
||||
std::copy(msg.get(), msg.get() + len, std::inserter(fileName, fileName.begin()));
|
||||
|
||||
if(load_party(fileName, univ)) {
|
||||
file_in_mem = fileName;
|
||||
party_in_scen = !univ.party.scen_name.empty();
|
||||
if(!party_in_scen) load_base_item_defs();
|
||||
scen_items_loaded = true;
|
||||
update_item_menu();
|
||||
menu_activate();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
-(void)handleQuit:(AEDescr*)theAppleEvent withReply: (AEDescr*)reply {
|
||||
(void) theAppleEvent; // Suppress "unused parameter" warning
|
||||
(void) reply;
|
||||
|
||||
-(NSApplicationTerminateReply)applicationShouldTerminate: (NSApplication*)sender {
|
||||
(void) sender; // Suppress "unused parameter" warning
|
||||
All_Done = verify_restore_quit("save-quit");
|
||||
return All_Done;
|
||||
}
|
||||
@end
|
||||
|
||||
|
Reference in New Issue
Block a user