ARC: Update DocumentWindow framework

This commit is contained in:
Allan Odgaard
2012-12-31 03:16:23 +01:00
parent 3d45b788f1
commit b84992bdb3
11 changed files with 93 additions and 159 deletions

View File

@@ -296,7 +296,7 @@ void run (bundle_command_t const& command, ng::buffer_t const& buffer, ng::range
std::string const title = text::format("Unable to run “%.*s”.", (int)command.name.size(), command.name.data());
std::string const message = text::format("This command requires %1$s which wasnt found on your system.\n\nThe following locations were searched:%2$s\n\nIf %1$s is installed elsewhere then you need to set %3$s in Preferences → Variables to the full path of where you installed it.", it->command.c_str(), ("\n\u2003• " + text::join(paths, "\n\u2003• ")).c_str(), it->variable.c_str());
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
NSAlert* alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert setMessageText:[NSString stringWithCxxString:title]];
[alert setInformativeText:[NSString stringWithCxxString:message]];
@@ -329,7 +329,7 @@ void show_command_error (std::string const& message, oak::uuid_t const& uuid, NS
bundles::item_ptr bundleItem = bundles::lookup(uuid);
std::string commandName = bundleItem ? bundleItem->name() : "(unknown)";
NSAlert* alert = [[[NSAlert alloc] init] autorelease];
NSAlert* alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert setMessageText:[NSString stringWithCxxString:text::format("Failure running “%.*s”.", (int)commandName.size(), commandName.data())]];
[alert setInformativeText:[NSString stringWithCxxString:message] ?: @"No output"];

View File

