Skip to content

Commit

Permalink
Merge pull request #791 from g-maxime/mas-bigfile
Browse files Browse the repository at this point in the history
Fix Cocoa GUI
  • Loading branch information
JeromeMartinez authored Jan 19, 2024
2 parents 27bfe06 + 6f9d0f4 commit 0bce20e
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Source/GUI/Cocoa/CompareView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef enum CompareViewMode {
@property (strong) IBOutlet NSOutlineView *outlineView;
@property (assign) IBOutlet NSMenu *closeMenu;
@property (nonatomic, strong) oMediaInfoList *files;
@property (strong) NSArray *fields;
@property (strong) NSMutableDictionary *fields;
@property (readonly) CompareViewMode mode;
@property (readonly) NSInteger selectedIndex;
@property (assign) IBOutlet NSTextField *showLabel;
Expand Down
152 changes: 79 additions & 73 deletions Source/GUI/Cocoa/CompareView.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ -(void)setFiles:(oMediaInfoList *)files {
_files = nil;
}
_files = [files retain];
[self createFields];
}

-(void) createFields {
Expand All @@ -112,20 +111,19 @@ -(void) createFields {
return;
}

NSMutableArray* fields = [[[NSMutableArray alloc] init] autorelease];
_fields = [[NSMutableDictionary alloc] init];

for(NSUInteger streamKind=MediaInfo_Stream_General; streamKind<MediaInfo_Stream_Max; streamKind++) {
NSMutableSet* toAdd = [[[NSMutableSet alloc] init] autorelease];
for(NSUInteger fileIndex=0; fileIndex<[_files count]; fileIndex++) {
NSUInteger streamCount=[_files numberOFStreamsAtIndex:fileIndex ofStreamKind:streamKind];
NSUInteger streamCount=[_files numberOFStreamsAtIndex:fileIndex ofStreamKind:(oMediaInfoStream)streamKind];
for(NSUInteger streamNumber=0; streamNumber<streamCount; streamNumber++) {
NSUInteger fieldCount=[_files FieldCountAtIndex:fileIndex streamKind:streamKind streamNumber:streamNumber];
NSUInteger fieldCount=[_files FieldCountAtIndex:fileIndex streamKind:(oMediaInfoStream)streamKind streamNumber:streamNumber];
for(NSUInteger fieldNumber=0; fieldNumber<fieldCount; fieldNumber++) {
NSString *field = [_files FieldAtIndex:fileIndex streamKind:streamKind streamNumber:streamNumber parameter:fieldNumber];
NSString *name = [_files FieldNameAtIndex:fileIndex streamKind:streamKind streamNumber:streamNumber parameter:fieldNumber];
if ((![_files ShowComplete] && ![_files ShowInInform:fileIndex streamKind:streamKind streamNumber:streamNumber parameter:fieldNumber]) || [[_files GetAtIndex:fileIndex streamKind:streamKind streamNumber:streamNumber parameter:field] isEqual:@""] || [field isEqual:@"CompleteName"])
NSString *field = [_files FieldAtIndex:fileIndex streamKind:(oMediaInfoStream)streamKind streamNumber:streamNumber parameter:fieldNumber];
NSString *name = [_files FieldNameAtIndex:fileIndex streamKind:(oMediaInfoStream)streamKind streamNumber:streamNumber parameter:fieldNumber];
if ((![_files ShowComplete] && ![_files ShowInInform:fileIndex streamKind:(oMediaInfoStream)streamKind streamNumber:streamNumber parameter:fieldNumber]) || [[_files GetAtIndex:fileIndex streamKind:(oMediaInfoStream)streamKind streamNumber:streamNumber parameter:field] isEqual:@""] || [field isEqual:@"CompleteName"])
continue;


NSString* section=nil;
if(streamKind==MediaInfo_Stream_General) section=@"General";
else if(streamKind==MediaInfo_Stream_Video) section=@"Video";
Expand All @@ -139,37 +137,40 @@ -(void) createFields {
section=[NSString stringWithFormat:@"%@ #%lu", section, streamNumber+1];

NSMutableDictionary *dic1 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:section, @"field", section, @"name", [[NSNumber alloc] initWithUnsignedInteger:streamKind], @"kind", [[NSNumber alloc] initWithUnsignedInteger:streamNumber], @"number", [[NSNumber alloc] initWithUnsignedInt:0], @"order", [[NSMutableArray alloc] initWithCapacity:0], @"entries", [[NSNumber alloc] initWithBool:NO], @"equal", nil];
[toAdd addObject:dic1];

NSMutableDictionary *dic2 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:field, @"field", name, @"name", [[NSNumber alloc] initWithUnsignedInteger:streamKind], @"kind", [[NSNumber alloc] initWithUnsignedInteger:streamNumber], @"number", [[NSNumber alloc] initWithUnsignedInteger:fieldNumber], @"order", [[NSMutableArray alloc] initWithCapacity:[_files count]], @"entries",[[NSNumber alloc] initWithBool:NO], @"equal", nil];
[toAdd addObject:dic2];

if ([_fields objectForKey:dic1] == nil)
[_fields setObject:[[[NSMutableArray alloc] init] autorelease] forKey:dic1];

if (![[_fields objectForKey:dic1] containsObject: dic2])
[[_fields objectForKey:dic1] addObject: dic2];

}
}
}
if([toAdd count])
[fields addObjectsFromArray:[toAdd allObjects]];
}

