Skip to content

Commit

Permalink
Merge pull request tinymind#17 from xxblsx/master
Browse files Browse the repository at this point in the history
资源排列&资源大小总计
  • Loading branch information
tinymind authored Dec 27, 2016
2 parents 620b539 + e191f6d commit 039c016
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion LSUnusedResources/ViewController/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
static NSString * const kTableColumnImageShortName = @"ImageShortName";
static NSString * const kTableColumnFileSize = @"FileSize";

@interface MainViewController () <NSTableViewDelegate, NSTableViewDataSource>
@interface MainViewController () <NSTableViewDelegate, NSTableViewDataSource>{
BOOL _fileSizeDesc;//文件大小按降序排列
}

// Project
@property (weak) IBOutlet NSButton *browseButton;
Expand Down Expand Up @@ -196,11 +198,27 @@ - (IBAction)onDeleteButtonClicked:(id)sender {
- (void)onResourceFileQueryDone:(NSNotification *)notification {
self.isFileDone = YES;
[self searchUnusedResourcesIfNeeded];
//统计总数
if(self.unusedResults.count > 0){
uint64_t countSize = 0;
for(ResourceFileInfo *info in self.unusedResults){
countSize += info.fileSize;
}
self.statusLabel.stringValue = [self.statusLabel.stringValue stringByAppendingString:[NSString stringWithFormat:@",total size is:%.2f(KB)", countSize / 1024.0]];
}
}

- (void)onResourceStringQueryDone:(NSNotification *)notification {
self.isStringDone = YES;
[self searchUnusedResourcesIfNeeded];
//统计总数
if(self.unusedResults.count > 0){
uint64_t countSize = 0;
for(ResourceFileInfo *info in self.unusedResults){
countSize += info.fileSize;
}
self.statusLabel.stringValue = [self.statusLabel.stringValue stringByAppendingString:[NSString stringWithFormat:@",total size is:%.2f(KB)", countSize / 1024.0]];
}
}

#pragma mark - <NSTableViewDelegate>
Expand Down Expand Up @@ -232,6 +250,33 @@ - (void)tableViewDoubleClicked {
[[NSWorkspace sharedWorkspace] selectFile:info.path inFileViewerRootedAtPath:@""];
}

- (void)tableView:(NSTableView *)tableView mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn{
if([tableColumn.identifier isEqualToString:@"FileSize"]){
//点击FileSize头部
_fileSizeDesc = !_fileSizeDesc;
if(_fileSizeDesc){
//降序
NSArray *array = [self.unusedResults sortedArrayUsingComparator:^NSComparisonResult(ResourceFileInfo *obj1, ResourceFileInfo *obj2) {
return obj1.fileSize < obj2.fileSize;
}];
self.unusedResults = [array mutableCopy];
[self.resultsTableView reloadData];
}else{
NSArray *array = [self.unusedResults sortedArrayUsingComparator:^NSComparisonResult(ResourceFileInfo *obj1, ResourceFileInfo *obj2) {
return obj1.fileSize > obj2.fileSize;
}];
self.unusedResults = [array mutableCopy];
[self.resultsTableView reloadData];
}
}else if([tableColumn.identifier isEqualToString:@"ImageShortName"]){
NSArray *array = [self.unusedResults sortedArrayUsingComparator:^NSComparisonResult(ResourceFileInfo *obj1, ResourceFileInfo *obj2) {
return [obj1.name compare:obj2.name];
}];
self.unusedResults = [array mutableCopy];
[self.resultsTableView reloadData];
}
}

#pragma mark - Private

- (void)showAlertWithStyle:(NSAlertStyle)style title:(NSString *)title subtitle:(NSString *)subtitle {
Expand Down

0 comments on commit 039c016

Please sign in to comment.