Browse Source

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

Signed-off-by: falkTX <falktx@falktx.com>
tags/22.02
falkTX 3 years ago
parent
commit
c6b0a0241e
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 29 additions and 14 deletions
  1. +8
    -2
      src/CardinalUI.cpp
  2. +21
    -12
      src/override/MenuBar.cpp

+ 8
- 2
src/CardinalUI.cpp 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.


+ 21
- 12
src/override/MenuBar.cpp 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)
: MenuButton(), isStandalone(standalone) {}
FileButton(Window& win, const bool 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", []() {
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", []() { 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)
: context(ctx)
MenuBar(Window& window, const bool isStandalone)
: 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) {
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; return menuBar;
} }




Loading…
Cancel
Save