summaryrefslogtreecommitdiffstats
path: root/Plugins/BuiltInFunctions/InspectorViewController.m
blob: 54d0d4e804859dec9e0131e7fae15b46eebe05dc (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//
//  InspectorViewController.m
//  Liaison
//
//  Created by Brian Cully on Wed May 21 2003.
//  Copyright (c) 2003 Brian Cully. All rights reserved.
//

#import "InspectorViewController.h"

#import "BDAlias.h"
#import "LiBuiltInFunctions.h"

static NSString *
myLocalizedString(NSString *aString)
{
    return NSLocalizedStringFromTableInBundle(aString, @"BuiltInFunctions",
                                              [LiBuiltInFunctions bundle], @"");
}

@implementation LiFileHandle (LiLocationStuff)
- (NSString *)location
{
    NSData *aliasData;
    NSString *location;

    aliasData = [self valueForAttribute: LiAliasDataAttribute];
    if (aliasData != nil) {
        BDAlias *alias;

        alias = [[BDAlias alloc] initWithData: aliasData];
        if (alias != nil)
            location = [alias fullPath];
        else
            location = myLocalizedString(@"UnableToResolveAlias");
    } else {
        location = [[self url] absoluteString];
    }
    
    return location;
}
@end

@implementation InspectorViewController
- (IBAction)setIcon:(id)sender
{
    [[sender cell] setHighlighted: NO];
}

- (IBAction)setFilename:(id)sender
{
    NSString *filename;

    filename = [theFilenameField stringValue];
    if ([filename compare: [[self file] filename]]) {
        [[self file] setFilename: filename];
    }
}

- (IBAction)setType:(id)sender
{
    NSString *type;

    type = [theTypeField stringValue];
    if ([type compare: [[self file] type]]) {
        [[self file] setType: type];
    }
}

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

- (IBAction)setHFSTypeField:(id)sender
{
    NSNumber *hfsType;

    hfsType = [hfsTypeField objectValue];
    if ([hfsType compare: [[self file] hfsType]]) {
        [[self file] setHFSType: hfsType];
    }
}

- (IBAction)setHFSCreatorField:(id)sender
{
    NSNumber *hfsCreator;

    hfsCreator = [hfsCreatorField objectValue];
    if ([hfsCreator compare: [[self file] hfsCreator]]) {
        [[self file] setHFSCreator: hfsCreator];
    }
}
@synthesize hfsTypeField;
@synthesize theFileTabView;
@synthesize theTypeField;
@synthesize theHFSTabView;
@synthesize hfsCreatorField;
@synthesize iconView;
@synthesize theApplicationButton;
@synthesize theFilenameField;
@synthesize pathField;
@synthesize theFile;
@end

@implementation InspectorViewController (Accessors)
- (NSView *)fileView
{
    return theFileTabView;
}

- (NSView *)hfsView
{
    return theHFSTabView;
}

- (LiFileHandle *)file
{
    return theFile;
}

- (void)initHFSFields
{
    [hfsCreatorField setObjectValue: [[self file] hfsCreator]];
    [hfsTypeField setObjectValue: [[self file] hfsType]];
}

- (void)setFile: (LiFileHandle *)aFile
{
    NSImage *icon;
    NSMutableArray *applications;
    NSString *filename, *type, *location;
    NSSize iconSize;
    
    [aFile retain];
    [theFile release];
    theFile = aFile;

    icon = [theFile icon];
    iconSize = [iconView bounds].size;
    iconSize.width -= 16.0;
    iconSize.height -= 16.0;
    [icon setSize: iconSize];
    [iconView setImage: icon];

    if ([theFile isEditable]) {
        [theFilenameField setEnabled: YES];
        [theTypeField setEnabled: YES];
        [theApplicationButton setEnabled: YES];
        [iconView setEditable: YES];
        [hfsCreatorField setEditable: YES];
        [hfsTypeField setEditable: YES];
    } else {
        [theFilenameField setEnabled: NO];
        [theTypeField setEnabled: NO];
        [theApplicationButton setEnabled: NO];
        [iconView setEditable: NO];
        [hfsCreatorField setEditable: NO];
        [hfsTypeField setEditable: NO];
    }
    
    filename = [theFile filename];
    if (filename != nil)
        [theFilenameField setStringValue: filename];
    else
        [theFilenameField setStringValue: @""];
    
    type = [theFile type];
    if (type != nil)
        [theTypeField setStringValue: type];
    else
        [theTypeField setStringValue: @""];

    location = [aFile location];
    if (location != nil)
        [pathField setStringValue: location];
    else
        [pathField setStringValue: @"Couldn't locate file."];

    
    applications = [NSMutableArray array];
    if ([theFile application] != nil)
        [applications addObject: [[theFile application] lastPathComponent]];
    
    [theApplicationButton removeAllItems];
    if ([applications count] > 0)
        [theApplicationButton addItemsWithTitles: applications];
    else
        [theApplicationButton addItemWithTitle: @"None"];

    [self initHFSFields];
}
@end