diff --git a/data/strings/en.ini b/data/strings/en.ini index 130c5b7b3..831ef037b 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -96,6 +96,12 @@ Aseprite END job_working = {0}<children()) { + if (auto listItem = dynamic_cast(item)) { + if (listItem->getValue() == kSectionExtensionsId) { + sectionListbox()->selectChild(item); + break; + } + } + } + + // Install? + if (ui::Alert::show( + fmt::format(Strings::alerts_install_extension(), filename)) != 1) + return false; + + installExtension(filename); + return true; + } + private: void fillExtensionsCombobox(ui::ComboBox* combobox, @@ -1076,7 +1095,7 @@ private: } void onAddExtension() { - base::paths exts = { "zip" }; + base::paths exts = { "aseprite-extension", "zip" }; base::paths filename; if (!app::show_file_selector( "Add Extension", "", exts, @@ -1084,13 +1103,16 @@ private: return; ASSERT(!filename.empty()); + installExtension(filename.front()); + } + void installExtension(const std::string& filename) { try { Extensions& exts = App::instance()->extensions(); // Get the extension information from the compressed // package.json file. - ExtensionInfo info = exts.getCompressedExtensionInfo(filename.front()); + ExtensionInfo info = exts.getCompressedExtensionInfo(filename); // Check if the extension already exist for (auto ext : exts) { @@ -1124,8 +1146,7 @@ private: break; } - Extension* ext = - exts.installCompressedExtension(filename.front(), info); + Extension* ext = exts.installCompressedExtension(filename, info); // Enable extension exts.enableExtension(ext, true); @@ -1133,8 +1154,9 @@ private: // Add the new extension in the listbox ExtensionItem* item = new ExtensionItem(ext); extensionsList()->addChild(item); - extensionsList()->selectChild(item); + extensionsList()->sortItems(); extensionsList()->layout(); + extensionsList()->selectChild(item); } catch (const std::exception& ex) { Console::showException(ex); @@ -1256,7 +1278,11 @@ public: Command* clone() const override { return new OptionsCommand(*this); } protected: + void onLoadParams(const Params& params) override; void onExecute(Context* context) override; + +private: + std::string m_installExtensionFilename; }; OptionsCommand::OptionsCommand() @@ -1268,11 +1294,23 @@ OptionsCommand::OptionsCommand() preferences.general.expandMenubarOnMouseover()); } +void OptionsCommand::onLoadParams(const Params& params) +{ + m_installExtensionFilename = params.get("installExtension"); +} + void OptionsCommand::onExecute(Context* context) { static int curSection = 0; OptionsWindow window(context, curSection); + window.openWindow(); + + if (!m_installExtensionFilename.empty()) { + if (!window.showDialogToInstallExtension(m_installExtensionFilename)) + return; + } + window.openWindowInForeground(); if (window.ok()) window.saveConfig(); diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index 8431bfe74..8dbf2b3c4 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2018 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -35,8 +36,10 @@ #include "app/ui/status_bar.h" #include "app/ui/toolbar.h" #include "app/ui_context.h" +#include "base/fs.h" #include "base/memory.h" #include "base/shared_ptr.h" +#include "base/string.h" #include "doc/sprite.h" #include "os/display.h" #include "os/error.h" @@ -327,10 +330,13 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg) break; case kDropFilesMessage: - { + // Files are processed only when the main window is the current + // window running. + // + // TODO could we send the files to each dialog? + if (getForegroundWindow() == App::instance()->mainWindow()) { base::paths files = static_cast(msg)->files(); UIContext* ctx = UIContext::instance(); - OpenFileCommand cmd; while (!files.empty()) { auto fn = files.front(); @@ -348,16 +354,31 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg) } // Load the file else { - Params params; - params.set("filename", fn.c_str()); - params.set("repeat_checkbox", "true"); - ctx->executeCommand(&cmd, params); + // Depending on the file type we will want to do different things: + std::string extension = base::string_to_lower( + base::get_file_extension(fn)); - // Remove all used file names from the "dropped files" - for (const auto& usedFn : cmd.usedFiles()) { - auto it = std::find(files.begin(), files.end(), usedFn); - if (it != files.end()) - files.erase(it); + // Install the extension + if (extension == "aseprite-extension") { + Command* cmd = Commands::instance()->byId(CommandId::Options()); + Params params; + params.set("installExtension", fn.c_str()); + ctx->executeCommand(cmd, params); + } + // Other extensions will be handled as an image/sprite + else { + OpenFileCommand cmd; + Params params; + params.set("filename", fn.c_str()); + params.set("repeat_checkbox", "true"); + ctx->executeCommand(&cmd, params); + + // Remove all used file names from the "dropped files" + for (const auto& usedFn : cmd.usedFiles()) { + auto it = std::find(files.begin(), files.end(), usedFn); + if (it != files.end()) + files.erase(it); + } } } }