diff --git a/Frameworks/OakFileBrowser/src/io/FSSCMDataSource.mm b/Frameworks/OakFileBrowser/src/io/FSSCMDataSource.mm index 30255898..fbc8df00 100644 --- a/Frameworks/OakFileBrowser/src/io/FSSCMDataSource.mm +++ b/Frameworks/OakFileBrowser/src/io/FSSCMDataSource.mm @@ -78,7 +78,13 @@ _Iter prune_path_children (_Iter it, _Iter last) std::string root = scm::root_for_path([aPath fileSystemRepresentation]); if(root != NULL_STR) return [NSURL URLWithString:[NSString stringWithCxxString:"scm://localhost" + encode::url_part(root, "/") + "/"]]; - return [NSURL fileURLWithPath:aPath]; + return [NSURL URLWithString:[@"scm://locahost" stringByAppendingString:[aPath stringByAppendingString:@"?status=unversioned"]]]; +} + ++ (NSString*)parseSCMURLStatusQuery:(NSURL*)anURL +{ + NSArray* query = [[anURL query] componentsSeparatedByString:@"="]; + return [query lastObject] ?: @"all"; } - (NSArray*)repositoryStatus @@ -104,13 +110,13 @@ _Iter prune_path_children (_Iter it, _Iter last) std::sort(unstagedPaths.begin(), unstagedPaths.end(), text::less_t()); std::sort(untrackedPaths.begin(), untrackedPaths.end(), text::less_t()); - FSItem* unstagedItem = [FSItem itemWithURL:URLAppend(self.rootItem.url, @".unstaged/")]; + FSItem* unstagedItem = [FSItem itemWithURL:URLAppend(self.rootItem.url, @"?status=unstaged")]; unstagedItem.icon = SCMFolderIcon(); unstagedItem.name = @"Uncommitted Changes"; unstagedItem.group = YES; unstagedItem.children = convert(unstagedPaths, scmInfo->root_path(), options); - FSItem* untrackedItem = [FSItem itemWithURL:URLAppend(self.rootItem.url, @".untracked/")]; + FSItem* untrackedItem = [FSItem itemWithURL:URLAppend(self.rootItem.url, @"?status=untracked")]; untrackedItem.icon = SCMFolderIcon(); untrackedItem.name = @"Untracked Items"; untrackedItem.group = YES; @@ -134,9 +140,21 @@ _Iter prune_path_children (_Iter it, _Iter last) options = someOptions; std::string const rootPath = [[anURL path] fileSystemRepresentation]; + std::string name = path::display_name(rootPath); + + NSString* status = [FSSCMDataSource parseSCMURLStatusQuery:anURL]; + if([status isEqualToString:@"unversioned"]) + { + self.rootItem = [FSItem itemWithURL:nil]; + self.rootItem.icon = [NSImage imageNamed:NSImageNameFolderSmart]; + self.rootItem.name = [NSString stringWithCxxString:text::format("%s (%s)", name.c_str(), "Unversioned")]; + self.rootItem.children = nil; + + return self; + } + if(scmInfo = scm::info(rootPath)) { - std::string name = path::display_name(rootPath); if(!scmInfo->dry()) { auto const& vars = scmInfo->scm_variables(); @@ -145,10 +163,27 @@ _Iter prune_path_children (_Iter it, _Iter last) name = text::format("%s (%s)", path::display_name(scmInfo->root_path()).c_str(), branch->second.c_str()); } - self.rootItem = [FSItem itemWithURL:anURL]; - self.rootItem.icon = [NSImage imageNamed:NSImageNameFolderSmart]; - self.rootItem.name = [NSString stringWithCxxString:name]; - self.rootItem.children = [self repositoryStatus]; + if([status isEqualToString:@"all"]) + { + self.rootItem = [FSItem itemWithURL:anURL]; + self.rootItem.icon = [NSImage imageNamed:NSImageNameFolderSmart]; + self.rootItem.name = [NSString stringWithCxxString:name]; + self.rootItem.children = [self repositoryStatus]; + } + else + { + name = path::display_name(rootPath); + for(FSItem* item in [self repositoryStatus]) + { + if([[FSSCMDataSource parseSCMURLStatusQuery:item.url] isEqualToString:status]) + { + self.rootItem = [FSItem itemWithURL:anURL]; + self.rootItem.icon = [NSImage imageNamed:NSImageNameFolderSmart]; + self.rootItem.name = [NSString stringWithFormat:@"%@ (%@)", [NSString stringWithCxxString:name], item.name]; + self.rootItem.children = item.children; + } + } + } __weak FSSCMDataSource* weakSelf = self; scmInfo->add_callback(^(scm::info_t const&){ @@ -161,6 +196,6 @@ _Iter prune_path_children (_Iter it, _Iter last) - (NSArray*)expandedURLs { - return @[ URLAppend(self.rootItem.url, @".unstaged/"), URLAppend(self.rootItem.url, @".untracked/") ]; + return @[ URLAppend(self.rootItem.url, @"?status=unstaged"), URLAppend(self.rootItem.url, @"?status=untracked") ]; } @end