Improve UX in File > Export in special cases for output filename extension

* When the extension is unknown, an error is shown.
* When the extension is not written, the default extension will
  be added (the default extension is different depending on
  if the file format is image format or an animation format).
This commit is contained in:
David Capello 2018-06-27 10:00:19 -03:00
parent 49106817d4
commit 51ce52981a
5 changed files with 48 additions and 6 deletions

View File

@ -95,6 +95,11 @@ Warning
<<Do you really want to uninstall '{0}' extension? <<Do you really want to uninstall '{0}' extension?
||&Yes||&No ||&Yes||&No
END END
unknown_output_file_format_error = <<<END
Aseprite
<<Unknown file format '{0}' in output filename
||&OK
END
update_screen_ui_scaling_with_theme_values = <<<END update_screen_ui_scaling_with_theme_values = <<<END
Update Screen/UI Scaling Update Screen/UI Scaling
<<The new theme '{0}' wants to adjust some values for you: <<The new theme '{0}' wants to adjust some values for you:

View File

@ -42,7 +42,7 @@
<hbox cell_hspan="3"> <hbox cell_hspan="3">
<boxfiller /> <boxfiller />
<hbox homogeneous="true"> <hbox homogeneous="true">
<button text="@.export" minwidth="60" closewindow="true" id="ok" magnet="true" /> <button text="@.export" minwidth="60" id="ok" magnet="true" />
<button text="@.cancel" minwidth="60" closewindow="true" /> <button text="@.cancel" minwidth="60" closewindow="true" />
</hbox> </hbox>
</hbox> </hbox>

2
laf

@ -1 +1 @@
Subproject commit 8cf772813063d25116dcf38a5f3a41a34a6a32b8 Subproject commit b135dbfb5adb32f9b14f85eef1e5fa744d1c553e

View File

@ -11,16 +11,21 @@
#include "app/ui/export_file_window.h" #include "app/ui/export_file_window.h"
#include "app/document.h" #include "app/document.h"
#include "app/file/file.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/ui/layer_frame_comboboxes.h" #include "app/ui/layer_frame_comboboxes.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "base/fs.h" #include "base/fs.h"
#include "base/string.h"
#include "doc/frame_tag.h" #include "doc/frame_tag.h"
#include "doc/selected_frames.h" #include "doc/selected_frames.h"
#include "doc/site.h" #include "doc/site.h"
#include "fmt/format.h" #include "fmt/format.h"
#include "ui/alert.h"
#include <algorithm>
namespace app { namespace app {
@ -29,8 +34,6 @@ ExportFileWindow::ExportFileWindow(const Document* doc)
, m_docPref(Preferences::instance().document(doc)) , m_docPref(Preferences::instance().document(doc))
, m_preferredResize(1) , m_preferredResize(1)
{ {
auto& pref = Preferences::instance();
// Is a default output filename in the preferences? // Is a default output filename in the preferences?
if (!m_docPref.saveCopy.filename().empty()) { if (!m_docPref.saveCopy.filename().empty()) {
setOutputFilename(m_docPref.saveCopy.filename()); setOutputFilename(m_docPref.saveCopy.filename());
@ -38,8 +41,7 @@ ExportFileWindow::ExportFileWindow(const Document* doc)
else { else {
std::string newFn = base::replace_extension( std::string newFn = base::replace_extension(
doc->filename(), doc->filename(),
(doc->sprite()->totalFrames() > 1 ? pref.exportFile.animationDefaultExtension(): defaultExtension());
pref.exportFile.imageDefaultExtension()));
if (newFn == doc->filename()) { if (newFn == doc->filename()) {
newFn = base::join_path( newFn = base::join_path(
base::get_file_path(newFn), base::get_file_path(newFn),
@ -80,6 +82,7 @@ ExportFileWindow::ExportFileWindow(const Document* doc)
frames()->Change.connect(base::Bind<void>(&ExportFileWindow::updateAniDir, this)); frames()->Change.connect(base::Bind<void>(&ExportFileWindow::updateAniDir, this));
forTwitter()->Click.connect(base::Bind<void>(&ExportFileWindow::updateAdjustResizeButton, this)); forTwitter()->Click.connect(base::Bind<void>(&ExportFileWindow::updateAdjustResizeButton, this));
adjustResize()->Click.connect(base::Bind<void>(&ExportFileWindow::onAdjustResize, this)); adjustResize()->Click.connect(base::Bind<void>(&ExportFileWindow::onAdjustResize, this));
ok()->Click.connect(base::Bind<void>(&ExportFileWindow::onOK, this));
} }
bool ExportFileWindow::show() bool ExportFileWindow::show()
@ -200,4 +203,36 @@ void ExportFileWindow::onAdjustResize()
adjustResize()->parent()->layout(); adjustResize()->parent()->layout();
} }
void ExportFileWindow::onOK()
{
base::paths exts = get_writable_extensions();
std::string ext = base::string_to_lower(
base::get_file_extension(m_outputFilename));
// Add default extension to output filename
if (std::find(exts.begin(), exts.end(), ext) == exts.end()) {
if (ext.empty()) {
m_outputFilename =
base::replace_extension(m_outputFilename,
defaultExtension());
}
else {
ui::Alert::show(
fmt::format(Strings::alerts_unknown_output_file_format_error(), ext));
return;
}
}
closeWindow(ok());
}
std::string ExportFileWindow::defaultExtension() const
{
auto& pref = Preferences::instance();
if (m_doc->sprite()->totalFrames() > 1)
return pref.exportFile.animationDefaultExtension();
else
return pref.exportFile.imageDefaultExtension();
}
} // namespace app } // namespace app

View File

@ -42,6 +42,8 @@ namespace app {
void updateAniDir(); void updateAniDir();
void updateAdjustResizeButton(); void updateAdjustResizeButton();
void onAdjustResize(); void onAdjustResize();
void onOK();
std::string defaultExtension() const;
const Document* m_doc; const Document* m_doc;
DocumentPreferences& m_docPref; DocumentPreferences& m_docPref;