@@ -23,6 +23,7 @@ namespace find_tags
#import <OakFoundation/OakFoundation.h>
#import <OakFoundation/NSArray Additions.h>
#import <OakFoundation/NSString Additions.h>
#import <OakAppKit/OakAppKit.h>
#import <OakAppKit/NSAlert Additions.h>
#import <OakAppKit/NSMenu Additions.h>
#import <OakAppKit/NSWindow Additions.h>
@@ -56,6 +57,7 @@ OAK_DEBUG_VAR(DocumentController);
@property (nonatomic, retain) NSString* windowTitle;
@property (nonatomic, retain) NSString* representedFile;
@property (nonatomic, assign) BOOL isDocumentEdited;
@property (nonatomic, retain) DocumentController* retainedSelf;
- (id)initWithDocuments:(std::vector<document::document_ptr> const&)someDocuments;
- (void)updateProxyIcon;
@end
@@ -76,7 +78,11 @@ OAK_DEBUG_VAR(DocumentController);
res["fileBrowserWidth"] = fileBrowser.view ? (int32_t)NSWidth(fileBrowser.view.frame) : fileBrowserWidth;
if(fileBrowser)
res["fileBrowserState"] = plist::convert((CFDictionaryRef)fileBrowser.sessionState);
{
CFDictionaryRef fbState = (CFDictionaryRef)CFBridgingRetain(fileBrowser.sessionState);
res["fileBrowserState"] = plist::convert(fbState);
CFRelease(fbState);
}
plist::array_t docs;
iterate(tab, documentTabs)
@@ -187,7 +193,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
else
{
close_scratch_project();
bring_to_front([[[DocumentController alloc] initWithDocuments:documents] autorelease]);
bring_to_front([[DocumentController alloc] initWithDocuments:documents]);
}
}
else if(DocumentController* delegate = [DocumentController controllerForPath:browserPath])
@@ -199,7 +205,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
else // if(browserPath != NULL_STR)
{
close_scratch_project();
delegate = documents.empty() ? [[[DocumentController alloc] init] autorelease] : [[[DocumentController alloc] initWithDocuments:documents] autorelease];
delegate = documents.empty() ? [[DocumentController alloc] init] : [[DocumentController alloc] initWithDocuments:documents];
[delegate window];
delegate.fileBrowserHidden = NO;
[delegate->fileBrowser showURL:[NSURL fileURLWithPath:[NSString stringWithCxxString:path::resolve(browserPath)]]];
@@ -229,7 +235,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
else
{
close_scratch_project();
delegate = [[[DocumentController alloc] initWithDocuments:std::vector<document::document_ptr>(1, document)] autorelease];
delegate = [[DocumentController alloc] initWithDocuments:std::vector<document::document_ptr>(1, document)];
[delegate showWindow:nil];
}
}
@@ -280,12 +286,12 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
if(documents.empty())
documents.push_back(document::create());
DocumentController* controller = [[[DocumentController alloc] initWithDocuments:documents] autorelease];
DocumentController* controller = [[DocumentController alloc] initWithDocuments:documents];
controller.selectedTabIndex = selectedTabIndex;
plist::dictionary_t fileBrowserState;
if(plist::get_key_path(*project, "fileBrowserState", fileBrowserState))
controller->fileBrowserState = [ns::to_dictionary(fileBrowserState) retain];
controller->fileBrowserState = ns::to_dictionary(fileBrowserState);
plist::get_key_path(*project, "fileBrowserWidth", controller->fileBrowserWidth);
plist::get_key_path(*project, "htmlOutputHeight", controller->htmlOutputHeight);
@@ -373,13 +379,13 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
- (id)initWithDocuments:(std::vector<document::document_ptr> const&)someDocuments
{
D(DBF_DocumentController, bug("%zu documents\n", someDocuments.size()););
if(self = [super initWithWindow:[[[NSWindow alloc] initWithContentRect:NSZeroRect styleMask:(NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask|NSTexturedBackgroundWindowMask) backing:NSBackingStoreBuffered defer:NO] autorelease]])
if(self = [super initWithWindow:[[NSWindow alloc] initWithContentRect:NSZeroRect styleMask:(NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask|NSTexturedBackgroundWindowMask) backing:NSBackingStoreBuffered defer:NO]])
{
identifier.generate();
fileBrowserHidden = YES;
[self addDocuments:someDocuments andSelect:kSelectDocumentFirst closeOther:YES pruneTabBar:YES];
layoutView = [[[ProjectLayoutView alloc] initWithFrame:NSZeroRect] autorelease];
layoutView = [[ProjectLayoutView alloc] initWithFrame:NSZeroRect];
[self.window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
[self.window setContentView:layoutView];
@@ -388,7 +394,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
[self.window bind:@"title" toObject:self withKeyPath:@"windowTitle" options:nil];
[self.window bind:@"documentEdited" toObject:self withKeyPath:@"isDocumentEdited" options:nil];
tabBarView = [[[OakTabBarView alloc] initWithFrame:NSZeroRect] autorelease];
tabBarView = [[OakTabBarView alloc] initWithFrame:NSZeroRect];
layoutView.tabBarView = tabBarView;
[self windowDidLoad];
@@ -473,7 +479,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
self.selectedTabIndex = selectedTabIndex;
[self updateProxyIcon];
[self retain];
self.retainedSelf = self;
}
- (void)synchronizeWindowTitle
@@ -579,9 +585,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
- (void)setRepresentedFile:(NSString*)aPath
{
NSString* oldRepresentedFile = representedFile;
representedFile = [aPath retain];
[oldRepresentedFile release];
representedFile = aPath;
[self updateProxyIcon]; // FIXME Skip for unchanged path. Problem is updateProxyIcon not being called for file appearing/disappearing on disk.
}
@@ -965,7 +969,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
- (IBAction)moveDocumentToNewWindow:(id)sender
{
ASSERT(documentTabs.size() > 1);
DocumentController* delegate = [[[DocumentController alloc] initWithDocuments:std::vector<document::document_ptr>(1, [self selectedDocument])] autorelease];
DocumentController* delegate = [[DocumentController alloc] initWithDocuments:std::vector<document::document_ptr>(1, [self selectedDocument])];
[delegate showWindow:self];
[self closeTabsAtIndexes:[NSIndexSet indexSetWithIndex:selectedTabIndex] quiet:YES];
}
@@ -1008,18 +1012,6 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
[self closeTabsAtIndexes:[NSIndexSet indexSetWithIndex:[sender tag]] quiet:NO];
}
- (void)closeSplitWarningDidEnd:(NSAlert*)alert returnCode:(NSInteger)returnCode contextInfo:(void*)stack
{
if(returnCode == NSAlertDefaultReturn) /* "Stop" */
{
runner.reset();
[htmlOutputView stopLoading];
[self toggleHTMLOutput:self];
}
[alert release];
}
- (void)performCloseSplit:(id)sender
{
D(DBF_DocumentController, bug("\n"););
@@ -1027,7 +1019,15 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
{
if(runner && runner->running())
{
[[[NSAlert alertWithMessageText:@"Stop task before closing?" defaultButton:@"Stop Task" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"The job that the task is performing will not be completed."] retain] beginSheetModalForWindow:self.window modalDelegate:self didEndSelector:@selector(closeSplitWarningDidEnd:returnCode:contextInfo:) contextInfo:NULL];
NSAlert* alert = [NSAlert alertWithMessageText:@"Stop task before closing?" defaultButton:@"Stop Task" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"The job that the task is performing will not be completed."];
OakShowAlertForWindow(alert, self.window, ^(NSInteger returnCode){
if(returnCode == NSAlertDefaultReturn) /* "Stop" */
{
runner.reset();
[htmlOutputView stopLoading];
[self toggleHTMLOutput:self];
}
});
}
else
{
@@ -1080,8 +1080,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
{
struct callback_t : close_warning_callback_t
{
callback_t (NSWindow* aWindow) { _window = [aWindow retain]; }
~callback_t () { [_window release]; }
callback_t (NSWindow* aWindow) : _window(aWindow) { }
void can_close_documents (bool flag)
{
@@ -1100,17 +1099,28 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
- (void)windowWillClose:(NSNotification*)aNotification
{
D(DBF_DocumentController, bug("retain count: %d\n", (int)[[aNotification object] retainCount]););
D(DBF_DocumentController, bug("\n"););
if(scmInfo && scmCallback)
{
scmInfo->remove_callback(scmCallback);
delete scmCallback;
scmCallback = NULL;
scmInfo.reset();
}
[self.window unbind:@"title"];
[self.window unbind:@"documentEdited"];
tabBarView.delegate = nil;
tabBarView.dataSource = nil;
fileBrowser.delegate = nil;
self.filterWindowController = nil;
[documentView release];
documentView = nil;
[self autorelease];
self.retainedSelf = nil;
}
// ========================
@@ -1144,7 +1154,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
std::vector<document::document_ptr> documents;
for(NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex:index])
documents.push_back(*documentTabs[index]);
DocumentController* delegate = [[[DocumentController alloc] initWithDocuments:documents] autorelease];
DocumentController* delegate = [[DocumentController alloc] initWithDocuments:documents];
[delegate showWindow:self];
[self closeTabsAtIndexes:indexSet quiet:YES];
}
@@ -1165,7 +1175,7 @@ static document::document_ptr create_document (NSString* fileBrowserPath)
[rightSideTabs removeIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, tabIndex + 1)]];
}
NSMenu* menu = [[NSMenu new] autorelease];
NSMenu* menu = [NSMenu new];
[menu setAutoenablesItems:NO];
[menu addItemWithTitle:@"New Tab" action:@selector(takeNewTabIndexFrom:) keyEquivalent:@""];
@@ -1245,19 +1255,7 @@ static NSString* const OakDocumentPboardType = @"OakDocumentPboardType";
{
D(DBF_DocumentController, bug("\n"););
// TODO remove document callbacks (not added at time of writing)
[windowTitle release];
self.representedFile = nil;
fileBrowser.delegate = nil;
[fileBrowser release];
[htmlOutputView release];
[fileBrowserState release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
// ===============================
@@ -1478,9 +1476,9 @@ static std::string file_chooser_glob (std::string const& path)
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:filterWindowController.window];
filterWindowController.target = nil;
[filterWindowController close];
[filterWindowController release];
}
if(filterWindowController = [controller retain])
if(filterWindowController = controller)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(filterWindowWillClose:) name:NSWindowWillCloseNotification object:filterWindowController.window];
}
}
@@ -1528,16 +1526,16 @@ static std::string file_chooser_glob (std::string const& path)
// = Forward to file browser =
// ===========================
- (IBAction)goBack:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)goForward:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)goToParentFolder:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)goBack:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
- (IBAction)goForward:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
- (IBAction)goToParentFolder:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
- (IBAction)goToComputer:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)goToHome:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)goToDesktop:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)goToFavorites:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)goToSCMDataSource:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)orderFrontGoToFolder:(id)sender { self.fileBrowserHidden = NO; [fileBrowser performSelector:_cmd withObject:sender]; }
- (IBAction)goToComputer:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
- (IBAction)goToHome:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
- (IBAction)goToDesktop:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
- (IBAction)goToFavorites:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
- (IBAction)goToSCMDataSource:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
- (IBAction)orderFrontGoToFolder:(id)sender { self.fileBrowserHidden = NO; [NSApp sendAction:_cmd to:fileBrowser from:sender]; }
// ====================
// = NSMenuValidation =

