Add options to suppress specific warnings (fix #917)

This commit is contained in:
David Capello 2018-02-07 14:35:12 -03:00
parent 70aaa4dada
commit b5dc3d263e
14 changed files with 161 additions and 72 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Aseprite -->
<!-- Copyright (C) 2014-2017 by David Capello -->
<!-- Copyright (C) 2014-2018 by David Capello -->
<preferences>
<types>
@ -245,6 +245,18 @@
<section id="slices">
<option id="default_color" type="app::Color" default="app::Color::fromRgb(0, 0, 255)" />
</section>
<section id="advanced_mode">
<option id="show_alert" type="bool" default="true" migrate="AdvancedMode.Warning" />
</section>
<section id="gif">
<option id="show_alert" type="bool" default="true" />
<option id="interlaced" type="bool" default="false" migrate="GIF.Interlaced" />
<option id="loop" type="bool" default="true" migrate="GIF.Loop" />
</section>
<section id="jpeg">
<option id="show_alert" type="bool" default="true" />
<option id="quality" type="double" default="1.0" migrate="JPEG.Quality" />
</section>
</global>
<tool>

View File

@ -1,10 +1,9 @@
# Aseprite
# Copyright (C) 2016-2017 by David Capello
# Copyright (C) 2016-2018 by David Capello
[advanced_mode]
title = Warning - Important
description = You are going to enter in "Advanced Mode".
dont_show_again = Don't show this again
[statusbar_tips]
all_layers_are_locked = All selected layers are locked
@ -514,6 +513,11 @@ yes = &Yes
no = &No
cancel = &Cancel
user_data = User Data
dont_show = Don't show this alert again
dont_show_tooltip = <<<END
Check in case that you want to establish
the given option as the default option.
END
[gif_options]
title = GIF Options
@ -792,6 +796,7 @@ skip = &Skip
[options]
title = Preferences
section_general = General
section_alerts = Alerts
section_editor = Editor
section_selection = Selection
section_timeline = Timeline
@ -942,6 +947,10 @@ the current frame & layer will be modified
to focus the undid/redid change.
END
undo_allow_nonlinear_history = Allow non-linear history
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
reset_alerts = Reset all alert dialogs
available_themes = Available Themes
select_theme = &Select
open_theme_folder = Open &Folder

View File

@ -1,11 +1,11 @@
<!-- Aseprite -->
<!-- Copyright (C) 2001-2016 by David Capello -->
<!-- Copyright (C) 2001-2018 by David Capello -->
<gui>
<window text="@.title" id="advanced_mode">
<grid columns="1">
<label text="@.description" />
<label text="" id="warning_label" />
<check text="@.dont_show_again" id="donot_show" />
<check text="@general.dont_show" id="donot_show" tooltip="@general.dont_show_tooltip" />
<separator horizontal="true" />
<button text="@general.ok" closewindow="true" magnet="true" minwidth="60" cell_align="center" />
</grid>

View File

@ -1,15 +1,16 @@
<!-- Aseprite -->
<!-- Copyright (C) 2014-2016 by David Capello -->
<!-- Copyright (C) 2014-2018 by David Capello -->
<gui>
<window id="gif_options" text="@gif_options.title">
<window id="gif_options" text="@.title">
<vbox>
<separator text="@gif_options.general_options" left="true" horizontal="true" />
<check text="@gif_options.interlaced" id="interlaced" />
<check text="@gif_options.animation_loop" id="loop" />
<separator text="@.general_options" left="true" horizontal="true" />
<check text="@.interlaced" id="interlaced" />
<check text="@.animation_loop" id="loop" />
<separator horizontal="true" />
<hbox>
<check text="@general.dont_show" id="dont_show" tooltip="@general.dont_show_tooltip" />
<boxfiller />
<hbox homogeneous="true">
<button text="@general.ok" closewindow="true" id="ok" magnet="true" minwidth="60" />

View File

@ -1,5 +1,5 @@
<!-- Aseprite -->
<!-- Copyright (C) 2001-2016 by David Capello -->
<!-- Copyright (C) 2001-2018 by David Capello -->
<gui>
<window id="jpeg_options" text="@.title">
<grid columns="2">
@ -8,10 +8,14 @@
<separator horizontal="true" cell_hspan="2" />
<box horizontal="true" homogeneous="true" cell_hspan="2" cell_align="right">
<button text="@general.ok" closewindow="true" id="ok" magnet="true" minwidth="60" />
<button text="@general.cancel" closewindow="true" />
</box>
<hbox cell_hspan="2">
<check text="@general.dont_show" id="dont_show" tooltip="@general.dont_show_tooltip" />
<boxfiller />
<hbox homogeneous="true">
<button text="@general.ok" closewindow="true" id="ok" magnet="true" minwidth="60" />
<button text="@general.cancel" closewindow="true" />
</hbox>
</hbox>
</grid>
</window>
</gui>

View File

@ -1,5 +1,5 @@
<!-- Aseprite -->
<!-- Copyright (C) 2001-2017 by David Capello -->
<!-- Copyright (C) 2001-2018 by David Capello -->
<gui>
<window id="options" text="@.title">
<vbox>
@ -7,6 +7,7 @@
<view maxsize="true">
<listbox id="section_listbox">
<listitem text="@.section_general" value="section_general" />
<listitem text="@.section_alerts" value="section_alerts" />
<listitem text="@.section_editor" value="section_editor" />
<listitem text="@.section_selection" value="section_selection" />
<listitem text="@.section_timeline" value="section_timeline" />
@ -22,6 +23,8 @@
</view>
<panel id="panel" expansive="true">
<!-- General -->
<vbox id="section_general">
<separator text="@.section_general" horizontal="true" />
<hbox>
@ -264,6 +267,19 @@
</vbox>
</vbox>
<!-- Alerts -->
<vbox id="section_alerts">
<separator text="@.section_alerts" horizontal="true" />
<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" />
<separator horizontal="true" />
<hbox>
<hbox expansive="true" />
<button id="reset_alerts" text="@.reset_alerts" />
</hbox>
</vbox>
<!-- Theme -->
<vbox id="section_theme">
<separator text="@.available_themes" horizontal="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.
@ -10,7 +10,7 @@
#include "app/app.h"
#include "app/commands/command.h"
#include "app/ini_file.h"
#include "app/pref/preferences.h"
#include "app/ui/keyboard_shortcuts.h"
#include "app/ui/main_window.h"
#include "ui/ui.h"
@ -58,8 +58,10 @@ void AdvancedModeCommand::onExecute(Context* context)
mainWindow->setMode(newMode);
auto& pref = Preferences::instance();
if (oldMode == MainWindow::NormalMode &&
get_config_bool("AdvancedMode", "Warning", true)) {
pref.advancedMode.showAlert()) {
Key* key = KeyboardShortcuts::instance()->command(this->id().c_str());
if (!key->accels().empty()) {
app::gen::AdvancedMode window;
@ -69,7 +71,7 @@ void AdvancedModeCommand::onExecute(Context* context)
window.openWindowInForeground();
set_config_bool("AdvancedMode", "Warning", !window.donotShow()->isSelected());
pref.advancedMode.showAlert(!window.donotShow()->isSelected());
}
}
}

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.
@ -140,6 +140,12 @@ public:
{
sectionListbox()->Change.connect(base::Bind<void>(&OptionsWindow::onChangeSection, this));
// Alerts
gifOptionsAlert()->setSelected(m_pref.gif.showAlert());
jpegOptionsAlert()->setSelected(m_pref.jpeg.showAlert());
advancedModeAlert()->setSelected(m_pref.advancedMode.showAlert());
resetAlerts()->Click.connect(base::Bind<void>(&OptionsWindow::onResetAlerts, this));
// Cursor
paintingCursorType()->setSelectedItemIndex(int(m_pref.cursor.paintingCursorType()));
cursorColor()->setColor(m_pref.cursor.cursorColor());
@ -384,6 +390,10 @@ public:
warnings += "<<- " + Strings::alerts_restart_by_preferences_save_recovery_data_period();
}
m_pref.gif.showAlert(gifOptionsAlert()->isSelected());
m_pref.jpeg.showAlert(jpegOptionsAlert()->isSelected());
m_pref.advancedMode.showAlert(advancedModeAlert()->isSelected());
m_pref.editor.zoomFromCenterWithWheel(zoomFromCenterWithWheel()->isSelected());
m_pref.editor.zoomFromCenterWithKeys(zoomFromCenterWithKeys()->isSelected());
m_pref.editor.showScrollbars(showScrollbars()->isSelected());
@ -560,6 +570,12 @@ private:
loadExtensions();
}
void onResetAlerts() {
gifOptionsAlert()->setSelected(m_pref.gif.showAlert.defaultValue());
jpegOptionsAlert()->setSelected(m_pref.jpeg.showAlert.defaultValue());
advancedModeAlert()->setSelected(m_pref.advancedMode.showAlert.defaultValue());
}
void onChangeBgScope() {
int item = bgScope()->getSelectedItemIndex();

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.
@ -15,8 +15,8 @@
#include "app/file/file_format.h"
#include "app/file/format_options.h"
#include "app/file/gif_options.h"
#include "app/ini_file.h"
#include "app/modules/gui.h"
#include "app/pref/preferences.h"
#include "app/util/autocrop.h"
#include "base/file_handle.h"
#include "base/fs.h"
@ -25,7 +25,6 @@
#include "render/ordered_dither.h"
#include "render/quantization.h"
#include "render/render.h"
#include "ui/alert.h"
#include "ui/button.h"
#include "gif_options.xml.h"
@ -897,6 +896,10 @@ public:
m_clearColor = rgba(0, 0, 0, 0);
const base::SharedPtr<GifOptions> gifOptions = fop->formatOptions();
LOG("GIF: Saving with options: interlaced=%d loop=%d\n",
gifOptions->interlaced(), gifOptions->loop());
m_interlaced = gifOptions->interlaced();
m_loop = (gifOptions->loop() ? 0: -1);
@ -1361,34 +1364,38 @@ base::SharedPtr<FormatOptions> GifFormat::onGetFormatOptions(FileOp* fop)
return gif_options;
try {
// Configuration parameters
gif_options->setInterlaced(get_config_bool("GIF", "Interlaced", gif_options->interlaced()));
gif_options->setLoop(get_config_bool("GIF", "Loop", gif_options->loop()));
auto& pref = Preferences::instance();
// Load the window to ask to the user the GIF options he wants.
if (pref.isSet(pref.gif.interlaced))
gif_options->setInterlaced(pref.gif.interlaced());
if (pref.isSet(pref.gif.loop))
gif_options->setLoop(pref.gif.loop());
app::gen::GifOptions win;
win.interlaced()->setSelected(gif_options->interlaced());
win.loop()->setSelected(gif_options->loop());
if (pref.gif.showAlert()) {
app::gen::GifOptions win;
win.interlaced()->setSelected(gif_options->interlaced());
win.loop()->setSelected(gif_options->loop());
win.openWindowInForeground();
win.openWindowInForeground();
if (win.closer() == win.ok()) {
gif_options->setInterlaced(win.interlaced()->isSelected());
gif_options->setLoop(win.loop()->isSelected());
if (win.closer() == win.ok()) {
pref.gif.interlaced(win.interlaced()->isSelected());
pref.gif.loop(win.loop()->isSelected());
pref.gif.showAlert(!win.dontShow()->isSelected());
set_config_bool("GIF", "Interlaced", gif_options->interlaced());
set_config_bool("GIF", "Loop", gif_options->loop());
}
else {
gif_options.reset(NULL);
gif_options->setInterlaced(pref.gif.interlaced());
gif_options->setLoop(pref.gif.loop());
}
else {
gif_options.reset(nullptr);
}
}
return gif_options;
}
catch (std::exception& e) {
Console::showException(e);
return base::SharedPtr<GifOptions>(0);
return base::SharedPtr<GifOptions>(nullptr);
}
}

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,17 +16,18 @@
#include "app/file/file_format.h"
#include "app/file/format_options.h"
#include "app/find_widget.h"
#include "app/ini_file.h"
#include "app/load_widget.h"
#include "app/pref/preferences.h"
#include "base/file_handle.h"
#include "base/memory.h"
#include "doc/doc.h"
#include "ui/ui.h"
#include <csetjmp>
#include <cstdio>
#include <cstdlib>
#include "jpeg_options.xml.h"
#include "jpeglib.h"
namespace app {
@ -37,7 +38,8 @@ class JpegFormat : public FileFormat {
// Data for JPEG files
class JpegOptions : public FormatOptions {
public:
float quality; // 1.0 maximum quality.
JpegOptions() : quality(1.0f) { } // 1.0 maximum quality.
float quality;
};
const char* onGetName() const override { return "jpeg"; }
@ -238,8 +240,11 @@ bool JpegFormat::onSave(FileOp* fop)
JSAMPARRAY buffer;
JDIMENSION buffer_height;
const base::SharedPtr<JpegOptions> jpeg_options = fop->formatOptions();
const int qualityValue = (int)MID(0, 100.0f * jpeg_options->quality, 100);
int c;
LOG("JPEG: Saving with options: quality=%d\n", qualityValue);
// Open the file for write in it.
FileHandle handle(open_file_with_exception(fop->filename(), "wb"));
FILE* file = handle.get();
@ -266,7 +271,7 @@ bool JpegFormat::onSave(FileOp* fop)
}
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, (int)MID(0, 100.0f * jpeg_options->quality, 100), true);
jpeg_set_quality(&cinfo, qualityValue, true);
cinfo.dct_method = JDCT_ISLOW;
cinfo.smoothing_factor = 0;
@ -363,24 +368,25 @@ base::SharedPtr<FormatOptions> JpegFormat::onGetFormatOptions(FileOp* fop)
return jpeg_options;
try {
// Configuration parameters
jpeg_options->quality = get_config_float("JPEG", "Quality", 1.0f);
auto& pref = Preferences::instance();
// Load the window to ask to the user the JPEG options he wants.
UniquePtr<ui::Window> window(app::load_widget<ui::Window>("jpeg_options.xml", "jpeg_options"));
ui::Slider* slider_quality = app::find_widget<ui::Slider>(window, "quality");
ui::Widget* ok = app::find_widget<ui::Widget>(window, "ok");
if (pref.isSet(pref.jpeg.quality))
jpeg_options->quality = pref.jpeg.quality();
slider_quality->setValue(int(jpeg_options->quality * 10.0f));
if (pref.jpeg.showAlert()) {
app::gen::JpegOptions win;
win.quality()->setValue(int(jpeg_options->quality * 10.0f));
win.openWindowInForeground();
window->openWindowInForeground();
if (win.closer() == win.ok()) {
pref.jpeg.quality(float(win.quality()->getValue()) / 10.0f);
pref.jpeg.showAlert(!win.dontShow()->isSelected());
if (window->closer() == ok) {
jpeg_options->quality = slider_quality->getValue() / 10.0f;
set_config_float("JPEG", "Quality", jpeg_options->quality);
}
else {
jpeg_options.reset(NULL);
jpeg_options->quality = pref.jpeg.quality();
}
else {
jpeg_options.reset(nullptr);
}
}
return jpeg_options;

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.
@ -13,7 +13,6 @@
#include "app/file/file.h"
#include "app/file/file_format.h"
#include "app/file/format_options.h"
#include "app/ini_file.h"
#include "base/file_handle.h"
#include "doc/doc.h"

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -25,12 +25,24 @@ namespace app {
std::string m_name;
};
class OptionBase {
public:
OptionBase(Section* section, const char* id)
: m_section(section)
, m_id(id) {
}
const char* section() const { return m_section->name(); }
const char* id() const { return m_id; }
protected:
Section* m_section;
const char* m_id;
};
template<typename T>
class Option {
class Option : public OptionBase {
public:
Option(Section* section, const char* id, const T& defaultValue = T())
: m_section(section)
, m_id(id)
: OptionBase(section, id)
, m_default(defaultValue)
, m_value(defaultValue)
, m_dirty(false) {
@ -60,8 +72,6 @@ namespace app {
setValue(value);
}
const char* section() const { return m_section->name(); }
const char* id() const { return m_id; }
const T& defaultValue() const { return m_default; }
void setDefaultValue(const T& defValue) {
m_default = defValue;
@ -91,8 +101,6 @@ namespace app {
obs::signal<void(const T&)> AfterChange;
private:
Section* m_section;
const char* m_id;
T m_default;
T m_value;
bool m_dirty;

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.
@ -77,6 +77,11 @@ void Preferences::save()
flush_config_file();
}
bool Preferences::isSet(OptionBase& opt) const
{
return (get_config_string(opt.section(), opt.id(), nullptr) != nullptr);
}
ToolPreferences& Preferences::tool(tools::Tool* tool)
{
ASSERT(tool != NULL);

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -54,6 +54,10 @@ namespace app {
void load();
void save();
// Returns true if the given option was set by the user or false
// if it contains the default value.
bool isSet(OptionBase& opt) const;
ToolPreferences& tool(tools::Tool* tool);
DocumentPreferences& document(const app::Document* doc);