Add preliminary OakDocumentEditor registration to OakDocument

This commit is contained in:
Allan Odgaard
2016-07-14 15:16:42 +02:00
parent fc33b25da1
commit 978e16174b
2 changed files with 55 additions and 1 deletions

View File

@@ -1,6 +1,12 @@
#import <text/types.h>
#import <authorization/authorization.h>
#import <undo/undo.h> // ng::buffer_t and ng::undo_manager_t types
#import <command/parser.h>
@protocol OakDocumentEditorProtocol
- (void)performReplacements:(std::multimap<std::pair<size_t, size_t>, std::string> const&)someReplacements;
- (BOOL)handleOutput:(std::string const&)string placement:(output::type)place format:(output_format::type)format caret:(output_caret::type)caret inputRanges:(ng::ranges_t const&)ranges environment:(std::map<std::string, std::string> const&)environment;
@end
PUBLIC extern NSString* OakDocumentContentDidChangeNotification;
PUBLIC extern NSString* OakDocumentMarksDidChangeNotification;
@@ -73,4 +79,11 @@ PUBLIC @interface OakDocument : NSObject
@property (nonatomic) BOOL softTabs;
- (void)runPrintOperationModalForWindow:(NSWindow*)aWindow fontName:(NSString*)aFontName;
- (void)registerDocumentEditor:(id <OakDocumentEditorProtocol>)anEditor;
- (void)unregisterDocumentEditor:(id <OakDocumentEditorProtocol>)anEditor;
@property (nonatomic, readonly) NSArray<id <OakDocumentEditorProtocol>>* documentEditors;
// Sent to the first OakDocumentEditorProtocol instance
- (BOOL)handleOutput:(std::string const&)string placement:(output::type)place format:(output_format::type)format caret:(output_caret::type)caret inputRanges:(ng::ranges_t const&)ranges environment:(std::map<std::string, std::string> const&)environment;
@end

View File

@@ -155,6 +155,8 @@ NSString* OakDocumentWillShowAlertNotification = @"OakDocumentWillShowAlertNo
{
OBJC_WATCH_LEAKS(OakDocument);
NSHashTable* _documentEditors;
std::unique_ptr<ng::buffer_t> _buffer;
std::unique_ptr<ng::detail::storage_t> _snapshot;
ng::callback_t* _callback;
@@ -302,6 +304,8 @@ private:
if(self = [super init])
{
_identifier = [NSUUID UUID];
_documentEditors = [NSHashTable weakObjectsHashTable];
DocumentContainer.add(self);
}
return self;
@@ -1228,6 +1232,37 @@ private:
return to_ns(v.empty() ? NULL_STR : "( " + text::join(v, ", ") + " )");
}
// ===============================
// = DocumentEditor Registration =
// ===============================
- (void)registerDocumentEditor:(id <OakDocumentEditorProtocol>)anEditor
{
[_documentEditors addObject:anEditor];
}
- (void)unregisterDocumentEditor:(id <OakDocumentEditorProtocol>)anEditor
{
[_documentEditors removeObject:anEditor];
}
- (NSArray<id <OakDocumentEditorProtocol>>*)documentEditors
{
NSMutableArray* res = [NSMutableArray array];
for(id <OakDocumentEditorProtocol> editor in _documentEditors)
{
if(editor)
[res addObject:editor];
}
return res;
}
- (BOOL)handleOutput:(std::string const&)string placement:(output::type)place format:(output_format::type)format caret:(output_caret::type)caret inputRanges:(ng::ranges_t const&)ranges environment:(std::map<std::string, std::string> const&)environment
{
id <OakDocumentEditorProtocol> documentEditor = self.documentEditors.firstObject;
return [documentEditor handleOutput:string placement:place format:format caret:caret inputRanges:ranges environment:environment];
}
// =======================
// = Observe File System =
// =======================
@@ -1417,7 +1452,13 @@ private:
- (BOOL)performReplacements:(std::multimap<std::pair<size_t, size_t>, std::string> const&)someReplacements checksum:(uint32_t)crc32
{
ASSERT_EQ(_openCount, 0);
if(self.isOpen)
{
id <OakDocumentEditorProtocol> documentEditor = self.documentEditors.firstObject;
[documentEditor performReplacements:someReplacements];
return YES;
}
ASSERT(_path);
ASSERT(!_buffer);