Skip to content

Commit f82a83d

Browse files
committed
Remember last used welcome panel, show confimation dialog after installing plugdata package
1 parent 89a5c90 commit f82a83d

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

Source/Dialogs/Dialogs.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,17 @@ void Dialogs::showMainMenu(PluginEditor* editor, Component* centre)
244244
}
245245
}
246246

247-
void Dialogs::showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component* parent, String const& title, std::function<void(int)> const& callback, StringArray const& options)
247+
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)
248248
{
249249

250250
class MultiChoiceDialog : public Component {
251251

252252
TextLayout layout;
253+
String icon;
253254

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

290291
void paint(Graphics& g) override
291292
{
292-
AttributedString warningIcon(Icons::Warning);
293+
AttributedString warningIcon(icon);
293294
warningIcon.setFont(Fonts::getIconFont().withHeight(48));
294295
warningIcon.setColour(findColour(PlugDataColour::panelTextColourId));
295296
warningIcon.setJustification(Justification::centred);
@@ -317,7 +318,7 @@ void Dialogs::showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component*
317318
};
318319

319320
auto* dialog = new Dialog(target, parent, 270, 220, false);
320-
auto* dialogContent = new MultiChoiceDialog(dialog, title, callback, options);
321+
auto* dialogContent = new MultiChoiceDialog(dialog, title, callback, options, icon);
321322

322323
dialog->height = dialogContent->getBestHeight();
323324
dialog->setViewedComponent(dialogContent);

Source/Dialogs/Dialogs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct Dialogs {
159159

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

162-
static void showMultiChoiceDialog(std::unique_ptr<Dialog>* target, Component* parent, String const& title, std::function<void(int)> const& callback, StringArray const& options = { "Okay", "Cancel " });
162+
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);
163163

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

Source/PluginEditor.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,18 @@ PluginEditor::PluginEditor(PluginProcessor& p)
214214
addChildComponent(recentlyOpenedPanelSelector);
215215
addChildComponent(libraryPanelSelector);
216216

217-
recentlyOpenedPanelSelector.onClick = [this](){
217+
recentlyOpenedPanelSelector.onClick = [this, settingsFile](){
218+
settingsFile->setProperty("last_welcome_panel", var(0));
218219
welcomePanel->setShownTab(WelcomePanel::Home);
219220
};
220-
libraryPanelSelector.onClick = [this](){
221+
libraryPanelSelector.onClick = [this, settingsFile](){
222+
settingsFile->setProperty("last_welcome_panel", var(1));
221223
welcomePanel->setShownTab(WelcomePanel::Library);
222224
};
223225

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

227230
// Edit, run and presentation mode buttons
228231
for (auto* button : SmallArray<ToolbarRadioButton*> { &editButton, &runButton, &presentButton }) {

Source/Standalone/PlugDataApp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class PlugDataApp : public JUCEApplication {
9898
else if(file.hasFileExtension("plugdata")) {
9999
auto zip = ZipFile(file);
100100
auto result = zip.uncompressTo(ProjectInfo::appDataDir.getChildFile("Patches"), false);
101+
auto* editor = dynamic_cast<PluginEditor*>(mainWindow->mainComponent->getEditor());
101102
if(result.wasOk())
102103
{
103104
auto macOSTrash = ProjectInfo::appDataDir.getChildFile("Patches").getChildFile("__MACOSX");
@@ -106,10 +107,10 @@ class PlugDataApp : public JUCEApplication {
106107
macOSTrash.deleteRecursively();
107108
}
108109

109-
// TODO: show success dialog
110+
Dialogs::showMultiChoiceDialog(&editor->openedDialog, editor, "Successfully installed " + file.getFileNameWithoutExtension(), [](int){}, { "Dismiss" }, Icons::Checkmark);
110111
}
111112
else {
112-
// TODO: show error dialog
113+
Dialogs::showMultiChoiceDialog(&editor->openedDialog, editor, "Failed to install " + file.getFileNameWithoutExtension(), [](int){}, { "Dismiss" });
113114
}
114115
}
115116
}

0 commit comments

Comments
 (0)