Skip to content

Commit

Permalink
support for standard ODB editor suite, as originally specified by Bar…
Browse files Browse the repository at this point in the history
…eBones <http://www.barebones.com/support/develop/odbsuite.html>; this implementation based on code from <http://gusmueller.com/odb/>
  • Loading branch information
scrod committed Mar 25, 2011
1 parent f7f845a commit 60c5e6c
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ODBEditor/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This work is hereby released into the Public Domain. To view a copy of the public domain dedication, visit http://creativecommons.org/licenses/publicdomain/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

8 changes: 8 additions & 0 deletions ODBEditor/NSAppleEventDescriptor-Extensions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <Foundation/Foundation.h>

@interface NSAppleEventDescriptor(Extensions)

+ (NSAppleEventDescriptor *)descriptorWithFilePath:(NSString *)fileName;
+ (NSAppleEventDescriptor *)descriptorWithFileURL:(NSURL *)fileURL;

@end
16 changes: 16 additions & 0 deletions ODBEditor/NSAppleEventDescriptor-Extensions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import "NSAppleEventDescriptor-Extensions.h"

@implementation NSAppleEventDescriptor(Extensions)

+ (NSAppleEventDescriptor *)descriptorWithFilePath:(NSString *)fileName {
NSURL *url = [NSURL fileURLWithPath: fileName];
return [self descriptorWithFileURL: url];
}

+ (NSAppleEventDescriptor *)descriptorWithFileURL:(NSURL *)fileURL {
NSString *string = [fileURL absoluteString];
NSData *data = [string dataUsingEncoding: NSUTF8StringEncoding];
return [self descriptorWithDescriptorType: typeFileURL data: data];
}

@end
55 changes: 55 additions & 0 deletions ODBEditor/ODBEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#import <Cocoa/Cocoa.h>

// http://gusmueller.com/odb/

extern NSString * const ODBEditorCustomPathKey;

@class TemporaryFileCachePreparer;

@interface ODBEditor : NSObject
{
UInt32 _signature;
NSMutableDictionary *_filePathsBeingEdited;

int currentNoteStorageFormat;
TemporaryFileCachePreparer *editingSpacePreparer;
}
+ (id)sharedODBEditor;

- (void)abortEditingFile:(NSString *)path;
- (void)abortAllEditingSessionsForClient:(id)client;

- (void)initializeDatabaseFormat:(int)fmt;
- (BOOL)fileCacheIsValid;

// NOTE that client is never retained - it is your reponsibility to
// make sure the client sticks around and abort editing for that client
// before it is dealloc'd
//
// Also note that while it is possible to start several editString
// sessions for a single client it is the client's responsibility to
// distinguish between the sessions (possibly using the original
// context that you supplied.) It is also the clients responsibility to
// do the same for file editing sessions, but this should be easier
// since the file path will remain static (except in the save as case)
// whereas the string returned is obviously going to change as the user
// edits it.

- (BOOL)editFile:(NSString *)path options:(NSDictionary *)options forClient:(id)client context:(NSDictionary *)context;

- (BOOL)editString:(NSString *)string options:(NSDictionary *)options forClient:(id)client context:(NSDictionary *)context;

@end

@interface NSObject(ODBEditorClient)

// see the ODB Editor documentation for when newFileLocation is sent
// if the file wasn't subject to a save as newpath will be nil

-(void)odbEditor:(ODBEditor *)editor didModifyFile:(NSString *)path newFileLocation:(NSString *)newPath context:(NSDictionary *)context;
-(void)odbEditor:(ODBEditor *)editor didClosefile:(NSString *)path context:(NSDictionary *)context;

-(void)odbEditor:(ODBEditor *)editor didModifyFileForString:(NSString *)newString context:(NSDictionary *)context;
-(void)odbEditor:(ODBEditor *)editor didCloseFileForString:(NSString *)newString context:(NSDictionary *)context;

@end
Loading

0 comments on commit 60c5e6c

Please sign in to comment.