From 732503eb30af837e6b2d11eb400a965ebcb36853 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 20 Sep 2020 13:16:14 -0300 Subject: [PATCH 1/7] Reword and fix some typos in CODING_STYLE guide --- docs/CODING_STYLE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index 732acec22..eeddccf33 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -77,11 +77,11 @@ private: ## C++11 -We are using some C++11 features, mainly: +We are using some modern C++ (C++11, C++14, etc.) features, mainly: * Use `nullptr` instead of `NULL` macro -* Use `auto` for complex types, iterators, or when it's variable type - obvious (e.g. `auto s = new Sprite;`) +* Use `auto` for complex types, iterators, or when the variable type + is obvious (e.g. `auto s = new Sprite;`) * Use range-based for loops (`for (const auto& item : values) { ... }`) * Use template alias (`template alias = orig;`) * Use non-generic lambda functions From 51b038ac024dd99902ab5b0c0d61524c48856b93 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 29 Sep 2020 15:42:55 -0300 Subject: [PATCH 2/7] Fix "H" character in mini font (to avoid confusion with "W") --- data/fonts/aseprite_mini.png | Bin 1510 -> 1522 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/data/fonts/aseprite_mini.png b/data/fonts/aseprite_mini.png index e1da15c7f4001014871014480d4d0e84a9b69f61..14b974ecb8524b41a837f827e42194ba28c2730b 100644 GIT binary patch delta 769 zcmaFH{fT>mGCu=jage(c!@6@aFBuqE*KAZZWvbVHH`o4QUCq_X6Q=I3#{Bvhz zQR&{|$;(!KvI+THvhPdRY0jWtdiE=!k{)x6I0$}9t~PT3K?OgDO?@y|TfZh!el zXZ|M&%a4A#b@zb28OFQEHT>ML}HU=LH3p=!`KYxJ-RZ&Efi7w}obxW`#b#z3!M#pR_IC!sG9s zEqGV9ZpPtyzgzET7S}}nuKdQ&{5RoZ^~#A+sWGLegG=sY_@>>_C|$E#+Qoiu_h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$IF2AaJFDe-_5R^P6Soc8wdhP&Te%#^oY`S$C3*}MC`!W%ZW zMpWJodl0xOKY-7MZU2pfa=Ga@l2zM)dM4ju;bKkRZoKu| Date: Tue, 13 Oct 2020 10:49:26 -0300 Subject: [PATCH 3/7] Fix copy & paste of images from GM2 --- src/clip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clip b/src/clip index 0a961d75f..5377679fd 160000 --- a/src/clip +++ b/src/clip @@ -1 +1 @@ -Subproject commit 0a961d75f4ffbf3bf24d707cfa66d6bcc1c295be +Subproject commit 5377679fd32f977b32b51d83e0fdc027adcdfe78 From 38d1b8a8e22fcc381f0257d88b6b15a14f4bebc9 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 17 Oct 2020 09:36:36 -0300 Subject: [PATCH 4/7] Fix Flip command labels when assigning shortcuts (fix #2545) --- src/app/commands/cmd_flip.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/commands/cmd_flip.cpp b/src/app/commands/cmd_flip.cpp index e66f84e71..82c497d54 100644 --- a/src/app/commands/cmd_flip.cpp +++ b/src/app/commands/cmd_flip.cpp @@ -252,9 +252,9 @@ std::string FlipCommand::onGetFriendlyName() const content = Strings::commands_Flip_Canvas(); if (m_flipType == doc::algorithm::FlipHorizontal) - content = Strings::commands_Flip_Horizontally(); + orientation = Strings::commands_Flip_Horizontally(); else - content = Strings::commands_Flip_Vertically(); + orientation = Strings::commands_Flip_Vertically(); return fmt::format(getBaseFriendlyName(), content, orientation); } From 661f4897b297fb529ec372ec14f42696ccdacb94 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 20 Oct 2020 09:50:27 -0300 Subject: [PATCH 5/7] Check that we're in the UI thread when modifying the widgets collection --- src/ui/intern.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ui/intern.cpp b/src/ui/intern.cpp index 75f3e94aa..96d490d61 100644 --- a/src/ui/intern.cpp +++ b/src/ui/intern.cpp @@ -1,4 +1,5 @@ // Aseprite UI Library +// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. @@ -9,6 +10,7 @@ #endif #include "ui/manager.h" +#include "ui/system.h" #include "ui/theme.h" #include "ui/widget.h" #include "ui/window.h" @@ -22,21 +24,29 @@ static std::list* widgets; void initWidgets() { + assert_ui_thread(); + widgets = new std::list; } void exitWidgets() { + assert_ui_thread(); + delete widgets; } void addWidget(Widget* widget) { + assert_ui_thread(); + widgets->push_back(widget); } void removeWidget(Widget* widget) { + assert_ui_thread(); + ASSERT(!Manager::widgetAssociatedToManager(widget)); auto it = std::find(widgets->begin(), widgets->end(), widget); @@ -46,6 +56,8 @@ void removeWidget(Widget* widget) void reinitThemeForAllWidgets() { + assert_ui_thread(); + // Reinitialize the theme of each widget auto theme = get_theme(); for (auto widget : *widgets) From 14893fbaf86fe6412738c265a14c02ea8d3a791f Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 22 Oct 2020 11:36:52 -0300 Subject: [PATCH 6/7] [lua] Add functions to make/remove directories with app.fs --- src/app/script/api_version.h | 2 +- src/app/script/app_fs_object.cpp | 72 +++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/app/script/api_version.h b/src/app/script/api_version.h index 9d7fa1b9f..dc6e480fd 100644 --- a/src/app/script/api_version.h +++ b/src/app/script/api_version.h @@ -10,6 +10,6 @@ // Increment this value if the scripting API is modified between two // released Aseprite versions. -#define API_VERSION 12 +#define API_VERSION 13 #endif diff --git a/src/app/script/app_fs_object.cpp b/src/app/script/app_fs_object.cpp index 9dd265492..58ea15775 100644 --- a/src/app/script/app_fs_object.cpp +++ b/src/app/script/app_fs_object.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2020 Igara Studio S.A. // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -11,6 +11,7 @@ #include "app/app.h" #include "app/resource_finder.h" #include "app/script/luacpp.h" +#include "app/script/security.h" #include "base/fs.h" namespace app { @@ -117,6 +118,71 @@ int AppFS_listFiles(lua_State* L) return 1; } +int AppFS_makeDirectory(lua_State* L) +{ + const char* path = lua_tostring(L, 1); + if (base::is_directory(path)) { + lua_pushboolean(L, true); + return 1; + } + + if (!ask_access(L, path, FileAccessMode::Write, true)) + return luaL_error(L, "the script doesn't have access to create the directory '%s'", path); + + try { + // TODO don't throw exception from base::make_directory() function + base::make_directory(path); + } + catch (const std::exception&) { + // Do nothing + } + lua_pushboolean(L, base::is_directory(path)); + return 1; +} + +int AppFS_makeAllDirectories(lua_State* L) +{ + const char* path = lua_tostring(L, 1); + if (base::is_directory(path)) { + lua_pushboolean(L, true); + return 1; + } + + if (!ask_access(L, path, FileAccessMode::Write, true)) + return luaL_error(L, "the script doesn't have access to create all directories '%s'", path); + + try { + base::make_all_directories(path); + } + catch (const std::exception&) { + // Do nothing + } + lua_pushboolean(L, base::is_directory(path)); + return 1; +} + +int AppFS_removeDirectory(lua_State* L) +{ + const char* path = lua_tostring(L, 1); + if (!base::is_directory(path)) { + lua_pushboolean(L, (base::is_file(path) ? false: // Cannot remove files + true)); // The directory is already removed + return 1; + } + + if (!ask_access(L, path, FileAccessMode::Write, true)) + return luaL_error(L, "the script doesn't have access to remove the directory '%s'", path); + + try { + base::remove_directory(path); + } + catch (const std::exception&) { + // do nothing... + } + lua_pushboolean(L, !base::is_directory(path)); + return 1; +} + const Property AppFS_properties[] = { { "pathSeparator", AppFS_pathSeparator, nullptr }, // Special folder names @@ -142,6 +208,10 @@ const luaL_Reg AppFS_methods[] = { { "isDirectory", AppFS_isDirectory }, { "fileSize", AppFS_fileSize }, { "listFiles", AppFS_listFiles }, + // Manipulate directories + { "makeDirectory", AppFS_makeDirectory }, + { "makeAllDirectories", AppFS_makeAllDirectories }, + { "removeDirectory", AppFS_removeDirectory }, { nullptr, nullptr } }; From ca013ff5d85dccaea00ee8ba13fca6aa5548c86c Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 22 Oct 2020 12:17:49 -0300 Subject: [PATCH 7/7] [lua] Check that some arguments are really strings in make/removeDir --- src/app/script/app_fs_object.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/script/app_fs_object.cpp b/src/app/script/app_fs_object.cpp index 58ea15775..1f872377c 100644 --- a/src/app/script/app_fs_object.cpp +++ b/src/app/script/app_fs_object.cpp @@ -120,7 +120,7 @@ int AppFS_listFiles(lua_State* L) int AppFS_makeDirectory(lua_State* L) { - const char* path = lua_tostring(L, 1); + const char* path = luaL_checkstring(L, 1); if (base::is_directory(path)) { lua_pushboolean(L, true); return 1; @@ -142,7 +142,7 @@ int AppFS_makeDirectory(lua_State* L) int AppFS_makeAllDirectories(lua_State* L) { - const char* path = lua_tostring(L, 1); + const char* path = luaL_checkstring(L, 1); if (base::is_directory(path)) { lua_pushboolean(L, true); return 1; @@ -163,7 +163,7 @@ int AppFS_makeAllDirectories(lua_State* L) int AppFS_removeDirectory(lua_State* L) { - const char* path = lua_tostring(L, 1); + const char* path = luaL_checkstring(L, 1); if (!base::is_directory(path)) { lua_pushboolean(L, (base::is_file(path) ? false: // Cannot remove files true)); // The directory is already removed