Add options to avoid showing dialogs saving files (#917)

This commit is contained in:
David Capello 2018-02-07 17:25:58 -03:00
parent b5dc3d263e
commit d4244fed48
10 changed files with 99 additions and 7 deletions

View File

@ -248,6 +248,10 @@
<section id="advanced_mode">
<option id="show_alert" type="bool" default="true" migrate="AdvancedMode.Warning" />
</section>
<section id="save_file">
<option id="show_file_format_doesnt_support_alert" type="bool" default="true" />
<option id="show_export_animation_in_sequence_alert" type="bool" default="true" />
</section>
<section id="gif">
<option id="show_alert" type="bool" default="true" />
<option id="interlaced" type="bool" default="false" migrate="GIF.Interlaced" />

View File

@ -947,6 +947,8 @@ the current frame & layer will be modified
to focus the undid/redid change.
END
undo_allow_nonlinear_history = Allow non-linear history
file_format_doesnt_support_alert = Show warning when saving a file with unsupported features
export_animation_in_sequence_alert = Show warning when saving an animation as a sequence of static images
gif_options_alert = Show GIF options when saving .gif files
jpeg_options_alert = Show JPEG options when saving .jpeg files
advanced_mode_alert = Show alert when we enter to Advanced Mode

View File

@ -270,6 +270,8 @@
<!-- Alerts -->
<vbox id="section_alerts">
<separator text="@.section_alerts" horizontal="true" />
<check id="file_format_doesnt_support_alert" text="@.file_format_doesnt_support_alert" />
<check id="export_animation_in_sequence_alert" text="@.export_animation_in_sequence_alert" />
<check id="gif_options_alert" text="@.gif_options_alert" />
<check id="jpeg_options_alert" text="@.jpeg_options_alert" />
<check id="advanced_mode_alert" text="@.advanced_mode_alert" />

View File

@ -1,5 +1,5 @@
# Aseprite
# Copyright (C) 2001-2017 David Capello
# Copyright (C) 2001-2018 David Capello
# Generate a ui::Widget for each widget in a XML file
file(GLOB widget_files ${CMAKE_SOURCE_DIR}/data/widgets/*.xml)
@ -495,6 +495,7 @@ add_library(app-lib
ui/main_window.cpp
ui/news_listbox.cpp
ui/notifications.cpp
ui/optional_alert.cpp
ui/palette_popup.cpp
ui/palette_view.cpp
ui/palettes_listbox.cpp

View File

@ -141,6 +141,8 @@ public:
sectionListbox()->Change.connect(base::Bind<void>(&OptionsWindow::onChangeSection, this));
// Alerts
fileFormatDoesntSupportAlert()->setSelected(m_pref.saveFile.showFileFormatDoesntSupportAlert());
exportAnimationInSequenceAlert()->setSelected(m_pref.saveFile.showExportAnimationInSequenceAlert());
gifOptionsAlert()->setSelected(m_pref.gif.showAlert());
jpegOptionsAlert()->setSelected(m_pref.jpeg.showAlert());
advancedModeAlert()->setSelected(m_pref.advancedMode.showAlert());
@ -390,6 +392,8 @@ public:
warnings += "<<- " + Strings::alerts_restart_by_preferences_save_recovery_data_period();
}
m_pref.saveFile.showFileFormatDoesntSupportAlert(fileFormatDoesntSupportAlert()->isSelected());
m_pref.saveFile.showExportAnimationInSequenceAlert(exportAnimationInSequenceAlert()->isSelected());
m_pref.gif.showAlert(gifOptionsAlert()->isSelected());
m_pref.jpeg.showAlert(jpegOptionsAlert()->isSelected());
m_pref.advancedMode.showAlert(advancedModeAlert()->isSelected());
@ -571,6 +575,8 @@ private:
}
void onResetAlerts() {
fileFormatDoesntSupportAlert()->setSelected(m_pref.saveFile.showFileFormatDoesntSupportAlert.defaultValue());
exportAnimationInSequenceAlert()->setSelected(m_pref.saveFile.showExportAnimationInSequenceAlert.defaultValue());
gifOptionsAlert()->setSelected(m_pref.gif.showAlert.defaultValue());
jpegOptionsAlert()->setSelected(m_pref.jpeg.showAlert.defaultValue());
advancedModeAlert()->setSelected(m_pref.advancedMode.showAlert.defaultValue());

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2017 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -22,6 +22,8 @@
#include "app/i18n/strings.h"
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/pref/preferences.h"
#include "app/ui/optional_alert.h"
#include "app/ui/status_bar.h"
#include "base/fs.h"
#include "base/mutex.h"
@ -33,7 +35,6 @@
#include "fmt/format.h"
#include "render/quantization.h"
#include "render/render.h"
#include "ui/alert.h"
#include "open_sequence.xml.h"
@ -447,7 +448,9 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context,
if (!warnings.empty()) {
// Interative
if (context && context->isUIAvailable()) {
int ret = ui::Alert::show(
int ret = OptionalAlert::show(
Preferences::instance().saveFile.showFileFormatDoesntSupportAlert,
1, // Yes is the default option when the alert dialog is disabled
fmt::format(
(fatal ? Strings::alerts_file_format_doesnt_support_error():
Strings::alerts_file_format_doesnt_support_warning()),
@ -505,7 +508,9 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context,
if (context && context->isUIAvailable() &&
fop->m_seq.filename_list.size() > 1 &&
ui::Alert::show(
OptionalAlert::show(
Preferences::instance().saveFile.showExportAnimationInSequenceAlert,
1,
fmt::format(
Strings::alerts_export_animation_in_sequence(),
int(fop->m_seq.filename_list.size()),

View File

@ -0,0 +1,35 @@
// Aseprite
// Copyright (C) 2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/ui/optional_alert.h"
#include "app/i18n/strings.h"
#include "ui/alert.h"
#include "ui/button.h"
namespace app {
// static
int OptionalAlert::show(Option<bool>& option,
const int optionWhenDisabled,
const std::string& msg)
{
if (!option())
return optionWhenDisabled;
ui::AlertPtr alert(ui::Alert::create(msg));
ui::CheckBox* cb = alert->addCheckBox(Strings::general_dont_show());
const int ret = alert->show();
if (ret == optionWhenDisabled)
option(!cb->isSelected());
return ret;
}
} // namespace app

View File

@ -0,0 +1,26 @@
// Aseprite
// Copyright (C) 2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_UI_OPTIONAL_ALERT_H_INCLUDED
#define APP_UI_OPTIONAL_ALERT_H_INCLUDED
#pragma once
#include "app/pref/option.h"
#include <string>
namespace app {
class OptionalAlert {
public:
static int show(Option<bool>& option,
const int optionWhenDisabled,
const std::string& msg);
};
}
#endif

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2001-2017 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -66,6 +66,14 @@ void Alert::addProgress()
m_progressPlaceholder->setVisible(true);
}
CheckBox* Alert::addCheckBox(const std::string& text)
{
auto checkBox = new CheckBox(text);
m_progressPlaceholder->addChild(checkBox);
m_progressPlaceholder->setVisible(true);
return checkBox;
}
void Alert::setProgress(double progress)
{
ASSERT(m_progress);

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2001-2017 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -17,6 +17,7 @@
namespace ui {
class Box;
class CheckBox;
class Slider;
class Alert;
@ -29,6 +30,8 @@ namespace ui {
void addProgress();
void setProgress(double progress);
CheckBox* addCheckBox(const std::string& text);
int show();
static AlertPtr create(const std::string& msg);