| @@ -19,8 +19,6 @@ | |||
| #include "pugl.hpp" | |||
| #include "../../distrho/extra/String.hpp" | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| # include <direct.h> | |||
| # include <winsock2.h> | |||
| @@ -451,62 +449,20 @@ bool Window::PrivateData::removeIdleCallback(IdleCallback* const callback) | |||
| // ----------------------------------------------------------------------- | |||
| // file handling | |||
| bool Window::PrivateData::openFileBrowser(const Window::FileBrowserOptions& options) | |||
| bool Window::PrivateData::openFileBrowser(const FileBrowserOptions& options) | |||
| { | |||
| using DISTRHO_NAMESPACE::String; | |||
| // -------------------------------------------------------------------------- | |||
| // configure start dir | |||
| String startDir(options.startDir); | |||
| if (startDir.isEmpty()) | |||
| { | |||
| // TESTING verify this whole thing... | |||
| # ifdef DISTRHO_OS_WINDOWS | |||
| if (char* const cwd = _getcwd(nullptr, 0)) | |||
| { | |||
| startDir = cwd; | |||
| std::free(cwd); | |||
| } | |||
| # else | |||
| if (char* const cwd = getcwd(nullptr, 0)) | |||
| { | |||
| startDir = cwd; | |||
| std::free(cwd); | |||
| } | |||
| # endif | |||
| } | |||
| DISTRHO_SAFE_ASSERT_RETURN(startDir.isNotEmpty(), false); | |||
| if (! startDir.endsWith(DISTRHO_OS_SEP)) | |||
| startDir += DISTRHO_OS_SEP_STR; | |||
| // -------------------------------------------------------------------------- | |||
| // configure window title | |||
| String windowTitle(options.title); | |||
| if (windowTitle.isEmpty()) | |||
| { | |||
| windowTitle = puglGetWindowTitle(view); | |||
| if (windowTitle.isEmpty()) | |||
| windowTitle = "FileBrowser"; | |||
| } | |||
| // -------------------------------------------------------------------------- | |||
| // show | |||
| if (fileBrowserHandle != nullptr) | |||
| fileBrowserClose(fileBrowserHandle); | |||
| fileBrowserHandle = fileBrowserOpen(isEmbed, | |||
| puglGetNativeWindow(view), autoScaling ? autoScaleFactor : scaleFactor, | |||
| startDir, | |||
| windowTitle.buffer(), | |||
| options); | |||
| FileBrowserOptions options2 = options; | |||
| if (options2.title == nullptr) | |||
| options2.title = puglGetWindowTitle(view); | |||
| fileBrowserHandle = fileBrowserCreate(isEmbed, | |||
| puglGetNativeWindow(view), | |||
| autoScaling ? autoScaleFactor : scaleFactor, | |||
| options2); | |||
| return fileBrowserHandle != nullptr; | |||
| } | |||
| @@ -159,7 +159,7 @@ struct Window::PrivateData : IdleCallback { | |||
| #ifndef DGL_FILE_BROWSER_DISABLED | |||
| // file handling | |||
| bool openFileBrowser(const Window::FileBrowserOptions& options); | |||
| bool openFileBrowser(const FileBrowserOptions& options); | |||
| #endif | |||
| static void renderToPicture(const char* filename, const GraphicsContext& context, uint width, uint height); | |||
| @@ -16,12 +16,15 @@ | |||
| #include "FileBrowserDialog.hpp" | |||
| #include "ScopedPointer.hpp" | |||
| #include "String.hpp" | |||
| #ifdef DISTRHO_OS_MAC | |||
| # import <Cocoa/Cocoa.h> | |||
| #endif | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| # include <process.h> | |||
| # include <winsock2.h> | |||
| # include <windows.h> | |||
| # include <vector> | |||
| #endif | |||
| #ifdef HAVE_DBUS | |||
| @@ -226,13 +229,40 @@ namespace DISTRHO_FILE_BROWSER_DIALOG_EXTRA_NAMESPACE { | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| FileBrowserHandle fileBrowserOpen(const bool isEmbed, | |||
| const uintptr_t windowId, | |||
| const double scaleFactor, | |||
| const char* const startDir, | |||
| const char* const windowTitle, | |||
| const FileBrowserOptions& options) | |||
| FileBrowserHandle fileBrowserCreate(const bool isEmbed, | |||
| const uintptr_t windowId, | |||
| const double scaleFactor, | |||
| const FileBrowserOptions& options) | |||
| { | |||
| String startDir(options.startDir); | |||
| if (startDir.isEmpty()) | |||
| { | |||
| #ifdef DISTRHO_OS_WINDOWS | |||
| if (char* const cwd = _getcwd(nullptr, 0)) | |||
| { | |||
| startDir = cwd; | |||
| std::free(cwd); | |||
| } | |||
| #else | |||
| if (char* const cwd = getcwd(nullptr, 0)) | |||
| { | |||
| startDir = cwd; | |||
| std::free(cwd); | |||
| } | |||
| #endif | |||
| } | |||
| DISTRHO_SAFE_ASSERT_RETURN(startDir.isNotEmpty(), nullptr); | |||
| if (! startDir.endsWith(DISTRHO_OS_SEP)) | |||
| startDir += DISTRHO_OS_SEP_STR; | |||
| String windowTitle(options.title); | |||
| if (windowTitle.isEmpty()) | |||
| windowTitle = "FileBrowser"; | |||
| ScopedPointer<FileBrowserData> handle; | |||
| handle = new FileBrowserData(isEmbed); | |||
| @@ -360,9 +390,6 @@ FileBrowserHandle fileBrowserOpen(const bool isEmbed, | |||
| // might be unused | |||
| (void)windowId; | |||
| (void)scaleFactor; | |||
| (void)startDir; | |||
| (void)windowTitle; | |||
| (void)options; | |||
| } | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| @@ -447,6 +474,7 @@ bool fileBrowserIdle(const FileBrowserHandle handle) | |||
| } | |||
| } | |||
| #endif | |||
| #ifdef HAVE_X11 | |||
| Display* const x11display = handle->x11display; | |||
| @@ -30,11 +30,8 @@ typedef FileBrowserData* FileBrowserHandle; | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| /** | |||
| File browser options. | |||
| @see Window::openFileBrowser | |||
| @note This is exactly the same API as provided by the Window class, | |||
| but redefined so that non-embed/DGL based UIs can still use file browser related functions. | |||
| File browser options, for customizing the file browser dialog.@n | |||
| By default the file browser dialog will be work as "open file" in the current working directory. | |||
| */ | |||
| struct FileBrowserOptions { | |||
| /** Whether we are saving, opening files otherwise (default) */ | |||
| @@ -91,24 +88,35 @@ struct FileBrowserOptions { | |||
| namespace DISTRHO_FILE_BROWSER_DIALOG_EXTRA_NAMESPACE { | |||
| #endif | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| FileBrowserHandle fileBrowserOpen(bool isEmbed, uintptr_t windowId, double scaleFactor, | |||
| const char* startDir, const char* windowTitle, const FileBrowserOptions& options); | |||
| /** | |||
| Create a new file browser dialog. | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| // returns true if dialog was closed (with or without a file selection) | |||
| @p isEmbed: Whether the window this dialog belongs to is an embed/child window (needed to close dialog on Windows) | |||
| @p windowId: The native window id to attach this dialog to as transient parent (X11 Window, HWND or NSView*) | |||
| @p scaleFactor: Scale factor to use (only used on X11) | |||
| @p options: Extra options, optional | |||
| By default the file browser dialog will be work as "open file" in the current working directory. | |||
| */ | |||
| FileBrowserHandle fileBrowserCreate(bool isEmbed, | |||
| uintptr_t windowId, | |||
| double scaleFactor, | |||
| const FileBrowserOptions& options = {}); | |||
| /** | |||
| Idle the file browser dialog handle.@n | |||
| Returns true if dialog was closed (with or without a file selection), handle must not be used afterwards. | |||
| */ | |||
| bool fileBrowserIdle(const FileBrowserHandle handle); | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| // close sofd file dialog | |||
| /** | |||
| Close the file browser dialog, handle must not be used afterwards. | |||
| */ | |||
| void fileBrowserClose(const FileBrowserHandle handle); | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| // get path chosen via sofd file dialog | |||
| /** | |||
| Get the path chosen by the user or null.@n | |||
| Should only be called after fileBrowserIdle returns true. | |||
| */ | |||
| const char* fileBrowserGetPath(const FileBrowserHandle handle); | |||
| // -------------------------------------------------------------------------------------------------------------------- | |||
| @@ -433,7 +433,7 @@ inline bool UI::PrivateData::fileRequestCallback(const char* const key) | |||
| snprintf(title, sizeof(title)-1u, DISTRHO_PLUGIN_NAME ": %s", key); | |||
| title[sizeof(title)-1u] = '\0'; | |||
| DGL_NAMESPACE::Window::FileBrowserOptions opts; | |||
| FileBrowserOptions opts; | |||
| opts.title = title; | |||
| return window->openFileBrowser(opts); | |||
| #endif | |||