NSSortDescriptor *firstDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"kind" ascending:YES] autorelease];
NSSortDescriptor *secondDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"number" ascending:YES] autorelease];
NSSortDescriptor *thirdDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"order" ascending:YES] autorelease];

NSArray *sortDescriptors = [NSArray arrayWithObjects:firstDescriptor, secondDescriptor, thirdDescriptor, nil];

NSArray* sorted = [fields sortedArrayUsingDescriptors:sortDescriptors];
NSArray* descriptors = _outlineView.sortDescriptors;
if(![descriptors count]) {
NSSortDescriptor *firstDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"kind" ascending:YES] autorelease];
NSSortDescriptor *secondDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"number" ascending:YES] autorelease];
NSSortDescriptor *thirdDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"order" ascending:YES] autorelease];
descriptors = [NSArray arrayWithObjects:firstDescriptor, secondDescriptor, thirdDescriptor, nil];
}

for(NSUInteger pos=0; pos<[sorted count]; pos++) {
NSMutableDictionary *field=sorted[pos];
if([field[@"order"] unsignedIntegerValue] == 0)
continue;
for (id key in _fields) {
[[_fields objectForKey:key] sortUsingDescriptors:descriptors];

for(NSUInteger fileIndex=0; fileIndex<[_files count]; fileIndex++) {
NSString *value = [_files GetAtIndex:fileIndex streamKind:[(NSNumber*)field[@"kind"] unsignedIntegerValue] streamNumber:[(NSNumber*)field[@"number"] unsignedIntegerValue] parameter:field[@"field"]];
[field[@"entries"] addObject:value];
}
for(id field in [_fields objectForKey:key]) {
for(NSUInteger fileIndex=0; fileIndex<[_files count]; fileIndex++) {
NSString *value = [_files GetAtIndex:fileIndex streamKind:[(NSNumber*)field[@"kind"] unsignedIntegerValue] streamNumber:[(NSNumber*)field[@"number"] unsignedIntegerValue] parameter:field[@"field"]];
[field[@"entries"] addObject:value];
}

if([[[[NSSet alloc] initWithArray:field[@"entries"]] autorelease] count]<2) {
field[@"equal"]=[[NSNumber alloc] initWithBool:YES];
if([[[[NSSet alloc] initWithArray:field[@"entries"]] autorelease] count]<2) {
field[@"equal"]=[[NSNumber alloc] initWithBool:YES];
}
}
}

Expand All @@ -188,12 +189,6 @@ -(void) createFields {
[_outlineView addTableColumn:column];
}

NSArray* descriptors = _outlineView.sortDescriptors;
if([descriptors count])
_fields = [[sorted sortedArrayUsingDescriptors:descriptors] copy];
else
_fields = [sorted copy];

[_outlineView reloadData];
[_outlineView sizeToFit];
[_outlineView expandItem:nil expandChildren:YES];
Expand All @@ -214,29 +209,38 @@ -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(nonnull id)cell
}

-(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
NSPredicate *predicate = nil;
NSInteger count = -1;

if(item) {
NSMutableString *filter = [[[NSMutableString alloc] init] autorelease];
NSMutableArray *arguments = [[[NSMutableArray alloc] init] autorelease];
[filter appendString:@"kind == %@ AND number == %@ AND order != 0"];
[arguments addObject:item[@"kind"]];
[arguments addObject:item[@"number"]];
if(_mode == CompareViewModeEquals)
[filter appendString:@" AND equal == YES"];
else if (_mode == CompareViewModeDiffers)
[filter appendString:@" AND equal == NO"];

predicate = [NSPredicate predicateWithFormat:filter argumentArray:arguments];
for (id key in _fields) {
if ([key[@"kind"] isEqualTo: item[@"kind"]] && [key[@"number"] isEqualTo: item[@"number"]]) {
for (id field in _fields[key]) {
if (_mode == CompareViewModeEquals) {
if ([field[@"equal"] isEqualTo: @YES]) {
if (++count == index)
return field;
}
}
else if (_mode == CompareViewModeDiffers) {
if ([field[@"equal"] isEqualTo: @NO]) {
if (++count == index)
return field;
}
}
else {
if (++count == index)
return field;
}
}
}
}
}
else {
predicate = [NSPredicate predicateWithFormat:@"order == 0"];
if (index < [_fields count])
return [[_fields allKeys] objectAtIndex: index];
}

NSArray *result = [_fields filteredArrayUsingPredicate:predicate];
if(index >= [result count])
return nil;

return result[index];
return nil;
}

-(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
Expand All @@ -247,25 +251,29 @@ -(NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)
if(!_fields)
return 0;

NSPredicate *predicate = nil;
NSInteger count = 0;

if(item) {
NSMutableString *filter = [[[NSMutableString alloc] init] autorelease];
NSMutableArray *arguments = [[[NSMutableArray alloc] init] autorelease];
[filter appendString:@"kind == %@ AND number == %@ AND order != 0"];
[arguments addObject:item[@"kind"]];
[arguments addObject:item[@"number"]];
if(_mode == CompareViewModeEquals)
[filter appendString:@" AND equal == YES"];
else if (_mode == CompareViewModeDiffers)
[filter appendString:@" AND equal == NO"];

predicate = [NSPredicate predicateWithFormat:filter argumentArray:arguments];
for (id field in [_fields objectForKey: item]) {
if ([field[@"kind"] isEqualTo: item[@"kind"]] && [field[@"number"] isEqualTo: item[@"number"]] && [field[@"order"] isNotEqualTo: @0]) {
if (_mode == CompareViewModeEquals) {
if ([field[@"equal"] isEqualTo: @YES])
count++;
}
else if (_mode == CompareViewModeDiffers) {
if ([field[@"equal"] isEqualTo: @NO])
count++;
}
else
count++;
}
}
}
else {
predicate = [NSPredicate predicateWithFormat:@"order == 0"];
count = [_fields count];
}

return [[_fields filteredArrayUsingPredicate:predicate] count];
return count;
}

-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
Expand All @@ -289,12 +297,10 @@ -(void)outlineView:(NSOutlineView *)outlineView sortDescriptorsDidChange:(NSArra
if(!_fields)
return;

NSArray *fields = [_fields copy];
[_fields release];
_fields = nil;
for (id key in _fields) {
[[_fields objectForKey:key] sortUsingDescriptors:outlineView.sortDescriptors];
}

NSArray* descriptors =outlineView.sortDescriptors;
_fields = [[fields sortedArrayUsingDescriptors:descriptors] copy];
[outlineView reloadData];
}

Expand Down
47 changes: 39 additions & 8 deletions Source/GUI/Cocoa/MyWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,37 @@ -(IBAction)selectCompareTab:(id)sender {
if (@available(macOS 10.9, *)) {
[self hideFileSelector];
[tabSelector setSelectedSegment:kCompareTabIndex];

if(mediaList) {
[compareView setFiles:mediaList];
[compareView reload];
}

[tabs selectTabViewItemAtIndex:kCompareTabIndex];
}
}

-(IBAction)selectEasyTab:(id)sender {
[self showFileSelector];
[tabSelector setSelectedSegment:kEasyTabIndex];

if(mediaList && selectedFileIndex < [mediaList count])
[self updateEasyTabWithFileAtIndex:selectedFileIndex];

[tabs selectTabViewItemAtIndex:kEasyTabIndex];
}

-(IBAction)selectTreeTab:(id)sender {
[self showFileSelector];
[tabSelector setSelectedSegment:kTreeTabIndex];

if(mediaList) {
[treeView setFiles:mediaList];

if(selectedFileIndex < [mediaList count])
[treeView setIndex:selectedFileIndex];
}

[tabs selectTabViewItemAtIndex:kTreeTabIndex];
}

Expand All @@ -267,6 +285,10 @@ -(IBAction)selectTextTab:(id)sender {
[self updateTextTabWithFileAtIndex:selectedFileIndex];
}
[tabSelector setSelectedSegment:kTextTabIndex];

if(mediaList && selectedFileIndex < [mediaList count])
[self updateTextTabWithFileAtIndex:selectedFileIndex];

[tabs selectTabViewItemAtIndex:kTextTabIndex];
}

