Revision: 4750
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4750&view=rev
Author:   hofman
Date:     2008-10-07 16:17:12 +0000 (Tue, 07 Oct 2008)

Log Message:
-----------
Add search field to note document in toolbar

Modified Paths:
--------------
    trunk/English.lproj/NotesDocument.nib/classes.nib
    trunk/English.lproj/NotesDocument.nib/info.nib
    trunk/English.lproj/NotesDocument.nib/keyedobjects.nib
    trunk/SKNotesDocument.h
    trunk/SKNotesDocument.m

Modified: trunk/English.lproj/NotesDocument.nib/classes.nib
===================================================================
--- trunk/English.lproj/NotesDocument.nib/classes.nib   2008-10-07 15:05:10 UTC 
(rev 4749)
+++ trunk/English.lproj/NotesDocument.nib/classes.nib   2008-10-07 16:17:12 UTC 
(rev 4750)
@@ -9,6 +9,8 @@
                        <dict>
                                <key>openPDF</key>
                                <string>id</string>
+                               <key>searchNotes</key>
+                               <string>id</string>
                        </dict>
                        <key>CLASS</key>
                        <string>SKNotesDocument</string>
@@ -20,6 +22,8 @@
                                <string>NSArrayController</string>
                                <key>outlineView</key>
                                <string>SKNoteOutlineView</string>
+                               <key>searchField</key>
+                               <string>NSSearchField</string>
                                <key>statusBar</key>
                                <string>SKStatusBar</string>
                        </dict>

Modified: trunk/English.lproj/NotesDocument.nib/info.nib
===================================================================
--- trunk/English.lproj/NotesDocument.nib/info.nib      2008-10-07 15:05:10 UTC 
(rev 4749)
+++ trunk/English.lproj/NotesDocument.nib/info.nib      2008-10-07 16:17:12 UTC 
(rev 4750)
@@ -10,7 +10,7 @@
        <integer>5</integer>
        <key>IBOpenObjects</key>
        <array>
-               <integer>6</integer>
+               <integer>89</integer>
        </array>
        <key>IBSystem Version</key>
        <string>9F33</string>

Modified: trunk/SKNotesDocument.h
===================================================================
--- trunk/SKNotesDocument.h     2008-10-07 15:05:10 UTC (rev 4749)
+++ trunk/SKNotesDocument.h     2008-10-07 16:17:12 UTC (rev 4750)
@@ -44,11 +44,14 @@
     IBOutlet SKNoteOutlineView *outlineView;
     IBOutlet NSArrayController *arrayController;
     IBOutlet SKStatusBar *statusBar;
+    IBOutlet NSSearchField *searchField;
+    NSMutableDictionary *toolbarItems;
     NSMutableArray *notes;
     BOOL exportUsingPanel;
 }
 
 - (IBAction)openPDF:(id)sender;
+- (IBAction)searchNotes:(id)sender;
 
 - (NSArray *)notes;
 - (unsigned int)countOfNotes;
@@ -56,4 +59,6 @@
 - (void)insertObject:(NSDictionary *)note inNotesAtIndex:(unsigned int)index;
 - (void)removeObjectFromNotesAtIndex:(unsigned int)index;
 
+- (void)setupToolbar:(NSWindowController *)aController;
+
 @end

Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m     2008-10-07 15:05:10 UTC (rev 4749)
+++ trunk/SKNotesDocument.m     2008-10-07 16:17:12 UTC (rev 4750)
@@ -56,9 +56,13 @@
 #import "NSView_SKExtensions.h"
 #import "Files_SKExtensions.h"
 #import "BDSKPrintableView.h"
+#import "SKToolbarItem.h"
 
 static NSString *SKNotesDocumentWindowFrameAutosaveName = 
@"SKNotesDocumentWindow";
 
+static NSString *SKNotesDocumentToolbarIdentifier = 
@"SKNotesDocumentToolbarIdentifier";
+static NSString *SKNotesDocumentSearchToolbarItemIdentifier = 
@"SKNotesDocumentSearchToolbarItemIdentifier";
+
 static NSString *SKLastExportedNotesTypeKey = @"SKLastExportedNotesType";
 
 static NSString *SKNotesDocumentRowHeightKey = @"rowHeight";
