3 * Implementation of a finder menu plugin for git-cheetah
5 * This provides Mac OS X specific utility functions
7 * Copyright (C) Heiko Voigt, 2009
9 * inspired by an example from Brent Simmons
10 * brent@ranchero.com, http://macte.ch/kmyXM
13 #include "../common/git-compat-util.h"
17 #include "../common/strbuf.h"
18 #include "../common/debug.h"
19 #include "../common/exec.h"
25 const char *git_path()
30 void message_box(const char *string
)
32 CFStringRef msg
= CFStringCreateWithCString(NULL
,
33 string
, kCFStringEncodingASCII
);
35 CFUserNotificationDisplayNotice(0,
36 kCFUserNotificationNoteAlertLevel
,
37 NULL
, NULL
, NULL
, CFSTR("Git Cheetah says"),
41 int selection_to_path(char *path
, int len
, const AEDesc
*selection
)
43 AEDesc selected_item
= { typeNull
, NULL
};
47 AliasHandle item_data_handle
;
49 Boolean changed
= false;
51 if ((!get_file_from_selection(selection
, &selected_item
)) &&
52 (!get_file_from_selection_list(selection
, &selected_item
))) {
53 debug_git("failure get_file_from_*");
57 item_size
= AEGetDescDataSize(&selected_item
);
59 item_data_handle
= (AliasHandle
) NewHandle(item_size
);
60 if (item_data_handle
== nil
) {
62 goto selection_to_path_fail
;
65 if (AEGetDescData(&selected_item
, *item_data_handle
, item_size
) != noErr
) {
67 goto selection_to_path_fail
;
70 if (FSResolveAlias (NULL
, item_data_handle
, &file_ref
, &changed
) != noErr
) {
72 goto selection_to_path_fail
;
75 if (FSRefMakePath(&file_ref
, (UInt8
*) path
, len
) != noErr
)
78 selection_to_path_fail
:
79 DisposeHandle((Handle
) item_data_handle
);
80 AEDisposeDesc(&selected_item
);
85 /* if this selection is a file return it, if not NULL is returned */
86 AEDesc
*get_file_from_selection(const AEDesc
*selection
, AEDesc
*file
)
88 AEDesc temp
= { typeNull
, NULL
};
90 if (selection
->descriptorType
== typeAlias
) {
91 if (AEDuplicateDesc(selection
, file
) != noErr
)
96 if (AECoerceDesc(selection
, typeAlias
, &temp
) != noErr
)
97 goto get_file_from_selection_fail
;
99 if (temp
.descriptorType
!= typeAlias
)
100 goto get_file_from_selection_fail
;
102 if (AEDuplicateDesc(&temp
, file
) != noErr
)
103 goto get_file_from_selection_fail
;
105 /* TODO: check if this is a memory leak */
108 get_file_from_selection_fail
:
109 AEDisposeDesc(&temp
);
113 AEDesc
*get_file_from_selection_list(const AEDesc
*selection
, AEDesc
*file
116 AEDesc temp
= { typeNull
, NULL
};
121 if (selection
->descriptorType
!= typeAEList
)
124 if (AECountItems(selection
, &count
) != noErr
)
130 if (AEGetNthDesc(selection
, 1, typeWildCard
, &dummy
, &temp
) != noErr
)
133 result
= get_file_from_selection(&temp
, file
);
134 AEDisposeDesc(&temp
);