23 #import <Foundation/NSError.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSArray.h>
26 #import <Foundation/NSBundle.h>
27 #import <Foundation/NSFileManager.h>
28 #import <Foundation/NSNotification.h>
29 #import <Foundation/NSUserDefaults.h>
30 #import <Foundation/NSException.h>
31 #import <Foundation/NSValue.h>
33 #import <AppKit/NSPanel.h>
34 #import <AppKit/NSTextField.h>
36 #import "FileManager.h"
60 DescribeError (NSError * error,
62 NSString * aDescription,
63 NSString * firstButton,
64 NSString * secondButton,
65 NSString * thirdButton,
68 NSString * description;
69 NSString * prefix, * errorDescription;
71 if (aDescription == nil)
79 va_start (arglist, thirdButton);
80 prefix = [NSString stringWithFormat: aDescription arguments: arglist];
83 prefix = [prefix stringByAppendingString: _(
@": ")];
86 errorDescription = [[error userInfo] objectForKey:
87 NSLocalizedDescriptionKey];
89 description = [NSString stringWithFormat:
@"%@%@", prefix, errorDescription];
91 return NSRunAlertPanel (aTitle,
113 SetFileError (NSError ** ptr,
int code, NSString * reasonFormat, ...)
118 NSDictionary * userInfo;
121 va_start (arglist, reasonFormat);
122 reason = [[[NSString alloc]
123 initWithFormat: reasonFormat arguments: arglist]
127 userInfo = [NSDictionary
128 dictionaryWithObject: reason forKey: NSLocalizedDescriptionKey];
129 *ptr = [NSError errorWithDomain: ProjectFilesErrorDomain
149 PostFilesChangedNotification (
FileManager * sender, NSString * category)
151 NSDictionary * userInfo;
152 NSString * projectPath;
153 static NSNotificationCenter * nc = nil;
157 nc = [NSNotificationCenter defaultCenter];
160 projectPath = [[sender document] fileName];
163 userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
164 projectPath,
@"Project",
165 category,
@"Category",
170 userInfo = [NSDictionary dictionaryWithObject: projectPath
174 [nc postNotificationName: ProjectFilesDidChangeNotification
187 SetTextFieldEnabled (NSTextField * tf, BOOL flag)
189 if ([tf isEnabled] != flag)
191 [tf setEnabled: flag];
192 [tf setEditable: flag];
193 [tf setSelectable: flag];
194 [tf setDrawsBackground: flag];
206 static inline NSString *
207 MakeSizeStringFromValue (
unsigned long long size)
211 return [NSString stringWithFormat: _(
@"%i bytes"), size];
213 else if (size < 1024 * 1024)
215 return [NSString stringWithFormat: _(
@"%.2f kB"), (double) size / 1024];
217 else if (size < 1024 * 1024 * 1024)
219 return [NSString stringWithFormat: _(
@"%.2f MB"), (double) size /
224 return [NSString stringWithFormat: _(
@"%.2f GB"),
225 (double) size / (1024 * 1024 * 1024)];
236 static inline NSString *
237 TranslocateLinkTarget (NSString * linkTarget, NSString * oldLocation,
238 NSString * newLocation)
241 if ([linkTarget isAbsolutePath])
247 return [newLocation stringByConstructingRelativePathTo:
248 [oldLocation stringByConcatenatingWithPath: linkTarget]];
257 PurgeUnneededDirectories (NSString * aPath, NSError ** error)
259 NSFileManager * fm = [NSFileManager defaultManager];
262 [[fm directoryContentsAtPath: aPath] count] == 0;
263 aPath = [aPath stringByDeletingLastPathComponent])
265 if (![fm removeFileAtPath: aPath handler: nil])
267 SetFileError (error, ProjectFilesDeletionError,
268 _(
@"Couldn't delete directory at path %@."), aPath);