mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-25 23:37:05 +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
|
END
|
||||||
job_working = {0}<<Working...||&Cancel
|
job_working = {0}<<Working...||&Cancel
|
||||||
nothing_to_report = Crash Report<<Nothing to report||&OK
|
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
|
uninstall_extension_warning = <<<END
|
||||||
Warning
|
Warning
|
||||||
<<Do you really want to uninstall '{0}' extension?
|
<<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:
|
private:
|
||||||
|
|
||||||
void fillExtensionsCombobox(ui::ComboBox* combobox,
|
void fillExtensionsCombobox(ui::ComboBox* combobox,
|
||||||
@ -1076,7 +1095,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onAddExtension() {
|
void onAddExtension() {
|
||||||
base::paths exts = { "zip" };
|
base::paths exts = { "aseprite-extension", "zip" };
|
||||||
base::paths filename;
|
base::paths filename;
|
||||||
if (!app::show_file_selector(
|
if (!app::show_file_selector(
|
||||||
"Add Extension", "", exts,
|
"Add Extension", "", exts,
|
||||||
@ -1084,13 +1103,16 @@ private:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ASSERT(!filename.empty());
|
ASSERT(!filename.empty());
|
||||||
|
installExtension(filename.front());
|
||||||
|
}
|
||||||
|
|
||||||
|
void installExtension(const std::string& filename) {
|
||||||
try {
|
try {
|
||||||
Extensions& exts = App::instance()->extensions();
|
Extensions& exts = App::instance()->extensions();
|
||||||
|
|
||||||
// Get the extension information from the compressed
|
// Get the extension information from the compressed
|
||||||
// package.json file.
|
// package.json file.
|
||||||
ExtensionInfo info = exts.getCompressedExtensionInfo(filename.front());
|
ExtensionInfo info = exts.getCompressedExtensionInfo(filename);
|
||||||
|
|
||||||
// Check if the extension already exist
|
// Check if the extension already exist
|
||||||
for (auto ext : exts) {
|
for (auto ext : exts) {
|
||||||
@ -1124,8 +1146,7 @@ private:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Extension* ext =
|
Extension* ext = exts.installCompressedExtension(filename, info);
|
||||||
exts.installCompressedExtension(filename.front(), info);
|
|
||||||
|
|
||||||
// Enable extension
|
// Enable extension
|
||||||
exts.enableExtension(ext, true);
|
exts.enableExtension(ext, true);
|
||||||
@ -1133,8 +1154,9 @@ private:
|
|||||||
// Add the new extension in the listbox
|
// Add the new extension in the listbox
|
||||||
ExtensionItem* item = new ExtensionItem(ext);
|
ExtensionItem* item = new ExtensionItem(ext);
|
||||||
extensionsList()->addChild(item);
|
extensionsList()->addChild(item);
|
||||||
extensionsList()->selectChild(item);
|
extensionsList()->sortItems();
|
||||||
extensionsList()->layout();
|
extensionsList()->layout();
|
||||||
|
extensionsList()->selectChild(item);
|
||||||
}
|
}
|
||||||
catch (const std::exception& ex) {
|
catch (const std::exception& ex) {
|
||||||
Console::showException(ex);
|
Console::showException(ex);
|
||||||
@ -1256,7 +1278,11 @@ public:
|
|||||||
Command* clone() const override { return new OptionsCommand(*this); }
|
Command* clone() const override { return new OptionsCommand(*this); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void onLoadParams(const Params& params) override;
|
||||||
void onExecute(Context* context) override;
|
void onExecute(Context* context) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_installExtensionFilename;
|
||||||
};
|
};
|
||||||
|
|
||||||
OptionsCommand::OptionsCommand()
|
OptionsCommand::OptionsCommand()
|
||||||
@ -1268,11 +1294,23 @@ OptionsCommand::OptionsCommand()
|
|||||||
preferences.general.expandMenubarOnMouseover());
|
preferences.general.expandMenubarOnMouseover());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionsCommand::onLoadParams(const Params& params)
|
||||||
|
{
|
||||||
|
m_installExtensionFilename = params.get("installExtension");
|
||||||
|
}
|
||||||
|
|
||||||
void OptionsCommand::onExecute(Context* context)
|
void OptionsCommand::onExecute(Context* context)
|
||||||
{
|
{
|
||||||
static int curSection = 0;
|
static int curSection = 0;
|
||||||
|
|
||||||
OptionsWindow window(context, curSection);
|
OptionsWindow window(context, curSection);
|
||||||
|
window.openWindow();
|
||||||
|
|
||||||
|
if (!m_installExtensionFilename.empty()) {
|
||||||
|
if (!window.showDialogToInstallExtension(m_installExtensionFilename))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window.openWindowInForeground();
|
window.openWindowInForeground();
|
||||||
if (window.ok())
|
if (window.ok())
|
||||||
window.saveConfig();
|
window.saveConfig();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -35,8 +36,10 @@
|
|||||||
#include "app/ui/status_bar.h"
|
#include "app/ui/status_bar.h"
|
||||||
#include "app/ui/toolbar.h"
|
#include "app/ui/toolbar.h"
|
||||||
#include "app/ui_context.h"
|
#include "app/ui_context.h"
|
||||||
|
#include "base/fs.h"
|
||||||
#include "base/memory.h"
|
#include "base/memory.h"
|
||||||
#include "base/shared_ptr.h"
|
#include "base/shared_ptr.h"
|
||||||
|
#include "base/string.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "os/display.h"
|
#include "os/display.h"
|
||||||
#include "os/error.h"
|
#include "os/error.h"
|
||||||
@ -327,10 +330,13 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kDropFilesMessage:
|
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();
|
base::paths files = static_cast<DropFilesMessage*>(msg)->files();
|
||||||
UIContext* ctx = UIContext::instance();
|
UIContext* ctx = UIContext::instance();
|
||||||
OpenFileCommand cmd;
|
|
||||||
|
|
||||||
while (!files.empty()) {
|
while (!files.empty()) {
|
||||||
auto fn = files.front();
|
auto fn = files.front();
|
||||||
@ -348,16 +354,31 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
|||||||
}
|
}
|
||||||
// Load the file
|
// Load the file
|
||||||
else {
|
else {
|
||||||
Params params;
|
// Depending on the file type we will want to do different things:
|
||||||
params.set("filename", fn.c_str());
|
std::string extension = base::string_to_lower(
|
||||||
params.set("repeat_checkbox", "true");
|
base::get_file_extension(fn));
|
||||||
ctx->executeCommand(&cmd, params);
|
|
||||||
|
|
||||||
// Remove all used file names from the "dropped files"
|
// Install the extension
|
||||||
for (const auto& usedFn : cmd.usedFiles()) {
|
if (extension == "aseprite-extension") {
|
||||||
auto it = std::find(files.begin(), files.end(), usedFn);
|
Command* cmd = Commands::instance()->byId(CommandId::Options());
|
||||||
if (it != files.end())
|
Params params;
|
||||||
files.erase(it);
|
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