Skip to content
This repository
Browse code

Add some much nicer UI for icon setting. Now includes a select button…

…, drag/drop and paste
  • Loading branch information...
commit 240aeb124a12ad006aaaa15d78f9770f15f3dee8 1 parent 0cddf55
Michael Gorbach authored
18 MFAdvancedViewController.h
... ... @@ -0,0 +1,18 @@
  1 +//
  2 +// MFAdvancedViewController.h
  3 +// MacFusion2
  4 +//
  5 +// Created by Michael Gorbach on 3/20/08.
  6 +// Copyright 2008 Michael Gorbach. All rights reserved.
  7 +//
  8 +
  9 +#import <Cocoa/Cocoa.h>
  10 +
  11 +@class MFIconSettingImageView;
  12 +@interface MFAdvancedViewController : NSViewController {
  13 + IBOutlet MFIconSettingImageView* iconView;
  14 +}
  15 +
  16 +- (IBAction)chooseIcon:(id)sender;
  17 +
  18 +@end
33 MFAdvancedViewController.m
... ... @@ -0,0 +1,33 @@
  1 +//
  2 +// MFAdvancedViewController.m
  3 +// MacFusion2
  4 +//
  5 +// Created by Michael Gorbach on 3/20/08.
  6 +// Copyright 2008 Michael Gorbach. All rights reserved.
  7 +//
  8 +
  9 +#import "MFAdvancedViewController.h"
  10 +#import "MFClientFS.h"
  11 +
  12 +@implementation MFAdvancedViewController
  13 +- (void)awakeFromNib
  14 +{
  15 + [iconView bind:@"fs" toObject:self withKeyPath:@"representedObject" options:nil];
  16 +}
  17 +
  18 +- (IBAction)chooseIcon:(id)sender
  19 +{
  20 + NSOpenPanel* panel = [NSOpenPanel openPanel];
  21 + [panel setAllowsMultipleSelection: NO];
  22 + [panel setAllowedFileTypes: [NSArray arrayWithObject: @"icns"]];
  23 + NSInteger returnValue = [panel runModalForTypes: [NSArray arrayWithObject: @"icns"]];
  24 + if (returnValue == NSOKButton && [[panel filenames] count] > 0)
  25 + {
  26 + NSString* filename = [[panel filenames] objectAtIndex: 0];
  27 + NSImage* iconImage = [[NSImage alloc] initWithContentsOfFile: filename];
  28 + if (iconImage)
  29 + [(MFClientFS*)[self representedObject] setIconImage: iconImage];
  30 + }
  31 +}
  32 +
  33 +@end
1  MFClientFS.h
@@ -49,6 +49,7 @@
49 49
50 50 // UI
51 51 - (NSDictionary*)configurationViewControllers;
  52 +- (void)setIconImage:(NSImage*)image;
52 53
53 54 @property(readwrite, assign) NSInteger displayOrder;
54 55 @property(readwrite, retain) id<MFClientFSDelegateProtocol> clientFSDelegate;
83 MFClientFS.m
@@ -19,6 +19,10 @@
19 19 #import "MFClientPlugin.h"
20 20 #import "MFServerFSProtocol.h"
21 21 #import "MFSecurity.h"
  22 +#import "IconFamily.h"
  23 +#import "MFAdvancedViewController.h"
  24 +#import "MGNSImage.h"
  25 +#import <QuartzCore/QuartzCore.h>
