Skip to content

Commit

Permalink
Remember last used welcome panel, show confimation dialog after insta…
Browse files Browse the repository at this point in the history
…lling plugdata package
  • Loading branch information
timothyschoen committed Nov 27, 2024
1 parent 89a5c90 commit f82a83d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
11 changes: 6 additions & 5 deletions Source/Dialogs/Dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,17 @@ void Dialogs::showMainMenu(PluginEditor* editor, Component* centre)
}
}

void Dialogs::showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component* parent, String const& title, std::function<void(int)> const& callback, StringArray const& options)
void Dialogs::showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component* parent, String const& title, std::function<void(int)> const& callback, StringArray const& options, String const& icon)
{

class MultiChoiceDialog : public Component {

TextLayout layout;
String icon;

public:
MultiChoiceDialog(Dialog* dialog, String const& title, std::function<void(int)> const& callback, StringArray const& options)
: label("", title)
MultiChoiceDialog(Dialog* dialog, String const& title, std::function<void(int)> const& callback, StringArray const& options, String const& icon)
: label("", title), icon(icon)
{
auto attributedTitle = AttributedString(title);
attributedTitle.setJustification(Justification::horizontallyCentred);
Expand Down Expand Up @@ -289,7 +290,7 @@ void Dialogs::showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component*

void paint(Graphics& g) override
{
AttributedString warningIcon(Icons::Warning);
AttributedString warningIcon(icon);
warningIcon.setFont(Fonts::getIconFont().withHeight(48));
warningIcon.setColour(findColour(PlugDataColour::panelTextColourId));
warningIcon.setJustification(Justification::centred);
Expand Down Expand Up @@ -317,7 +318,7 @@ void Dialogs::showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component*
};

auto* dialog = new Dialog(target, parent, 270, 220, false);
auto* dialogContent = new MultiChoiceDialog(dialog, title, callback, options);
auto* dialogContent = new MultiChoiceDialog(dialog, title, callback, options, icon);

dialog->height = dialogContent->getBestHeight();
dialog->setViewedComponent(dialogContent);
Expand Down
2 changes: 1 addition & 1 deletion Source/Dialogs/Dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct Dialogs {

static void showMainMenu(PluginEditor* editor, Component* centre);

static void showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component* parent, String const& title, std::function<void(int)> const& callback, StringArray const& options = { "Okay", "Cancel " });
static void showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component* parent, String const& title, std::function<void(int)> const& callback, StringArray const& options = { "Okay", "Cancel " }, String const& icon = Icons::Warning);

static void showHeavyExportDialog(std::unique_ptr<Dialog>* target, Component* parent);

Expand Down
11 changes: 7 additions & 4 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,18 @@ PluginEditor::PluginEditor(PluginProcessor& p)
addChildComponent(recentlyOpenedPanelSelector);
addChildComponent(libraryPanelSelector);

recentlyOpenedPanelSelector.onClick = [this](){
recentlyOpenedPanelSelector.onClick = [this, settingsFile](){
settingsFile->setProperty("last_welcome_panel", var(0));
welcomePanel->setShownTab(WelcomePanel::Home);
};
libraryPanelSelector.onClick = [this](){
libraryPanelSelector.onClick = [this, settingsFile](){
settingsFile->setProperty("last_welcome_panel", var(1));
welcomePanel->setShownTab(WelcomePanel::Library);
};


recentlyOpenedPanelSelector.setToggleState(true, dontSendNotification); // TODO: save the last panel value to settings
auto lastWelcomePanel = settingsFile->getProperty<int>("last_welcome_panel");
recentlyOpenedPanelSelector.setToggleState(!lastWelcomePanel, sendNotification);
libraryPanelSelector.setToggleState(lastWelcomePanel, sendNotification);

// Edit, run and presentation mode buttons
for (auto* button : SmallArray<ToolbarRadioButton*> { &editButton, &runButton, &presentButton }) {
Expand Down
5 changes: 3 additions & 2 deletions Source/Standalone/PlugDataApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class PlugDataApp : public JUCEApplication {
else if(file.hasFileExtension("plugdata")) {
auto zip = ZipFile(file);
auto result = zip.uncompressTo(ProjectInfo::appDataDir.getChildFile("Patches"), false);
auto* editor = dynamic_cast<PluginEditor*>(mainWindow->mainComponent->getEditor());
if(result.wasOk())
{
auto macOSTrash = ProjectInfo::appDataDir.getChildFile("Patches").getChildFile("__MACOSX");
Expand All @@ -106,10 +107,10 @@ class PlugDataApp : public JUCEApplication {
macOSTrash.deleteRecursively();
}

// TODO: show success dialog
Dialogs::showMultiChoiceDialog(&editor->openedDialog, editor, "Successfully installed " + file.getFileNameWithoutExtension(), [](int){}, { "Dismiss" }, Icons::Checkmark);
}
else {
// TODO: show error dialog
Dialogs::showMultiChoiceDialog(&editor->openedDialog, editor, "Failed to install " + file.getFileNameWithoutExtension(), [](int){}, { "Dismiss" });
}
}
}
Expand Down

0 comments on commit f82a83d

Please sign in to comment.