mirror of
https://github.com/textmate/textmate.git
synced 2026-01-20 04:08:04 -05:00
Make bundles in bundle preferences table sortable
This commit is contained in:
committed by
Allan Odgaard
parent
610624ca5a
commit
32a972da03
@@ -50,6 +50,9 @@ static std::string textify (std::string str)
|
||||
if(enabledCategories.empty() || enabledCategories.find(bundle->category()) != enabledCategories.end())
|
||||
bundles.push_back(bundle);
|
||||
}
|
||||
for(NSTableColumn* tableColumn in [bundlesTableView tableColumns])
|
||||
[bundlesTableView setIndicatorImage:nil inTableColumn:tableColumn];
|
||||
[bundlesTableView setIndicatorImage:[NSImage imageNamed:@"NSAscendingSortIndicator"] inTableColumn:[bundlesTableView tableColumnWithIdentifier:@"name"]];
|
||||
[bundlesTableView reloadData];
|
||||
}
|
||||
|
||||
@@ -64,6 +67,11 @@ static std::string textify (std::string str)
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[bundlesTableView setIndicatorImage:[NSImage imageNamed:@"NSAscendingSortIndicator"] inTableColumn:[bundlesTableView tableColumnWithIdentifier:@"name"]];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
@@ -116,6 +124,28 @@ static std::string textify (std::string str)
|
||||
// = NSTableView Delegate =
|
||||
// ========================
|
||||
|
||||
- (void)tableView:(NSTableView*)aTableView didClickTableColumn:(NSTableColumn*)aTableColumn
|
||||
{
|
||||
text::less_t lessThan;
|
||||
|
||||
if([[aTableColumn identifier] isEqualToString:@"name"])
|
||||
std::sort(bundles.begin(), bundles.end(), [&lessThan](bundles_db::bundle_ptr lhs, bundles_db::bundle_ptr rhs){ return lessThan(lhs.get()->name(), rhs.get()->name()); });
|
||||
else if([[aTableColumn identifier] isEqualToString:@"date"])
|
||||
std::sort(bundles.begin(), bundles.end(), [](bundles_db::bundle_ptr lhs, bundles_db::bundle_ptr rhs){ return (rhs.get()->installed() ? rhs.get()->path_updated() : rhs.get()->url_updated()) < (lhs.get()->installed() ? lhs.get()->path_updated() : lhs.get()->url_updated()); });
|
||||
else if([[aTableColumn identifier] isEqualToString:@"description"])
|
||||
std::sort(bundles.begin(), bundles.end(), [&lessThan](bundles_db::bundle_ptr lhs, bundles_db::bundle_ptr rhs){ return lessThan(textify(lhs.get()->description()), textify(rhs.get()->description())); });
|
||||
|
||||
BOOL sortDescending = [aTableView indicatorImageInTableColumn:aTableColumn] == [NSImage imageNamed:@"NSAscendingSortIndicator"];
|
||||
if(sortDescending)
|
||||
std::reverse(bundles.begin(), bundles.end());
|
||||
|
||||
for(NSTableColumn* tableColumn in [aTableView tableColumns])
|
||||
[aTableView setIndicatorImage:nil inTableColumn:tableColumn];
|
||||
[aTableView setIndicatorImage:[NSImage imageNamed:(sortDescending ? @"NSDescendingSortIndicator" : @"NSAscendingSortIndicator")] inTableColumn:aTableColumn];
|
||||
|
||||
[aTableView reloadData];
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(NSTableView*)aTableView shouldEditTableColumn:(NSTableColumn*)aTableColumn row:(NSInteger)rowIndex
|
||||
{
|
||||
if([[aTableColumn identifier] isEqualToString:@"installed"])
|
||||
|
||||
Reference in New Issue
Block a user