Browse Source

Implement Window::openFileBrowser() fallback for state files

pull/282/head
falkTX 4 years ago
parent
commit
c153a8b36c
1 changed files with 48 additions and 9 deletions
  1. +48
    -9
      distrho/src/DistrhoUIPrivateData.hpp

+ 48
- 9
distrho/src/DistrhoUIPrivateData.hpp View File

@@ -94,6 +94,9 @@ struct UI::PrivateData {
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
double scaleFactor;
uintptr_t winId;
# ifndef DGL_FILE_BROWSER_DISABLED
char* uiStateFileKeyRequest;
# endif
#endif

// Callbacks
@@ -118,6 +121,9 @@ struct UI::PrivateData {
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
scaleFactor(1.0),
winId(0),
# ifndef DGL_FILE_BROWSER_DISABLED
uiStateFileKeyRequest(nullptr),
# endif
#endif
callbacksPtr(nullptr),
editParamCallbackFunc(nullptr),
@@ -144,6 +150,11 @@ struct UI::PrivateData {
#endif
}

~PrivateData() noexcept
{
std::free(uiStateFileKeyRequest);
}

void editParamCallback(const uint32_t rindex, const bool started)
{
if (editParamCallbackFunc != nullptr)
@@ -174,15 +185,8 @@ struct UI::PrivateData {
setSizeCallbackFunc(callbacksPtr, width, height);
}

bool fileRequestCallback(const char* key)
{
if (fileRequestCallbackFunc != nullptr)
return fileRequestCallbackFunc(callbacksPtr, key);

// TODO use old style DPF dialog here

return false;
}
// implemented below, after PluginWindow
bool fileRequestCallback(const char* const key);

static UI::PrivateData* s_nextPrivateData;
static PluginWindow& createNextWindow(UI* ui, uint width, uint height);
@@ -261,6 +265,16 @@ protected:
{
DISTRHO_SAFE_ASSERT_RETURN(ui != nullptr,);

# if DISTRHO_PLUGIN_WANT_STATEFILES
if (char* const key = ui->uiData->uiStateFileKeyRequest)
{
ui->uiData->uiStateFileKeyRequest = nullptr;
ui->stateChanged(key, filename);
std::free(key);
return;
}
# endif

ui->uiFileBrowserSelected(filename);
}
# endif
@@ -269,6 +283,31 @@ protected:
};
#endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI

// -----------------------------------------------------------------------
// UI private data fileRequestCallback, which requires PluginWindow definitions

inline bool UI::PrivateData::fileRequestCallback(const char* const key)
{
if (fileRequestCallbackFunc != nullptr)
return fileRequestCallbackFunc(callbacksPtr, key);

#if DISTRHO_PLUGIN_WANT_STATEFILES && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI && !defined(DGL_FILE_BROWSER_DISABLED)
std::free(uiStateFileKeyRequest);
uiStateFileKeyRequest = strdup(key);
DISTRHO_SAFE_ASSERT_RETURN(uiStateFileKeyRequest != nullptr, false);

char title[0xff];
snprintf(title, sizeof(title)-1u, DISTRHO_PLUGIN_NAME ": %s", key);
title[sizeof(title)-1u] = '\0';

Window::FileBrowserOptions opts;
opts.title = title;
return window->openFileBrowser(opts);
#endif

return false;
}

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO


Loading…
Cancel
Save