View File

@@ -4,10 +4,7 @@
@protocol DocumentOpenHelperDelegate;
@interface DocumentOpenHelper : NSObject <FileTypeDialogDelegate>
{
id <DocumentOpenHelperDelegate> delegate;
}
@property (nonatomic, assign) id <DocumentOpenHelperDelegate> delegate;
@property (nonatomic, weak) id <DocumentOpenHelperDelegate> delegate;
- (void)tryOpenDocument:(document::document_ptr const&)aDocument forWindow:(NSWindow*)aWindow delegate:(id <DocumentOpenHelperDelegate>)aDelegate;
@end

View File

@@ -33,7 +33,7 @@ namespace
{
[_window.attachedSheet orderOut:_self];
NSAlert* alert = [[NSAlert alertWithMessageText:@"Unknown Encoding" defaultButton:@"Continue" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"This file is not UTF-8 nor does it have any encoding information stored."] retain];
NSAlert* alert = [NSAlert alertWithMessageText:@"Unknown Encoding" defaultButton:@"Continue" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"This file is not UTF-8 nor does it have any encoding information stored."];
EncodingViewController* controller = [[EncodingViewController alloc] initWithFirst:content->begin() last:content->end()];
[alert setAccessoryView:controller.view];
[alert beginSheetModalForWindow:_window modalDelegate:_self didEndSelector:@selector(selectEncodingSheetDidEnd:returnCode:contextInfo:) contextInfo:new info_t(controller, context)];
@@ -73,8 +73,6 @@ namespace
}
@implementation DocumentOpenHelper
@synthesize delegate;
- (id)init
{
if(self = [super init])
@@ -83,15 +81,11 @@ namespace
return self;
}
- (void)setDelegate:(id <DocumentOpenHelperDelegate>)aDelegate { delegate = aDelegate; }
- (id <DocumentOpenHelperDelegate>)delegate { return delegate; }
- (void)tryOpenDocument:(document::document_ptr const&)aDocument forWindow:(NSWindow*)aWindow delegate:(id <DocumentOpenHelperDelegate>)aDelegate
{
D(DBF_DocumentController_OpenHelper, bug("%s, already open %s\n", aDocument->display_name().c_str(), BSTR(aDocument->is_open())););
[self retain]; // keep us retained until document is opened
delegate = aDelegate;
self.delegate = aDelegate;
if(aDocument->try_open(document::open_callback_ptr((document::open_callback_t*)new open_callback_t(self, aWindow))))
{
[self didOpenDocument:aDocument];
@@ -103,8 +97,6 @@ namespace
{
if(returnCode == NSAlertDefaultReturn)
info->context->set_charset(text::split(to_s(info->controller.currentEncoding), " ")[0]);
[alert release];
[info->controller release];
delete info;
}
@@ -112,7 +104,6 @@ namespace
{
if(aFileType)
((info_t*)info)->context->set_file_type(to_s(aFileType));
[fileTypeDialog release];
delete (info_t*)info;
}
@@ -121,16 +112,14 @@ namespace
D(DBF_DocumentController_OpenHelper, bug("%s\n", aDocument->display_name().c_str()););
if(aDocument->recent_tracking() && aDocument->path() != NULL_STR)
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:[NSString stringWithCxxString:aDocument->path()]]];
if([delegate respondsToSelector:@selector(documentOpenHelper:didOpenDocument:)])
[delegate documentOpenHelper:self didOpenDocument:aDocument];
[self release];
if([self.delegate respondsToSelector:@selector(documentOpenHelper:didOpenDocument:)])
[self.delegate documentOpenHelper:self didOpenDocument:aDocument];
}
- (void)failedToOpenDocument:(document::document_ptr const&)aDocument error:(std::string const&)aMessage usingFilter:(oak::uuid_t const&)filterUUID
{
D(DBF_DocumentController_OpenHelper, bug("%s\n", aDocument->display_name().c_str()););
if([delegate respondsToSelector:@selector(documentOpenHelper:failedToOpenDocument:error:usingFilter:)])
[delegate documentOpenHelper:self failedToOpenDocument:aDocument error:aMessage usingFilter:filterUUID];
[self release];
if([self.delegate respondsToSelector:@selector(documentOpenHelper:failedToOpenDocument:error:usingFilter:)])
[self.delegate documentOpenHelper:self failedToOpenDocument:aDocument error:aMessage usingFilter:filterUUID];
}
@end