22 26
23 27 @interface MFClientFS (PrivateAPI)
24 28 - (void)fillInitialData;
@@ -42,7 +46,8 @@ + (MFClientFS*)clientFSWithRemoteFS:(id)remoteFS
42 46
43 47 + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key
44 48 {
45   - if ([key isEqualToString: @"displayDictionary"])
  49 + if ([key isEqualToString: @"displayDictionary"] ||
  50 + [key isEqualToString: @"imagePath"])
46 51 return [NSSet setWithObjects:
47 52 KMFStatusDict, kMFParameterDict, nil];
48 53 else
@@ -242,7 +247,7 @@ - (void)setPauseTimeout:(BOOL)p
242 247 - (NSDictionary*)configurationViewControllers
243 248 {
244 249 NSMutableDictionary* myControllers = [NSMutableDictionary dictionary];
245   - NSViewController* macfusionAdvancedController = [[NSViewController alloc] initWithNibName: @"macfusionAdvancedView"
  250 + NSViewController* macfusionAdvancedController = [[MFAdvancedViewController alloc] initWithNibName: @"macfusionAdvancedView"
246 251 bundle: [NSBundle bundleForClass: [self class]]];
247 252 [myControllers setObject: macfusionAdvancedController forKey:kMFUIMacfusionAdvancedViewKey];
248 253 NSDictionary* delegateControllers = [delegate configurationViewControllers];
@@ -255,5 +260,79 @@ - (NSDictionary*)configurationViewControllers
255 260 return [myControllers copy];
256 261 }
257 262
  263 +- (void)setIconImage:(NSImage*)image
  264 +{
  265 + if (image == nil)
  266 + {
  267 + [self willChangeValueForKey:@"parameters"];
  268 + [parameters removeObjectForKey: kMFFSVolumeIconPathParameter];
  269 + [parameters removeObjectForKey: kMFFSVolumeImagePathParameter];
  270 + [self didChangeValueForKey:@"parameters"];
  271 + return;
  272 + }
  273 +
  274 + // MFLogS(self, @"Writing image %@", image);
  275 + BOOL isDir;
  276 + NSString* iconDirPath = [@"~/Library/Application Support/Macfusion/Icons" stringByExpandingTildeInPath];
  277 +
  278 + // Make Icons Directory if needed
  279 + if (![[NSFileManager defaultManager] fileExistsAtPath:iconDirPath isDirectory:&isDir] || !isDir)
  280 + {
  281 + NSError* dirCreateError;
  282 + BOOL ok = [[NSFileManager defaultManager] createDirectoryAtPath:iconDirPath
  283 + withIntermediateDirectories:YES
  284 + attributes:nil
  285 + error:&dirCreateError];
  286 + if (!ok)
  287 + {
  288 + MFLogS(self, @"Directory create for icon storage failed. Error %@", dirCreateError);
  289 + return;
  290 + }
  291 + }
  292 +
  293 + // Write Icon
  294 + NSString* fullIconPath = [iconDirPath stringByAppendingPathComponent:
  295 + [NSString stringWithFormat:@"%@.icns", self.uuid]];
  296 + if ([[NSFileManager defaultManager] fileExistsAtPath:fullIconPath])
  297 + [[NSFileManager defaultManager] removeFileAtPath:fullIconPath handler:nil];
  298 +
  299 + IconFamily* icon = [[IconFamily alloc] initWithThumbnailsOfImage: image];
  300 + BOOL writeOK = [icon writeToFile: fullIconPath];
  301 + if (!writeOK)
  302 + {
  303 + MFLogS(self, @"Failed to write to file icon %@", icon);
  304 + return;
  305 + }
  306 +
  307 + // Write Black and White image
  308 + NSString* fullBWImagePath = [iconDirPath stringByAppendingPathComponent:
  309 + [NSString stringWithFormat:@"%@.tiff", self.uuid]];
  310 + if ([[NSFileManager defaultManager] fileExistsAtPath:fullBWImagePath])
  311 + [[NSFileManager defaultManager] removeFileAtPath: fullBWImagePath handler:nil];
  312 +
  313 +
  314 + CIFilter* bwFilter = [CIFilter filterWithName:@"CIColorControls"];
  315 + [bwFilter setDefaults];
  316 + [bwFilter setValue: [image ciImageRepresentation] forKey: @"inputImage"];
  317 + [bwFilter setValue: [NSNumber numberWithFloat:0.0] forKey: @"inputSaturation"];
  318 + CIImage* bwCIImage = [bwFilter valueForKey:@"outputImage"];
  319 +
  320 + NSData* tiffData = [[bwCIImage nsImageRepresentation] TIFFRepresentation];
  321 + writeOK = [tiffData writeToFile:fullBWImagePath atomically:YES];
  322 + if(!writeOK)
  323 + {
  324 + MFLogS(self, @"Failed to write BW tiff file at path %@", fullBWImagePath);
  325 + return;
  326 + }
  327 +
  328 + // Set the data and cause updates
  329 + [self willChangeValueForKey:@"parameters"];
  330 + [parameters setObject:fullIconPath
  331 + forKey:kMFFSVolumeIconPathParameter];
  332 + [parameters setObject:fullBWImagePath
  333 + forKey:kMFFSVolumeImagePathParameter];
  334 + [self didChangeValueForKey:@"parameters"];
  335 +}
  336 +
258 337 @synthesize displayOrder, clientFSDelegate;
259 338 @end
5 MFFilesystem.m
@@ -165,6 +165,7 @@ - (NSArray*)parameterList
165 165 [parameterList addObject: kMFFSVolumeIconPathParameter ];
166 166 [parameterList addObject: kMFFSFilePathParameter ];
167 167 [parameterList addObject: kMFFSPersistentParameter ];
  168 + [parameterList addObject: kMFFSVolumeImagePathParameter ];
168 169
169 170 return [parameterList copy];
170 171 }
@@ -205,11 +206,13 @@ - (NSMutableDictionary*)parametersWithImpliedValues
205 206
206 207 - (NSString*)iconPath
207 208 {
208   - return [self valueForParameterNamed: kMFFSVolumeIconPathParameter ];
  209 + NSString* iconPath = [self valueForParameterNamed: kMFFSVolumeIconPathParameter ];
  210 + return iconPath;
209 211 }
210 212
211 213 - (NSString*)imagePath
212 214 {
  215 + // NSLog(@"Calc imagePath parammeter %@ implied %@", parameters, [self parametersWithImpliedValues]);
213 216 return [self valueForParameterNamed: kMFFSVolumeImagePathParameter ];
214 217 }
215 218
1  MFServerFS.m
@@ -275,6 +275,7 @@ - (NSDictionary*)taskEnvironment
275 275 - (NSArray*)taskArguments
276 276 {
277 277 NSArray* delegateArgs;
  278 + // MFLogS(self, @"Parameters in server are %@, implied are %@", parameters, [self parametersWithImpliedValues]);
278 279 if ([delegate respondsToSelector:@selector(taskArgumentsForParameters:)])
279 280 {
280 281 delegateArgs = [delegate taskArgumentsForParameters: [self parametersWithImpliedValues]];
68 MacFusion2.xcodeproj/project.pbxproj
@@ -123,6 +123,14 @@
123 123 D4E51FE80CE03AC3009B1A30 /* MFFilesystem.h in Headers */ = {isa = PBXBuildFile; fileRef = D42E14540CDFCF9000C81814 /* MFFilesystem.h */; };
124 124 D4E51FEA0CE03ACA009B1A30 /* MFPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = D42E141C0CDFC99A00C81814 /* MFPlugin.m */; };
125 125 D4E51FEB0CE03ACA009B1A30 /* MFFilesystem.m in Sources */ = {isa = PBXBuildFile; fileRef = D42E14550CDFCF9000C81814 /* MFFilesystem.m */; };
  126 + D4E6CCA20D9202AA0022763F /* MFIconSettingImageView.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E6CCA00D9202AA0022763F /* MFIconSettingImageView.h */; };
  127 + D4E6CCA30D9202AA0022763F /* MFIconSettingImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E6CCA10D9202AA0022763F /* MFIconSettingImageView.m */; };
  128 + D4E6CEFC0D9223770022763F /* IconFamily.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E6CEF80D9223770022763F /* IconFamily.h */; };
  129 + D4E6CEFD0D9223770022763F /* IconFamily.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E6CEF90D9223770022763F /* IconFamily.m */; };
  130 + D4E6CEFE0D9223770022763F /* NSString+CarbonFSRefCreation.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E6CEFA0D9223770022763F /* NSString+CarbonFSRefCreation.m */; };
  131 + D4E6CEFF0D9223770022763F /* NSString+CarbonFSRefCreation.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E6CEFB0D9223770022763F /* NSString+CarbonFSRefCreation.h */; };
  132 + D4E6CF3E0D9224DB0022763F /* MFAdvancedViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E6CF3C0D9224DB0022763F /* MFAdvancedViewController.h */; };
  133 + D4E6CF3F0D9224DB0022763F /* MFAdvancedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E6CF3D0D9224DB0022763F /* MFAdvancedViewController.m */; };
