mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-01 19:13:43 +00:00
Fix using default preferences on new documents (fix #2198)
Fixed regression introduced in 002abc92452d89dabe601af0bfedf81e3e2ab0fd. Bug reports: * https://github.com/aseprite/aseprite/issues/2198 * https://steamcommunity.com/app/431730/discussions/2/1657817111845334892/ * https://community.aseprite.org/t/grid-size-for-new-documents-not-applied/4305 Added new ASEPRITE_USER_FOLDER environment variable to test preferences from a clean folder.
This commit is contained in:
parent
f53ecab282
commit
6cab7b208c
@ -86,8 +86,13 @@ namespace app {
|
||||
|
||||
// Changes the default value and the current one.
|
||||
void setValueAndDefault(const T& value) {
|
||||
bool wasDirty = isDirty();
|
||||
|
||||
setDefaultValue(value);
|
||||
setValue(value);
|
||||
|
||||
if (!wasDirty)
|
||||
cleanDirtyFlag();
|
||||
}
|
||||
|
||||
const T& defaultValue() const { return m_default; }
|
||||
|
@ -50,6 +50,16 @@ Preferences::Preferences()
|
||||
|
||||
load();
|
||||
|
||||
// Create a connection with the default document preferences grid
|
||||
// bounds to sync the default grid bounds for new sprites in the
|
||||
// "doc" layer.
|
||||
auto& defPref = document(nullptr);
|
||||
defPref.grid.bounds.AfterChange.connect(
|
||||
[](const gfx::Rect& newValue){
|
||||
doc::Sprite::SetDefaultGridBounds(newValue);
|
||||
});
|
||||
doc::Sprite::SetDefaultGridBounds(defPref.grid.bounds());
|
||||
|
||||
// Hide the menu bar depending on:
|
||||
// 1. this is the first run of the program
|
||||
// 2. the native menu bar is available
|
||||
@ -135,21 +145,21 @@ DocumentPreferences& Preferences::document(const Doc* doc)
|
||||
DocumentPreferences* docPref = new DocumentPreferences("");
|
||||
m_docs[doc] = docPref;
|
||||
|
||||
// If there is not a .ini file with the "doc" preferences to be
|
||||
// loaded, we will setup the default preferences for this file.
|
||||
// (This must be done just one time, when the .ini file with the
|
||||
// specific settings for "doc" doesn't exist.)
|
||||
if (doc && !base::is_file(docConfigFileName(doc))) {
|
||||
// Setup the preferences of this document with the default ones
|
||||
// (these preferences will be overwritten in the next statement
|
||||
// loading the preferences from the .ini file of this doc)
|
||||
if (doc) {
|
||||
// The default preferences for this document are the current
|
||||
// defaults for (document=nullptr).
|
||||
DocumentPreferences& defPref = this->document(nullptr);
|
||||
*docPref = defPref;
|
||||
|
||||
// Default values for symmetry
|
||||
docPref->symmetry.xAxis.setDefaultValue(doc->sprite()->width()/2);
|
||||
docPref->symmetry.yAxis.setDefaultValue(doc->sprite()->height()/2);
|
||||
docPref->symmetry.xAxis.setValueAndDefault(doc->sprite()->width()/2);
|
||||
docPref->symmetry.yAxis.setValueAndDefault(doc->sprite()->height()/2);
|
||||
}
|
||||
|
||||
// Load specific settings of this document
|
||||
serializeDocPref(doc, docPref, false);
|
||||
|
||||
return *docPref;
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -152,7 +153,11 @@ void ResourceFinder::includeUserDir(const char* filename)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
||||
if (App::instance()->isPortable()) {
|
||||
// $ASEPRITE_USER_FOLDER/filename
|
||||
if (const wchar_t* env = _wgetenv(L"ASEPRITE_USER_FOLDER")) {
|
||||
addPath(base::join_path(base::to_utf8(env), filename));
|
||||
}
|
||||
else if (App::instance()->isPortable()) {
|
||||
// $BINDIR/filename
|
||||
includeBinDir(filename);
|
||||
}
|
||||
@ -161,20 +166,30 @@ void ResourceFinder::includeUserDir(const char* filename)
|
||||
includeHomeDir(filename);
|
||||
}
|
||||
|
||||
#elif __APPLE__
|
||||
#else // Unix-like
|
||||
|
||||
// $HOME/Library/Application Support/Aseprite/filename
|
||||
addPath(
|
||||
base::join_path(
|
||||
base::join_path(base::get_lib_app_support_path(), PACKAGE),
|
||||
filename).c_str());
|
||||
// $ASEPRITE_USER_FOLDER/filename
|
||||
if (const char* env = std::getenv("ASEPRITE_USER_FOLDER")) {
|
||||
addPath(base::join_path(env, filename));
|
||||
}
|
||||
else {
|
||||
#ifdef __APPLE__
|
||||
|
||||
#else
|
||||
// $HOME/Library/Application Support/Aseprite/filename
|
||||
addPath(
|
||||
base::join_path(
|
||||
base::join_path(base::get_lib_app_support_path(), PACKAGE),
|
||||
filename).c_str());
|
||||
|
||||
// $HOME/.config/aseprite/filename
|
||||
includeHomeDir((std::string(".config/aseprite/") + filename).c_str());
|
||||
#else // !__APPLE__
|
||||
|
||||
#endif
|
||||
// $HOME/.config/aseprite/filename
|
||||
includeHomeDir((std::string(".config/aseprite/") + filename).c_str());
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // end Unix-like
|
||||
}
|
||||
|
||||
void ResourceFinder::includeDesktopDir(const char* filename)
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -42,6 +43,10 @@ namespace app {
|
||||
|
||||
// Tries to add the given filename in these locations:
|
||||
// For Windows:
|
||||
// - If ASEPRITE_USER_FOLDER environment variable is defined, it
|
||||
// should point the folder where the "user dir" is (it's useful
|
||||
// for testing purposes to test with an empty preferences
|
||||
// folder)
|
||||
// - If the app is running in portable mode, the filename
|
||||
// will be in the same location as the .exe file.
|
||||
// - If the app is installed, the filename will be inside
|
||||
|
@ -34,8 +34,19 @@ namespace doc {
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Constructors/Destructor
|
||||
|
||||
static gfx::Rect g_defaultGridBounds(0, 0, 16, 16);
|
||||
|
||||
// static
|
||||
gfx::Rect Sprite::DefaultGridBounds() { return gfx::Rect(0, 0, 16, 16); }
|
||||
gfx::Rect Sprite::DefaultGridBounds()
|
||||
{
|
||||
return g_defaultGridBounds;
|
||||
}
|
||||
|
||||
// static
|
||||
void Sprite::SetDefaultGridBounds(const gfx::Rect& defGridBounds)
|
||||
{
|
||||
g_defaultGridBounds = defGridBounds;
|
||||
}
|
||||
|
||||
Sprite::Sprite(const ImageSpec& spec,
|
||||
int ncolors)
|
||||
|
@ -101,6 +101,8 @@ namespace doc {
|
||||
void setTransparentColor(color_t color);
|
||||
|
||||
static gfx::Rect DefaultGridBounds();
|
||||
static void SetDefaultGridBounds(const gfx::Rect& defGridBounds);
|
||||
|
||||
const gfx::Rect& gridBounds() const { return m_gridBounds; }
|
||||
void setGridBounds(const gfx::Rect& rc) { m_gridBounds = rc; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user