Skip to content

Commit

Permalink
Update auto-preview to on click not on hold. (#1454)
Browse files Browse the repository at this point in the history
Make the feature a preference also
  • Loading branch information
baconpaul authored Nov 21, 2024
1 parent 10a872a commit f3d08c7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
50 changes: 31 additions & 19 deletions src-ui/app/browser-ui/BrowserPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "sst/jucegui/components/GlyphButton.h"
#include "sst/plugininfra/strnatcmp.h"

#include <infrastructure/user_defaults.h>

namespace scxt::ui::app::browser_ui
{
namespace jcmp = sst::jucegui::components;
Expand Down Expand Up @@ -300,24 +302,24 @@ struct DriveFSListBoxRow : public juce::Component
isMouseDownWithoutDrag = true;
if (browserPane->autoPreviewEnabled && isFile())
{
juce::Timer::callAfterDelay(500, [w = juce::Component::SafePointer(this)]() {
if (!w)
return;
if (!w->isMouseDownWithoutDrag)
return;

const auto &data = w->browserPane->devicesPane->driveFSArea->contents;
const auto &entry = data[w->rowNumber];
if (hasStartedPreview)
{
stopPreview();
}
else
{
const auto &data = browserPane->devicesPane->driveFSArea->contents;
const auto &entry = data[rowNumber];
if (browser::Browser::isLoadableSingleSample(entry.path()))
{
w->hasStartedPreview = true;
hasStartedPreview = true;
namespace cmsg = scxt::messaging::client;
scxt::messaging::client::clientSendToSerialization(
cmsg::PreviewBrowserSample({true, data[w->rowNumber].path().u8string()}),
w->browserPane->editor->msgCont);
w->repaint();
cmsg::PreviewBrowserSample({true, data[rowNumber].path().u8string()}),
browserPane->editor->msgCont);
repaint();
}
});
}
}

enclosingBox()->selectRowsBasedOnModifierKeys(rowNumber, event.mods, false);
Expand All @@ -338,9 +340,9 @@ struct DriveFSListBoxRow : public juce::Component

isMouseDownWithoutDrag = false;

stopPreview();
if (!isDragging && e.getDistanceFromDragStart() > 1.5f)
{
stopPreview();
if (auto *container = juce::DragAndDropContainer::findParentDragContainerFor(this))
{
const auto &data = browserPane->devicesPane->driveFSArea->contents;
Expand All @@ -356,7 +358,6 @@ struct DriveFSListBoxRow : public juce::Component
void mouseUp(const juce::MouseEvent &event) override
{
isMouseDownWithoutDrag = false;
stopPreview();
if (isDragging)
{
isDragging = false;
Expand All @@ -383,6 +384,7 @@ struct DriveFSListBoxRow : public juce::Component
void mouseDoubleClick(const juce::MouseEvent &event) override
{
isMouseDownWithoutDrag = false;
stopPreview();
const auto &data = browserPane->devicesPane->driveFSArea->contents;
if (rowNumber >= 0 && rowNumber < data.size())
{
Expand Down Expand Up @@ -472,9 +474,9 @@ struct DriveFSListBoxRow : public juce::Component

if (hasStartedPreview)
{
auto q = r.translated(getWidth() - r.getHeight() - 2, 0);
jcmp::GlyphPainter::paintGlyph(g, q, jcmp::GlyphPainter::SPEAKER,
textColor.withAlpha(0.5f));
// auto q = r.translated(getWidth() - r.getHeight() - 2, 0);
// jcmp::GlyphPainter::paintGlyph(g, q, jcmp::GlyphPainter::SPEAKER,
// textColor.withAlpha(0.5f));
}
g.setColour(textColor);
g.drawText(entry.path().filename().u8string(), 14, 1, width - 16, height - 2,
Expand Down Expand Up @@ -544,7 +546,15 @@ struct BrowserPaneFooter : HasEditor, juce::Component
autoPreview->setDrawMode(sst::jucegui::components::ToggleButton::DrawMode::GLYPH_WITH_BG);
autoPreview->setGlyph(sst::jucegui::components::GlyphPainter::SPEAKER);
autoPreviewAtt = std::make_unique<connectors::DirectBooleanPayloadDataAttachment>(
[](auto) {}, parent->autoPreviewEnabled);
[w = juce::Component::SafePointer(this)](auto v) {
if (!w)
return;
auto *ed = w->editor;

ed->defaultsProvider.updateUserDefaultValue(
infrastructure::DefaultKeys::browserAutoPreviewEnabled, v);
},
parent->autoPreviewEnabled);
autoPreview->setSource(autoPreviewAtt.get());
addAndMakeVisible(*autoPreview);
}
Expand Down Expand Up @@ -599,6 +609,8 @@ BrowserPane::BrowserPane(SCXTEditor *e)
: HasEditor(e), sst::jucegui::components::NamedPanel("Browser")
{
hasHamburger = true;
autoPreviewEnabled = editor->defaultsProvider.getUserDefaultValue(
infrastructure::DefaultKeys::browserAutoPreviewEnabled, true);

selectedFunction = std::make_unique<sst::jucegui::components::ToggleButtonRadioGroup>();
selectedFunctionData = std::make_unique<sfData>(this);
Expand Down
3 changes: 3 additions & 0 deletions src/infrastructure/user_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum DefaultKeys
colormapPathIfFile,
welcomeScreenSeen,
playModeExpanded,
browserAutoPreviewEnabled,

nKeys // must be last K?
};
Expand All @@ -67,6 +68,8 @@ inline std::string defaultKeyToString(DefaultKeys k)
return "welcomeScreenSeen";
case playModeExpanded:
return "playModeExpanded";
case browserAutoPreviewEnabled:
return "browserAutoPreviewEnabled";
default:
std::terminate(); // for now
}
Expand Down

0 comments on commit f3d08c7

Please sign in to comment.