Add an (optional) alert before running a script

This commit is contained in:
David Capello 2018-09-17 14:59:44 -03:00
parent f6e3aa9fd8
commit 9b259a7a43
4 changed files with 32 additions and 1 deletions

View File

@ -298,6 +298,9 @@
<section id="filters">
<option id="cels_target" type="CelsTarget" default="CelsTarget::Selected" />
</section>
<section id="scripts">
<option id="show_run_script_alert" type="bool" default="true" />
</section>
</global>
<tool>

View File

@ -130,6 +130,16 @@ Warning
<<to their original default settings?
||&Yes||&No
END
run_script = <<<END
Run Script
<<Do you want to run the following script?
<<
<< {0}
<<
<<WARNING: Scripts can crash Aseprite, please save your work
<<before running a script.
||&Run||&Cancel
END
save_sprite_changes = <<<END
Warning
<<Saving changes to the sprite
@ -1024,6 +1034,7 @@ 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
invalid_fg_bg_color_alert = Show alert when drawing with index out of palette bounds
run_script_alert = Show alert when we try to run a script
reset_alerts = Reset all alert dialogs
available_themes = Available Themes
select_theme = &Select

View File

@ -329,6 +329,8 @@
pref="advanced_mode.show_alert" />
<check id="invalid_fg_bg_color_alert" text="@.invalid_fg_bg_color_alert"
pref="color_bar.show_invalid_fg_bg_color_alert" />
<check id="run_script_alert" text="@.run_script_alert"
pref="scripts.show_run_script_alert" />
<separator horizontal="true" />
<hbox>
<hbox expansive="true" />

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.
@ -16,8 +16,12 @@
#include "app/commands/command.h"
#include "app/commands/params.h"
#include "app/console.h"
#include "app/context.h"
#include "app/i18n/strings.h"
#include "app/pref/preferences.h"
#include "app/resource_finder.h"
#include "app/script/engine.h"
#include "app/ui/optional_alert.h"
#include "base/fs.h"
#include "fmt/format.h"
#include "ui/manager.h"
@ -67,6 +71,17 @@ void RunScriptCommand::onLoadParams(const Params& params)
void RunScriptCommand::onExecute(Context* context)
{
#if ENABLE_UI
if (context->isUIAvailable()) {
int ret = OptionalAlert::show(
Preferences::instance().scripts.showRunScriptAlert,
1, // Yes is the default option when the alert dialog is disabled
fmt::format(Strings::alerts_run_script(), m_filename));
if (ret != 1)
return;
}
#endif // ENABLE_UI
script::Engine* engine = App::instance()->scriptEngine();
{
ConsoleEngineDelegate delegate;