Browse Source

Add UI::openFileBrowser that matches Window::openFileBrowser

pull/349/head
falkTX 4 years ago
parent
commit
c734166344
2 changed files with 70 additions and 5 deletions
  1. +1
    -1
      dgl/Window.hpp
  2. +69
    -4
      distrho/DistrhoUI.hpp

+ 1
- 1
dgl/Window.hpp View File

@@ -361,7 +361,7 @@ public:


#ifndef DGL_FILE_BROWSER_DISABLED #ifndef DGL_FILE_BROWSER_DISABLED
/** /**
Open a file browser dialog with this window as parent.
Open a file browser dialog with this window as transient parent.
A few options can be specified to setup the dialog. A few options can be specified to setup the dialog.


If a path is selected, onFileSelected() will be called with the user chosen path. If a path is selected, onFileSelected() will be called with the user chosen path.


+ 69
- 4
distrho/DistrhoUI.hpp View File

@@ -183,6 +183,72 @@ public:
void sendNote(uint8_t channel, uint8_t note, uint8_t velocity); void sendNote(uint8_t channel, uint8_t note, uint8_t velocity);
#endif #endif


#ifndef DGL_FILE_BROWSER_DISABLED
/**
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.
*/
struct FileBrowserOptions {
/**
File browser button state.
This allows to customize the behaviour of the file browse dialog buttons.
Note these are merely hints, not all systems support them.
*/
enum ButtonState {
kButtonInvisible,
kButtonVisibleUnchecked,
kButtonVisibleChecked,
};

/** Start directory, uses current working directory if null */
const char* startDir;
/** File browser dialog window title, uses "FileBrowser" if null */
const char* title;
// TODO file filter

/**
File browser buttons.
*/
struct Buttons {
/** Whether to list all files vs only those with matching file extension */
ButtonState listAllFiles;
/** Whether to show hidden files */
ButtonState showHidden;
/** Whether to show list of places (bookmarks) */
ButtonState showPlaces;

/** Constructor for default values */
Buttons()
: listAllFiles(kButtonVisibleChecked),
showHidden(kButtonVisibleUnchecked),
showPlaces(kButtonVisibleChecked) {}
} buttons;

/** Constructor for default values */
FileBrowserOptions()
: startDir(nullptr),
title(nullptr),
buttons() {}
};

/**
Open a file browser dialog with this window as transient parent.@n
A few options can be specified to setup the dialog.

If a path is selected, onFileSelected() will be called with the user chosen path.
If the user cancels or does not pick a file, onFileSelected() will be called with nullptr as filename.

This function does not block the event loop.

@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.
*/
bool openFileBrowser(const FileBrowserOptions& options = FileBrowserOptions());
#endif

#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
/* -------------------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------------------
* Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */ * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
@@ -277,7 +343,6 @@ protected:
*/ */
virtual void uiScaleFactorChanged(double scaleFactor); virtual void uiScaleFactorChanged(double scaleFactor);


#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
/** /**
Windows focus function, called when the window gains or loses the keyboard focus. Windows focus function, called when the window gains or loses the keyboard focus.
This function is for plugin UIs to be able to override Window::onFocus(bool, CrossingMode). This function is for plugin UIs to be able to override Window::onFocus(bool, CrossingMode).
@@ -297,8 +362,9 @@ protected:
The most common exception is custom OpenGL setup, but only really needed for custom OpenGL drawing code. The most common exception is custom OpenGL setup, but only really needed for custom OpenGL drawing code.
*/ */
virtual void uiReshape(uint width, uint height); virtual void uiReshape(uint width, uint height);
#endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI


# ifndef DGL_FILE_BROWSER_DISABLED
#ifndef DGL_FILE_BROWSER_DISABLED
/** /**
Window file selected function, called when a path is selected by the user, as triggered by openFileBrowser(). Window file selected function, called when a path is selected by the user, as triggered by openFileBrowser().
This function is for plugin UIs to be able to override Window::onFileSelected(const char*). This function is for plugin UIs to be able to override Window::onFileSelected(const char*).
@@ -309,8 +375,7 @@ protected:
If you need to use files as plugin state, please setup and use DISTRHO_PLUGIN_WANT_STATEFILES instead. If you need to use files as plugin state, please setup and use DISTRHO_PLUGIN_WANT_STATEFILES instead.
*/ */
virtual void uiFileBrowserSelected(const char* filename); virtual void uiFileBrowserSelected(const char* filename);
# endif
#endif // !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
#endif


/* -------------------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------------------
* UI Resize Handling, internal */ * UI Resize Handling, internal */


Loading…
Cancel
Save