Skip to content

Commit

Permalink
Add right click menu to tiles, add 24hour time display setting
Browse files Browse the repository at this point in the history
  • Loading branch information
alcomposer committed Nov 27, 2024
1 parent ab94bca commit e0393c6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
61 changes: 56 additions & 5 deletions Source/Components/WelcomePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class WelcomePanel : public Component
nvgFillColor(nvg, NVGComponent::convertColour(findColour(PlugDataColour::panelTextColourId)));
nvgText(nvg, 96, 138, "Recently Opened", NULL);

nvgFontFace(nvg, "plugdata_icon_font");
nvgFontFace(nvg, "icon_font-Regular");
nvgFontSize(nvg, 14);
nvgFillColor(nvg, NVGComponent::convertColour(findColour(PlugDataColour::panelTextColourId).withAlpha(isHoveringClearButton ? 0.6f : 1.0f)));
nvgText(nvg, clearButtonBounds.getCentreX(), clearButtonBounds.getCentreY(), Icons::Clear.toRawUTF8(), NULL);
Expand Down Expand Up @@ -216,6 +216,7 @@ class WelcomePanel : public Component
bool isFavourited;
std::function<void()> onClick = []() { };
std::function<void(bool)> onFavourite = nullptr;
std::function<void()> onRemove = []() { };

private:
WelcomePanel& parent;
Expand All @@ -228,16 +229,31 @@ class WelcomePanel : public Component
Image thumbnailImageData;
int lastWidth = -1;
int lastHeight = -1;

String creationTimeDescription = String();

