Automatic split layers/tags if we use {layer} or {tag} in --save-as (fix #1149)

This commit is contained in:
David Capello 2016-06-06 16:28:49 -03:00
parent 617afaed78
commit 04f67a1697
2 changed files with 27 additions and 4 deletions

View File

@ -198,8 +198,27 @@ void CliProcessor::process()
// --save-as <filename>
else if (opt == &m_options.saveAs()) {
if (lastDoc) {
std::string fn = value.value();
// Automatic --split-layer or --split-tags in case the
// output filename already contains {layer} or {tag}
// template elements.
bool hasLayerTemplate = (fn.find("{layer}") != std::string::npos);
bool hasTagTemplate = (fn.find("{tag}") != std::string::npos);
if (hasLayerTemplate || hasTagTemplate) {
cof.splitLayers = (cof.splitLayers || hasLayerTemplate);
cof.splitTags = (cof.splitTags || hasTagTemplate);
cof.filenameFormat =
get_default_filename_format(
fn,
true, // With path
(lastDoc->sprite()->totalFrames() > 1), // Has frames
false, // Has layer
false); // Has frame tag
}
cof.document = lastDoc;
cof.filename = value.value();
cof.filename = fn;
saveFile(cof);
}
else

View File

@ -123,12 +123,16 @@ std::string get_default_filename_format(
if (hasFrameTag)
format += " #{tag}";
if (hasFrames && is_static_image_format(filename)) {
const bool autoFrameFromLastDigit = (!hasLayer && !hasFrameTag);
int frameBase = -1, frameWidth = 0;
if (hasFrames && is_static_image_format(filename) &&
filename.find("{frame") == std::string::npos &&
filename.find("{tagframe") == std::string::npos) {
const bool autoFrameFromLastDigit =
(!hasLayer &&
!hasFrameTag);
// Check if we already have a frame number at the end of the
// filename (e.g. output01.png)
int frameBase = -1, frameWidth = 0;
std::string left, right;
if (autoFrameFromLastDigit)
frameBase = split_filename(filename.c_str(), left, right, frameWidth);