126 134 D4E983450D7223CE0058AF73 /* MGNSImage.m in Sources */ = {isa = PBXBuildFile; fileRef = D4E983440D7223CE0058AF73 /* MGNSImage.m */; };
127 135 D4E983470D7223D70058AF73 /* MGNSImage.h in Headers */ = {isa = PBXBuildFile; fileRef = D4E983460D7223D70058AF73 /* MGNSImage.h */; };
128 136 D4EA61570D8B30ED006D8885 /* MFMainController.m in Sources */ = {isa = PBXBuildFile; fileRef = D42E13E50CDFC69500C81814 /* MFMainController.m */; };
@@ -399,6 +407,14 @@
399 407 D4DF34CD0D80FC73005C9402 /* topView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = topView.xib; sourceTree = "<group>"; };
400 408 D4DF353A0D812AA7005C9402 /* MGSmoothingImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGSmoothingImageView.h; sourceTree = "<group>"; };
401 409 D4DF353B0D812AA7005C9402 /* MGSmoothingImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGSmoothingImageView.m; sourceTree = "<group>"; };
  410 + D4E6CCA00D9202AA0022763F /* MFIconSettingImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MFIconSettingImageView.h; path = Settings/MFIconSettingImageView.h; sourceTree = "<group>"; };
  411 + D4E6CCA10D9202AA0022763F /* MFIconSettingImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MFIconSettingImageView.m; path = Settings/MFIconSettingImageView.m; sourceTree = "<group>"; };
  412 + D4E6CEF80D9223770022763F /* IconFamily.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconFamily.h; sourceTree = "<group>"; };
  413 + D4E6CEF90D9223770022763F /* IconFamily.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IconFamily.m; sourceTree = "<group>"; };
  414 + D4E6CEFA0D9223770022763F /* NSString+CarbonFSRefCreation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+CarbonFSRefCreation.m"; sourceTree = "<group>"; };
  415 + D4E6CEFB0D9223770022763F /* NSString+CarbonFSRefCreation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+CarbonFSRefCreation.h"; sourceTree = "<group>"; };
  416 + D4E6CF3C0D9224DB0022763F /* MFAdvancedViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFAdvancedViewController.h; sourceTree = "<group>"; };
  417 + D4E6CF3D0D9224DB0022763F /* MFAdvancedViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFAdvancedViewController.m; sourceTree = "<group>"; };
402 418 D4E983440D7223CE0058AF73 /* MGNSImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGNSImage.m; sourceTree = "<group>"; };
403 419 D4E983460D7223D70058AF73 /* MGNSImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGNSImage.h; sourceTree = "<group>"; };
404 420 D4EA61500D8B30DA006D8885 /* macfusionAgent.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = macfusionAgent.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -541,12 +557,9 @@
541 557 D413146B0D7F224900F55B9B /* Shared */ = {
542 558 isa = PBXGroup;
543 559 children = (
544   - D413146D0D7F225E00F55B9B /* MGTransitioningTabView.h */,
545   - D413146E0D7F225E00F55B9B /* MGTransitioningTabView.m */,
546   - D4DF353A0D812AA7005C9402 /* MGSmoothingImageView.h */,
547   - D4DF353B0D812AA7005C9402 /* MGSmoothingImageView.m */,
548   - D41E24280D897F0B00F46F50 /* MFPreferencesController.h */,
549   - D41E24290D897F0B00F46F50 /* MFPreferencesController.m */,
  560 + D4E6CF3B0D9224C70022763F /* Other */,
  561 + D4E6CF3A0D9224AE0022763F /* Controllers */,
  562 + D4E6CF380D92249F0022763F /* Views */,
550 563 );
551 564 name = Shared;
552 565 sourceTree = "<group>";
@@ -815,6 +828,41 @@
815 828 path = SSHFS;
816 829 sourceTree = "<group>";
817 830 };
  831 + D4E6CF380D92249F0022763F /* Views */ = {
  832 + isa = PBXGroup;
  833 + children = (
  834 + D4E6CCA00D9202AA0022763F /* MFIconSettingImageView.h */,
  835 + D4E6CCA10D9202AA0022763F /* MFIconSettingImageView.m */,
  836 + D413146D0D7F225E00F55B9B /* MGTransitioningTabView.h */,
  837 + D413146E0D7F225E00F55B9B /* MGTransitioningTabView.m */,
  838 + D4DF353A0D812AA7005C9402 /* MGSmoothingImageView.h */,
  839 + D4DF353B0D812AA7005C9402 /* MGSmoothingImageView.m */,
  840 + );
  841 + name = Views;
  842 + sourceTree = "<group>";
  843 + };
  844 + D4E6CF3A0D9224AE0022763F /* Controllers */ = {
  845 + isa = PBXGroup;
  846 + children = (
  847 + D41E24280D897F0B00F46F50 /* MFPreferencesController.h */,
  848 + D41E24290D897F0B00F46F50 /* MFPreferencesController.m */,
  849 + D4E6CF3C0D9224DB0022763F /* MFAdvancedViewController.h */,
  850 + D4E6CF3D0D9224DB0022763F /* MFAdvancedViewController.m */,
  851 + );
  852 + name = Controllers;
  853 + sourceTree = "<group>";
  854 + };
  855 + D4E6CF3B0D9224C70022763F /* Other */ = {
  856 + isa = PBXGroup;
  857 + children = (
  858 + D4E6CEF80D9223770022763F /* IconFamily.h */,
  859 + D4E6CEF90D9223770022763F /* IconFamily.m */,
  860 + D4E6CEFA0D9223770022763F /* NSString+CarbonFSRefCreation.m */,
  861 + D4E6CEFB0D9223770022763F /* NSString+CarbonFSRefCreation.h */,
  862 + );
  863 + name = Other;
  864 + sourceTree = "<group>";
  865 + };
818 866 /* End PBXGroup section */
819 867
820 868 /* Begin PBXHeadersBuildPhase section */
@@ -844,6 +892,10 @@
844 892 D41E1DA30D87557900F46F50 /* MFCore.h in Headers */,
845 893 D41E242A0D897F0C00F46F50 /* MFPreferencesController.h in Headers */,
846 894 D4CF0E460D8C75B30065A2C3 /* MFPreferences.h in Headers */,
  895 + D4E6CCA20D9202AA0022763F /* MFIconSettingImageView.h in Headers */,
  896 + D4E6CEFC0D9223770022763F /* IconFamily.h in Headers */,
  897 + D4E6CEFF0D9223770022763F /* NSString+CarbonFSRefCreation.h in Headers */,
  898 + D4E6CF3E0D9224DB0022763F /* MFAdvancedViewController.h in Headers */,
847 899 );
848 900 runOnlyForDeploymentPostprocessing = 0;
849 901 };
@@ -1133,6 +1185,10 @@
1133 1185 D41E1DA40D87557900F46F50 /* MFCore.m in Sources */,
1134 1186 D41E242B0D897F0C00F46F50 /* MFPreferencesController.m in Sources */,
1135 1187 D4CF0E470D8C75B30065A2C3 /* MFPreferences.m in Sources */,
  1188 + D4E6CCA30D9202AA0022763F /* MFIconSettingImageView.m in Sources */,
  1189 + D4E6CEFD0D9223770022763F /* IconFamily.m in Sources */,
  1190 + D4E6CEFE0D9223770022763F /* NSString+CarbonFSRefCreation.m in Sources */,
  1191 + D4E6CF3F0D9224DB0022763F /* MFAdvancedViewController.m in Sources */,