View File

@@ -54,7 +54,7 @@ namespace
init(context);
// TODO “unlock file” checkbox (presently implied)
NSAlert* alert = [[NSAlert tmAlertWithMessageText:[NSString stringWithCxxString:text::format("The file “%s” is locked.", _document->display_name().c_str())] informativeText:@"Do you want to overwrite it anyway?" buttons:@"Overwrite", @"Cancel", nil] retain];
NSAlert* alert = [NSAlert tmAlertWithMessageText:[NSString stringWithCxxString:text::format("The file “%s” is locked.", _document->display_name().c_str())] informativeText:@"Do you want to overwrite it anyway?" buttons:@"Overwrite", @"Cancel", nil];
[alert beginSheetModalForWindow:_window modalDelegate:_self didEndSelector:@selector(makeWritableSheetDidEnd:returnCode:contextInfo:) contextInfo:NULL];
}
@@ -74,8 +74,8 @@ namespace
if(charset != kCharsetNoEncoding)
{
// TODO transliteration / BOM check box
NSAlert* alert = [[NSAlert tmAlertWithMessageText:[NSString stringWithCxxString:text::format("Unable to save document using “%s” as encoding.", charset.c_str())] informativeText:@"Please choose another encoding:" buttons:@"Retry", @"Cancel", nil] retain];
[alert setAccessoryView:[[OakEncodingPopUpButton new] autorelease]];
NSAlert* alert = [NSAlert tmAlertWithMessageText:[NSString stringWithCxxString:text::format("Unable to save document using “%s” as encoding.", charset.c_str())] informativeText:@"Please choose another encoding:" buttons:@"Retry", @"Cancel", nil];
[alert setAccessoryView:[OakEncodingPopUpButton new]];
[alert beginSheetModalForWindow:_window modalDelegate:_self didEndSelector:@selector(encodingSheetDidEnd:returnCode:contextInfo:) contextInfo:NULL];
[[alert window] recalculateKeyViewLoop];
}
@@ -129,7 +129,7 @@ namespace
+ (void)trySaveDocuments:(std::vector<document::document_ptr> const&)someDocuments forWindow:(NSWindow*)aWindow defaultDirectory:(NSString*)aFolder andCallback:(document_save_callback_t*)aCallback
{
[[[[DocumentSaveHelper alloc] init] autorelease] trySaveDocuments:someDocuments forWindow:aWindow defaultDirectory:aFolder andCallback:aCallback];
[[[DocumentSaveHelper alloc] init] trySaveDocuments:someDocuments forWindow:aWindow defaultDirectory:aFolder andCallback:aCallback];
}
+ (void)trySaveDocument:(document::document_ptr const&)aDocument forWindow:(NSWindow*)aWindow defaultDirectory:(NSString*)aFolder andCallback:(document_save_callback_t*)aCallback
@@ -140,9 +140,6 @@ namespace
- (void)dealloc
{
D(DBF_DocumentController_SaveHelper, bug("\n"););
[window release];
[saveFolder release];
[super dealloc];
}
- (file::save_context_ptr const&)context { return context; }
@@ -153,8 +150,6 @@ namespace
if(documents.empty())
return;
[self retain]; // keep us retained until document is saved
document::document_ptr document = documents.back();
D(DBF_DocumentController_SaveHelper, bug("%s (%zu total)\n", document->display_name().c_str(), documents.size()););
document->try_save(document::save_callback_ptr((document::save_callback_t*)new save_callback_t(document, self, window)));
@@ -163,8 +158,8 @@ namespace
- (void)trySaveDocuments:(std::vector<document::document_ptr> const&)someDocuments forWindow:(NSWindow*)aWindow defaultDirectory:(NSString*)aFolder andCallback:(document_save_callback_t*)aCallback
{
documents = someDocuments;
window = [aWindow retain];
saveFolder = [aFolder retain];
window = aWindow;
saveFolder = aFolder;
callback = aCallback;
std::reverse(documents.begin(), documents.end());
[[NSNotificationCenter defaultCenter] postNotificationName:@"OakDocumentNotificationWillSave" object:self userInfo:@{ @"window" : window }];
@@ -190,8 +185,6 @@ namespace
if(flag && [[window delegate] respondsToSelector:@selector(updateProxyIcon)])
[[window delegate] performSelector:@selector(updateProxyIcon)]; // FIXME The delegate needs to update proxy icon based on “exists on disk” notifications from document_t
[self release];
}
// ===================
@@ -222,7 +215,6 @@ namespace
if(returnCode == NSAlertFirstButtonReturn)
ctxt->set_make_writable(true);
else userAbort = YES;
[alert release];
}
- (void)encodingSheetDidEnd:(NSAlert*)alert returnCode:(NSInteger)returnCode contextInfo:(void*)info
@@ -236,6 +228,5 @@ namespace
OakEncodingPopUpButton* popUp = (OakEncodingPopUpButton*)[alert accessoryView];
ctxt->set_charset(to_s(popUp.encoding));
}
[alert release];
}
@end

