2 // LynkCreationController.m
5 // Created by MacDeveloper on
03/06/08.
6 // Copyright
2008 __MyCompanyName__.
All rights reserved.
9 #import "LynkCreationController.h"
12 @implementation LynkCreationController
15 return lynkCreationSheet
;
18 - (IBAction
) save:(id
) sender
{
19 NSMutableDictionary
*linkConfiguration
= nil
;
20 if([[[textFieldLinkDestPath stringValue
] stringByTrimmingCharactersInSet
:[NSCharacterSet whitespaceAndNewlineCharacterSet
]] length] == 0 ||
21 [[[textfieldLinkName stringValue
] stringByTrimmingCharactersInSet
:[NSCharacterSet whitespaceAndNewlineCharacterSet
]] length] == 0 )
24 //load all configuration
25 NSData
*prefData
= (NSData
*)CFPreferencesCopyValue
((CFStringRef
)PREFERENCE_LINK_CONFIGURATION
, (CFStringRef
)kAfsCommanderID
, kCFPreferencesCurrentUser
, kCFPreferencesAnyHost
);
27 linkConfiguration
= [NSPropertyListSerialization propertyListFromData
:prefData
28 mutabilityOption
:NSPropertyListMutableContainers
30 errorDescription
:nil
];
32 linkConfiguration
= [NSMutableDictionary dictionaryWithCapacity
:1];
35 [linkConfiguration setObject
:[textFieldLinkDestPath stringValue
]
36 forKey
:[textfieldLinkName stringValue
]];
38 //save new configuration
39 prefData
= [NSPropertyListSerialization dataWithPropertyList
:linkConfiguration
40 format:NSPropertyListXMLFormat_v1_0
43 CFPreferencesSetValue
((CFStringRef
)PREFERENCE_LINK_CONFIGURATION
,
45 (CFStringRef
)kAfsCommanderID
, kCFPreferencesCurrentUser
, kCFPreferencesAnyHost
);
46 CFPreferencesSynchronize
((CFStringRef
)kAfsCommanderID
, kCFPreferencesCurrentUser
, kCFPreferencesAnyHost
);
47 [NSApp endSheet
:lynkCreationSheet
];
50 - (IBAction
) cancell
:(id
) sender
{
51 [NSApp endSheet
:lynkCreationSheet
];
54 - (IBAction
) selectLinkDest
:(id
) sender
{
55 NSOpenPanel
*openPanel
= [NSOpenPanel openPanel
];
56 [openPanel setCanChooseFiles
:NO
];
57 [openPanel setCanChooseDirectories
:YES
];
58 [openPanel setAllowsMultipleSelection
:NO
];
59 choiceResult
= [openPanel runModalForTypes
:nil
];
62 if([[openPanel filenames
] count
] == 1) {
63 [textFieldLinkDestPath setStringValue
:[[openPanel filenames
] objectAtIndex
:0]];
68 [textFieldLinkDestPath setStringValue
:@""
];