Skip to content

Commit

Permalink
Merge pull request MediaArea#511 from g-maxime/compare-fix
Browse files Browse the repository at this point in the history
Cocoa GUI: Fix columns reordering in compare view
  • Loading branch information
JeromeMartinez authored Dec 18, 2020
2 parents 9f3b187 + 449cda5 commit ee0a77f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
39 changes: 30 additions & 9 deletions Source/GUI/Cocoa/CompareView.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#import "CompareView.h"

#import "IndexedTableColumn.h"

@implementation CompareView
- (IBAction)changeViewMode:(NSButton *)sender {
if(sender)
Expand Down Expand Up @@ -164,7 +166,7 @@ -(void) createFields {
}

for(NSUInteger fileIndex=0; fileIndex<[_files count]; fileIndex++) {
NSTableColumn *column = [[[NSTableColumn alloc] init] autorelease];
IndexedTableColumn *column = [[[IndexedTableColumn alloc] init] autorelease];

NSString* fileName=[_files GetAtIndex:fileIndex streamKind:0 streamNumber:0 parameter:@"FileName"];
NSString *fileExtension=[_files GetAtIndex:fileIndex streamKind:0 streamNumber:0 parameter:@"FileExtension"];
Expand All @@ -173,6 +175,7 @@ -(void) createFields {
fileName=[NSString stringWithFormat:@"%@.%@", fileName, fileExtension];
}

[column setIndex: fileIndex];
[[column headerCell] setTitle:fileName];
[_outlineView addTableColumn:column];
}
Expand Down Expand Up @@ -259,16 +262,17 @@ -(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTable
if (!item)
return @"";

NSInteger column = [[outlineView tableColumns] indexOfObject:tableColumn];

if(column == 0)
if([[outlineView tableColumns] indexOfObject:tableColumn] == 0)
return item[@"name"];

column--;
if(column >= [item[@"entries"] count])
if (![tableColumn isKindOfClass:[IndexedTableColumn class]])
return @"";

return item[@"entries"][column];
NSInteger index = [(IndexedTableColumn *)tableColumn index];
if(index >= [item[@"entries"] count])
return @"";

return item[@"entries"][index];
}

-(void)outlineView:(NSOutlineView *)outlineView sortDescriptorsDidChange:(NSArray<NSSortDescriptor *> *)oldDescriptors {
Expand Down Expand Up @@ -296,7 +300,15 @@ -(BOOL)outlineView:(NSOutlineView *)outlineView shouldReorderColumn:(NSInteger)c
}

-(void)outlineViewSelectionDidChange:(NSNotification *)notification {
_selectedIndex = [_outlineView selectedColumn];
NSUInteger index = [_outlineView clickedColumn];
if (index >= [[_outlineView tableColumns] count])
return;

NSTableColumn *column = [[_outlineView tableColumns] objectAtIndex:index];
if (![column isKindOfClass: [IndexedTableColumn class]])
return;

_selectedIndex = [(IndexedTableColumn*)column index];
}

-(void)menuWillOpen:(NSMenu *)menu {
Expand All @@ -316,7 +328,16 @@ -(IBAction)closeFileInColumn:(id)sender {

id mainWindowController = [[[NSApplication sharedApplication] mainWindow] windowController];

_selectedIndex = [_outlineView clickedColumn];
NSUInteger index = [_outlineView clickedColumn];
if (index >= [[_outlineView tableColumns] count])
return;

NSTableColumn *column = [[_outlineView tableColumns] objectAtIndex:index];
if (![column isKindOfClass: [IndexedTableColumn class]])
return;

_selectedIndex = [(IndexedTableColumn*)column index];

[mainWindowController performSelector:@selector(closeFile:)];
[self reload];
}
Expand Down
15 changes: 15 additions & 0 deletions Source/GUI/Cocoa/IndexedTableColumn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/

#import <Cocoa/Cocoa.h>

NS_ASSUME_NONNULL_BEGIN

@interface IndexedTableColumn : NSTableColumn
@property (readwrite) NSUInteger index;
@end

NS_ASSUME_NONNULL_END
10 changes: 10 additions & 0 deletions Source/GUI/Cocoa/IndexedTableColumn.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/

#import "IndexedTableColumn.h"

@implementation IndexedTableColumn
@end
6 changes: 6 additions & 0 deletions Source/GUI/Cocoa/MediaInfo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
9C182E0B257D1337007646AC /* IndexedTableColumn.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C182E0A257D1337007646AC /* IndexedTableColumn.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -360,6 +361,8 @@
43EC2995153F108700943F0A /* tr */ = {isa = PBXFileReference; lastKnownFileType = text; name = tr; path = tr.lproj/lang.csv; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* MediaInfo-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "MediaInfo-Info.plist"; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* MediaInfo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MediaInfo.app; sourceTree = BUILT_PRODUCTS_DIR; };
9C182E09257D1337007646AC /* IndexedTableColumn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IndexedTableColumn.h; sourceTree = "<group>"; };
9C182E0A257D1337007646AC /* IndexedTableColumn.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IndexedTableColumn.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -420,6 +423,8 @@
0299EC7D2291FD5F00D937F6 /* SubscribeWindowController.m */,
0299EC8522949EE200D937F6 /* SubscriptionManager.m */,
0268340422949FB50060542A /* SubscriptionManager.h */,
9C182E09257D1337007646AC /* IndexedTableColumn.h */,
9C182E0A257D1337007646AC /* IndexedTableColumn.m */,
);
name = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -672,6 +677,7 @@
436C50A615B9E06D000AF072 /* TreeOutlineDelegate.m in Sources */,
43E0EFB415DC12AC001E8F7C /* easyStreamsTableDelegate.m in Sources */,
43B17B9D1CE672110012C3E3 /* SegmentedControlWithMenu.m in Sources */,
9C182E0B257D1337007646AC /* IndexedTableColumn.m in Sources */,
43E0EFBA15DD64B3001E8F7C /* HyperlinkButton.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 2 additions & 2 deletions Source/GUI/Cocoa/MyWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,8 @@ -(IBAction)closeFile:(id)sender {
if(mediaList && [mediaList count]) {

if ([tabs indexOfTabViewItem:tabs.selectedTabViewItem] == kCompareTabIndex) {
if(compareView.selectedIndex > 0 && (compareView.selectedIndex - 1) < [mediaList count])
[self closeFileAtIndex:(compareView.selectedIndex - 1)];
if(compareView.selectedIndex >= 0 && (compareView.selectedIndex) < [mediaList count])
[self closeFileAtIndex:(compareView.selectedIndex)];

return;
}
Expand Down

0 comments on commit ee0a77f

Please sign in to comment.