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 app {
widget::Widget* createMenuBar(CardinalPluginContext* context, bool isStandalone);
widget::Widget* createMenuBar(Window& window, bool isStandalone);
}
namespace window {
void WindowInit(Window* window, DISTRHO_NAMESPACE::UI* ui);
@ -116,7 +116,7 @@ public:
rack::window::WindowInit(fContext->window, this);
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);
}
@ -476,6 +476,12 @@ protected:
fContext->event->handleLeave();
}
void uiFileBrowserSelected(const char* const filename) override
{
const ScopedContext sc(this);
fContext->patch->loadAction(filename);
}
private:
/**
Set our UI class as non-copyable and add a leak detector just in case.

View file

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