@@ -81,6 +85,7 @@
 
 - (void)dealloc {
     [notes release];
+    [toolbarItems release];
     [super dealloc];
 }
 
@@ -96,6 +101,8 @@
 - (void)windowControllerDidLoadNib:(NSWindowController *)aController {
     [aController setShouldCloseDocument:YES];
     
+    [self setupToolbar:aController];
+    
     [aController 
setWindowFrameAutosaveNameOrCascade:SKNotesDocumentWindowFrameAutosaveName];
     
     [outlineView setAutoresizesOutlineColumn: NO];
@@ -285,6 +292,45 @@
     return setup;
 }
 
+- (void)updateNoteFilterPredicate {
+    NSPredicate *filterPredicate = nil;
+    NSPredicate *typePredicate = nil;
+    NSPredicate *searchPredicate = nil;
+    NSArray *types = [outlineView noteTypes];
+    NSString *searchString = [searchField stringValue];
+    if ([types count] < 8) {
+        NSExpression *lhs = [NSExpression expressionForKeyPath:@"type"];
+        NSMutableArray *predicateArray = [NSMutableArray array];
+        NSEnumerator *typeEnum = [types objectEnumerator];
+        NSString *type;
+        
+        while (type = [typeEnum nextObject]) {
+            NSExpression *rhs = [NSExpression expressionForConstantValue:type];
+            NSPredicate *predicate = [NSComparisonPredicate 
predicateWithLeftExpression:lhs rightExpression:rhs 
modifier:NSDirectPredicateModifier type:NSEqualToPredicateOperatorType 
options:0];
+            [predicateArray addObject:predicate];
+        }
+        typePredicate = [NSCompoundPredicate 
orPredicateWithSubpredicates:predicateArray];
+    }
+    if (searchString && [searchString isEqualToString:@""] == NO) {
+        NSExpression *lhs = [NSExpression 
expressionForConstantValue:searchString];
+        NSExpression *rhs = [NSExpression expressionForKeyPath:@"string"];
+        NSPredicate *stringPredicate = [NSComparisonPredicate 
predicateWithLeftExpression:lhs rightExpression:rhs 
modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType 
options:NSCaseInsensitivePredicateOption | 
NSDiacriticInsensitivePredicateOption];
+        rhs = [NSExpression expressionForKeyPath:@"text.string"];
+        NSPredicate *textPredicate = [NSComparisonPredicate 
predicateWithLeftExpression:lhs rightExpression:rhs 
modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType 
options:NSCaseInsensitivePredicateOption | 
NSDiacriticInsensitivePredicateOption];
+        searchPredicate = [NSCompoundPredicate 
orPredicateWithSubpredicates:[NSArray arrayWithObjects:stringPredicate, 
textPredicate, nil]];
+    }
+    if (typePredicate) {
+        if (searchPredicate)
+            filterPredicate = [NSCompoundPredicate 
andPredicateWithSubpredicates:[NSArray arrayWithObjects:typePredicate, 
searchPredicate, nil]];
+        else
+            filterPredicate = typePredicate;
+    } else if (searchPredicate) {
+        filterPredicate = searchPredicate;
+    }
+    [arrayController setFilterPredicate:filterPredicate];
+    [outlineView reloadData];
+}
+
 #pragma mark Printing
 
 - (NSView *)printableView{
@@ -317,6 +363,15 @@
     } else NSBeep();
 }
 
+- (IBAction)searchNotes:(id)sender {
+    [self updateNoteFilterPredicate];
+    if ([[sender stringValue] length]) {
+        NSPasteboard *findPboard = [NSPasteboard 
pasteboardWithName:NSFindPboard];
+        [findPboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] 
owner:nil];
+        [findPboard setString:[sender stringValue] forType:NSStringPboardType];
+    }
+}
+
 - (void)copyNote:(id)sender {
     NSDictionary *item = [sender representedObject];
     [self outlineView:outlineView copyItems:[NSArray arrayWithObjects:item, 
nil]];
@@ -447,23 +502,7 @@
 }
 
 - (void)outlineViewNoteTypesDidChange:(NSOutlineView *)ov {
-    NSArray *types = [outlineView noteTypes];
-    if ([types count] == 8) {
-        [arrayController setFilterPredicate:nil];
-    } else {
-        NSExpression *lhs = [NSExpression 
expressionForKeyPath:SKNPDFAnnotationTypeKey];
-        NSMutableArray *predicateArray = [NSMutableArray array];
-        NSEnumerator *typeEnum = [types objectEnumerator];
-        NSString *type;
-        
-        while (type = [typeEnum nextObject]) {
-            NSExpression *rhs = [NSExpression expressionForConstantValue:type];
-            NSPredicate *predicate = [NSComparisonPredicate 
predicateWithLeftExpression:lhs rightExpression:rhs 
modifier:NSDirectPredicateModifier type:NSEqualToPredicateOperatorType 
options:0];
-            [predicateArray addObject:predicate];
-        }
-        [arrayController setFilterPredicate:[NSCompoundPredicate 
orPredicateWithSubpredicates:predicateArray]];
-    }
-    [outlineView reloadData];
+    [self updateNoteFilterPredicate];
 }
 
 - (void)outlineView:(NSOutlineView *)ov copyItems:(NSArray *)items  {
@@ -574,4 +613,62 @@
         [statusBar setLeftStringValue:@""];
 }
 
+#pragma mark Toolbar
+
+- (void)setupToolbar:(NSWindowController *)aController {
+    // Create a new toolbar instance, and attach it to our document window
+    NSToolbar *toolbar = [[[NSToolbar alloc] 
initWithIdentifier:SKNotesDocumentToolbarIdentifier] autorelease];
+    SKToolbarItem *item;
+    
+    toolbarItems = [[NSMutableDictionary alloc] initWithCapacity:1];
+    
+    // Set up toolbar properties: Allow customization, give a default display 
mode, and remember state in user defaults
+    [toolbar setAllowsUserCustomization:YES];
+    [toolbar setAutosavesConfiguration:YES];
+    [toolbar setDisplayMode: NSToolbarDisplayModeDefault];
+    
+    // We are the delegate
+    [toolbar setDelegate:self];
+    
+    // Add template toolbar items
+    
+    NSSize minSize = [searchField frame].size;
+    NSSize maxSize = minSize;
+    maxSize.width = 1000.0;
+    
+    item = [[SKToolbarItem alloc] 
initWithItemIdentifier:SKNotesDocumentSearchToolbarItemIdentifier];
+    [item setLabels:NSLocalizedString(@"Search", @"Toolbar item label")];
+    [item setToolTip:NSLocalizedString(@"Search Notes", @"Tool tip message")];
+    [item setView:searchField];
+    [item setMinSize:minSize];
+    [item setMaxSize:maxSize];
+    [toolbarItems setObject:item 
forKey:SKNotesDocumentSearchToolbarItemIdentifier];
+    [item release];
+    
+    // Attach the toolbar to the window
+    [[aController window] setToolbar:toolbar];
+}
+
+- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar 
itemForItemIdentifier:(NSString *)itemIdent 
willBeInsertedIntoToolbar:(BOOL)willBeInserted {
+    NSToolbarItem *item = [toolbarItems objectForKey:itemIdent];
+    if (willBeInserted == NO)
+        item = [[item copy] autorelease];
+    return item;
+}
+
+- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
+    return [NSArray arrayWithObjects:
+        SKNotesDocumentSearchToolbarItemIdentifier,
+        NSToolbarFlexibleSpaceItemIdentifier, nil];
+}
+
+- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
+    return [NSArray arrayWithObjects: 
+        SKNotesDocumentSearchToolbarItemIdentifier, 
+        NSToolbarFlexibleSpaceItemIdentifier, 
+               NSToolbarSpaceItemIdentifier, 
+               NSToolbarSeparatorItemIdentifier, 
+               NSToolbarCustomizeToolbarItemIdentifier, nil];
+}
+
 @end


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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to