1136 1192 );
1137 1193 runOnlyForDeploymentPostprocessing = 0;
1138 1194 };
25 NSString+CarbonFSRefCreation.h
... ... @@ -0,0 +1,25 @@
  1 +/*
  2 + Copyright (c) 2001-2006 Troy N. Stephens
  3 +
  4 + Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
  5 +
  6 + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  7 +
  8 + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  9 +
  10 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  11 +*/
  12 +
  13 +#import <Foundation/Foundation.h>
  14 +#import <Carbon/Carbon.h>
  15 +
  16 +@interface NSString (CarbonFSRefCreation)
  17 +
  18 +// Fills in the given FSRef struct so it specifies the file whose path is in this string.
  19 +// If the file doesn't exist, and "createFile" is YES, this method will attempt to create
  20 +// an empty file with the specified path. (The caller should insure that the directory
  21 +// the file is to be placed in already exists.)
  22 +
  23 +- (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile;
  24 +
  25 +@end
58 NSString+CarbonFSRefCreation.m
... ... @@ -0,0 +1,58 @@
  1 +/*
  2 + Copyright (c) 2001-2006 Troy N. Stephens
  3 +
  4 + Use and distribution of this source code is governed by the MIT License, whose terms are as follows.
  5 +
  6 + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  7 +
  8 + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  9 +
  10 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  11 +*/
  12 +
  13 +#import "NSString+CarbonFSRefCreation.h"
  14 +
  15 +@implementation NSString (CarbonFSRefCreation)
  16 +
  17 +- (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile
  18 +{
  19 + NSFileManager* fileManager = [NSFileManager defaultManager];
  20 + CFURLRef urlRef;
  21 + Boolean gotFSRef;
  22 +
  23 + // Check whether the file exists already. If not, create an empty file if requested.
  24 + if (![fileManager fileExistsAtPath:self]) {
  25 + if (createFile) {
  26 + if (![@"" writeToFile:self atomically:YES]) {
  27 + return NO;
  28 + }
  29 + } else {
  30 + return NO;
  31 + }
  32 + }
  33 +
  34 + // Create a CFURL with the specified POSIX path.
  35 + urlRef = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
  36 + (CFStringRef) self,
  37 + kCFURLPOSIXPathStyle,
  38 + FALSE /* isDirectory */ );
  39 + if (urlRef == NULL) {
  40 +// printf( "** Couldn't make a CFURLRef for the file.\n" );
  41 + return NO;
  42 + }
  43 +
  44 + // Try to create an FSRef from the URL. (If the specified file doesn't exist, this
  45 + // function will return false, but if we've reached this code we've already insured
  46 + // that the file exists.)
  47 + gotFSRef = CFURLGetFSRef( urlRef, fsRef );
  48 + CFRelease( urlRef );
  49 +
  50 + if (!gotFSRef) {
  51 +// printf( "** Couldn't get an FSRef for the file.\n" );
  52 + return NO;
  53 + }
  54 +
  55 + return YES;
  56 +}
  57 +
  58 +@end
252 Resources/macfusionAdvancedView.xib
@@ -18,7 +18,7 @@
18 18 <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
19 19 <bool key="EncodedWithXMLCoder">YES</bool>
20 20 <object class="NSCustomObject" id="1001">
21   - <string key="NSClassName">NSViewController</string>
  21 + <string key="NSClassName">MFAdvancedViewController</string>
22 22 </object>
23 23 <object class="NSCustomObject" id="1003">
24 24 <string key="NSClassName">FirstResponder</string>
@@ -92,25 +92,25 @@
92 92 <object class="NSTextFieldCell" key="NSCell" id="270109062">
93 93 <int key="NSCellFlags">67239488</int>
94 94 <int key="NSCellFlags2">71304192</int>
95   - <string key="NSContents">Icon Path:</string>
  95 + <string key="NSContents">Icon:</string>
96 96 <reference key="NSSupport" ref="935590397"/>
97 97 <reference key="NSControlView" ref="276761339"/>
98 98 <reference key="NSBackgroundColor" ref="308739193"/>
99 99 <reference key="NSTextColor" ref="903214777"/>
100 100 </object>
101 101 </object>
102   - <object class="NSTextField" id="423694427">
  102 + <object class="NSTextField" id="199033250">
103 103 <reference key="NSNextResponder" ref="1005"/>
104 104 <int key="NSvFlags">268</int>
105   - <string key="NSFrame">{{123, 50}, {159, 22}}</string>
  105 + <string key="NSFrame">{{123, 78}, {159, 22}}</string>
106 106 <reference key="NSSuperview" ref="1005"/>
107 107 <bool key="NSEnabled">YES</bool>
108   - <object class="NSTextFieldCell" key="NSCell" id="708190014">
  108 + <object class="NSTextFieldCell" key="NSCell" id="1023661536">
109 109 <int key="NSCellFlags">-1804468671</int>
110 110 <int key="NSCellFlags2">272630784</int>
111 111 <string key="NSContents"/>
112 112 <reference key="NSSupport" ref="935590397"/>
113   - <reference key="NSControlView" ref="423694427"/>
  113 + <reference key="NSControlView" ref="199033250"/>
114 114 <bool key="NSDrawsBackground">YES</bool>
115 115 <object class="NSColor" key="NSBackgroundColor" id="609403963">
116 116 <int key="NSColorSpace">6</int>
@@ -129,38 +129,88 @@
129 129 </object>
130 130 </object>
131 131 </object>
132   - <object class="NSTextField" id="199033250">
  132 + <object class="NSTextField" id="723853799">
133 133 <reference key="NSNextResponder" ref="1005"/>
134 134 <int key="NSvFlags">268</int>
135   - <string key="NSFrame">{{123, 78}, {159, 22}}</string>
  135 + <string key="NSFrame">{{123, 108}, {159, 22}}</string>
136 136 <reference key="NSSuperview" ref="1005"/>
137 137 <bool key="NSEnabled">YES</bool>
138   - <object class="NSTextFieldCell" key="NSCell" id="1023661536">
  138 + <object class="NSTextFieldCell" key="NSCell" id="407684255">
139 139 <int key="NSCellFlags">-1804468671</int>
140 140 <int key="NSCellFlags2">272630784</int>
141 141 <string key="NSContents"/>
142 142 <reference key="NSSupport" ref="935590397"/>
143   - <reference key="NSControlView" ref="199033250"/>
  143 + <reference key="NSControlView" ref="723853799"/>
144 144 <bool key="NSDrawsBackground">YES</bool>
145 145 <reference key="NSBackgroundColor" ref="609403963"/>
146 146 <reference key="NSTextColor" ref="850791367"/>
147 147 </object>
148 148 </object>
149   - <object class="NSTextField" id="723853799">
  149 + <object class="NSCustomView" id="759955439">
150 150 <reference key="NSNextResponder" ref="1005"/>
151 151 <int key="NSvFlags">268</int>
152   - <string key="NSFrame">{{123, 108}, {159, 22}}</string>
  152 + <string key="NSFrame">{{123, 10}, {60, 60}}</string>
  153 + <reference key="NSSuperview" ref="1005"/>
  154 + <string key="NSClassName">MFIconSettingImageView</string>
  155 + </object>
  156 + <object class="NSButton" id="806716958">
  157 + <reference key="NSNextResponder" ref="1005"/>
  158 + <int key="NSvFlags">268</int>
  159 + <string key="NSFrame">{{199, 31}, {60, 19}}</string>
153 160 <reference key="NSSuperview" ref="1005"/>
154 161 <bool key="NSEnabled">YES</bool>
155   - <object class="NSTextFieldCell" key="NSCell" id="407684255">
156   - <int key="NSCellFlags">-1804468671</int>
157   - <int key="NSCellFlags2">272630784</int>
158   - <string key="NSContents"/>
159   - <reference key="NSSupport" ref="935590397"/>
160   - <reference key="NSControlView" ref="723853799"/>
161   - <bool key="NSDrawsBackground">YES</bool>
162   - <reference key="NSBackgroundColor" ref="609403963"/>
163   - <reference key="NSTextColor" ref="850791367"/>
  162 + <object class="NSButtonCell" key="NSCell" id="238980317">
  163 + <int key="NSCellFlags">-2080244224</int>
  164 + <int key="NSCellFlags2">134217728</int>
  165 + <string key="NSContents">Choose</string>
  166 + <object class="NSFont" key="NSSupport">
  167 + <string key="NSName">LucidaGrande</string>
  168 + <double key="NSSize">1.200000e+01</double>
  169 + <int key="NSfFlags">16</int>
  170 + </object>
  171 + <reference key="NSControlView" ref="806716958"/>
  172 + <int key="NSButtonFlags">-2038152961</int>
  173 + <int key="NSButtonFlags2">164</int>
  174 + <string key="NSAlternateContents"/>
  175 + <string key="NSKeyEquivalent"/>
  176 + <int key="NSPeriodicDelay">400</int>
  177 + <int key="NSPeriodicInterval">75</int>
  178 + </object>
  179 + </object>
  180 + <object class="NSTextField" id="978895456">
  181 + <reference key="NSNextResponder" ref="1005"/>
  182 + <int key="NSvFlags">268</int>
  183 + <string key="NSFrame">{{-18, 35}, {132, 13}}</string>
  184 + <reference key="NSSuperview" ref="1005"/>
  185 + <bool key="NSEnabled">YES</bool>
  186 + <object class="NSTextFieldCell" key="NSCell" id="790831384">
  187 + <int key="NSCellFlags">67239488</int>
  188 + <int key="NSCellFlags2">71304192</int>
  189 + <string key="NSContents">Drag/Copy To Image </string>
  190 + <object class="NSFont" key="NSSupport" id="24">
  191 + <string key="NSName">LucidaGrande</string>
  192 + <double key="NSSize">1.000000e+01</double>
  193 + <int key="NSfFlags">16</int>
  194 + </object>
  195 + <reference key="NSControlView" ref="978895456"/>
  196 + <reference key="NSBackgroundColor" ref="308739193"/>
  197 + <reference key="NSTextColor" ref="903214777"/>
  198 + </object>
  199 + </object>
  200 + <object class="NSTextField" id="771675830">
  201 + <reference key="NSNextResponder" ref="1005"/>
  202 + <int key="NSvFlags">268</int>
  203 + <string key="NSFrame">{{-18, 20}, {132, 13}}</string>
  204 + <reference key="NSSuperview" ref="1005"/>
  205 + <bool key="NSEnabled">YES</bool>
  206 + <object class="NSTextFieldCell" key="NSCell" id="552265122">
  207 + <int key="NSCellFlags">67239488</int>
  208 + <int key="NSCellFlags2">71304192</int>
  209 + <string key="NSContents">Delete To Clear</string>
  210 + <reference key="NSSupport" ref="24"/>
  211 + <reference key="NSControlView" ref="771675830"/>
  212 + <reference key="NSBackgroundColor" ref="308739193"/>
  213 + <reference key="NSTextColor" ref="903214777"/>
164 214 </object>
165 215 </object>
166 216 </object>
@@ -175,6 +225,9 @@
175 225 <string>parameters.volumeName</string>
176 226 <string>parameters.iconPath</string>
177 227 <string>parameters.advancedOptions</string>
  228 + <string>parameters.volumeIconPath</string>
  229 + <string>parameters.imagePath</string>
  230 + <string>imagePath</string>
178 231 </object>
179 232 <bool key="NSEditable">YES</bool>
180 233 <object class="_NSManagedProxy" key="_NSManagedProxy"/>
@@ -309,53 +362,20 @@
309 362 <int key="connectionID">25</int>
310 363 </object>
311 364 <object class="IBConnectionRecord">
312   - <object class="IBBindingConnection" key="connection">
313   - <string key="label">value: selection.parameters.iconPath</string>
314   - <reference key="source" ref="423694427"/>
315   - <reference key="destination" ref="583518196"/>
316   - <object class="NSNibBindingConnector" key="connector">
317   - <reference key="NSSource" ref="423694427"/>
318   - <reference key="NSDestination" ref="583518196"/>
319   - <string key="NSLabel">value: selection.parameters.iconPath</string>
320   - <string key="NSBinding">value</string>
321   - <string key="NSKeyPath">selection.parameters.iconPath</string>
322   - <object class="NSDictionary" key="NSOptions">
323   - <bool key="EncodedWithXMLCoder">YES</bool>
324   - <object class="NSMutableArray" key="dict.sortedKeys">
325   - <bool key="EncodedWithXMLCoder">YES</bool>
326   - <string>NSAllowsEditingMultipleValuesSelection</string>
327   - <string>NSAlwaysPresentsApplicationModalAlerts</string>
328   - <string>NSConditionallySetsEditable</string>
329   - <string>NSConditionallySetsEnabled</string>
330   - <string>NSConditionallySetsHidden</string>
331   - <string>NSContinuouslyUpdatesValue</string>
332   - <string>NSMultipleValuesPlaceholder</string>
333   - <string>NSNoSelectionPlaceholder</string>
334   - <string>NSNotApplicablePlaceholder</string>
335   - <string>NSNullPlaceholder</string>
336   - <string>NSRaisesForNotApplicableKeys</string>
337   - <string>NSValidatesImmediately</string>
338   - </object>
339   - <object class="NSMutableArray" key="dict.values">
340   - <bool key="EncodedWithXMLCoder">YES</bool>
341   - <reference ref="5"/>
342   - <reference ref="6"/>
343   - <reference ref="5"/>
344   - <reference ref="6"/>
345   - <reference ref="6"/>
346   - <reference ref="6"/>
347   - <string/>
348   - <string/>
349   - <string/>
350   - <string>Default</string>
351   - <reference ref="5"/>
352   - <reference ref="6"/>
353   - </object>
354   - </object>
355   - <int key="NSNibBindingConnectorVersion">2</int>
356   - </object>
  365 + <object class="IBOutletConnection" key="connection">
  366 + <string key="label">iconView</string>
  367 + <reference key="source" ref="1001"/>
  368 + <reference key="destination" ref="759955439"/>
  369 + </object>
  370 + <int key="connectionID">54</int>
  371 + </object>
  372 + <object class="IBConnectionRecord">
  373 + <object class="IBActionConnection" key="connection">
  374 + <string key="label">chooseIcon:</string>
  375 + <reference key="source" ref="1001"/>
  376 + <reference key="destination" ref="806716958"/>
357 377 </object>
358   - <int key="connectionID">31</int>
  378 + <int key="connectionID">59</int>
359 379 </object>
360 380 </object>
361 381 <object class="IBMutableOrderedSet" key="objectRecords">
@@ -395,9 +415,12 @@
395 415 <reference ref="979704784"/>
396 416 <reference ref="608696671"/>
397 417 <reference ref="276761339"/>
398   - <reference ref="423694427"/>
399 418 <reference ref="199033250"/>
400 419 <reference ref="723853799"/>
  420 + <reference ref="759955439"/>
  421 + <reference ref="806716958"/>
  422 + <reference ref="978895456"/>
  423 + <reference ref="771675830"/>
401 424 </object>
402 425 <reference key="parent" ref="1002"/>
403 426 </object>
@@ -482,18 +505,51 @@
482 505 <reference key="parent" ref="276761339"/>
483 506 </object>
484 507 <object class="IBObjectRecord">
485   - <int key="objectID">28</int>
486   - <reference key="object" ref="423694427"/>
  508 + <int key="objectID">53</int>
  509 + <reference key="object" ref="759955439"/>
  510 + <reference key="parent" ref="1005"/>
  511 + </object>
  512 + <object class="IBObjectRecord">
  513 + <int key="objectID">55</int>
  514 + <reference key="object" ref="978895456"/>
  515 + <object class="NSMutableArray" key="children">
  516 + <bool key="EncodedWithXMLCoder">YES</bool>
  517 + <reference ref="790831384"/>
  518 + </object>
  519 + <reference key="parent" ref="1005"/>
  520 + </object>
  521 + <object class="IBObjectRecord">
  522 + <int key="objectID">56</int>
  523 + <reference key="object" ref="790831384"/>
  524 + <reference key="parent" ref="978895456"/>
  525 + </object>
  526 + <object class="IBObjectRecord">
  527 + <int key="objectID">57</int>
  528 + <reference key="object" ref="806716958"/>
  529 + <object class="NSMutableArray" key="children">
  530 + <bool key="EncodedWithXMLCoder">YES</bool>
  531 + <reference ref="238980317"/>
  532 + </object>
  533 + <reference key="parent" ref="1005"/>
  534 + </object>
  535 + <object class="IBObjectRecord">
  536 + <int key="objectID">58</int>
  537 + <reference key="object" ref="238980317"/>
  538 + <reference key="parent" ref="806716958"/>
  539 + </object>
  540 + <object class="IBObjectRecord">
  541 + <int key="objectID">60</int>
  542 + <reference key="object" ref="771675830"/>
487 543 <object class="NSMutableArray" key="children">
488 544 <bool key="EncodedWithXMLCoder">YES</bool>
489   - <reference ref="708190014"/>
  545 + <reference ref="552265122"/>
490 546 </object>
491 547 <reference key="parent" ref="1005"/>
492 548 </object>
493 549 <object class="IBObjectRecord">
494   - <int key="objectID">29</int>
495   - <reference key="object" ref="708190014"/>
496   - <reference key="parent" ref="423694427"/>
  550 + <int key="objectID">61</int>
  551 + <reference key="object" ref="552265122"/>
  552 + <reference key="parent" ref="771675830"/>
497 553 </object>
498 554 </object>
499 555 </object>
@@ -517,11 +573,16 @@
517 573 <string>2.IBPluginDependency</string>
518 574 <string>26.IBPluginDependency</string>
519 575 <string>27.IBPluginDependency</string>
520   - <string>28.IBPluginDependency</string>
521   - <string>29.IBPluginDependency</string>
522 576 <string>3.IBPluginDependency</string>
523 577 <string>4.IBPluginDependency</string>
524 578 <string>5.IBPluginDependency</string>
  579 + <string>53.IBPluginDependency</string>
  580 + <string>55.IBPluginDependency</string>
  581 + <string>56.IBPluginDependency</string>
  582 + <string>57.IBPluginDependency</string>
  583 + <string>58.IBPluginDependency</string>
  584 + <string>60.IBPluginDependency</string>
  585 + <string>61.IBPluginDependency</string>
525 586 </object>
526 587 <object class="NSMutableArray" key="dict.values">
527 588 <bool key="EncodedWithXMLCoder">YES</bool>
@@ -542,7 +603,7 @@
542 603 <object class="NSMutableArray" key="dict.values">
543 604 <bool key="EncodedWithXMLCoder">YES</bool>
544 605 <string>{{0, 0}, {300, 150}}</string>
545   - <string>{{0, 0}, {300, 300}}</string>
  606 + <string>{{0, 0}, {300, 150}}</string>
546 607 </object>
547 608 </object>
548 609 <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -558,6 +619,11 @@
558 619 <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
559 620 <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
560 621 <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
  622 + <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
  623 + <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
  624 + <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
  625 + <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
  626 + <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
561 627 </object>
562 628 </object>
563 629 <object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -580,9 +646,37 @@
580 646 </object>
581 647 </object>
582 648 <nil key="sourceID"/>
583   - <int key="maxID">37</int>
  649 + <int key="maxID">61</int>
  650 + </object>
  651 + <object class="IBClassDescriber" key="IBDocument.Classes">
  652 + <object class="NSMutableArray" key="referencedPartialClassDescriptions">
  653 + <bool key="EncodedWithXMLCoder">YES</bool>
  654 + <object class="IBPartialClassDescription">
  655 + <string key="className">MFAdvancedViewController</string>
  656 + <string key="superclassName">NSViewController</string>
  657 + <object class="NSMutableDictionary" key="actions">
  658 + <string key="NS.key.0">chooseIcon:</string>
  659 + <string key="NS.object.0">id</string>
  660 + </object>
  661 + <object class="NSMutableDictionary" key="outlets">
  662 + <string key="NS.key.0">iconView</string>
  663 + <string key="NS.object.0">MFIconSettingImageView</string>
  664 + </object>
  665 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  666 + <string key="majorKey">IBProjectSource</string>
  667 + <string key="minorKey">MFAdvancedViewController.h</string>
  668 + </object>
  669 + </object>
  670 + <object class="IBPartialClassDescription">
  671 + <string key="className">MFIconSettingImageView</string>
  672 + <string key="superclassName">NSView</string>
  673 + <object class="IBClassDescriptionSource" key="sourceIdentifier">
  674 + <string key="majorKey">IBProjectSource</string>
  675 + <string key="minorKey">Settings/MFIconSettingImageView.h</string>
  676 + </object>
  677 + </object>
  678 + </object>
584 679 </object>
585   - <object class="IBClassDescriber" key="IBDocument.Classes"/>
586 680 <int key="IBDocument.localizationMode">0</int>
587 681 <string key="IBDocument.LastKnownRelativeProjectPath">../MacFusion2.xcodeproj</string>
588 682 <int key="IBDocument.defaultPropertyAccessControl">3</int>
6 Resources/topView.xib
@@ -34,7 +34,7 @@
34 34 <object class="NSTextField" id="761970304">
35 35 <reference key="NSNextResponder" ref="1005"/>
36 36 <int key="NSvFlags">268</int>
37   - <string key="NSFrame">{{20, 20}, {145, 22}}</string>
  37 + <string key="NSFrame">{{20, 20}, {224, 22}}</string>
38 38 <reference key="NSSuperview" ref="1005"/>
39 39 <bool key="NSEnabled">YES</bool>
40 40 <object class="NSTextFieldCell" key="NSCell" id="636741428">
@@ -238,7 +238,7 @@
238 238 <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
239 239 <string>com.apple.InterfaceBuilderKit</string>
240 240 <string>com.apple.InterfaceBuilderKit</string>
241   - <string>{{21, 1449}, {320, 62}}</string>
  241 + <string>{{494, 684}, {320, 62}}</string>
242 242 <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
243 243 <string>{628, 654}</string>
244 244 <string>{{797, 991}, {320, 62}}</string>
@@ -298,7 +298,7 @@
298 298 </object>
299 299 </object>
300 300 <int key="IBDocument.localizationMode">0</int>
301   - <string key="IBDocument.LastKnownRelativeProjectPath">MacFusion2.xcodeproj</string>
  301 + <string key="IBDocument.LastKnownRelativeProjectPath">../MacFusion2.xcodeproj</string>
302 302 <int key="IBDocument.defaultPropertyAccessControl">3</int>
303 303 </data>
304 304 </archive>
1  SSHFS/SSHFSDelegate.m
@@ -52,6 +52,7 @@ - (NSArray*)secretsClientsList;
52 52 #pragma mark Mounting
53 53 - (NSArray*)taskArgumentsForParameters:(NSDictionary*)parameters
54 54 {
  55 + // MFLogS(self, @"Parameters received %@", parameters);
55 56 NSMutableArray* arguments = [NSMutableArray array];
56 57 [arguments addObject: [NSString stringWithFormat:@"%@@%@:%@",
57 58 [parameters objectForKey: kNetFSUserParameter],
20 Settings/MFIconSettingImageView.h
... ... @@ -0,0 +1,20 @@
  1 +//
  2 +// MFIconSettingImageView.h
  3 +// MacFusion2
  4 +//
  5 +// Created by Michael Gorbach on 3/19/08.
  6 +// Copyright 2008 Michael Gorbach. All rights reserved.
  7 +//
  8 +
  9 +#import <Cocoa/Cocoa.h>
  10 +@class MFClientFS;
  11 +
  12 +@interface MFIconSettingImageView : NSView {
  13 + MFClientFS* fs;
  14 + CIImage* normalImage;
  15 + CIImage* selectedImage;
  16 + BOOL dragHighlight;
  17 +}
  18 +
  19 +@property(readwrite, retain) MFClientFS* fs;
  20 +@end
226 Settings/MFIconSettingImageView.m
... ... @@ -0,0 +1,226 @@
  1 +//
  2 +// MFIconSettingImageView.m
  3 +// MacFusion2
  4 +//
  5 +// Created by Michael Gorbach on 3/19/08.
  6 +// Copyright 2008 Michael Gorbach. All rights reserved.
  7 +//
  8 +
  9 +#import "MFIconSettingImageView.h"
  10 +#import "MFClientFS.h"
  11 +#import <QuartzCore/QuartzCore.h>
  12 +#import "MGNSImage.h"
  13 +
  14 +@implementation MFIconSettingImageView
  15 ++ (void)initialize
  16 +{
  17 + [self exposeBinding: @"fs"];
  18 +}
  19 +
  20 +- (id)initWithFrame:(NSRect)frame
  21 +{
  22 + if (self = [super initWithFrame: frame])
  23 + {
  24 + // MFLogS(self, @"Registering for types");
  25 + [self registerForDraggedTypes:
  26 + [NSArray arrayWithObjects: NSFilenamesPboardType, (NSString*)kUTTypeAppleICNS,
  27 + nil] ];
  28 + dragHighlight = NO;
  29 + }
  30 +
  31 + return self;
  32 +}
  33 +
  34 +- (void)recalcImages
  35 +{
  36 + NSRect rect = [self bounds];
  37 + NSImage* imageToDraw = [fs iconImage];
  38 + normalImage = [[[imageToDraw ciImageRepresentation] ciImageByScalingToSize:
  39 + NSMakeSize(rect.size.width, rect.size.height)] flippedImage];
  40 + CIFilter* bloomFilter = [CIFilter filterWithName:@"CIBloom"];
  41 + // [bloomFilter setDefaults];
  42 + [bloomFilter setValue:[NSNumber numberWithFloat:2.5] forKey:@"inputRadius"];
  43 + [bloomFilter setValue:[NSNumber numberWithFloat:0.7] forKey:@"inputIntensity"];
  44 + [bloomFilter setValue: normalImage forKey: @"inputImage"];
  45 + // ciRep = [bloomFilter valueForKey: @"outputImage"];
  46 + selectedImage = [bloomFilter valueForKey:@"outputImage"];
  47 + [self setNeedsDisplay: YES];
  48 +}
  49 +
  50 +- (void)awakeFromNib
  51 +{
  52 + [self addObserver:self
  53 + forKeyPath:@"fs.imagePath"
  54 + options:NSKeyValueObservingOptionNew
  55 + context:self];
  56 +}
  57 +
  58 +- (void)drawRect:(NSRect)rect
  59 +{
  60 + // MFLogS(self, @"Image is %@", image);
  61 + [[NSGraphicsContext currentContext] setImageInterpolation: NSImageInterpolationHigh];
  62 + CIImage* imageToDraw = ([[self window] firstResponder] == self) ? selectedImage : normalImage;
  63 +
  64 + if (dragHighlight)
  65 + {
  66 + [[NSColor darkGrayColor] set];
  67 + [NSBezierPath setDefaultLineWidth: 3.0];
  68 + [NSBezierPath strokeRect: rect];
  69 + }
  70 +
  71 + [imageToDraw drawInRect:rect
  72 + fromRect:NSMakeRect(0, 0, rect.size.width, rect.size.height)
  73 + operation:NSCompositeSourceOver
  74 + fraction:1.0];
  75 +}
  76 +
  77 +# pragma mark C&P
  78 +- (void)setImageFromPasteboard:(NSPasteboard*)pb
  79 +{
  80 + // MFLogS(self, @"Pasting pb types %@", [pb types]);
  81 + NSImage* imageToSet = nil;
  82 +
  83 + // Try getting filename data first
  84 + NSArray* fileNameData = [pb propertyListForType: NSFilenamesPboardType];
  85 + NSString* firstFileName = [fileNameData objectAtIndex: 0];
  86 + if ([firstFileName isLike:@"*.icns"])
  87 + {
  88 + NSImage* iconImage = [[NSImage alloc] initWithContentsOfFile: firstFileName];
  89 + if (iconImage)
  90 + imageToSet = iconImage;
  91 + }
  92 +
  93 + if(!imageToSet)
  94 + {
  95 + NSData* icnsData = [pb dataForType: (NSString*)kUTTypeAppleICNS];
  96 + NSImage* icnsImage = [[NSImage alloc] initWithData: icnsData];
  97 + if (icnsImage)
  98 + imageToSet = icnsImage;
  99 + }
  100 +
  101 + if (imageToSet)
  102 + {
  103 + [self.fs setIconImage: imageToSet];
  104 + [self setNeedsDisplay: YES];
  105 + }
  106 +}
  107 +
  108 +
  109 +
  110 +- (void)paste:(id)paste
  111 +{
  112 + [self setImageFromPasteboard: [NSPasteboard generalPasteboard]];
  113 +}
  114 +
  115 +# pragma mark NSResponder
  116 +- (BOOL)acceptsFirstResponder
  117 +{
  118 + return YES;
  119 +}
  120 +
  121 +- (BOOL)becomeFirstResponder
  122 +{
  123 + [self setNeedsDisplay: YES];
  124 + return YES;
  125 +}
  126 +
  127 +- (void)resignFirstResponder
  128 +{
  129 + [self setNeedsDisplay: YES];
  130 +}
  131 +
  132 +- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
  133 +{
  134 + // MFLogS(self, @"Validating %@", item);
  135 + if ([item action] == @selector(paste:))
  136 + {
  137 + if ([[NSPasteboard generalPasteboard] dataForType: (NSString*)kUTTypeAppleICNS])
  138 + return YES;
  139 +
  140 + NSArray* fileNames = [[NSPasteboard generalPasteboard] propertyListForType: NSFilenamesPboardType];
  141 + if (fileNames && [[fileNames objectAtIndex: 0] isLike: @"*.icns"])
  142 + return YES;
  143 +
  144 + return NO;
  145 + }
  146 +
  147 + return NO;
  148 +}
  149 +
  150 +- (void)keyDown:(NSEvent*)event
  151 +{
  152 + if ([event keyCode] == 117)
  153 + {
  154 + [fs setIconImage: nil];
  155 + [self setNeedsDisplay: YES];
  156 + }
  157 + else
  158 + {
  159 + [super keyDown: event];
  160 + }
  161 +}
  162 +
  163 +# pragma mark D&D
  164 +- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
  165 +{
  166 + NSPasteboard* pb = [sender draggingPasteboard];
  167 + NSString* type = [pb availableTypeFromArray: [NSArray arrayWithObjects: NSFilenamesPboardType,
  168 + (NSString*)kUTTypeAppleICNS, nil]];
  169 + if (type)
  170 + {
  171 + dragHighlight = YES;
  172 + [self setNeedsDisplay: YES];
  173 + return NSDragOperationCopy;
  174 + }
  175 +
  176 + return NSDragOperationNone;
  177 +}
  178 +
  179 +- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
  180 +{
  181 + return NSDragOperationCopy;
  182 +}
  183 +
  184 +- (void)draggingExited:(id <NSDraggingInfo>)sender
  185 +{
  186 + dragHighlight = NO;
  187 + [self setNeedsDisplay: YES];
  188 +}
  189 +
  190 +- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
  191 +{
  192 + return NSDragOperationCopy;
  193 +}
  194 +
  195 +- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
  196 +{
  197 + return YES;
  198 +}
  199 +
  200 +- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
  201 +{
  202 + [self setImageFromPasteboard: [sender draggingPasteboard]];
  203 + return YES;
  204 +}
  205 +
  206 +- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
  207 +{
  208 + dragHighlight = NO;
  209 + [self setNeedsDisplay: YES];
  210 +}
  211 +
  212 +# pragma mark KVO
  213 +- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
  214 + change:(NSDictionary *)change context:(void *)context
  215 +{
  216 + // MFLogS(self, @"Observe triggered");
  217 + if (context == self) {
  218 + [self recalcImages];
  219 + }
  220 + else {
  221 + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  222 + }
  223 +}
  224 +
  225 +@synthesize fs;
  226 +@end

0 comments on commit 240aeb1

Please sign in to comment.
Something went wrong with that request. Please try again.