Revision: 7325
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7325&view=rev
Author:   hofman
Date:     2011-07-05 18:39:10 +0000 (Tue, 05 Jul 2011)

Log Message:
-----------
Use panes for next/previous pane actions and validate menu items

Modified Paths:
--------------
    trunk/SKPreferenceController.m

Modified: trunk/SKPreferenceController.m
===================================================================
--- trunk/SKPreferenceController.m      2011-07-05 18:26:29 UTC (rev 7324)
+++ trunk/SKPreferenceController.m      2011-07-05 18:39:10 UTC (rev 7325)
@@ -211,8 +211,7 @@
     return nil;
 }
 
-- (void)selectPane:(id)sender {
-    SKPreferencePane *pane = [self preferencePaneForItemIdentifier:[sender 
itemIdentifier]];
+- (void)selectPane:(SKPreferencePane *)pane {
     if ([pane isEqual:currentPane] == NO) {
         
         [[self window] setTitle:[pane title]];
@@ -239,13 +238,17 @@
     }
 }
 
+- (void)selectPaneAction:(id)sender {
+    [self selectPane:[self preferencePaneForItemIdentifier:[sender 
itemIdentifier]]];
+}
+
 - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar 
itemForItemIdentifier:(NSString *)itemIdent 
willBeInsertedIntoToolbar:(BOOL)willBeInserted {
     SKPreferencePane *pane = [self preferencePaneForItemIdentifier:itemIdent];
     NSToolbarItem *item = [[[NSToolbarItem alloc] 
initWithItemIdentifier:itemIdent] autorelease];
     [item setLabel:[pane title]];
     [item setImage:[pane icon]];
     [item setTarget:self];
-    [item setAction:@selector(selectPane:)];
+    [item setAction:@selector(selectPaneAction:)];
     return item;
 }
 
@@ -262,25 +265,29 @@
 }
 
 - (IBAction)doGoToNextPage:(id)sender {
-    NSToolbar *toolbar = [[self window] toolbar];
-    NSString *itemID = [toolbar selectedItemIdentifier];
-    NSArray *itemIDs = [[toolbar visibleItems] valueForKey:@"itemIdentifier"];
-    NSUInteger itemIndex = [itemIDs indexOfObject:itemID];
-    if (itemIndex != NSNotFound && ++itemIndex < [itemIDs count]) {
-        [toolbar setSelectedItemIdentifier:[itemIDs objectAtIndex:itemIndex]];
-        [self selectPane:[[toolbar visibleItems] objectAtIndex:itemIndex]];
+    NSUInteger itemIndex = [preferencePanes indexOfObject:currentPane];
+    if (itemIndex != NSNotFound && ++itemIndex < [preferencePanes count]) {
+        SKPreferencePane *pane = [preferencePanes objectAtIndex:itemIndex];
+        [[[self window] toolbar] setSelectedItemIdentifier:[pane nibName]];
+        [self selectPane:pane];
     }
 }
 
 - (IBAction)doGoToPreviousPage:(id)sender {
-    NSToolbar *toolbar = [[self window] toolbar];
-    NSString *itemID = [toolbar selectedItemIdentifier];
-    NSArray *itemIDs = [[toolbar visibleItems] valueForKey:@"itemIdentifier"];
-    NSUInteger itemIndex = [itemIDs indexOfObject:itemID];
+    NSUInteger itemIndex = [preferencePanes indexOfObject:currentPane];
     if (itemIndex != NSNotFound && itemIndex-- > 0) {
-        [toolbar setSelectedItemIdentifier:[itemIDs objectAtIndex:itemIndex]];
-        [self selectPane:[[toolbar visibleItems] objectAtIndex:itemIndex]];
+        SKPreferencePane *pane = [preferencePanes objectAtIndex:itemIndex];
+        [[[self window] toolbar] setSelectedItemIdentifier:[pane nibName]];
+        [self selectPane:pane];
     }
 }
 
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
+    if ([menuItem action] == @selector(doGoToNextPage:))
+        return [currentPane isEqual:[preferencePanes lastObject]] == NO;
+    else if ([menuItem action] == @selector(doGoToPreviousPage:))
+        return [currentPane isEqual:[preferencePanes objectAtIndex:0]] == NO;
+    return YES;
+}
+
 @end


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to