Add native helper to open a directory
This commit is contained in:
parent
7627f7c074
commit
bd13260046
3 changed files with 41 additions and 11 deletions
|
|
@ -27,14 +27,29 @@ bool openFileInExternalEditor(const char *filename)
|
||||||
|
|
||||||
return ShellExecuteExW(&info);
|
return ShellExecuteExW(&info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool openDirectoryInExplorer(const char *filename)
|
||||||
|
{
|
||||||
|
std::wstring path = fs::u8path(filename).wstring();
|
||||||
|
|
||||||
|
SHELLEXECUTEINFOW info;
|
||||||
|
memset(&info, 0, sizeof(info));
|
||||||
|
|
||||||
|
info.cbSize = sizeof(info);
|
||||||
|
info.lpVerb = L"explore";
|
||||||
|
info.lpFile = path.c_str();
|
||||||
|
info.nShow = SW_SHOW;
|
||||||
|
|
||||||
|
return ShellExecuteExW(&info);
|
||||||
|
}
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
// implemented in NativeHelpers.mm
|
// implemented in NativeHelpers.mm
|
||||||
#else
|
#else
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
|
||||||
bool openFileInExternalEditor(const char *filename)
|
static bool openFileByMimeType(const char *filename, const char *mimetype)
|
||||||
{
|
{
|
||||||
GAppInfo* appinfo = g_app_info_get_default_for_type("text/plain", FALSE);
|
GAppInfo* appinfo = g_app_info_get_default_for_type(mimetype, FALSE);
|
||||||
if (!appinfo)
|
if (!appinfo)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
@ -47,4 +62,14 @@ bool openFileInExternalEditor(const char *filename)
|
||||||
g_object_unref(appinfo);
|
g_object_unref(appinfo);
|
||||||
return success == TRUE;
|
return success == TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool openFileInExternalEditor(const char *filename)
|
||||||
|
{
|
||||||
|
return openFileByMimeType(filename, "text/plain");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool openDirectoryInExplorer(const char *filename)
|
||||||
|
{
|
||||||
|
return openFileByMimeType(filename, "inode/directory");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
bool openFileInExternalEditor(const char *filename);
|
bool openFileInExternalEditor(const char *filename);
|
||||||
|
bool openDirectoryInExplorer(const char *filename);
|
||||||
|
|
|
||||||
|
|
@ -11,20 +11,24 @@
|
||||||
#import <CoreServices/CoreServices.h>
|
#import <CoreServices/CoreServices.h>
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
bool openFileInExternalEditor(const char *fileNameUTF8)
|
static bool openFileWithApplication(const char *fileName, NSString *application)
|
||||||
{
|
{
|
||||||
BOOL wasOpened = NO;
|
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
|
||||||
|
NSString* fileNameNs = [NSString stringWithUTF8String:fileName];
|
||||||
|
return [workspace openFile:fileNameNs withApplication:application] == YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool openFileInExternalEditor(const char *fileName)
|
||||||
|
{
|
||||||
NSURL* applicationURL = (__bridge_transfer NSURL*)LSCopyDefaultApplicationURLForContentType(
|
NSURL* applicationURL = (__bridge_transfer NSURL*)LSCopyDefaultApplicationURLForContentType(
|
||||||
kUTTypePlainText, kLSRolesEditor, nil);
|
kUTTypePlainText, kLSRolesEditor, nil);
|
||||||
if (!applicationURL)
|
if (!applicationURL || ![applicationURL isFileURL])
|
||||||
return false;
|
return false;
|
||||||
if ([applicationURL isFileURL]) {
|
return openFileWithApplication(fileName, [applicationURL path]);
|
||||||
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
|
}
|
||||||
NSString* fileName = [NSString stringWithUTF8String:fileNameUTF8];
|
|
||||||
wasOpened = [workspace openFile:fileName withApplication:[applicationURL path]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return wasOpened == YES;
|
bool openDirectoryInExplorer(const char *fileName)
|
||||||
|
{
|
||||||
|
return openFileWithApplication(fileName, @"Finder");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue