mirror of https://github.com/aseprite/aseprite.git
Improve preference resetting: window, brushes and preserve uuid
This commit is contained in:
parent
2f2f522108
commit
039bdda695
|
@ -1551,6 +1551,9 @@ reset_installed = Remove installed themes, extensions, and palettes
|
|||
reset_recents = Clear the recently opened file list (including pinned files)
|
||||
reset_perfile = Remove any per-file settings
|
||||
reset_perfile_tooltip = These are specific to opened files and includes\nthings like grid options, background colors, etc.
|
||||
reset_window = Reset window sizes and placement
|
||||
reset_brushes = Reset user brushes
|
||||
reset_toggle = Toggle selection
|
||||
reset = &Reset
|
||||
ok = &OK
|
||||
apply = &Apply
|
||||
|
|
|
@ -622,7 +622,11 @@
|
|||
<check id="installed_reset" text="@.reset_installed" />
|
||||
<check id="recent_reset" text="@.reset_recents" />
|
||||
<check id="perfile_reset" text="@.reset_perfile" tooltip="@.reset_perfile_tooltip" />
|
||||
<check id="window_reset" text="@.reset_window" />
|
||||
<check id="brushes_reset" text="@.reset_brushes" />
|
||||
<separator horizontal="true" />
|
||||
<hbox>
|
||||
<check id="reset_toggle" text="@.reset_toggle" />
|
||||
<hbox expansive="true" />
|
||||
<button id="reset_selected_button" text="@.reset" minwidth="60" />
|
||||
</hbox>
|
||||
|
|
|
@ -181,20 +181,7 @@ void save_xml_image(XMLElement* imageElem, const Image* image)
|
|||
|
||||
AppBrushes::AppBrushes()
|
||||
{
|
||||
m_standard.push_back(BrushRef(new Brush(kCircleBrushType, 7, 0)));
|
||||
m_standard.push_back(BrushRef(new Brush(kSquareBrushType, 7, 0)));
|
||||
m_standard.push_back(BrushRef(new Brush(kLineBrushType, 7, 44)));
|
||||
|
||||
std::string fn = userBrushesFilename();
|
||||
if (base::is_file(fn)) {
|
||||
try {
|
||||
load(fn);
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
LOG(ERROR, "BRSH: Error loading user brushes from '%s': %s\n", fn.c_str(), ex.what());
|
||||
}
|
||||
}
|
||||
m_userBrushesFilename = fn;
|
||||
init();
|
||||
}
|
||||
|
||||
AppBrushes::~AppBrushes()
|
||||
|
@ -213,6 +200,13 @@ AppBrushes::~AppBrushes()
|
|||
}
|
||||
}
|
||||
|
||||
void AppBrushes::reset()
|
||||
{
|
||||
m_standard.clear();
|
||||
init();
|
||||
ItemsChange();
|
||||
}
|
||||
|
||||
AppBrushes::slot_id AppBrushes::addBrushSlot(const BrushSlot& brush)
|
||||
{
|
||||
// Use an empty slot
|
||||
|
@ -303,6 +297,25 @@ bool AppBrushes::isBrushSlotLocked(slot_id slot) const
|
|||
static const int kBrushFlags = int(BrushSlot::Flags::BrushType) | int(BrushSlot::Flags::BrushSize) |
|
||||
int(BrushSlot::Flags::BrushAngle);
|
||||
|
||||
void AppBrushes::init()
|
||||
{
|
||||
m_standard.resize(3);
|
||||
m_standard[0] = BrushRef(new Brush(kCircleBrushType, 7, 0));
|
||||
m_standard[1] = BrushRef(new Brush(kSquareBrushType, 7, 0));
|
||||
m_standard[2] = BrushRef(new Brush(kLineBrushType, 7, 44));
|
||||
|
||||
const std::string fn = userBrushesFilename();
|
||||
if (base::is_file(fn)) {
|
||||
try {
|
||||
load(fn);
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
LOG(ERROR, "BRSH: Error loading user brushes from '%s': %s\n", fn.c_str(), ex.what());
|
||||
}
|
||||
}
|
||||
m_userBrushesFilename = fn;
|
||||
}
|
||||
|
||||
void AppBrushes::load(const std::string& filename)
|
||||
{
|
||||
XMLDocumentRef doc = app::open_xml(filename);
|
||||
|
|
|
@ -27,6 +27,8 @@ public:
|
|||
AppBrushes();
|
||||
~AppBrushes();
|
||||
|
||||
void reset();
|
||||
|
||||
// Adds a new brush and returns the slot number where the brush
|
||||
// is now available.
|
||||
slot_id addBrushSlot(const BrushSlot& brush);
|
||||
|
@ -44,10 +46,12 @@ public:
|
|||
|
||||
obs::signal<void()> ItemsChange;
|
||||
|
||||
static std::string userBrushesFilename();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void load(const std::string& filename);
|
||||
void save(const std::string& filename) const;
|
||||
static std::string userBrushesFilename();
|
||||
|
||||
doc::Brushes m_standard;
|
||||
BrushSlots m_slots;
|
||||
|
|
|
@ -459,14 +459,35 @@ public:
|
|||
auto validateYesButton = [this] {
|
||||
resetSelectedButton()->setEnabled(
|
||||
defaultReset()->isSelected() || installedReset()->isSelected() ||
|
||||
recentReset()->isSelected() || perfileReset()->isSelected() || toolsReset()->isSelected());
|
||||
recentReset()->isSelected() || perfileReset()->isSelected() ||
|
||||
windowReset()->isSelected() || toolsReset()->isSelected() || brushesReset()->isSelected());
|
||||
|
||||
resetToggle()->setSelected(defaultReset()->isSelected() && installedReset()->isSelected() &&
|
||||
recentReset()->isSelected() && perfileReset()->isSelected() &&
|
||||
windowReset()->isSelected() && toolsReset()->isSelected() &&
|
||||
brushesReset()->isSelected());
|
||||
};
|
||||
|
||||
defaultReset()->Click.connect(validateYesButton);
|
||||
installedReset()->Click.connect(validateYesButton);
|
||||
recentReset()->Click.connect(validateYesButton);
|
||||
perfileReset()->Click.connect(validateYesButton);
|
||||
toolsReset()->Click.connect(validateYesButton);
|
||||
windowReset()->Click.connect(validateYesButton);
|
||||
brushesReset()->Click.connect(validateYesButton);
|
||||
resetSelectedButton()->Click.connect([this] { onResetDefault(); });
|
||||
resetToggle()->Click.connect([this] {
|
||||
bool toggle = resetToggle()->isSelected();
|
||||
defaultReset()->setSelected(toggle);
|
||||
installedReset()->setSelected(toggle);
|
||||
recentReset()->setSelected(toggle);
|
||||
perfileReset()->setSelected(toggle);
|
||||
toolsReset()->setSelected(toggle);
|
||||
windowReset()->setSelected(toggle);
|
||||
brushesReset()->setSelected(toggle);
|
||||
brushesReset()->Click(); // Hacky way to trigger validateYesButton
|
||||
brushesReset()->Click();
|
||||
});
|
||||
|
||||
defaultReset()->setSelected(true);
|
||||
|
||||
|
@ -1126,6 +1147,32 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
if (windowReset()->isSelected()) {
|
||||
static constexpr auto windowSections = {
|
||||
"GfxMode", "CanvasSize", "CelProperties", "ChangePixelFormat",
|
||||
"ExportSpriteSheet", "ImportSpriteSheet", "KeyboardShortcuts", "LayerProperties",
|
||||
"MaskColor", "ExportFile", "SpriteProperties", "SpriteSize",
|
||||
"UndoHistory", "FileSelector", "MiniEditor"
|
||||
};
|
||||
for (const auto* windowSection : windowSections)
|
||||
del_config_section(windowSection);
|
||||
}
|
||||
|
||||
if (brushesReset()->isSelected()) {
|
||||
const auto userBrushPath = AppBrushes::userBrushesFilename();
|
||||
if (base::is_file(userBrushPath)) {
|
||||
try {
|
||||
base::delete_file(userBrushPath);
|
||||
LOG(VERBOSE, "Deleted user brushes file");
|
||||
|
||||
App::instance()->brushes().reset();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
LOG(ERROR, "Error resetting user brushes: %s - %s", userBrushPath.c_str(), ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultReset()->isSelected()) {
|
||||
onResetAlerts();
|
||||
onResetBg();
|
||||
|
@ -1139,6 +1186,8 @@ private:
|
|||
|
||||
// Resetting all things.
|
||||
for (Section* section : m_pref.sectionList()) {
|
||||
if (strcmp(section->name(), "updater") == 0)
|
||||
continue; // Ignore updater to preserve the UUID and other data.
|
||||
for (OptionBase* option : section->optionList()) {
|
||||
option->resetToDefault();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue