summaryrefslogtreecommitdiffstats
path: root/Liaison/FindController.m
blob: 8b16bbf5641b07a693cafffcda7cd753182c8593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
//  FindController.m
//  Liaison
//
//  Created by Brian Cully on Sat Aug 23 2003.
//  Copyright (c) 2003 Brian Cully. All rights reserved.
//

#import "FindController.h"

#import "FileTableDelegate.h"

@implementation FindController (WindowDelegate)
- (void)windowDidBecomeKey: (NSNotification *)aNotificatin
{
    [LiLog logAsDebug: @"[FindController windowDidBecomeKey]"];
    [[theFindWindow firstResponder] becomeFirstResponder];
}
@end

@implementation FindController
- (id)init
{
    self = [super init];
    if (self != nil) {
        NSNotificationCenter *defaultCenter;
        
        defaultCenter = [NSNotificationCenter defaultCenter];
        [defaultCenter addObserver: self
                          selector: @selector(respondToFileStoreChanged:)
                              name: LiFileStoresChangedNotification
                            object: nil];
    }
    return self;
}

- (void)dealloc
{
    NSNotificationCenter *defaultCenter;

    defaultCenter = [NSNotificationCenter defaultCenter];
    [defaultCenter removeObserver: self];
    
    [self setFilter: nil];
    [self setTableColumns: nil];
    
    [super dealloc];
}

- (IBAction)showWindow: (id)sender
{
    FileTableDelegate *fileDelegate;

    [LiLog logAsDebug: @"[FindController showWindow: (sender)]"];

    fileDelegate = [theFileList delegate];
    [fileDelegate setFileStore: [[LiFileStore allFileStores] objectAtIndex: 0]];
    [fileDelegate setGroup: nil];

    [theFindWindow makeKeyAndOrderFront: self];
}

- (IBAction)libraryUpdated: (id)sender
{
    LiFileStore *selectedStore;
    int itemTag;

    itemTag = [[theLibraryPopUp selectedItem] tag];
    selectedStore = [LiFileStore fileStoreWithID: [NSNumber numberWithInt: itemTag]];
    if (selectedStore != nil) {
        FileTableDelegate *fileDelegate;

        [LiLog logAsDebug: @"Selected store: %@", [selectedStore name]];
        fileDelegate = [theFileList delegate];
        [fileDelegate setFileStore: selectedStore];
        [fileDelegate setGroup: nil];
    }
}

- (IBAction)addFilterRow: (id)sender
{
    [LiLog logAsDebug: @"[FindController addFilterRow: (sender)]"];
}

- (IBAction)removeFilterRow: (id)sender
{
    [LiLog logAsDebug: @"[FindController removeFilterRow: (sender)]"];
}
@synthesize theLibraryPopUp;
@synthesize theFilter;
@synthesize theFileList;
@synthesize theFindView;
@synthesize theTableColumns;
@synthesize theFindWindow;
@synthesize theFilterBox;
@synthesize theOperatorPopUp;
@end

@implementation FindController (Accessors)
- (LiFilter *)filter
{
    return theFilter;
}

- (void)setFilter: (LiFilter *)aFilter
{
    [aFilter retain];
    [theFilter release];
    aFilter = theFilter;
}

- (NSMutableDictionary *)tableColumns
{
    return theTableColumns;
}

- (void)setTableColumns: (NSMutableDictionary *)someColumns
{
    [someColumns retain];
    [theTableColumns release];
    theTableColumns = someColumns;
}
@end

@implementation FindController (Private)
- (void)respondToFileStoreChanged: (NSNotification *)aNotification
{
    LiFileStore *fileStore;
    NSEnumerator *fsEnum;
    NSMenu *libraryMenu;
    int i;

    [LiLog logAsDebug: @"[FindController respondToFileStoreChanged: (notification)]"];
    [LiLog indentDebugLog];

    libraryMenu = [[[NSMenu alloc] initWithTitle: @"Libraries"] autorelease];
    i = 0;
    fsEnum = [LiFileStore fileStoreEnumerator];
    for (i = 0; (fileStore = [fsEnum nextObject]) != nil; i++) {
        NSMenuItem *fsItem;

        [LiLog logAsDebug: @"found file store: %@", [fileStore name]];
        fsItem = [[[NSMenuItem alloc] initWithTitle: [fileStore name]
                                             action: nil
                                      keyEquivalent: @""] autorelease];
        [fsItem setImage: [fileStore icon]];
        [fsItem setTag: [[fileStore storeID] intValue]];
        [libraryMenu insertItem: fsItem atIndex: i];
    }
    [theLibraryPopUp setMenu: libraryMenu];

    [LiLog unindentDebugLog];
}
@end