Expand Down Expand Up @@ -691,8 +713,12 @@ -(void)processFiles:(NSArray *)URLs {
}

[comboController setContent:array];
[compareView setFiles:mediaList];
[treeView setFiles:mediaList];

if ([tabs indexOfTabViewItem:tabs.selectedTabViewItem] == kCompareTabIndex)
[compareView setFiles:mediaList];

if ([tabs indexOfTabViewItem:tabs.selectedTabViewItem] == kTreeTabIndex)
[treeView setFiles:mediaList];

//display first added file
[self setSelectedFileIndex:oldCount];
Expand All @@ -703,19 +729,24 @@ -(void)processFiles:(NSArray *)URLs {

-(void)showFileAtIndex:(NSUInteger)index {
// Easy view
[self updateEasyTabWithFileAtIndex:index];
if ([tabs indexOfTabViewItem:tabs.selectedTabViewItem] == kEasyTabIndex)
[self updateEasyTabWithFileAtIndex:index];

//Text View
[self updateTextTabWithFileAtIndex:index];
if ([tabs indexOfTabViewItem:tabs.selectedTabViewItem] == kTextTabIndex)
[self updateTextTabWithFileAtIndex:index];

//HTML View
[self updateHTMLTabWithFileAtIndex:index];
//HTML View
if ([tabs indexOfTabViewItem:tabs.selectedTabViewItem] == kHTMLTabIndex)
[self updateHTMLTabWithFileAtIndex:index];

//tree view
[treeView setIndex:index];
if ([tabs indexOfTabViewItem:tabs.selectedTabViewItem] == kTreeTabIndex)
[treeView setIndex:index];

// compare view
[compareView reload];
if ([tabs indexOfTabViewItem:tabs.selectedTabViewItem] == kCompareTabIndex)
[compareView reload];

//recent items
NSString *filename = [mediaList filenameAtIndex:index];
Expand Down

0 comments on commit 0bce20e

Please sign in to comment.