Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #244 from adobe/new-open-in-os
Browse files Browse the repository at this point in the history
APIs to open a folder with file pre-selected
  • Loading branch information
redmunds committed May 14, 2013
2 parents ab2a8a9 + 5f21d8f commit ee955f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
12 changes: 11 additions & 1 deletion appshell/appshell_extensions_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,17 @@ - (void) timeoutTimer:(NSTimer*)timer
int32 ShowFolderInOSWindow(ExtensionString pathname)
{
NSString *filepath = [NSString stringWithUTF8String:pathname.c_str()];
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:[NSArray arrayWithObject: [NSURL fileURLWithPath: filepath]]];
BOOL isDirectory;

if (![[NSFileManager defaultManager] fileExistsAtPath:filepath isDirectory:&isDirectory]) {
return ERR_NOT_FOUND;
}

if (isDirectory) {
[[NSWorkspace sharedWorkspace] openFile:filepath];
} else {
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:[NSArray arrayWithObject: [NSURL fileURLWithPath: filepath]]];
}
return NO_ERROR;
}

Expand Down
21 changes: 20 additions & 1 deletion appshell/appshell_extensions_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,26 @@ time_t FiletimeToTime(FILETIME const& ft) {
}

int32 ShowFolderInOSWindow(ExtensionString pathname) {
ShellExecute(NULL, L"open", pathname.c_str(), NULL, NULL, SW_SHOWDEFAULT);
ConvertToNativePath(pathname);

DWORD dwAttr = GetFileAttributes(pathname.c_str());
if (dwAttr == INVALID_FILE_ATTRIBUTES) {
return ConvertWinErrorCode(GetLastError());
}

if ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
// Folder: open it directly, with nothing selected inside
ShellExecute(NULL, L"open", pathname.c_str(), NULL, NULL, SW_SHOWDEFAULT);

} else {
// File: open its containing folder with this file selected
ITEMIDLIST *pidl = ILCreateFromPath(pathname.c_str());
if (pidl) {
SHOpenFolderAndSelectItems(pidl,0,0,0);
ILFree(pidl);
}
}

return NO_ERROR;
}

Expand Down

0 comments on commit ee955f1

Please sign in to comment.