View File

@@ -65,7 +65,7 @@ struct document_tab_t
}
}
private:
DocumentController* _self;
__weak DocumentController* _self;
};
typedef std::shared_ptr<callback_t> callback_ptr;

View File

@@ -213,14 +213,8 @@ namespace
{
callback_t (DocumentController* controller, NSIndexSet* indexSet)
{
_self = [controller retain];
_indexSet = [indexSet retain];
}
~callback_t ()
{
[_self release];
[_indexSet release];
_self = controller;
_indexSet = indexSet;
}
void can_close_documents (bool flag)
@@ -259,7 +253,6 @@ namespace
- (void)documentOpenHelper:(DocumentOpenHelper*)documentOpenHelper didOpenDocument:(document::document_ptr const&)aDocument
{
[documentOpenHelper autorelease];
if(aDocument != [self selectedDocument])
return;
@@ -292,8 +285,6 @@ namespace
[set addIndex:i];
}
[self closeTabsAtIndexes:set quiet:YES];
[documentOpenHelper release];
}
// =======================
@@ -346,7 +337,6 @@ namespace
break;
}
delete info;
[alert release];
}
- (void)showCloseWarningUIForDocuments:(std::vector<document::document_ptr> const&)someDocuments andCallback:(close_warning_callback_t*)aCallback

