Skip to content

Commit

Permalink
Drop a Skin to install it (#4949)
Browse files Browse the repository at this point in the history
Drag and Drop in a skin and you are

1. Prompted if you want to install it
2. If you say yes it copies to your user directory
3. And activate it

Closes #3757
  • Loading branch information
baconpaul authored Aug 29, 2021
1 parent 5a72ae0 commit 6f4cf77
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/gui/SkinSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,5 +1334,33 @@ std::array<SurgeImage *, 3> Skin::standardHoverAndHoverOnForCSB(SurgeImage *csb,
return res;
}

Maybe<SkinDB::Entry> SkinDB::installSkinFromPathToUserDirectory(SurgeStorage *s, const fs::path &p)
{
auto parentP = p.parent_path();
auto nmP = p.lexically_relative(parentP);
auto tgPath = string_to_path(s->userSkinsPath) / nmP;

try
{
fs::create_directories(tgPath);
fs::copy(p, tgPath, fs::copy_options::recursive | fs::copy_options::overwrite_existing);
}
catch (const fs::filesystem_error &e)
{
// This will give us a broken skin but no need to tell the users
FIXMEERROR << "Unable to install Skin: " << e.what();
return Maybe<Entry>();
}
rescanForSkins(s);

auto nameS = path_to_string(nmP);
for (auto &a : availableSkins)
{
if (a.rootType == USER && a.name.find(nameS) == 0)
return Maybe<Entry>(a);
}
return Maybe<Entry>();
}

} // namespace GUI
} // namespace Surge
3 changes: 3 additions & 0 deletions src/gui/SkinSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ class SkinDB : public juce::DeletedAtShutdown
return s;
}

Maybe<Entry> installSkinFromPathToUserDirectory(SurgeStorage *, const fs::path &from);

private:
SkinDB();
~SkinDB();
Expand Down Expand Up @@ -513,5 +515,6 @@ class SkinConsumingComponent
Skin::Control::ptr_t skinControl = nullptr;
std::shared_ptr<SurgeImageStore> associatedBitmapStore = nullptr;
};

} // namespace GUI
} // namespace Surge
30 changes: 30 additions & 0 deletions src/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ SurgeGUIEditor::SurgeGUIEditor(SurgeSynthEditor *jEd, SurgeSynthesizer *synth)

mod_editor = false;
editor_open = false;
editor_open = false;
queue_refresh = false;
memset(param, 0, n_paramslots * sizeof(void *));
for (int i = 0; i < n_fx_slots; ++i)
Expand Down Expand Up @@ -4541,6 +4542,8 @@ bool SurgeGUIEditor::canDropTarget(const std::string &fname)
extensions.insert(".wav");
extensions.insert(".wt");
extensions.insert(".fxp");
extensions.insert(".surge-skin");
extensions.insert(".zip");
}

fs::path fPath(fname);
Expand Down Expand Up @@ -4577,7 +4580,34 @@ bool SurgeGUIEditor::onDrop(const std::string &fname)
{
queuePatchFileLoad(fname);
}
else if (fExt == ".surge-skin")
{
std::ostringstream oss;
oss << "Do you wisk to install skin from '" << fname << "' into your Surge User Directory?";
auto cb = juce::ModalCallbackFunction::create([this, fPath](int okcs) {
if (okcs)
{
auto db = Surge::GUI::SkinDB::get();
auto me = db->installSkinFromPathToUserDirectory(&(this->synth->storage), fPath);
if (me.isJust())
{
this->setupSkinFromEntry(me.fromJust());
}
else
{
std::cout << "Could not find skin after load" << std::endl;
}
}
});
juce::AlertWindow::showOkCancelBox(juce::AlertWindow::InfoIcon, "Install Skin", oss.str(),

"Install", "Cancel", frame.get(), cb);
}
else if (fExt == ".zip")
{
juce::AlertWindow::showMessageBox(juce::AlertWindow::InfoIcon, "Coming Soom",
"Zip File Drops coming soon");
}
return true;
}

Expand Down

0 comments on commit 6f4cf77

Please sign in to comment.