summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--macosx/English.lproj/SubtitlesDefaults.xib7
-rw-r--r--macosx/HBLanguagesSelection.h7
-rw-r--r--macosx/HBLanguagesSelection.m140
-rw-r--r--macosx/HBSubtitlesDefaultsController.m26
4 files changed, 174 insertions, 6 deletions
diff --git a/macosx/English.lproj/SubtitlesDefaults.xib b/macosx/English.lproj/SubtitlesDefaults.xib
index b5505887d..11c528809 100644
--- a/macosx/English.lproj/SubtitlesDefaults.xib
+++ b/macosx/English.lproj/SubtitlesDefaults.xib
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="14A299l" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13F7" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment version="1060" defaultVersion="1090" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
@@ -138,6 +138,8 @@
</tableColumns>
<connections>
<binding destination="ZBe-aP-wvq" name="content" keyPath="arrangedObjects" id="ak7-UG-Fqe"/>
+ <outlet property="dataSource" destination="ZBe-aP-wvq" id="bDe-Wj-fNO"/>
+ <outlet property="delegate" destination="ZBe-aP-wvq" id="Tgj-bB-hZ2"/>
</connections>
</tableView>
</subviews>
@@ -155,7 +157,7 @@
<button verticalHuggingPriority="750" id="QAt-5X-NBT">
<rect key="frame" x="161" y="93" width="71" height="23"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <buttonCell key="cell" type="smallSquare" title="Show All" bezelStyle="smallSquare" imagePosition="overlaps" alignment="center" controlSize="small" state="on" borderStyle="border" inset="3" id="PiQ-bA-7P1">
+ <buttonCell key="cell" type="smallSquare" title="Show All" bezelStyle="smallSquare" imagePosition="overlaps" alignment="center" controlSize="small" borderStyle="border" inset="3" id="PiQ-bA-7P1">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="smallSystem"/>
</buttonCell>
@@ -187,6 +189,7 @@ DQ
</declaredKeys>
<connections>
<binding destination="-2" name="contentArray" keyPath="languagesList.languagesArray" id="vKV-y3-Zbg"/>
+ <outlet property="tableView" destination="Of7-71-Ci6" id="QIg-ml-iKO"/>
</connections>
</arrayController>
</objects>
diff --git a/macosx/HBLanguagesSelection.h b/macosx/HBLanguagesSelection.h
index 725fdf9d9..cb017555b 100644
--- a/macosx/HBLanguagesSelection.h
+++ b/macosx/HBLanguagesSelection.h
@@ -47,4 +47,11 @@
*/
@property (nonatomic, readwrite) BOOL showSelectedOnly;
+/**
+ * Set whether the user can drag the table view's elements.
+ */
+@property (nonatomic, readwrite) BOOL isDragginEnabled;
+
+@property (assign) IBOutlet NSTableView *tableView;
+
@end
diff --git a/macosx/HBLanguagesSelection.m b/macosx/HBLanguagesSelection.m
index 0ffe3e52a..c57df8bbe 100644
--- a/macosx/HBLanguagesSelection.m
+++ b/macosx/HBLanguagesSelection.m
@@ -36,8 +36,8 @@
if (self)
{
NSMutableArray *internal = [[NSMutableArray alloc] init];
+ NSMutableArray *selected = [[NSMutableArray alloc] init];
- int insertedItems = 0;
const iso639_lang_t *lang = lang_get_next(NULL);
for (lang = lang_get_next(lang); lang != NULL; lang = lang_get_next(lang))
{
@@ -48,7 +48,7 @@
if ([languages containsObject:item.iso639_2])
{
item.isSelected = YES;
- [internal insertObject:item atIndex:insertedItems++];
+ [selected addObject:item];
}
else
{
@@ -65,6 +65,16 @@
}
[internal insertObject:item atIndex:0];
+ // Insert the selected items
+ // in the original order.
+ [selected sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
+ return [languages indexOfObject:[obj1 iso639_2]] - [languages indexOfObject:[obj2 iso639_2]];
+ }];
+
+ [internal insertObjects:selected
+ atIndexes:[NSIndexSet indexSetWithIndexesInRange:(NSMakeRange(1, selected.count))]];
+ [selected release];
+
_languagesArray = internal;
}
@@ -122,4 +132,130 @@ NSString *kHBLanguagesDragRowsType = @"kHBLanguagesDragRowsType";
return [super arrangeObjects:filteredObjects];
}
+- (void) awakeFromNib
+{
+ [self.tableView registerForDraggedTypes:@[kHBLanguagesDragRowsType]];
+ self.isDragginEnabled = YES;
+}
+
+- (BOOL)tableView:(NSTableView *)tableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
+{
+ if (self.isDragginEnabled)
+ {
+ NSData *data = nil;
+ if (self.showSelectedOnly)
+ {
+ // If the show selected only filter
+ // is enabled, we need to modify the rowIndexes
+ // to match the position of the elements in the unfiltered array
+ NSArray *filteredArray = [[self arrangedObjects] copy];
+ self.showSelectedOnly = NO;
+ NSArray *unfilteredArray = [self arrangedObjects];
+
+ NSMutableIndexSet *unfilteredIndexes = [NSMutableIndexSet indexSet];
+ NSUInteger currentIndex = [rowIndexes firstIndex];
+ while (currentIndex != NSNotFound)
+ {
+ NSUInteger newIndex = [unfilteredArray indexOfObject:[filteredArray objectAtIndex:currentIndex]];
+ [unfilteredIndexes addIndex:newIndex];
+ currentIndex = [rowIndexes indexGreaterThanIndex:currentIndex];
+ }
+
+ data = [NSKeyedArchiver archivedDataWithRootObject:unfilteredIndexes];
+ [filteredArray release];
+ }
+ else
+ {
+ data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
+ }
+
+ [pboard declareTypes:[NSArray arrayWithObject:kHBLanguagesDragRowsType] owner:self];
+ [pboard setData:data forType:kHBLanguagesDragRowsType];
+ }
+
+ return self.isDragginEnabled;
+}
+
+- (NSDragOperation)tableView:(NSTableView *)view
+ validateDrop:(id <NSDraggingInfo>)info
+ proposedRow:(NSInteger)row
+ proposedDropOperation:(NSTableViewDropOperation)operation
+{
+ NSDragOperation dragOp = NSDragOperationNone;
+
+ // if drag source is our own table view, it's a move or a copy
+ if ([info draggingSource] == view)
+ {
+ // At a minimum, allow move
+ dragOp = NSDragOperationMove;
+ }
+
+ [view setDropRow:row dropOperation:NSTableViewDropAbove];
+
+ return dragOp;
+}
+
+- (BOOL)tableView:(NSTableView *)view acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
+{
+ if (([info draggingSourceOperationMask] == NSDragOperationCopy))
+ {
+ return nil;
+ }
+
+ if ([info draggingSource] == view)
+ {
+ // Get the index set from the pasteBoard.
+ NSData *rowData = [[info draggingPasteboard] dataForType:kHBLanguagesDragRowsType];
+ NSIndexSet *indexSet = [NSKeyedUnarchiver unarchiveObjectWithData:rowData];
+
+ NSUInteger i = [indexSet countOfIndexesInRange:NSMakeRange(0, row)];
+
+ // Rearrage the objects.
+ [self moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:row];
+
+ // Update the selection.
+ row -= i;
+ NSIndexSet *selectionSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(row, [indexSet count])];
+ [view selectRowIndexes:selectionSet byExtendingSelection:NO];
+
+ return YES;
+ }
+
+ return NO;
+}
+
+- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
+{
+ NSArray *objects = [self arrangedObjects];
+
+ NSInteger aboveInsertIndexCount = 0;
+ NSInteger removeIndex;
+
+ NSUInteger thisIndex = [indexSet lastIndex];
+ while (thisIndex != NSNotFound)
+ {
+ if (thisIndex >= insertIndex)
+ {
+ removeIndex = thisIndex + aboveInsertIndexCount;
+ aboveInsertIndexCount += 1;
+ }
+ else
+ {
+ removeIndex = thisIndex;
+ insertIndex -= 1;
+ }
+
+ // Get the object we're moving
+ id object = objects[removeIndex];
+
+ // Move the object
+ [object retain];
+ [self removeObjectAtArrangedObjectIndex:removeIndex];
+ [self insertObject:object atArrangedObjectIndex:insertIndex];
+ [object release];
+
+ thisIndex = [indexSet indexLessThanIndex:thisIndex];
+ }
+}
+
@end
diff --git a/macosx/HBSubtitlesDefaultsController.m b/macosx/HBSubtitlesDefaultsController.m
index f529798d4..ead542080 100644
--- a/macosx/HBSubtitlesDefaultsController.m
+++ b/macosx/HBSubtitlesDefaultsController.m
@@ -8,6 +8,8 @@
#import "HBSubtitlesSettings.h"
#import "HBLanguagesSelection.h"
+static void *HBSubtitlesDefaultsContex = &HBSubtitlesDefaultsContex;
+
@interface HBSubtitlesDefaultsController ()
@property (nonatomic, readonly) HBSubtitlesSettings *settings;
@@ -33,10 +35,25 @@
- (void)windowDidLoad
{
+ [self addObserver:self forKeyPath:@"tableController.showSelectedOnly" options:0 context:HBSubtitlesDefaultsContex];
+
if (self.settings.trackSelectionLanguages.count)
{
self.tableController.showSelectedOnly = YES;
- [self.showAllButton setState:NSOffState];
+ }
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ if (context == HBSubtitlesDefaultsContex) {
+ if ([keyPath isEqualToString:@"tableController.showSelectedOnly"])
+ {
+ [self.showAllButton setState:!self.tableController.showSelectedOnly];
+ }
+ }
+ else
+ {
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
@@ -61,8 +78,13 @@
- (void)dealloc
{
- [super dealloc];
[_settings release];
+
+ @try {
+ [self removeObserver:self forKeyPath:@"tableController.showSelectedOnly"];
+ } @catch (NSException * __unused exception) {}
+
+ [super dealloc];
}
@end