ARC: Update OakFileBrowser framework

This commit is contained in:
Allan Odgaard
2013-01-11 09:45:30 +01:00
parent f3c8b589b5
commit f3f0f577bf
21 changed files with 130 additions and 243 deletions

View File

@@ -109,8 +109,8 @@ static NSSet* VisibleItems (NSOutlineView* outlineView, FSItem* root, NSMutableS
{
recursiveExpandPaths = [NSMutableSet new];
expandedURLs = [ConvertURLArrayToSet([[NSUserDefaults standardUserDefaults] arrayForKey:@"ExpandedURLs"]) retain];
selectedURLs = [ConvertURLArrayToSet([[NSUserDefaults standardUserDefaults] arrayForKey:@"SelectedURLs"]) retain];
expandedURLs = ConvertURLArrayToSet([[NSUserDefaults standardUserDefaults] arrayForKey:@"ExpandedURLs"]);
selectedURLs = ConvertURLArrayToSet([[NSUserDefaults standardUserDefaults] arrayForKey:@"SelectedURLs"]);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:NSApp];
}
@@ -120,19 +120,7 @@ static NSSet* VisibleItems (NSOutlineView* outlineView, FSItem* root, NSMutableS
- (void)dealloc
{
[self applicationWillTerminate:nil];
self.pendingSelectURLs = nil;
self.pendingEditURL = nil;
self.pendingMakeVisibleURL = nil;
self.pendingExpandURLs = nil;
self.dataSource = nil;
self.outlineView = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:NSApp];
[recursiveExpandPaths release];
[expandedURLs release];
[selectedURLs release];
[super dealloc];
}
- (void)applicationWillTerminate:(NSNotification*)aNotification
@@ -147,8 +135,7 @@ static NSSet* VisibleItems (NSOutlineView* outlineView, FSItem* root, NSMutableS
if(outlineView != anOutlineView)
{
[outlineView setDelegate:nil];
[outlineView release];
outlineView = [anOutlineView retain];
outlineView = anOutlineView;
[outlineView setDelegate:self];
}
}
@@ -189,12 +176,11 @@ static NSSet* VisibleItems (NSOutlineView* outlineView, FSItem* root, NSMutableS
[outlineView deselectAll:self];
[outlineView setDataSource:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:FSItemDidReloadNotification object:dataSource];
[dataSource release];
}
itemsReloading = 0;
if(dataSource = [aDataSource retain])
if(dataSource = aDataSource)
{
[outlineView setDataSource:dataSource];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidReload:) name:FSItemDidReloadNotification object:dataSource];
@@ -277,7 +263,7 @@ static NSSet* VisibleItems (NSOutlineView* outlineView, FSItem* root, NSMutableS
for(NSURL* targetURL in someURLs)
{
NSMutableSet* currentAncestors = [[NSMutableSet alloc] init];
NSMutableSet* currentAncestors = [NSMutableSet set];
NSURL* currentURL;
for(currentURL = ParentForURL(targetURL); currentURL; currentURL = ParentForURL(currentURL))
@@ -290,8 +276,6 @@ static NSSet* VisibleItems (NSOutlineView* outlineView, FSItem* root, NSMutableS
if(currentURL)
[ancestors unionSet:currentAncestors];
[currentAncestors release];
}
self.pendingExpandURLs = ancestors;
@@ -362,7 +346,7 @@ static NSSet* VisibleItems (NSOutlineView* outlineView, FSItem* root, NSMutableS
NSImage* icon = item.icon;
if([modifiedURLs containsObject:item.url])
{
NSImage* tmp = [[[NSImage alloc] initWithSize:[icon size]] autorelease];
NSImage* tmp = [[NSImage alloc] initWithSize:[icon size]];
[tmp lockFocus];
[icon drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:0.4];
[tmp unlockFocus];

View File

@@ -26,7 +26,7 @@ NSString* DisplayName (NSURL* url, size_t numberOfParents)
{
NSString* res = nil;
if([[url scheme] isEqualToString:[kURLLocationComputer scheme]])
res = [(NSString*)SCDynamicStoreCopyComputerName(NULL, NULL) autorelease];
res = CFBridgingRelease(SCDynamicStoreCopyComputerName(NULL, NULL));
else if([[url scheme] isEqualToString:[kURLLocationBundles scheme]])
res = @"Bundles";
else // if([url isFileURL])
@@ -67,5 +67,5 @@ NSURL* ParentForURL (NSURL* url)
else if([@[ @"xcodeproj", @"search" ] containsObject:[url scheme]])
return [NSURL fileURLWithPath:parentPath isDirectory:YES];
else
return [[[NSURL alloc] initWithScheme:[url scheme] host:[url host] path:parentPath] autorelease];
return [[NSURL alloc] initWithScheme:[url scheme] host:[url host] path:parentPath];
}

View File

@@ -22,7 +22,7 @@ PUBLIC @interface OakFileBrowser : NSResponder <OFBOutlineViewMenuDelegate>
NSUInteger dataSourceOptions;
OakHistoryController* historyController;
id <OakFileBrowserDelegate> delegate;
__weak id <OakFileBrowserDelegate> delegate;
OakFileBrowserView* view;
FSOutlineViewDelegate* outlineViewDelegate;
}

View File

@@ -59,7 +59,7 @@ static bool is_binary (std::string const& path)
static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anotherSet)
{
NSMutableSet* unionSet = [[aSet mutableCopy] autorelease];
NSMutableSet* unionSet = [aSet mutableCopy];
[unionSet unionSet:anotherSet];
[anotherSet intersectSet:aSet];
[unionSet minusSet:anotherSet];
@@ -544,7 +544,7 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
- (NSMenu*)menuForOutlineView:(NSOutlineView*)anOutlineView
{
NSMenu* menu = [[NSMenu new] autorelease];
NSMenu* menu = [NSMenu new];
[menu setAutoenablesItems:NO];
NSInteger numberOfSelectedRows = [anOutlineView numberOfSelectedRows];
@@ -634,7 +634,7 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
}
}
OakFinderLabelChooser* swatch = [[[OakFinderLabelChooser alloc] initWithFrame:NSMakeRect(0, 0, 166, 37)] autorelease];
OakFinderLabelChooser* swatch = [[OakFinderLabelChooser alloc] initWithFrame:NSMakeRect(0, 0, 166, 37)];
swatch.selectedIndex = numberOfSelectedRows == 1 ? [[self.selectedItems lastObject] labelIndex] : 0;
swatch.target = self;
swatch.action = @selector(changeColor:);
@@ -663,7 +663,7 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
NSString* urlString = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsInitialFileBrowserURLKey];
self.url = urlString ? [NSURL URLWithString:urlString] : kURLLocationHome;
self.historyController = [[OakHistoryController new] autorelease];
self.historyController = [OakHistoryController new];
[self loadFileBrowserOptions];
BOOL foldersOnTop = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsFoldersOnTopKey];
@@ -697,12 +697,6 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
self.view = nil;
self.url = nil;
self.historyController = nil;
[super dealloc];
}
- (void)setView:(OakFileBrowserView*)aView
@@ -711,18 +705,15 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
{
if(view)
{
[outlineViewDelegate release];
outlineViewDelegate = nil;
if(view.delegate == self)
view.delegate = nil;
if(view.persistentNextResponder == self)
view.persistentNextResponder = nil;
[view release];
}
if(view = [aView retain])
if(view = aView)
{
view.delegate = self;
view.persistentNextResponder = self;
@@ -746,7 +737,7 @@ static NSMutableSet* SymmetricDifference (NSMutableSet* aSet, NSMutableSet* anot
- (void)setupViewWithState:(NSDictionary*)fileBrowserState
{
self.view = [[[OakFileBrowserView alloc] initWithFrame:NSZeroRect] autorelease];
self.view = [[OakFileBrowserView alloc] initWithFrame:NSZeroRect];
historyController.state = fileBrowserState;
if(!historyController.currentURL)
[historyController addURLToHistory:url];
@@ -827,7 +818,7 @@ static struct data_source_options_map_t { NSString* const name; NSUInteger flag;
- (IBAction)showOptionsPopUpMenu:(id)sender
{
NSMenu* menu = [[NSMenu new] autorelease];
NSMenu* menu = [NSMenu new];
iterate(it, DataSourceOptionsMap)
{
NSMenuItem* item = [menu addItemWithTitle:it->name action:@selector(toggleViewOption:) keyEquivalent:@""];
@@ -916,7 +907,7 @@ static struct data_source_options_map_t { NSString* const name; NSUInteger flag;
- (IBAction)showFolderPopUpMenu:(id)sender
{
NSMenu* menu = [[NSMenu new] autorelease];
NSMenu* menu = [NSMenu new];
NSMutableSet* visibleLocations = [NSMutableSet setWithObjects:kURLLocationComputer, kURLLocationHome, kURLLocationFavorites, nil];
// Add path hierarchy
@@ -988,7 +979,7 @@ static struct data_source_options_map_t { NSString* const name; NSUInteger flag;
{
// TODO DisplayName paths
NSMutableSet* seenPaths = [NSMutableSet set];
NSMenu* menu = [[NSMenu new] autorelease];
NSMenu* menu = [NSMenu new];
for(NSURL* aURL in urls)
{
if([seenPaths containsObject:[aURL path]])
@@ -1041,7 +1032,7 @@ static struct data_source_options_map_t { NSString* const name; NSUInteger flag;
}
}
NSMenu* menu = [[NSMenu new] autorelease];
NSMenu* menu = [NSMenu new];
iterate(pair, urls)
{
NSMenuItem* menuItem = [menu addItemWithTitle:[NSString stringWithCxxString:pair->first] action:@selector(takeURLFrom:) keyEquivalent:@""];

View File

@@ -1,24 +1,21 @@
@interface OakHistoryController : NSObject
{
NSMutableArray* historyArray;
NSMutableArray* recentLocationsArray;
NSInteger historyIndex;
}
@property (nonatomic, retain) NSDictionary* state;
@property (nonatomic) NSDictionary* state;
@property (nonatomic, readonly) NSURL* previousURL;
@property (nonatomic, readonly) NSURL* nextURL;
@property (nonatomic, readonly) NSURL* currentURL;
@property (nonatomic, assign) CGFloat currentURLScrollOffset;
@property (nonatomic) CGFloat currentURLScrollOffset;
- (void)addURLToHistory:(NSURL*)path;
- (BOOL)advance:(id)sender;
- (BOOL)retreat:(id)sender;
@property (nonatomic, readonly) NSArray* recentLocations;
@property (nonatomic, assign) NSInteger historyIndex;
@property (nonatomic) NSInteger historyIndex;
@property (nonatomic, readonly) NSInteger historyCount;
- (NSURL*)urlAtIndex:(NSInteger)index;
@end
@interface OakHistoryController (WorkaroundForBeingBackedByNSMutableArray)
@property (nonatomic, readonly) NSArray* recentLocations;
@end

View File

@@ -2,109 +2,100 @@
#import <oak/algorithm.h>
#import <oak/debug.h>
@implementation OakHistoryController
@synthesize historyIndex;
@interface OakHistoryController ()
@property (nonatomic) NSMutableArray* recentLocations;
@property (nonatomic) NSMutableArray* history;
@end
@implementation OakHistoryController { OBJC_WATCH_LEAKS(OakHistoryController); }
- (id)init
{
if(self = [super init])
{
historyArray = [NSMutableArray new];
historyIndex = -1;
recentLocationsArray = [NSMutableArray new];
_history = [NSMutableArray new];
_historyIndex = -1;
_recentLocations = [NSMutableArray new];
}
return self;
}
- (void)dealloc
{
[historyArray release];
[recentLocationsArray release];
[super dealloc];
}
- (NSDictionary*)state
{
NSMutableArray* history = [NSMutableArray array];
for(NSDictionary* entry in historyArray)
for(NSDictionary* entry in _history)
{
NSMutableDictionary* dict = [[entry mutableCopy] autorelease];
[dict setObject:[[dict objectForKey:@"url"] absoluteString] forKey:@"url"];
NSMutableDictionary* dict = [entry mutableCopy];
dict[@"url"] = [dict[@"url"] absoluteString];
[history addObject:dict];
}
return @{ @"history" : history, @"historyIndex" : @(historyIndex) };
return @{ @"history" : history, @"historyIndex" : @(_historyIndex) };
}
- (void)setState:(NSDictionary*)newState
{
[recentLocationsArray removeAllObjects];
[historyArray removeAllObjects];
for(NSDictionary* entry in [newState objectForKey:@"history"])
[_recentLocations removeAllObjects];
[_history removeAllObjects];
for(NSDictionary* entry in newState[@"history"])
{
id value = nil;
if((value = [entry objectForKey:@"path"]) && [value isKindOfClass:[NSString class]])
if((value = entry[@"path"]) && [value isKindOfClass:[NSString class]])
value = [NSURL fileURLWithPath:value isDirectory:YES];
else if((value = [entry objectForKey:@"url"]) && [value isKindOfClass:[NSString class]])
else if((value = entry[@"url"]) && [value isKindOfClass:[NSString class]])
value = [NSURL URLWithString:value];
else
continue;
if(value)
{
NSMutableDictionary* dict = [[entry mutableCopy] autorelease];
NSMutableDictionary* dict = [entry mutableCopy];
[dict removeObjectForKey:@"path"];
[dict setObject:value forKey:@"url"];
[historyArray addObject:dict];
dict[@"url"] = value;
[_history addObject:dict];
}
}
historyIndex = oak::cap<NSInteger>(-1, [[newState objectForKey:@"historyIndex"] intValue], [historyArray count]-1);
_historyIndex = oak::cap<NSInteger>(-1, [newState[@"historyIndex"] intValue], [_history count]-1);
}
- (NSURL*)previousURL { return historyIndex > 0 ? [[historyArray objectAtIndex:historyIndex-1] objectForKey:@"url"] : nil; }
- (NSURL*)nextURL { return historyIndex+1 < [historyArray count] ? [[historyArray objectAtIndex:historyIndex+1] objectForKey:@"url"] : nil; }
- (NSURL*)currentURL { return historyIndex != -1 ? [[historyArray objectAtIndex:historyIndex] objectForKey:@"url"] : nil; }
- (CGFloat)currentURLScrollOffset { return historyIndex != -1 ? [[[historyArray objectAtIndex:historyIndex] objectForKey:@"scrollOffset"] floatValue] : 0; }
- (NSURL*)previousURL { return _historyIndex > 0 ? _history[_historyIndex-1][@"url"] : nil; }
- (NSURL*)nextURL { return _historyIndex+1 < [_history count] ? _history[_historyIndex+1][@"url"] : nil; }
- (NSURL*)currentURL { return _historyIndex != -1 ? _history[_historyIndex][@"url"] : nil; }
- (CGFloat)currentURLScrollOffset { return _historyIndex != -1 ? [_history[_historyIndex][@"scrollOffset"] floatValue] : 0; }
- (void)addURLToHistory:(NSURL*)url
{
ASSERT(url);
[recentLocationsArray removeObject:url];
[recentLocationsArray addObject:url];
[_recentLocations removeObject:url];
[_recentLocations addObject:url];
if(++historyIndex < [historyArray count])
[historyArray removeObjectsInRange:NSMakeRange(historyIndex, [historyArray count] - historyIndex)];
if(++_historyIndex < [_history count])
[_history removeObjectsInRange:NSMakeRange(_historyIndex, [_history count] - _historyIndex)];
[historyArray addObject:@{ @"url" : url }];
[_history addObject:@{ @"url" : url }];
}
- (BOOL)advance:(id)sender { return historyIndex+1 < [historyArray count] ? (++historyIndex, YES) : NO; }
- (BOOL)retreat:(id)sender { return historyIndex > 0 ? (--historyIndex, YES) : NO; }
- (BOOL)advance:(id)sender { return _historyIndex+1 < [_history count] ? (++_historyIndex, YES) : NO; }
- (BOOL)retreat:(id)sender { return _historyIndex > 0 ? (--_historyIndex, YES) : NO; }
- (void)setCurrentURLScrollOffset:(CGFloat)offset
{
if(historyIndex != -1)
if(_historyIndex != -1)
{
NSMutableDictionary* dict = [[[historyArray objectAtIndex:historyIndex] mutableCopy] autorelease];
NSMutableDictionary* dict = [_history[_historyIndex] mutableCopy];
if(offset)
[dict setObject:@(offset) forKey:@"scrollOffset"];
dict[@"scrollOffset"] = @(offset);
else [dict removeObjectForKey:@"scrollOffset"];
[historyArray replaceObjectAtIndex:historyIndex withObject:dict];
_history[_historyIndex] = dict;
}
}
- (NSArray*)recentLocations
{
return recentLocationsArray;
}
- (NSInteger)historyCount
{
return historyArray.count;
return [_history count];
}
- (NSURL*)urlAtIndex:(NSInteger)index
{
ASSERT(index >= 0 && index < historyArray.count);
return [[historyArray objectAtIndex:index] objectForKey:@"url"];
ASSERT(index >= 0 && index < [_history count]);
return _history[index][@"url"];
}
@end

View File

@@ -13,6 +13,7 @@
#import <io/path.h>
#import <io/move_path.h>
#import <io/resource.h>
#import <oak/debug.h>
NSString* const FSItemDidReloadNotification = @"FSItemDidReloadNotification";
@@ -21,40 +22,34 @@ FSDataSource* DataSourceForURL (NSURL* anURL, NSUInteger someOptions)
FSDataSource* res = nil;
NSString* scheme = [anURL scheme];
if([scheme isEqualToString:@"xcodeproj"])
res = [[[FSXcodeProjectDataSource alloc] initWithURL:anURL options:someOptions] autorelease];
res = [[FSXcodeProjectDataSource alloc] initWithURL:anURL options:someOptions];
else if([scheme isEqualToString:@"file"])
res = [[[FSDirectoryDataSource alloc] initWithURL:anURL options:someOptions] autorelease];
res = [[FSDirectoryDataSource alloc] initWithURL:anURL options:someOptions];
else if([scheme isEqualToString:@"computer"])
res = [[[FSVolumesDataSource alloc] initWithURL:anURL options:someOptions] autorelease];
res = [[FSVolumesDataSource alloc] initWithURL:anURL options:someOptions];
else if([scheme isEqualToString:@"search"])
res = [[[FSSearchDataSource alloc] initWithURL:anURL options:someOptions] autorelease];
res = [[FSSearchDataSource alloc] initWithURL:anURL options:someOptions];
// else if([scheme isEqualToString:@"bundles"])
// res = [[[FSBundlesDataSource alloc] initWithURL:anURL options:someOptions] autorelease];
// res = [[FSBundlesDataSource alloc] initWithURL:anURL options:someOptions];
else if([scheme isEqualToString:@"scm"])
res = [[[FSSCMDataSource alloc] initWithURL:anURL options:someOptions] autorelease];
res = [[FSSCMDataSource alloc] initWithURL:anURL options:someOptions];
return res;
}
@implementation FSDataSource
@implementation FSDataSource { OBJC_WATCH_LEAKS(FSDataSource); }
@synthesize rootItem;
+ (NSArray*)sortArray:(NSArray*)anArray usingOptions:(NSUInteger)someOptions
{
NSMutableArray* descriptors = [NSMutableArray array];
if(someOptions & kFSDataSourceOptionGroupsFirst)
[descriptors addObject:[[[NSSortDescriptor alloc] initWithKey:@"sortAsFolder" ascending:NO] autorelease]];
[descriptors addObject:[[NSSortDescriptor alloc] initWithKey:@"sortAsFolder" ascending:NO]];
if(someOptions & kFSDataSourceOptionSortByType)
[descriptors addObject:[[[NSSortDescriptor alloc] initWithKey:@"name.pathExtensions" ascending:YES selector:@selector(displayNameCompare:)] autorelease]];
[descriptors addObject:[[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(displayNameCompare:)] autorelease]];
[descriptors addObject:[[NSSortDescriptor alloc] initWithKey:@"name.pathExtensions" ascending:YES selector:@selector(displayNameCompare:)]];
[descriptors addObject:[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(displayNameCompare:)]];
return [anArray sortedArrayUsingDescriptors:descriptors];
}
- (void)dealloc
{
[rootItem release];
[super dealloc];
}
- (BOOL)reloadItem:(FSItem*)anItem
{
return NO;

View File

@@ -16,7 +16,7 @@
OAK_DEBUG_VAR(FileBrowser_DSDirectory);
@interface FSDirectoryDataSource ()
@interface FSDirectoryDataSource () { OBJC_WATCH_LEAKS(FSDirectoryDataSource); }
@property (nonatomic, retain) NSMutableDictionary* visible;
- (void)internalReloadItem:(FSItem*)anItem requested:(BOOL)flag;
- (void)lostItems:(NSArray*)someItems;
@@ -147,8 +147,8 @@ namespace
{
D(DBF_FileBrowser_DSDirectory, bug("%s\n", [[[item url] path] UTF8String]););
_data_source = [dataSource retain];
_item = [item retain];
_data_source = dataSource;
_item = item;
_client_key = server().register_client(this);
server().send_request(_client_key, request_t([[item.url path] fileSystemRepresentation], options));
}
@@ -156,8 +156,6 @@ namespace
scanner_t::~scanner_t ()
{
server().unregister_client(_client_key);
[_item release];
[_data_source release];
}
std::vector<fs_item_t> scanner_t::handle_request (request_t const& request)
@@ -313,7 +311,7 @@ static void remove_callbacks (scm::callback_t* cb, std::string const& path, std:
}
private:
FSDirectoryDataSource* _self;
__weak FSDirectoryDataSource* _self;
};
callback = new event_callback_t(self);
@@ -334,7 +332,7 @@ static void remove_callbacks (scm::callback_t* cb, std::string const& path, std:
}
private:
FSDirectoryDataSource* _self;
__weak FSDirectoryDataSource* _self;
};
scmCallback = new scm_callback_t(self);
@@ -357,8 +355,6 @@ static void remove_callbacks (scm::callback_t* cb, std::string const& path, std:
fs::unwatch([[self.rootItem.url path] fileSystemRepresentation], callback);
delete callback;
self.visible = nil;
[super dealloc];
}
- (void)internalReloadItem:(FSItem*)anItem requested:(BOOL)flag

View File

@@ -3,8 +3,9 @@
#import <OakAppKit/OakFileIconImage.h>
#import <io/path.h>
#import <oak/oak.h>
#import <oak/debug.h>
@implementation FSItem
@implementation FSItem { OBJC_WATCH_LEAKS(FSItem); }
@synthesize icon, name, toolTip, labelIndex, url, urlType, target, children, leaf, group, sortAsFolder;
- (FSItem*)initWithURL:(NSURL*)anURL
@@ -26,23 +27,12 @@
+ (FSItem*)itemWithURL:(NSURL*)anURL
{
return [[[self alloc] initWithURL:anURL] autorelease];
return [[self alloc] initWithURL:anURL];
}
- (id)copyWithZone:(NSZone*)zone
{
return [self retain];
}
- (void)dealloc
{
[icon release];
[name release];
[toolTip release];
[url release];
[target release];
[children release];
[super dealloc];
return self;
}
- (BOOL)isEqual:(id)otherObject

View File

@@ -61,7 +61,7 @@ _Iter prune_path_children (_Iter it, _Iter last)
return out;
}
@implementation FSSCMDataSource
@implementation FSSCMDataSource { OBJC_WATCH_LEAKS(FSSCMDataSource); }
+ (NSURL*)scmURLWithPath:(NSString*)aPath
{
if(scm::info_ptr info = scm::info([aPath fileSystemRepresentation]))
@@ -129,7 +129,7 @@ _Iter prune_path_children (_Iter it, _Iter last)
}
private:
FSSCMDataSource* _self;
__weak FSSCMDataSource* _self;
};
std::string name = path::display_name(scmInfo->path());
@@ -155,7 +155,5 @@ _Iter prune_path_children (_Iter it, _Iter last)
scmInfo->remove_callback(scmCallback);
delete scmCallback;
}
[super dealloc];
}
@end

View File

@@ -1,7 +1,5 @@
#import "FSDataSource.h"
@interface FSSearchDataSource : FSDataSource
{
}
- (id)initWithURL:(NSURL*)anURL options:(NSUInteger)someOptions;
@end

View File

@@ -83,18 +83,14 @@ namespace
}
}
@implementation FSSearchDataSource
@implementation FSSearchDataSource { OBJC_WATCH_LEAKS(FSSearchDataSource); }
- (id)initWithURL:(NSURL*)anURL options:(NSUInteger)someOptions
{
if((self = [super init]))
{
NSMutableArray* results = [NSMutableArray new];
citerate(item, execute_saved_search([[anURL path] fileSystemRepresentation]))
{
CFStringRef path = (CFStringRef)MDItemCopyAttribute(*item, kMDItemPath);
[results addObject:[FSItem itemWithURL:[NSURL fileURLWithPath:(NSString*)path isDirectory:NO]]];
CFRelease(path);
}
[results addObject:[FSItem itemWithURL:[NSURL fileURLWithPath:CFBridgingRelease(MDItemCopyAttribute(*item, kMDItemPath)) isDirectory:NO]]];
self.rootItem = [FSItem itemWithURL:anURL];
self.rootItem.icon = [OakFileIconImage fileIconImageWithPath:[anURL path] size:NSMakeSize(16, 16)];

View File

@@ -3,8 +3,9 @@
#import <OakFoundation/NSString Additions.h>
#import <io/path.h>
#import <oak/oak.h>
#import <oak/debug.h>
@implementation FSVolumesDataSource
@implementation FSVolumesDataSource { OBJC_WATCH_LEAKS(FSVolumesDataSource); }
- (NSArray*)volumeList
{
NSMutableArray* volumes = [NSMutableArray new];
@@ -34,7 +35,7 @@
self.rootItem = [FSItem itemWithURL:anURL];
self.rootItem.icon = [NSImage imageNamed:NSImageNameComputer];
self.rootItem.name = [(NSString*)SCDynamicStoreCopyComputerName(NULL, NULL) autorelease];
self.rootItem.name = CFBridgingRelease(SCDynamicStoreCopyComputerName(NULL, NULL));
self.rootItem.children = [self volumeList];
}
return self;
@@ -43,6 +44,5 @@
- (void)dealloc
{
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
[super dealloc];
}
@end

View File

@@ -28,7 +28,7 @@ static NSString *caseSensitiveMatchInArrayForString(NSArray *array, NSString *st
for (NSString *possibleString in array)
{
if (![stringToMatch caseInsensitiveCompare:possibleString])
return [[possibleString copy] autorelease];
return [possibleString copy];
}
return nil;
}
@@ -68,14 +68,6 @@ static NSString *caseSensitiveMatchInArrayForString(NSArray *array, NSString *st
return self;
}
- (void) dealloc
{
[_projects release];
[_developerDirectoryPath release];
[super dealloc];
}
#pragma mark -
- (FSItem*)itemForFrameworkAtPath:(NSString*)path
@@ -104,16 +96,16 @@ static NSString *caseSensitiveMatchInArrayForString(NSArray *array, NSString *st
- (NSArray*)itemsForDirectoryAtPath:(NSString*)path
{
NSMutableArray* results = [NSMutableArray array];
for (NSString* file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil])
for (NSString* name in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil])
{
file = [path stringByAppendingPathComponent:file];
NSString* file = [path stringByAppendingPathComponent:name];
FSItem* item = [FSItem itemWithURL:[NSURL fileURLWithPath:file]];
if ([file isDirectory])
item.children = [self itemsForDirectoryAtPath:file];
[results addObject:item];
}
return [[results copy] autorelease];
return [results copy];
}
#pragma mark -
@@ -216,7 +208,7 @@ static NSString *caseSensitiveMatchInArrayForString(NSArray *array, NSString *st
[results addObject:item];
}
}
return [[results copy] autorelease];
return [results copy];
}
#pragma mark -

View File

@@ -8,7 +8,7 @@
static NSButton* ImageButton (NSString* imageName)
{
NSButton* res = [[NSButton new] autorelease];
NSButton* res = [NSButton new];
[[res cell] setBackgroundStyle:NSBackgroundStyleRaised];
[res setButtonType:NSMomentaryChangeButton];
@@ -16,7 +16,7 @@ static NSButton* ImageButton (NSString* imageName)
[res setBordered:NO];
[res setTranslatesAutoresizingMaskIntoConstraints:NO];
NSImage* image = [[[NSImage imageNamed:imageName] copy] autorelease];
NSImage* image = [[NSImage imageNamed:imageName] copy];
[image setSize:NSMakeSize(13, 13)];
[res setImage:image];
[res setImagePosition:NSImageOnly];
@@ -26,17 +26,17 @@ static NSButton* ImageButton (NSString* imageName)
static NSPopUpButton* PopUpButton ()
{
NSPopUpButton* res = [[NSPopUpButton new] autorelease];
NSPopUpButton* res = [NSPopUpButton new];
[[res cell] setBackgroundStyle:NSBackgroundStyleRaised];
[res setBordered:NO];
[res setTranslatesAutoresizingMaskIntoConstraints:NO];
NSMenu* menu = [[NSMenu new] autorelease];
NSMenu* menu = [NSMenu new];
[menu setAutoenablesItems:NO];
NSString* path = NSHomeDirectory();
NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle:[[NSFileManager defaultManager] displayNameAtPath:path] action:@selector(nop:) keyEquivalent:@""] autorelease];
NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:[[NSFileManager defaultManager] displayNameAtPath:path] action:@selector(nop:) keyEquivalent:@""];
[menuItem setIconForFile:path];
[menu addItem:menuItem];
@@ -62,16 +62,6 @@ static NSPopUpButton* PopUpButton ()
return self;
}
- (void)dealloc
{
self.folderPopUpButton = nil;
self.goBackButton = nil;
self.goForwardButton = nil;
self.buttonConstraints = nil;
[super dealloc];
}
- (void)updateConstraints
{
if(self.buttonConstraints)

View File

@@ -6,11 +6,10 @@
{
OBJC_WATCH_LEAKS(OFBOutlineView);
id <OFBOutlineViewMenuDelegate> menuDelegate;
BOOL fieldEditorWasUp;
NSRect mouseHoverRect;
NSIndexSet* draggedRows;
}
@property (nonatomic, assign) id <OFBOutlineViewMenuDelegate> menuDelegate;
@property (nonatomic, weak) id <OFBOutlineViewMenuDelegate> menuDelegate;
- (void)performEditSelectedRow:(id)sender;
@end

View File

@@ -25,17 +25,11 @@
@end
@implementation OFBOutlineView
@synthesize menuDelegate, draggedRows;
- (void)dealloc
{
self.draggedRows = nil;
[super dealloc];
}
@synthesize draggedRows;
- (void)showContextMenu:(id)sender
{
if(NSMenu* menu = [menuDelegate menuForOutlineView:self])
if(NSMenu* menu = [self.menuDelegate menuForOutlineView:self])
{
NSInteger row = [self selectedRow] != -1 ? [self selectedRow] : 0;
NSRect rect = [self convertRect:[self rectOfRow:row] toView:nil];
@@ -61,7 +55,7 @@
- (NSMenu*)menuForEvent:(NSEvent*)theEvent
{
if(!menuDelegate)
if(!self.menuDelegate)
return [super menuForEvent:theEvent];
int row = [self rowAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]];
@@ -69,7 +63,7 @@
[self selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO];
else if(![self.selectedRowIndexes containsIndex:row])
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
return [menuDelegate menuForOutlineView:self];
return [self.menuDelegate menuForOutlineView:self];
}
// =============================
@@ -105,7 +99,7 @@
- (void)performDoubleClick:(id)sender
{
[[self target] performSelector:[self doubleAction] withObject:self];
[NSApp sendAction:[self doubleAction] to:[self target] from:self];
}
- (void)performEditSelectedRow:(id)sender
@@ -244,14 +238,10 @@
NSRect imageFrame = [[[[self tableColumns] lastObject] dataCell] imageFrameWithFrame:cellFrame inControlView:self];
imageFrame.origin.y = cellFrame.origin.y;
imageFrame.size.height = cellFrame.size.height + self.intercellSpacing.height;
NSTrackingArea* cursorRect = [[NSTrackingArea alloc] initWithRect:imageFrame options:NSTrackingCursorUpdate|NSTrackingActiveInKeyWindow owner:self userInfo:NULL];
[self addTrackingArea:cursorRect];
[cursorRect release];
[self addTrackingArea:[[NSTrackingArea alloc] initWithRect:imageFrame options:NSTrackingCursorUpdate|NSTrackingActiveInKeyWindow owner:self userInfo:NULL]];
}
NSTrackingArea* trackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect] options:NSTrackingMouseMoved|NSTrackingActiveInKeyWindow owner:self userInfo:NULL];
[self addTrackingArea:trackingArea];
[trackingArea release];
[self addTrackingArea:[[NSTrackingArea alloc] initWithRect:[self visibleRect] options:NSTrackingMouseMoved|NSTrackingActiveInKeyWindow owner:self userInfo:NULL]];
}
// ===============

