mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-23 13:20:50 +00:00
Add support to drag-and-drop .aseprite-extension files into the main window
This commit is contained in:
parent
d1fb49ba83
commit
a38a23e2e5
@ -96,6 +96,12 @@ Aseprite
|
||||
END
|
||||
job_working = {0}<<Working...||&Cancel
|
||||
nothing_to_report = Crash Report<<Nothing to report||&OK
|
||||
install_extension = <<<END
|
||||
Warning
|
||||
<<Do you really want to install the given extension?
|
||||
<<'{0}'
|
||||
||&Install||&Cancel
|
||||
END
|
||||
uninstall_extension_warning = <<<END
|
||||
Warning
|
||||
<<Do you really want to uninstall '{0}' extension?
|
||||
|
@ -601,6 +601,25 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool showDialogToInstallExtension(const std::string& filename) {
|
||||
for (Widget* item : sectionListbox()->children()) {
|
||||
if (auto listItem = dynamic_cast<const ListItem*>(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();
|
||||
|
@ -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<DropFilesMessage*>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user