OSDN Git Service

画面上での操作をタッチバーに反映するようにした
authormasakih <masakih@users.sourceforge.jp>
Tue, 6 Dec 2016 14:08:01 +0000 (23:08 +0900)
committermasakih <masakih@users.sourceforge.jp>
Tue, 6 Dec 2016 14:08:01 +0000 (23:08 +0900)
KCD/Base.lproj/HMBroserWindowController.xib
KCD/BroswerTouchBar.xib
KCD/HMBroserWindowController.m
KCD/HMScreenshotListViewController.m

index 64c6592..5245f96 100644 (file)
@@ -81,6 +81,9 @@
                                 </view>
                             </tabViewItem>
                         </tabViewItems>
+                        <connections>
+                            <binding destination="-2" name="selectedIndex" keyPath="selectedMainTabIndex" id="bvs-iv-JKe"/>
+                        </connections>
                     </tabView>
                     <customView id="0dQ-uF-j2x">
                         <rect key="frame" x="809" y="9" width="352" height="103"/>
index fc743ce..803810d 100644 (file)
@@ -33,6 +33,7 @@
                             </segmentedCell>
                             <connections>
                                 <action selector="changeMainTab:" target="-2" id="Rk4-So-gqY"/>
+                                <binding destination="-2" name="selectedIndex" keyPath="selectedMainTabIndex" id="b2F-bE-3gb"/>
                             </connections>
                         </segmentedControl>
                     </viewController>
index 8f5e897..cb98d94 100644 (file)
@@ -76,6 +76,7 @@ typedef NS_ENUM(NSUInteger, FleetViewPosition) {
 
 @property (nonatomic, strong) IBOutlet NSTouchBar *mainTouchBar;
 
+@property (nonatomic) NSInteger selectedMainTabIndex;
 
 @end
 
index d3fd008..3b52b41 100644 (file)
     NSNib *nib = [[NSNib alloc] initWithNibNamed:@"HMScreenshotCollectionViewItem" bundle:nil];
     [self.collectionView registerClass:[NSCollectionViewItem class] forItemWithIdentifier:@"item"];
     [self.collectionView registerNib:nib forItemWithIdentifier:@"item"];
-
-       NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO];
-       self.screenshots.sortDescriptors = @[sortDescriptor];
-
+    
+    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO];
+    self.screenshots.sortDescriptors = @[sortDescriptor];
+    
     [self.collectionView addObserver:self
                           forKeyPath:@"selectionIndexPaths"
                              options:0
                              context:nil];
     self.collectionView.postsFrameChangedNotifications = YES;
-    [[NSNotificationCenter defaultCenter] addObserver:self
-                                             selector:@selector(viewFrameDidChange:)
-                                                 name:NSViewFrameDidChangeNotification
-                                               object:self.collectionView];
+    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
+    [nc addObserver:self
+           selector:@selector(viewFrameDidChange:)
+               name:NSViewFrameDidChangeNotification
+             object:self.collectionView];
     [self viewFrameDidChange:nil];
+    
+    [nc addObserver:self
+           selector:@selector(scrollViewDidLiveScrollNotification:)
+               name:NSScrollViewDidLiveScrollNotification
+             object:self.collectionView.enclosingScrollView];
+    
        
        [self performSelector:@selector(reloadData:)
                           withObject:nil
@@ -168,6 +175,16 @@ CGFloat realFromZoom(CGFloat zoom) {
     if(_zoom > f) self.zoom = f;
 }
 
+- (void)scrollViewDidLiveScrollNotification:(NSNotification *)notification
+{
+    NSSet<NSIndexPath *> *visibleItems = self.collectionView.indexPathsForVisibleItems;
+    NSIndexPath *index = visibleItems.allObjects.firstObject;
+    NSInteger middle = index.item + visibleItems.count / 2;
+    if(middle < [self.screenshotsController.arrangedObjects count] - 1) {
+        [self.scrubber scrollItemAtIndex:middle toAlignment:NSScrubberAlignmentNone];
+    }
+}
+
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
 {
     if( object == self.collectionView ) {
@@ -177,6 +194,7 @@ CGFloat realFromZoom(CGFloat zoom) {
             [selectionIndexes addIndex:[indexPath indexAtPosition:1]];
         }
         self.screenshots.selectedIndexes = selectionIndexes;
+        self.scrubber.selectedIndex = selectionIndexes.firstIndex;
         
         return;
     }
@@ -458,9 +476,7 @@ static NSTouchBarItemIdentifier ServicesItemIdentifier = @"com.masakih.sharingTo
     [mainBundle loadNibNamed:@"HMScreenshotTouchBar"
                        owner:self
              topLevelObjects:&array];
-    
-    self.scrubber.continuous = YES;
-    
+        
     NSMutableArray *identifires = [self.screenshotTouchBar.defaultItemIdentifiers mutableCopy];
     [identifires addObject:ServicesItemIdentifier];
     self.screenshotTouchBar.defaultItemIdentifiers = identifires;