View File

@@ -26,7 +26,7 @@
[super loadView];
ASSERT(self.view); ASSERT(popUpButton); ASSERT(textView);
[[textView textStorage] setAttributedString:[[[NSAttributedString alloc] initWithString:[NSString stringWithCxxString:text::to_hex(first, last)] attributes:@{ NSFontAttributeName : [NSFont userFixedPitchFontOfSize:12] }] autorelease]];
[[textView textStorage] setAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithCxxString:text::to_hex(first, last)] attributes:@{ NSFontAttributeName : [NSFont userFixedPitchFontOfSize:12] }]];
[textView setEditable:NO];
int lines = oak::cap(5, (int)((last - first) / 16), 20);

View File

@@ -7,6 +7,7 @@
#import <file/type.h>
#import <ns/ns.h>
#import <network/network.h>
#import <OakAppKit/OakAppKit.h>
#import <OakFoundation/NSArray Additions.h>
#import <OakFoundation/NSString Additions.h>
#import <BundlesManager/BundlesManager.h>
@@ -61,24 +62,6 @@ static NSArray* wrap (std::set<grammar_info_t> const& array)
return self;
}
- (void)dealloc
{
self.path = nil;
self.recommendedGrammars = nil;
self.installedGrammars = nil;
self.allGrammars = nil;
self.grammars = nil;
self.selectedGrammarIndexes = nil;
self.alertFormatString = nil;
self.infoFormatString = nil;
self.useForAllFormatString = nil;
[super dealloc];
}
- (void)setupGrammars
{
std::set<grammar_info_t> recommended, installed, all;
@@ -184,7 +167,10 @@ static NSArray* wrap (std::set<grammar_info_t> const& array)
mainWindow = aWindow;
delegate = aDelegate;
contextInfo = info;
[NSApp beginSheet:self.window modalForWindow:aWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:NULL];
OakShowSheetForWindow(self.window, aWindow, ^(NSInteger returnCode){
[self sheetDidEnd:self.window returnCode:returnCode contextInfo:NULL];
});
}
static bool is_installed (oak::uuid_t const& uuid)
@@ -204,7 +190,6 @@ static bool is_installed (oak::uuid_t const& uuid)
[installingBundleActivityTextField unbind:@"value"];
[NSApp endSheet:installingBundleWindow];
[installingBundleWindow orderOut:self];
[delegate fileTypeDialog:self didSelectFileType:self.fileType contextInfo:contextInfo];
}
}
@@ -235,7 +220,9 @@ static bool is_installed (oak::uuid_t const& uuid)
[installingBundleActivityTextField bind:@"value" toObject:[BundlesManager sharedInstance] withKeyPath:@"activityText" options:nil];
[installingBundleProgressIndicator bind:@"value" toObject:[BundlesManager sharedInstance] withKeyPath:@"progress" options:nil];
[installingBundleProgressIndicator startAnimation:self];
[NSApp beginSheet:installingBundleWindow modalForWindow:mainWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
OakShowSheetForWindow(installingBundleWindow, mainWindow, ^(NSInteger returnCode){
[delegate fileTypeDialog:self didSelectFileType:self.fileType contextInfo:contextInfo];
});
return;
}
}

