Get file->open to use DPF file browser actions, not osdialog

Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
falkTX 2021-10-22 14:22:49 +01:00
parent 88beb01572
commit c6b0a0241e
No known key found for this signature in database
GPG key ID: CDBAA37ABC74FBA0
2 changed files with 29 additions and 14 deletions

View file

@ -42,7 +42,7 @@ GLFWAPI int glfwGetKeyScancode(int key) { return 0; }
namespace rack { namespace rack {
namespace app { namespace app {
widget::Widget* createMenuBar(CardinalPluginContext* context, bool isStandalone); widget::Widget* createMenuBar(Window& window, bool isStandalone);
} }
namespace window { namespace window {
void WindowInit(Window* window, DISTRHO_NAMESPACE::UI* ui); void WindowInit(Window* window, DISTRHO_NAMESPACE::UI* ui);
@ -116,7 +116,7 @@ public:
rack::window::WindowInit(fContext->window, this); rack::window::WindowInit(fContext->window, this);
fContext->scene->removeChild(fContext->scene->menuBar); fContext->scene->removeChild(fContext->scene->menuBar);
fContext->scene->menuBar = rack::app::createMenuBar(fContext, getApp().isStandalone()); fContext->scene->menuBar = rack::app::createMenuBar(getWindow(), getApp().isStandalone());
fContext->scene->addChildBelow(fContext->scene->menuBar, fContext->scene->rackScroll); fContext->scene->addChildBelow(fContext->scene->menuBar, fContext->scene->rackScroll);
} }
@ -476,6 +476,12 @@ protected:
fContext->event->handleLeave(); fContext->event->handleLeave();
} }
void uiFileBrowserSelected(const char* const filename) override
{
const ScopedContext sc(this);
fContext->patch->loadAction(filename);
}
private: private:
/** /**
Set our UI class as non-copyable and add a leak detector just in case. Set our UI class as non-copyable and add a leak detector just in case.

View file

@ -57,6 +57,7 @@
# undef DEBUG # undef DEBUG
#endif #endif
#include <Window.hpp>
#include "../PluginContext.hpp" #include "../PluginContext.hpp"
@ -88,10 +89,11 @@ struct MenuButton : ui::Button {
struct FileButton : MenuButton { struct FileButton : MenuButton {
Window& window;
const bool isStandalone; const bool isStandalone;
FileButton(const bool standalone) FileButton(Window& win, const bool standalone)
: MenuButton(), isStandalone(standalone) {} : MenuButton(), window(win), isStandalone(standalone) {}
void onAction(const ActionEvent& e) override { void onAction(const ActionEvent& e) override {
ui::Menu* menu = createMenu(); ui::Menu* menu = createMenu();
@ -99,11 +101,16 @@ struct FileButton : MenuButton {
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y)); menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->addChild(createMenuItem("New", RACK_MOD_CTRL_NAME "+N", []() { menu->addChild(createMenuItem("New", RACK_MOD_CTRL_NAME "+N", []() {
APP->patch->loadTemplateDialog(); // APP->patch->loadTemplateDialog();
APP->patch->loadTemplate();
})); }));
menu->addChild(createMenuItem("Open", RACK_MOD_CTRL_NAME "+O", []() { menu->addChild(createMenuItem("Open", RACK_MOD_CTRL_NAME "+O", [this]() {
APP->patch->loadDialog(); Window::FileBrowserOptions opts;
const std::string dir = system::getDirectory(APP->patch->path);
opts.startDir = dir.c_str();
window.openFileBrowser(opts);
// APP->patch->loadDialog();
})); }));
/* /*
@ -121,7 +128,8 @@ struct FileButton : MenuButton {
*/ */
menu->addChild(createMenuItem("Revert", RACK_MOD_CTRL_NAME "+" RACK_MOD_SHIFT_NAME "+O", []() { menu->addChild(createMenuItem("Revert", RACK_MOD_CTRL_NAME "+" RACK_MOD_SHIFT_NAME "+O", []() {
APP->patch->revertDialog(); // APP->patch->revertDialog();
APP->patch->loadAction(APP->patch->path);
}, APP->patch->path == "")); }, APP->patch->path == ""));
if (isStandalone) { if (isStandalone) {
@ -569,11 +577,12 @@ struct MeterLabel : ui::Label {
struct MenuBar : widget::OpaqueWidget { struct MenuBar : widget::OpaqueWidget {
CardinalPluginContext* const context; // CardinalPluginContext* const context;
MeterLabel* meterLabel; MeterLabel* meterLabel;
MenuBar(CardinalPluginContext* const ctx, const bool isStandalone) MenuBar(Window& window, const bool isStandalone)
: context(ctx) : widget::OpaqueWidget()
// : context(ctx)
{ {
const float margin = 5; const float margin = 5;
box.size.y = BND_WIDGET_HEIGHT + 2 * margin; box.size.y = BND_WIDGET_HEIGHT + 2 * margin;
@ -583,7 +592,7 @@ struct MenuBar : widget::OpaqueWidget {
layout->spacing = math::Vec(0, 0); layout->spacing = math::Vec(0, 0);
addChild(layout); addChild(layout);
FileButton* fileButton = new FileButton(isStandalone); FileButton* fileButton = new FileButton(window, isStandalone);
fileButton->text = "File"; fileButton->text = "File";
layout->addChild(fileButton); layout->addChild(fileButton);
@ -636,8 +645,8 @@ widget::Widget* createMenuBar() {
return new widget::Widget; return new widget::Widget;
} }
widget::Widget* createMenuBar(CardinalPluginContext* const context, const bool isStandalone) { widget::Widget* createMenuBar(Window& window, const bool isStandalone) {
menuBar::MenuBar* menuBar = new menuBar::MenuBar(context, isStandalone); menuBar::MenuBar* menuBar = new menuBar::MenuBar(window, isStandalone);
return menuBar; return menuBar;
} }