public:
WelcomePanelTile(WelcomePanel& welcomePanel, String name, String subtitle, String svgImage, Colour iconColour, float scale, bool favourited, Image const& thumbImage = Image())
WelcomePanelTile(WelcomePanel& welcomePanel, String name, String subtitle, String svgImage, Colour iconColour, float scale, bool favourited, Image const& thumbImage = Image(), Time creationTime = Time())
: isFavourited(favourited)
, parent(welcomePanel)
, snapshotScale(scale)
, tileName(name)
, tileSubtitle(subtitle)
, thumbnailImageData(thumbImage)
{
if (creationTime.getMillisecondCounter() != 0) {
auto diff = Time::getCurrentTime() - creationTime;
String date;
if (diff.inDays() < 1)
date = "Today";
else if (diff.inDays() == 1)
date = "Yesterday";
else
date = creationTime.toString(true, false);
String time = creationTime.toString(false, true, false, SettingsFile::getInstance()->getProperty<bool>("24_hour_time"));
creationTimeDescription = date + ", " + time;
}

if (!thumbImage.isValid()) {
snapshot = Drawable::createFromImageData(svgImage.toRawUTF8(), svgImage.getNumBytesAsUTF8());
if (snapshot) {
Expand Down Expand Up @@ -398,6 +414,30 @@ class WelcomePanel : public Component
repaint();
}

void mouseDown(MouseEvent const& e) override
{
if (!e.mods.isRightButtonDown())
return;

PopupMenu tileMenu;

tileMenu.addItem(String("Patch: " + tileName + ".pd"), false, false, nullptr);
tileMenu.addItem(String("Opened: " + tileSubtitle), false, false, nullptr);
tileMenu.addItem(String("Created: " + creationTimeDescription), false, false, nullptr);
tileMenu.addSeparator();
tileMenu.addItem(isFavourited ? "Remove from favourites" : "Add to favourites", [this]() {
isFavourited = !isFavourited;
onFavourite(isFavourited);
});
tileMenu.addSeparator();
tileMenu.addItem("Remove from recents", onRemove);

PopupMenu::Options options;
options.withTargetComponent(this);

tileMenu.showMenuAsync(options);
}

void mouseUp(MouseEvent const& e) override
{
if (!getScreenBounds().reduced(12).contains(e.getScreenPosition()))
Expand Down Expand Up @@ -612,6 +652,7 @@ class WelcomePanel : public Component

auto subTree = recentlyOpenedTree.getChild(i);
auto patchFile = File(subTree.getProperty("Path").toString());
auto creationTime = patchFile.getCreationTime();
auto patchThumbnailBase = File(patchFile.getParentDirectory().getFullPathName() + "\\" + patchFile.getFileNameWithoutExtension() + "_thumb");

auto favourited = subTree.hasProperty("Pinned") && static_cast<bool>(subTree.getProperty("Pinned"));
Expand Down Expand Up @@ -641,16 +682,16 @@ class WelcomePanel : public Component
auto openTime = Time(static_cast<int64>(subTree.getProperty("Time")));
auto diff = Time::getCurrentTime() - openTime;
String date;
if (diff.inDays() == 0)
if (diff.inDays() < 1)
date = "Today";
else if (diff.inDays() == 1)
date = "Yesterday";
else
date = openTime.toString(true, false);
String time = openTime.toString(false, true, false, true);
String time = openTime.toString(false, true, false, SettingsFile::getInstance()->getProperty<bool>("24_hour_time"));
String timeDescription = date + ", " + time;

auto* tile = recentlyOpenedTiles.add(new WelcomePanelTile(*this, patchFile.getFileNameWithoutExtension(), timeDescription, silhoutteSvg, snapshotColour, 1.0f, favourited, thumbImage));
auto* tile = recentlyOpenedTiles.add(new WelcomePanelTile(*this, patchFile.getFileNameWithoutExtension(), timeDescription, silhoutteSvg, snapshotColour, 1.0f, favourited, thumbImage, creationTime));
tile->onClick = [this, patchFile]() mutable {
if (patchFile.existsAsFile()) {
editor->pd->autosave->checkForMoreRecentAutosave(patchFile, editor, [this, patchFile]() {
Expand All @@ -671,6 +712,16 @@ class WelcomePanel : public Component
subTree.setProperty("Pinned", shouldBeFavourite, nullptr);
resized();
};
tile->onRemove = [this, path = subTree.getProperty("Path")]() {
auto settingsTree = SettingsFile::getInstance()->getValueTree();
auto recentlyOpenedTree = settingsTree.getChildWithName("RecentlyOpened");
auto subTree = recentlyOpenedTree.getChildWithProperty("Path", path);
recentlyOpenedTree.removeChild(subTree, nullptr);
// Make sure to clear the recent items in the current welcome panel
if (editor->welcomePanel)
editor->welcomePanel->triggerAsyncUpdate();
};

contentComponent.addAndMakeVisible(tile);
}
}
Expand Down
13 changes: 13 additions & 0 deletions Source/Dialogs/AdvancedSettingsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// WARRANTIES, see the file, "LICENSE.txt," in this distribution.
*/
#include "LookAndFeel.h"
#include "Components/WelcomePanel.h"
#include "Utility/Autosave.h"
#pragma once

Expand Down Expand Up @@ -133,6 +134,10 @@ class AdvancedSettingsPanel : public SettingsDialogPanel
centreSidepanelButtons = settingsFile->getPropertyAsValue("centre_sidepanel_buttons");
interfaceProperties.add(new PropertiesPanel::BoolComponent("Centre canvas sidepanel selectors", centreSidepanelButtons, { "No", "Yes" }));

use24HourTime.referTo(settingsFile->getPropertyAsValue("24_hour_time"));
use24HourTime.addListener(this);
interfaceProperties.add(new PropertiesPanel::BoolComponent("Use 24 hour time in welcome panel", use24HourTime, { "No", "Yes" }));

patchDownwardsOnly = settingsFile->getPropertyAsValue("patch_downwards_only");
otherProperties.add(new PropertiesPanel::BoolComponent("Patch downwards only", patchDownwardsOnly, { "No", "Yes" }));

Expand Down Expand Up @@ -177,6 +182,13 @@ class AdvancedSettingsPanel : public SettingsDialogPanel
SettingsFile::getInstance()->setProperty("default_zoom", zoom);
defaultZoom = zoom;
}
if (v.refersToSameSourceAs(use24HourTime)) {
if (auto ed = dynamic_cast<PluginEditor*>(editor)) {
std::cout << "update welcome panel" << std::endl;
if (ed->welcomePanel && ed->welcomePanel->isVisible())
ed->welcomePanel->triggerAsyncUpdate();
}
}
}
Component* editor;

Expand All @@ -185,6 +197,7 @@ class AdvancedSettingsPanel : public SettingsDialogPanel
Value defaultZoom;
Value centreResized;
Value centreSidepanelButtons;
Value use24HourTime;

Value openPatchesInWindow;
Value showPalettesValue;
Expand Down
2 changes: 1 addition & 1 deletion Source/NVGSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void NVGSurface::initialise()
nvgCreateFontMem(nvg, "Inter-Bold", (unsigned char*)BinaryData::InterBold_ttf, BinaryData::InterBold_ttfSize, 0);
nvgCreateFontMem(nvg, "Inter-SemiBold", (unsigned char*)BinaryData::InterSemiBold_ttf, BinaryData::InterSemiBold_ttfSize, 0);
nvgCreateFontMem(nvg, "Inter-Tabular", (unsigned char*)BinaryData::InterTabular_ttf, BinaryData::InterTabular_ttfSize, 0);
nvgCreateFontMem(nvg, "plugdata_icon_font", (unsigned char*)BinaryData::IconFont_ttf, BinaryData::IconFont_ttfSize, 0);
nvgCreateFontMem(nvg, "icon_font-Regular", (unsigned char*)BinaryData::IconFont_ttf, BinaryData::IconFont_ttfSize, 0);

invalidateAll();
}
Expand Down
1 change: 1 addition & 0 deletions Source/Utility/SettingsFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class SettingsFile : public ValueTree::Listener
{ "cpu_meter_mapping_mode", var(0) },
{ "centre_resized_canvas", var(true) },
{ "centre_sidepanel_buttons", var(true) },
{ "24_hour_time", var(false) },
{ "show_all_audio_device_rates", var(false) },
{ "add_object_menu_pinned", var(false) },
{ "autosave_interval", var(5) },
Expand Down

0 comments on commit e0393c6

Please sign in to comment.