diff --git a/data/widgets/export_sprite_sheet.xml b/data/widgets/export_sprite_sheet.xml
index 22521dd9a..95872a903 100644
--- a/data/widgets/export_sprite_sheet.xml
+++ b/data/widgets/export_sprite_sheet.xml
@@ -42,7 +42,7 @@
-
+
diff --git a/src/app/commands/cmd_export_sprite_sheet.cpp b/src/app/commands/cmd_export_sprite_sheet.cpp
index 02e098b35..49281f029 100644
--- a/src/app/commands/cmd_export_sprite_sheet.cpp
+++ b/src/app/commands/cmd_export_sprite_sheet.cpp
@@ -21,11 +21,13 @@
#include "app/ui/status_bar.h"
#include "base/bind.h"
#include "base/convert_to.h"
+#include "base/fs.h"
#include "base/path.h"
#include "generated_export_sprite_sheet.h"
#include
+#include
namespace app {
@@ -111,6 +113,29 @@ namespace {
columns, 0);
}
+ bool ask_overwrite(bool askFilename, std::string filename,
+ bool askDataname, std::string dataname) {
+ if ((askFilename &&
+ base::is_file(filename)) ||
+ (askDataname &&
+ !dataname.empty() &&
+ base::is_file(dataname))) {
+ std::stringstream text;
+ text << "Export Sprite Sheet Warning<Click.connect(Bind(&ExportSpriteSheetWindow::onExport, this));
sheetType()->Change.connect(&ExportSpriteSheetWindow::onSheetTypeChange, this);
columns()->EntryChange.connect(Bind(&ExportSpriteSheetWindow::onColumnsChange, this));
fitWidth()->Change.connect(Bind(&ExportSpriteSheetWindow::onSizeChange, this));
@@ -270,6 +298,14 @@ public:
protected:
+ void onExport() {
+ if (!ask_overwrite(m_filenameAskOverwrite, filenameValue(),
+ m_dataFilenameAskOverwrite, dataFilenameValue()))
+ return;
+
+ closeWindow(exportButton());
+ }
+
void onSheetTypeChange() {
bool state = false;
switch (spriteSheetTypeValue()) {
@@ -318,6 +354,7 @@ protected:
return;
m_filename = newFilename;
+ m_filenameAskOverwrite = false; // Already asked in file selector
onFileNamesChange();
}
@@ -329,10 +366,13 @@ protected:
return;
m_dataFilename = newFilename;
+ m_dataFilenameAskOverwrite = false; // Already asked in file selector
onFileNamesChange();
}
void onDataEnabledChange() {
+ m_dataFilenameAskOverwrite = true;
+
dataFilename()->setVisible(dataEnabled()->isSelected());
resize();
}
@@ -379,6 +419,8 @@ private:
DocumentPreferences& m_docPref;
std::string m_filename;
std::string m_dataFilename;
+ bool m_filenameAskOverwrite;
+ bool m_dataFilenameAskOverwrite;
};
class ExportSpriteSheetCommand : public Command {
@@ -395,6 +437,7 @@ protected:
private:
bool m_useUI;
+ bool m_askOverwrite;
};
ExportSpriteSheetCommand::ExportSpriteSheetCommand()
@@ -402,6 +445,7 @@ ExportSpriteSheetCommand::ExportSpriteSheetCommand()
"Export Sprite Sheet",
CmdRecordableFlag)
, m_useUI(true)
+ , m_askOverwrite(true)
{
}
@@ -411,6 +455,11 @@ void ExportSpriteSheetCommand::onLoadParams(const Params& params)
m_useUI = params.get_as("ui");
else
m_useUI = true;
+
+ if (params.has_param("ask-overwrite"))
+ m_askOverwrite = params.get_as("ask-overwrite");
+ else
+ m_askOverwrite = true;
}
bool ExportSpriteSheetCommand::onEnabled(Context* context)
@@ -423,6 +472,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
Document* document(context->activeDocument());
Sprite* sprite = document->sprite();
DocumentPreferences& docPref(Preferences::instance().document(document));
+ bool askOverwrite = m_askOverwrite;
if (m_useUI && context->isUIAvailable()) {
ExportSpriteSheetWindow window(document, sprite, docPref);
@@ -441,6 +491,8 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
docPref.spriteSheet.shapePadding(window.shapePaddingValue());
docPref.spriteSheet.innerPadding(window.innerPaddingValue());
docPref.spriteSheet.openGenerated(window.openGeneratedValue());
+
+ askOverwrite = false; // Already asked in the ExportSpriteSheetWindow
}
app::gen::SpriteSheetType type = docPref.spriteSheet.type();
@@ -457,6 +509,12 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
shapePadding = MID(0, shapePadding, 100);
innerPadding = MID(0, innerPadding, 100);
+ if (context->isUIAvailable() && askOverwrite) {
+ if (!ask_overwrite(true, filename,
+ true, dataFilename))
+ return; // Do not overwrite
+ }
+
if (bestFit) {
Fit fit = best_fit(sprite, borderPadding, shapePadding, innerPadding);
columns = fit.columns;