View File

@@ -37,16 +37,6 @@ NSString* const kUserDefaultsHTMLOutputHeightKey = @"htmlOutputHeight";
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
self.tabBarView = nil;
self.documentView = nil;
self.fileBrowserView = nil;
self.htmlOutputView = nil;
self.fileBrowserWidthConstraint = nil;
self.htmlOutputHeightConstraint = nil;
[super dealloc];
}
- (void)userDefaultsDidChange:(NSNotification*)aNotification
@@ -55,36 +45,32 @@ NSString* const kUserDefaultsHTMLOutputHeightKey = @"htmlOutputHeight";
self.htmlOutputOnRight = [[[NSUserDefaults standardUserDefaults] objectForKey:kUserDefaultsHTMLOutputPlacementKey] isEqualToString:@"right"];
}
- (void)replaceView:(NSView**)oldView withView:(NSView*)newView
- (NSView*)replaceView:(NSView*)oldView withView:(NSView*)newView
{
if(newView == *oldView)
return;
if(newView == oldView)
return oldView;
if(NSView* view = *oldView)
{
[view removeFromSuperview];
[view release];
*oldView = nil;
}
[oldView removeFromSuperview];
if(newView)
{
[newView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addSubview:newView];
*oldView = [newView retain];
}
[self setNeedsUpdateConstraints:YES];
[[self window] invalidateCursorRectsForView:self];
return newView;
}
- (void)setTabBarView:(NSView*)aTabBarView { [self replaceView:&_tabBarView withView:aTabBarView]; }
- (void)setDocumentView:(NSView*)aDocumentView { [self replaceView:&_documentView withView:aDocumentView]; }
- (void)setHtmlOutputView:(NSView*)aHtmlOutputView { [self replaceView:&_htmlOutputView withView:aHtmlOutputView]; }
- (void)setTabBarView:(NSView*)aTabBarView { _tabBarView = [self replaceView:_tabBarView withView:aTabBarView]; }
- (void)setDocumentView:(NSView*)aDocumentView { _documentView = [self replaceView:_documentView withView:aDocumentView]; }
- (void)setHtmlOutputView:(NSView*)aHtmlOutputView { _htmlOutputView = [self replaceView:_htmlOutputView withView:aHtmlOutputView]; }
- (void)setFileBrowserView:(NSView*)aFileBrowserView
{
[self replaceView:&_fileBrowserView withView:aFileBrowserView];
_fileBrowserView = [self replaceView:_fileBrowserView withView:aFileBrowserView];
}
- (void)setFileBrowserOnRight:(BOOL)flag
@@ -196,7 +182,7 @@ NSString* const kUserDefaultsHTMLOutputHeightKey = @"htmlOutputHeight";
if(!view || [anEvent type] != NSLeftMouseDown)
return [super mouseDown:anEvent];
NSEvent* mouseDownEvent = [anEvent retain];
NSEvent* mouseDownEvent = anEvent;
NSRect initialFrame = view.frame;
BOOL didDrag = NO;
@@ -239,8 +225,6 @@ NSString* const kUserDefaultsHTMLOutputHeightKey = @"htmlOutputHeight";
[view mouseDown:mouseDownEvent];
}
}
[mouseDownEvent release];
}
- (BOOL)isOpaque

View File

@@ -3,5 +3,3 @@ CP_Resources = resources/*
LINK += command text authorization scm bundles cf Find HTMLOutputWindow io ns OakAppKit OakFileBrowser OakFilterList OakFoundation OakSystem OakTextView BundleEditor network Preferences
EXPORT = src/DocumentController.h src/DocumentOpenHelper.h src/FileTypeDialog.h
FRAMEWORKS = Cocoa
OBJCXX_FLAGS += -fno-objc-arc