View File

@@ -34,8 +34,7 @@
if([self isHighlighted])
r.size.height = r.size.width = 16;
NSGradient* gradient = [[[NSGradient alloc] initWithStartingColor:[NSColor colorWithString:startCol[labelColorIndex-1]]
endingColor:[NSColor colorWithString:stopCol[labelColorIndex-1]]] autorelease];
NSGradient* gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithString:startCol[labelColorIndex-1]] endingColor:[NSColor colorWithString:stopCol[labelColorIndex-1]]];
NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:r xRadius:8.0 yRadius:8.0];
[gradient drawInBezierPath:path angle:90];
}
@@ -159,12 +158,6 @@ static void DrawSpinner (NSRect cellFrame, BOOL isFlipped, NSColor* color, doubl
return [super hitTestForEvent:event inRect:cellFrame ofView:controlView];
}
- (void)dealloc
{
self.spinTimer = nil;
[super dealloc];
}
- (BOOL)trackMouse:(NSEvent*)theEvent inRect:(NSRect)cellFrame ofView:(NSView*)controlView untilMouseUp:(BOOL)untilMouseUp
{
NSPoint mousePos = [controlView convertPoint:[theEvent locationInWindow] fromView:nil];

View File

@@ -16,8 +16,8 @@ namespace fb
@interface OakFileBrowserView : NSView
// Initial setup
@property (nonatomic, assign) id delegate;
@property (nonatomic, assign) NSResponder* persistentNextResponder;
@property (nonatomic, weak) id delegate;
@property (nonatomic, weak) NSResponder* persistentNextResponder;
// Header info
@property (nonatomic, assign) BOOL canGoBackward;

View File

@@ -9,13 +9,9 @@
{
OBJC_WATCH_LEAKS(OakFileBrowserView);
// These two properties are retained only as subviews
OFBOutlineView* outlineView;
OFBHeaderView* headerView;
id delegate;
NSResponder* persistentNextResponder;
// Header view
BOOL canGoBackward;
BOOL canGoForward;
@@ -30,8 +26,7 @@ OAK_DEBUG_VAR(FileBrowser_View);
@implementation OakFileBrowserView
@synthesize outlineView;
@synthesize persistentNextResponder;
@synthesize delegate, canGoBackward, canGoForward, titleText, titleImage;
@synthesize canGoBackward, canGoForward, titleText, titleImage;
// ==================
// = Setup/Teardown =
@@ -46,11 +41,6 @@ OAK_DEBUG_VAR(FileBrowser_View);
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (NSSize)intrinsicContentSize
{
return NSMakeSize(NSViewNoInstrinsicMetric, NSViewNoInstrinsicMetric);
@@ -60,13 +50,13 @@ OAK_DEBUG_VAR(FileBrowser_View);
{
ASSERT(!outlineView);
NSScrollView* scrollView = [[[NSScrollView alloc] initWithFrame:NSZeroRect] autorelease];
NSScrollView* scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect];
scrollView.hasVerticalScroller = YES;
scrollView.hasHorizontalScroller = NO;
scrollView.borderType = NSNoBorder;
[self addSubview:scrollView];
outlineView = [[[OFBOutlineView alloc] initWithFrame:NSMakeRect(10, 10, scrollView.contentSize.width, scrollView.contentSize.height)] autorelease];
outlineView = [[OFBOutlineView alloc] initWithFrame:NSMakeRect(10, 10, scrollView.contentSize.width, scrollView.contentSize.height)];
outlineView.focusRingType = NSFocusRingTypeNone;
outlineView.allowsMultipleSelection = YES;
outlineView.autoresizesOutlineColumn = NO;
@@ -74,14 +64,14 @@ OAK_DEBUG_VAR(FileBrowser_View);
scrollView.documentView = outlineView;
headerView = [[[OFBHeaderView alloc] initWithFrame:NSZeroRect] autorelease];
headerView = [[OFBHeaderView alloc] initWithFrame:NSZeroRect];
[self addSubview:headerView];
NSCell* cell = [[OFBPathInfoCell new] autorelease];
NSCell* cell = [OFBPathInfoCell new];
cell.lineBreakMode = NSLineBreakByTruncatingMiddle;
[cell setEditable:YES];
NSTableColumn* tableColumn = [[NSTableColumn new] autorelease];
NSTableColumn* tableColumn = [NSTableColumn new];
[tableColumn setDataCell:cell];
[outlineView addTableColumn:tableColumn];
[outlineView setOutlineTableColumn:tableColumn];
@@ -100,9 +90,9 @@ OAK_DEBUG_VAR(FileBrowser_View);
- (void)setPersistentNextResponder:(NSResponder*)aResponder
{
if(aResponder != persistentNextResponder)
if(_persistentNextResponder != aResponder)
{
persistentNextResponder = aResponder;
_persistentNextResponder = aResponder;
[self viewDidMoveToSuperview];
}
}
@@ -160,10 +150,9 @@ static inline NSImage* Pressed (NSString* name) { return Image([NSString stringW
- (void)setCanGoBackward:(BOOL)flag { canGoBackward = flag; [self updateHeaderView]; }
- (void)setCanGoForward:(BOOL)flag { canGoForward = flag; [self updateHeaderView]; }
- (void)setTitleText:(NSString*)text { [titleText autorelease]; titleText = [text retain]; [self updateHeaderView]; }
- (void)setTitleText:(NSString*)text { titleText = text; [self updateHeaderView]; }
- (void)setTitleImage:(NSImage*)image
{
[titleImage release];
titleImage = [[NSImage alloc] initWithSize:NSMakeSize(15, 15)];
[titleImage lockFocus];
[image drawInRect:NSMakeRect(1, 1, 13, 13) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
@@ -171,16 +160,16 @@ static inline NSImage* Pressed (NSString* name) { return Image([NSString stringW
[self updateHeaderView];
}
- (IBAction)clickHeaderCell:(id)sender { [delegate didClickHeaderColumn:sender]; }
- (IBAction)holdHeaderCell:(id)sender { [delegate didTriggerMenuForHeaderColumn:sender]; }
- (IBAction)clickHeaderCell:(id)sender { [_delegate didClickHeaderColumn:sender]; }
- (IBAction)holdHeaderCell:(id)sender { [_delegate didTriggerMenuForHeaderColumn:sender]; }
- (void)swipeWithEvent:(NSEvent*)anEvent
{
if([anEvent deltaX] == +1 && [delegate respondsToSelector:@selector(goBack:)])
[delegate performSelector:@selector(goBack:) withObject:self];
else if([anEvent deltaX] == -1 && [delegate respondsToSelector:@selector(goForward:)])
[delegate performSelector:@selector(goForward:) withObject:self];
else if([anEvent deltaY] == +1 && [delegate respondsToSelector:@selector(goToParentFolder:)])
[delegate performSelector:@selector(goToParentFolder:) withObject:self];
if([anEvent deltaX] == +1 && [_delegate respondsToSelector:@selector(goBack:)])
[_delegate performSelector:@selector(goBack:) withObject:self];
else if([anEvent deltaX] == -1 && [_delegate respondsToSelector:@selector(goForward:)])
[_delegate performSelector:@selector(goForward:) withObject:self];
else if([anEvent deltaY] == +1 && [_delegate respondsToSelector:@selector(goToParentFolder:)])
[_delegate performSelector:@selector(goToParentFolder:) withObject:self];
}
@end

View File

@@ -3,5 +3,3 @@ EXPORT = src/OakFileBrowser.h
CP_Resources = resources/* gfx/**/*
LINK += text cf document editor io regexp settings ns plist OakAppKit OakFoundation scm OakSystem Preferences XcodeEditor
FRAMEWORKS = Cocoa Carbon SystemConfiguration
OBJCXX_FLAGS += -fno-objc-arc