Use Tx instead of Transaction in commands

This commit is contained in:
David Capello 2018-08-20 16:00:59 -03:00
parent 587f697bda
commit 70629d6f89
56 changed files with 310 additions and 312 deletions

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2016-2017 David Capello // Copyright (C) 2016-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -17,7 +17,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/palettes.h" #include "app/modules/palettes.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/context_bar.h" #include "app/ui/context_bar.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
@ -121,9 +121,9 @@ void AddColorCommand::onExecute(Context* ctx)
if (document) { if (document) {
frame_t frame = writer.frame(); frame_t frame = writer.frame();
Transaction transaction(writer.context(), friendlyName(), ModifyDocument); Tx tx(writer.context(), friendlyName(), ModifyDocument);
transaction.execute(new cmd::SetPalette(sprite, frame, newPalette)); tx(new cmd::SetPalette(sprite, frame, newPalette));
transaction.commit(); tx.commit();
} }
set_current_palette(newPalette, true); set_current_palette(newPalette, true);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -12,7 +12,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -53,10 +53,10 @@ void BackgroundFromLayerCommand::onExecute(Context* context)
Doc* document(writer.document()); Doc* document(writer.document());
{ {
Transaction transaction(writer.context(), "Background from Layer"); Tx tx(writer.context(), "Background from Layer");
document->getApi(transaction).backgroundFromLayer( document->getApi(tx).backgroundFromLayer(
static_cast<LayerImage*>(writer.layer())); static_cast<LayerImage*>(writer.layer()));
transaction.commit(); tx.commit();
} }
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -13,7 +13,7 @@
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/button_set.h" #include "app/ui/button_set.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
@ -331,14 +331,14 @@ void CanvasSizeCommand::onExecute(Context* context)
ContextWriter writer(reader); ContextWriter writer(reader);
Doc* document = writer.document(); Doc* document = writer.document();
Sprite* sprite = writer.sprite(); Sprite* sprite = writer.sprite();
Transaction transaction(writer.context(), "Canvas Size"); Tx tx(writer.context(), "Canvas Size");
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
api.cropSprite(sprite, api.cropSprite(sprite,
gfx::Rect(x1, y1, gfx::Rect(x1, y1,
MID(1, x2-x1, DOC_SPRITE_MAX_WIDTH), MID(1, x2-x1, DOC_SPRITE_MAX_WIDTH),
MID(1, y2-y1, DOC_SPRITE_MAX_HEIGHT))); MID(1, y2-y1, DOC_SPRITE_MAX_HEIGHT)));
transaction.commit(); tx.commit();
document->generateMaskBoundaries(); document->generateMaskBoundaries();
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -16,7 +16,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/cels_range.h" #include "doc/cels_range.h"
@ -72,7 +72,7 @@ void CelOpacityCommand::onExecute(Context* context)
return; return;
{ {
Transaction transaction(writer.context(), "Set Cel Opacity"); Tx tx(writer.context(), "Set Cel Opacity");
// TODO the range of selected cels should be in app::Site. // TODO the range of selected cels should be in app::Site.
DocRange range = App::instance()->timeline()->range(); DocRange range = App::instance()->timeline()->range();
@ -86,12 +86,12 @@ void CelOpacityCommand::onExecute(Context* context)
if (!c->layer()->isBackground() && if (!c->layer()->isBackground() &&
c->layer()->isEditable() && c->layer()->isEditable() &&
m_opacity != c->opacity()) { m_opacity != c->opacity()) {
transaction.execute(new cmd::SetCelOpacity(c, m_opacity)); tx(new cmd::SetCelOpacity(c, m_opacity));
} }
} }
} }
transaction.commit(); tx.commit();
} }
update_screen_for_document(writer.document()); update_screen_for_document(writer.document());

View File

@ -17,7 +17,7 @@
#include "app/doc_event.h" #include "app/doc_event.h"
#include "app/doc_range.h" #include "app/doc_range.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "app/ui/user_data_popup.h" #include "app/ui/user_data_popup.h"
#include "app/ui_context.h" #include "app/ui_context.h"
@ -167,7 +167,7 @@ private:
m_userData != m_cel->data()->userData()))) { m_userData != m_cel->data()->userData()))) {
try { try {
ContextWriter writer(UIContext::instance()); ContextWriter writer(UIContext::instance());
Transaction transaction(writer.context(), "Set Cel Properties"); Tx tx(writer.context(), "Set Cel Properties");
DocRange range; DocRange range;
if (m_range.enabled()) if (m_range.enabled())
@ -181,12 +181,12 @@ private:
for (Cel* cel : sprite->uniqueCels(range.selectedFrames())) { for (Cel* cel : sprite->uniqueCels(range.selectedFrames())) {
if (range.contains(cel->layer())) { if (range.contains(cel->layer())) {
if (!cel->layer()->isBackground() && newOpacity != cel->opacity()) { if (!cel->layer()->isBackground() && newOpacity != cel->opacity()) {
transaction.execute(new cmd::SetCelOpacity(cel, newOpacity)); tx(new cmd::SetCelOpacity(cel, newOpacity));
} }
if (m_newUserData && if (m_newUserData &&
m_userData != cel->data()->userData()) { m_userData != cel->data()->userData()) {
transaction.execute(new cmd::SetUserData(cel->data(), m_userData)); tx(new cmd::SetUserData(cel->data(), m_userData));
// Redraw timeline because the cel's user data/color // Redraw timeline because the cel's user data/color
// might have changed. // might have changed.
@ -195,7 +195,7 @@ private:
} }
} }
transaction.commit(); tx.commit();
} }
catch (const std::exception& e) { catch (const std::exception& e) {
Console::showException(e); Console::showException(e);

View File

@ -472,9 +472,9 @@ void ChangePixelFormatCommand::onExecute(Context* context)
Sprite* sprite(job.sprite()); Sprite* sprite(job.sprite());
if (flatten) if (flatten)
job.transaction().execute(new cmd::FlattenLayers(sprite)); job.tx()(new cmd::FlattenLayers(sprite));
job.transaction().execute( job.tx()(
new cmd::SetPixelFormat( new cmd::SetPixelFormat(
sprite, m_format, sprite, m_format,
m_ditheringAlgorithm, m_ditheringAlgorithm,

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -13,7 +13,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/layer.h" #include "doc/layer.h"
@ -47,7 +47,7 @@ void ClearCelCommand::onExecute(Context* context)
Doc* document(writer.document()); Doc* document(writer.document());
bool nonEditableLayers = false; bool nonEditableLayers = false;
{ {
Transaction transaction(writer.context(), "Clear Cel"); Tx tx(writer.context(), "Clear Cel");
const Site* site = writer.site(); const Site* site = writer.site();
if (site->inTimeline() && if (site->inTimeline() &&
@ -66,18 +66,18 @@ void ClearCelCommand::onExecute(Context* context)
for (frame_t frame : site->selectedFrames().reversed()) { for (frame_t frame : site->selectedFrames().reversed()) {
if (layerImage->cel(frame)) if (layerImage->cel(frame))
document->getApi(transaction).clearCel(layerImage, frame); document->getApi(tx).clearCel(layerImage, frame);
} }
} }
} }
else if (writer.cel()) { else if (writer.cel()) {
if (writer.layer()->isEditableHierarchy()) if (writer.layer()->isEditableHierarchy())
document->getApi(transaction).clearCel(writer.cel()); document->getApi(tx).clearCel(writer.cel());
else else
nonEditableLayers = true; nonEditableLayers = true;
} }
transaction.commit(); tx.commit();
} }
if (nonEditableLayers) if (nonEditableLayers)

View File

@ -140,7 +140,7 @@ void ColorQuantizationCommand::onExecute(Context* context)
} }
if (*curPalette != *newPalette) if (*curPalette != *newPalette)
job.transaction().execute(new cmd::SetPalette(sprite, frame, newPalette.get())); job.tx()(new cmd::SetPalette(sprite, frame, newPalette.get()));
set_current_palette(newPalette.get(), false); set_current_palette(newPalette.get(), false);
ui::Manager::getDefault()->invalidate(); ui::Manager::getDefault()->invalidate();

View File

@ -12,7 +12,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/util/autocrop.h" #include "app/util/autocrop.h"
#include "doc/image.h" #include "doc/image.h"
@ -71,9 +71,9 @@ void CropSpriteCommand::onExecute(Context* context)
bounds = m_bounds; bounds = m_bounds;
{ {
Transaction transaction(writer.context(), "Sprite Crop"); Tx tx(writer.context(), "Sprite Crop");
document->getApi(transaction).cropSprite(sprite, bounds); document->getApi(tx).cropSprite(sprite, bounds);
transaction.commit(); tx.commit();
} }
document->generateMaskBoundaries(); document->generateMaskBoundaries();
@ -109,9 +109,9 @@ void AutocropSpriteCommand::onExecute(Context* context)
Doc* document(writer.document()); Doc* document(writer.document());
Sprite* sprite(writer.sprite()); Sprite* sprite(writer.sprite());
{ {
Transaction transaction(writer.context(), "Trim Sprite"); Tx tx(writer.context(), "Trim Sprite");
document->getApi(transaction).trimSprite(sprite); document->getApi(tx).trimSprite(sprite);
transaction.commit(); tx.commit();
} }
document->generateMaskBoundaries(); document->generateMaskBoundaries();

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-42017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -12,7 +12,7 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -44,9 +44,9 @@ void DeselectMaskCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
Doc* document(writer.document()); Doc* document(writer.document());
{ {
Transaction transaction(writer.context(), "Deselect", DoesntModifyDocument); Tx tx(writer.context(), "Deselect", DoesntModifyDocument);
transaction.execute(new cmd::DeselectMask(document)); tx(new cmd::DeselectMask(document));
transaction.commit(); tx.commit();
} }
document->generateMaskBoundaries(); document->generateMaskBoundaries();
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -16,7 +16,7 @@
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -51,13 +51,13 @@ void DuplicateLayerCommand::onExecute(Context* context)
Doc* document = writer.document(); Doc* document = writer.document();
{ {
Transaction transaction(writer.context(), "Layer Duplication"); Tx tx(writer.context(), "Layer Duplication");
LayerImage* sourceLayer = static_cast<LayerImage*>(writer.layer()); LayerImage* sourceLayer = static_cast<LayerImage*>(writer.layer());
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
api.duplicateLayerAfter(sourceLayer, api.duplicateLayerAfter(sourceLayer,
sourceLayer->parent(), sourceLayer->parent(),
sourceLayer); sourceLayer);
transaction.commit(); tx.commit();
} }
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -16,7 +16,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/util/expand_cel_canvas.h" #include "app/util/expand_cel_canvas.h"
#include "doc/algorithm/fill_selection.h" #include "doc/algorithm/fill_selection.h"
@ -77,11 +77,11 @@ void FillCommand::onExecute(Context* ctx)
app::Color color = pref.colorBar.fgColor(); app::Color color = pref.colorBar.fgColor();
{ {
Transaction transaction(writer.context(), "Fill Selection with Foreground Color"); Tx tx(writer.context(), "Fill Selection with Foreground Color");
{ {
ExpandCelCanvas expand( ExpandCelCanvas expand(
site, layer, site, layer,
TiledMode::NONE, transaction, TiledMode::NONE, tx,
ExpandCelCanvas::None); ExpandCelCanvas::None);
gfx::Region rgn(sprite->bounds() | gfx::Region rgn(sprite->bounds() |
@ -115,9 +115,9 @@ void FillCommand::onExecute(Context* ctx)
// If the cel wasn't deleted by cmd::ClearMask, we trim it. // If the cel wasn't deleted by cmd::ClearMask, we trim it.
Cel* cel = ctx->activeSite().cel(); Cel* cel = ctx->activeSite().cel();
if (cel && layer->isTransparent()) if (cel && layer->isTransparent())
transaction.execute(new cmd::TrimCel(cel)); tx(new cmd::TrimCel(cel));
transaction.commit(); tx.commit();
} }
doc->notifyGeneralUpdate(); doc->notifyGeneralUpdate();

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -12,7 +12,7 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -43,9 +43,9 @@ void FlattenLayersCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
Sprite* sprite = writer.sprite(); Sprite* sprite = writer.sprite();
{ {
Transaction transaction(writer.context(), "Flatten Layers"); Tx tx(writer.context(), "Flatten Layers");
transaction.execute(new cmd::FlattenLayers(sprite)); tx(new cmd::FlattenLayers(sprite));
transaction.commit(); tx.commit();
} }
update_screen_for_document(writer.document()); update_screen_for_document(writer.document());
} }

View File

@ -24,7 +24,7 @@
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/tools/tool_box.h" #include "app/tools/tool_box.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/editor/moving_pixels_state.h" #include "app/ui/editor/moving_pixels_state.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
@ -111,8 +111,8 @@ void FlipCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
Doc* document = writer.document(); Doc* document = writer.document();
Sprite* sprite = writer.sprite(); Sprite* sprite = writer.sprite();
Transaction transaction(writer.context(), friendlyName()); Tx tx(writer.context(), friendlyName());
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
Mask* mask = document->mask(); Mask* mask = document->mask();
if (m_flipMask && document->isMaskVisible()) { if (m_flipMask && document->isMaskVisible()) {
@ -141,12 +141,12 @@ void FlipCommand::onExecute(Context* context)
continue; continue;
if (mask->bitmap() && !mask->isRectangular()) if (mask->bitmap() && !mask->isRectangular())
transaction.execute(new cmd::FlipMaskedCel(cel, m_flipType)); tx(new cmd::FlipMaskedCel(cel, m_flipType));
else else
api.flipImage(image, flipBounds, m_flipType); api.flipImage(image, flipBounds, m_flipType);
if (cel->layer()->isTransparent()) if (cel->layer()->isTransparent())
transaction.execute(new cmd::TrimCel(cel)); tx(new cmd::TrimCel(cel));
} }
// When the mask is bigger than the cel bounds, we have to // When the mask is bigger than the cel bounds, we have to
// expand the cel, make the flip, and shrink it again. // expand the cel, make the flip, and shrink it again.
@ -157,7 +157,7 @@ void FlipCommand::onExecute(Context* context)
ExpandCelCanvas expand( ExpandCelCanvas expand(
site, cel->layer(), site, cel->layer(),
TiledMode::NONE, transaction, TiledMode::NONE, tx,
ExpandCelCanvas::None); ExpandCelCanvas::None);
expand.validateDestCanvas(gfx::Region(flipBounds)); expand.validateDestCanvas(gfx::Region(flipBounds));
@ -188,7 +188,7 @@ void FlipCommand::onExecute(Context* context)
if (m_flipType == doc::algorithm::FlipVertical) if (m_flipType == doc::algorithm::FlipVertical)
bounds.y = sprite->height() - bounds.h - bounds.y; bounds.y = sprite->height() - bounds.h - bounds.y;
transaction.execute(new cmd::SetCelBoundsF(cel, bounds)); tx(new cmd::SetCelBoundsF(cel, bounds));
} }
else { else {
api.setCelPosition api.setCelPosition
@ -208,11 +208,11 @@ void FlipCommand::onExecute(Context* context)
// Flip the mask. // Flip the mask.
Image* maskBitmap = mask->bitmap(); Image* maskBitmap = mask->bitmap();
if (maskBitmap) { if (maskBitmap) {
transaction.execute(new cmd::FlipMask(document, m_flipType)); tx(new cmd::FlipMask(document, m_flipType));
// Flip the mask position because the // Flip the mask position because the
if (!m_flipMask) if (!m_flipMask)
transaction.execute( tx(
new cmd::SetMaskPosition( new cmd::SetMaskPosition(
document, document,
gfx::Point( gfx::Point(
@ -226,7 +226,7 @@ void FlipCommand::onExecute(Context* context)
document->generateMaskBoundaries(); document->generateMaskBoundaries();
} }
transaction.commit(); tx.commit();
update_screen_for_document(document); update_screen_for_document(document);
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -15,7 +15,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/transaction.h" #include "app/tx.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -128,13 +128,13 @@ void FramePropertiesCommand::onExecute(Context* context)
int newMsecs = window.frlen()->textInt(); int newMsecs = window.frlen()->textInt();
ContextWriter writer(reader); ContextWriter writer(reader);
Transaction transaction(writer.context(), "Frame Duration"); Tx tx(writer.context(), "Frame Duration");
DocApi api = writer.document()->getApi(transaction); DocApi api = writer.document()->getApi(tx);
for (frame_t frame : selFrames) for (frame_t frame : selFrames)
api.setFrameDuration(writer.sprite(), frame, newMsecs); api.setFrameDuration(writer.sprite(), frame, newMsecs);
transaction.commit(); tx.commit();
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -17,7 +17,7 @@
#include "app/commands/params.h" #include "app/commands/params.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/loop_tag.h" #include "app/loop_tag.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/frame_tag_window.h" #include "app/ui/frame_tag_window.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/anidir.h" #include "doc/anidir.h"
@ -87,29 +87,29 @@ void FrameTagPropertiesCommand::onExecute(Context* context)
return; return;
ContextWriter writer(reader); ContextWriter writer(reader);
Transaction transaction(writer.context(), "Change Frame Tag Properties"); Tx tx(writer.context(), "Change Frame Tag Properties");
FrameTag* tag = const_cast<FrameTag*>(foundTag); FrameTag* tag = const_cast<FrameTag*>(foundTag);
std::string name = window.nameValue(); std::string name = window.nameValue();
if (tag->name() != name) if (tag->name() != name)
transaction.execute(new cmd::SetFrameTagName(tag, name)); tx(new cmd::SetFrameTagName(tag, name));
doc::frame_t from, to; doc::frame_t from, to;
window.rangeValue(from, to); window.rangeValue(from, to);
if (tag->fromFrame() != from || if (tag->fromFrame() != from ||
tag->toFrame() != to) { tag->toFrame() != to) {
transaction.execute(new cmd::SetFrameTagRange(tag, from, to)); tx(new cmd::SetFrameTagRange(tag, from, to));
} }
doc::color_t docColor = window.colorValue(); doc::color_t docColor = window.colorValue();
if (tag->color() != docColor) if (tag->color() != docColor)
transaction.execute(new cmd::SetFrameTagColor(tag, docColor)); tx(new cmd::SetFrameTagColor(tag, docColor));
doc::AniDir anidir = window.aniDirValue(); doc::AniDir anidir = window.aniDirValue();
if (tag->aniDir() != anidir) if (tag->aniDir() != anidir)
transaction.execute(new cmd::SetFrameTagAniDir(tag, anidir)); tx(new cmd::SetFrameTagAniDir(tag, anidir));
transaction.commit(); tx.commit();
} }
Command* CommandFactory::createFrameTagPropertiesCommand() Command* CommandFactory::createFrameTagPropertiesCommand()

View File

@ -21,7 +21,7 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/modules/palettes.h" #include "app/modules/palettes.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/drop_down_button.h" #include "app/ui/drop_down_button.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_decorator.h" #include "app/ui/editor/editor_decorator.h"
@ -385,8 +385,8 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
// The following steps modify the sprite, so we wrap all // The following steps modify the sprite, so we wrap all
// operations in a undo-transaction. // operations in a undo-transaction.
ContextWriter writer(context); ContextWriter writer(context);
Transaction transaction(writer.context(), "Import Sprite Sheet", ModifyDocument); Tx tx(writer.context(), "Import Sprite Sheet", ModifyDocument);
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
// Add the layer in the sprite. // Add the layer in the sprite.
LayerImage* resultLayer = api.newLayer(sprite->root(), "Sprite Sheet"); LayerImage* resultLayer = api.newLayer(sprite->root(), "Sprite Sheet");
@ -416,7 +416,7 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
// Set the size of the sprite to the tile size. // Set the size of the sprite to the tile size.
api.setSpriteSize(sprite, frameBounds.w, frameBounds.h); api.setSpriteSize(sprite, frameBounds.w, frameBounds.h);
transaction.commit(); tx.commit();
ASSERT(docPref); ASSERT(docPref);
if (docPref) { if (docPref) {

View File

@ -13,7 +13,7 @@
#include "app/commands/commands.h" #include "app/commands/commands.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/image.h" #include "doc/image.h"
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/primitives.h" #include "doc/primitives.h"
@ -93,9 +93,9 @@ void InvertMaskCommand::onExecute(Context* context)
mask->intersect(sprite->bounds()); mask->intersect(sprite->bounds());
// Set the new mask // Set the new mask
Transaction transaction(writer.context(), "Mask Invert", DoesntModifyDocument); Tx tx(writer.context(), "Mask Invert", DoesntModifyDocument);
transaction.execute(new cmd::SetMask(document, mask.get())); tx(new cmd::SetMask(document, mask.get()));
transaction.commit(); tx.commit();
document->generateMaskBoundaries(); document->generateMaskBoundaries();
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -12,7 +12,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -52,9 +52,9 @@ void LayerFromBackgroundCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
Doc* document(writer.document()); Doc* document(writer.document());
{ {
Transaction transaction(writer.context(), "Layer from Background"); Tx tx(writer.context(), "Layer from Background");
document->getApi(transaction).layerFromBackground(writer.layer()); document->getApi(tx).layerFromBackground(writer.layer());
transaction.commit(); tx.commit();
} }
update_screen_for_document(document); update_screen_for_document(document);
} }

View File

@ -16,7 +16,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "fmt/format.h" #include "fmt/format.h"
@ -68,7 +68,7 @@ void LayerOpacityCommand::onExecute(Context* context)
return; return;
{ {
Transaction transaction(writer.context(), "Set Layer Opacity"); Tx tx(writer.context(), "Set Layer Opacity");
// TODO the range of selected frames should be in app::Site. // TODO the range of selected frames should be in app::Site.
SelectedLayers selLayers; SelectedLayers selLayers;
@ -82,11 +82,10 @@ void LayerOpacityCommand::onExecute(Context* context)
for (auto layer : selLayers) { for (auto layer : selLayers) {
if (layer->isImage()) if (layer->isImage())
transaction.execute( tx(new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), m_opacity));
new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), m_opacity));
} }
transaction.commit(); tx.commit();
} }
update_screen_for_document(writer.document()); update_screen_for_document(writer.document());

View File

@ -19,7 +19,7 @@
#include "app/doc.h" #include "app/doc.h"
#include "app/doc_event.h" #include "app/doc_event.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/separator_in_view.h" #include "app/ui/separator_in_view.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "app/ui/user_data_popup.h" #include "app/ui/user_data_popup.h"
@ -223,7 +223,7 @@ private:
newBlendMode != static_cast<LayerImage*>(m_layer)->blendMode()))))) { newBlendMode != static_cast<LayerImage*>(m_layer)->blendMode()))))) {
try { try {
ContextWriter writer(UIContext::instance()); ContextWriter writer(UIContext::instance());
Transaction transaction(writer.context(), "Set Layer Properties"); Tx tx(writer.context(), "Set Layer Properties");
DocRange range; DocRange range;
if (m_range.enabled()) if (m_range.enabled())
@ -240,17 +240,17 @@ private:
for (Layer* layer : range.selectedLayers()) { for (Layer* layer : range.selectedLayers()) {
if (nameChanged && newName != layer->name()) if (nameChanged && newName != layer->name())
transaction.execute(new cmd::SetLayerName(layer, newName)); tx(new cmd::SetLayerName(layer, newName));
if (userDataChanged && m_userData != layer->userData()) if (userDataChanged && m_userData != layer->userData())
transaction.execute(new cmd::SetUserData(layer, m_userData)); tx(new cmd::SetUserData(layer, m_userData));
if (layer->isImage()) { if (layer->isImage()) {
if (opacityChanged && newOpacity != static_cast<LayerImage*>(layer)->opacity()) if (opacityChanged && newOpacity != static_cast<LayerImage*>(layer)->opacity())
transaction.execute(new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), newOpacity)); tx(new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), newOpacity));
if (blendModeChanged && newBlendMode != static_cast<LayerImage*>(layer)->blendMode()) if (blendModeChanged && newBlendMode != static_cast<LayerImage*>(layer)->blendMode())
transaction.execute(new cmd::SetLayerBlendMode(static_cast<LayerImage*>(layer), newBlendMode)); tx(new cmd::SetLayerBlendMode(static_cast<LayerImage*>(layer), newBlendMode));
} }
} }
@ -258,7 +258,7 @@ private:
// might have changed. // might have changed.
App::instance()->timeline()->invalidate(); App::instance()->timeline()->invalidate();
transaction.commit(); tx.commit();
} }
catch (const std::exception& e) { catch (const std::exception& e) {
Console::showException(e); Console::showException(e);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -13,7 +13,7 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/layer.h" #include "doc/layer.h"
@ -57,7 +57,7 @@ void LinkCelsCommand::onExecute(Context* context)
if (!site.inTimeline()) if (!site.inTimeline())
return; return;
Transaction transaction(writer.context(), friendlyName()); Tx tx(writer.context(), friendlyName());
for (Layer* layer : site.selectedLayers()) { for (Layer* layer : site.selectedLayers()) {
if (!layer->isImage()) if (!layer->isImage())
@ -76,7 +76,7 @@ void LinkCelsCommand::onExecute(Context* context)
Cel* cel = layerImage->cel(frame); Cel* cel = layerImage->cel(frame);
if (cel) { if (cel) {
for (++it; it != end; ++it) { for (++it; it != end; ++it) {
transaction.execute( tx(
new cmd::CopyCel( new cmd::CopyCel(
layerImage, cel->frame(), layerImage, cel->frame(),
layerImage, *it, layerImage, *it,
@ -87,7 +87,7 @@ void LinkCelsCommand::onExecute(Context* context)
} }
} }
transaction.commit(); tx.commit();
} }
if (nonEditableLayers) if (nonEditableLayers)

View File

@ -15,7 +15,7 @@
#include "app/file_selector.h" #include "app/file_selector.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/util/msk_file.h" #include "app/util/msk_file.h"
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -77,9 +77,9 @@ void LoadMaskCommand::onExecute(Context* context)
{ {
ContextWriter writer(reader); ContextWriter writer(reader);
Doc* document = writer.document(); Doc* document = writer.document();
Transaction transaction(writer.context(), "Mask Load", DoesntModifyDocument); Tx tx(writer.context(), "Mask Load", DoesntModifyDocument);
transaction.execute(new cmd::SetMask(document, mask.get())); tx(new cmd::SetMask(document, mask.get()));
transaction.commit(); tx.commit();
document->generateMaskBoundaries(); document->generateMaskBoundaries();
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -12,7 +12,7 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
@ -49,9 +49,9 @@ void MaskAllCommand::onExecute(Context* context)
Mask newMask; Mask newMask;
newMask.replace(sprite->bounds()); newMask.replace(sprite->bounds());
Transaction transaction(writer.context(), "Select All", DoesntModifyDocument); Tx tx(writer.context(), "Select All", DoesntModifyDocument);
transaction.execute(new cmd::SetMask(document, &newMask)); tx(new cmd::SetMask(document, &newMask));
transaction.commit(); tx.commit();
document->resetTransformation(); document->resetTransformation();
document->generateMaskBoundaries(); document->generateMaskBoundaries();

View File

@ -19,7 +19,7 @@
#include "app/ini_file.h" #include "app/ini_file.h"
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/color_button.h" #include "app/ui/color_button.h"
#include "base/bind.h" #include "base/bind.h"
@ -159,10 +159,10 @@ void MaskByColorCommand::onExecute(Context* context)
Doc* document(writer.document()); Doc* document(writer.document());
if (apply) { if (apply) {
Transaction transaction(writer.context(), "Mask by Color", DoesntModifyDocument); Tx tx(writer.context(), "Mask by Color", DoesntModifyDocument);
std::unique_ptr<Mask> mask(generateMask(sprite, image, xpos, ypos)); std::unique_ptr<Mask> mask(generateMask(sprite, image, xpos, ypos));
transaction.execute(new cmd::SetMask(document, mask.get())); tx(new cmd::SetMask(document, mask.get()));
transaction.commit(); tx.commit();
set_config_color("MaskColor", "Color", m_buttonColor->getColor()); set_config_color("MaskColor", "Color", m_buttonColor->getColor());
set_config_int("MaskColor", "Tolerance", m_sliderTolerance->getValue()); set_config_int("MaskColor", "Tolerance", m_sliderTolerance->getValue());

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -17,7 +17,7 @@
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/tools/tool_box.h" #include "app/tools/tool_box.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/toolbar.h" #include "app/ui/toolbar.h"
#include "doc/algorithm/shrink_bounds.h" #include "doc/algorithm/shrink_bounds.h"
@ -82,9 +82,9 @@ void MaskContentCommand::onExecute(Context* context)
newMask.replace(cel->bounds()); newMask.replace(cel->bounds());
} }
Transaction transaction(writer.context(), "Select Content", DoesntModifyDocument); Tx tx(writer.context(), "Select Content", DoesntModifyDocument);
transaction.execute(new cmd::SetMask(document, &newMask)); tx(new cmd::SetMask(document, &newMask));
transaction.commit(); tx.commit();
document->resetTransformation(); document->resetTransformation();
document->generateMaskBoundaries(); document->generateMaskBoundaries();

View File

@ -18,7 +18,7 @@
#include "app/doc.h" #include "app/doc.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/blend_internals.h" #include "doc/blend_internals.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/image.h" #include "doc/image.h"
@ -68,7 +68,7 @@ void MergeDownLayerCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
Doc* document(writer.document()); Doc* document(writer.document());
Sprite* sprite(writer.sprite()); Sprite* sprite(writer.sprite());
Transaction transaction(writer.context(), "Merge Down Layer", ModifyDocument); Tx tx(writer.context(), "Merge Down Layer", ModifyDocument);
LayerImage* src_layer = static_cast<LayerImage*>(writer.layer()); LayerImage* src_layer = static_cast<LayerImage*>(writer.layer());
Layer* dst_layer = src_layer->getPrevious(); Layer* dst_layer = src_layer->getPrevious();
@ -106,7 +106,7 @@ void MergeDownLayerCommand::onExecute(Context* context)
dst_cel->setPosition(src_cel->x(), src_cel->y()); dst_cel->setPosition(src_cel->x(), src_cel->y());
dst_cel->setOpacity(opacity); dst_cel->setOpacity(opacity);
transaction.execute(new cmd::AddCel(dst_layer, dst_cel)); tx(new cmd::AddCel(dst_layer, dst_cel));
} }
// With destination // With destination
else { else {
@ -138,22 +138,22 @@ void MergeDownLayerCommand::onExecute(Context* context)
opacity, opacity,
src_layer->blendMode()); src_layer->blendMode());
transaction.execute(new cmd::SetCelPosition(dst_cel, tx(new cmd::SetCelPosition(dst_cel,
bounds.x, bounds.y)); bounds.x, bounds.y));
if (dst_cel->links()) if (dst_cel->links())
transaction.execute(new cmd::UnlinkCel(dst_cel)); tx(new cmd::UnlinkCel(dst_cel));
transaction.execute(new cmd::ReplaceImage(sprite, tx(new cmd::ReplaceImage(sprite,
dst_cel->imageRef(), new_image)); dst_cel->imageRef(), new_image));
} }
} }
} }
document->notifyLayerMergedDown(src_layer, dst_layer); document->notifyLayerMergedDown(src_layer, dst_layer);
document->getApi(transaction).removeLayer(src_layer); // src_layer is deleted inside removeLayer() document->getApi(tx).removeLayer(src_layer); // src_layer is deleted inside removeLayer()
transaction.commit(); tx.commit();
update_screen_for_document(document); update_screen_for_document(document);
} }

View File

@ -16,7 +16,7 @@
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/transaction.h" #include "app/tx.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/algorithm/modify_selection.h" #include "doc/algorithm/modify_selection.h"
#include "doc/brush_type.h" #include "doc/brush_type.h"
@ -138,11 +138,11 @@ void ModifySelectionCommand::onExecute(Context* context)
} }
// Set the new mask // Set the new mask
Transaction transaction(writer.context(), Tx tx(writer.context(),
friendlyName(), friendlyName(),
DoesntModifyDocument); DoesntModifyDocument);
transaction.execute(new cmd::SetMask(document, mask.get())); tx(new cmd::SetMask(document, mask.get()));
transaction.commit(); tx.commit();
document->generateMaskBoundaries(); document->generateMaskBoundaries();
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -19,7 +19,7 @@
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/doc_view.h" #include "app/ui/doc_view.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui_context.h" #include "app/ui_context.h"
@ -82,10 +82,10 @@ void MoveMaskCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
Doc* document(writer.document()); Doc* document(writer.document());
{ {
Transaction transaction(writer.context(), "Move Selection", DoesntModifyDocument); Tx tx(writer.context(), "Move Selection", DoesntModifyDocument);
gfx::Point pt = document->mask()->bounds().origin(); gfx::Point pt = document->mask()->bounds().origin();
document->getApi(transaction).setMaskPosition(pt.x+delta.x, pt.y+delta.y); document->getApi(tx).setMaskPosition(pt.x+delta.x, pt.y+delta.y);
transaction.commit(); tx.commit();
} }
document->generateMaskBoundaries(); document->generateMaskBoundaries();
@ -98,9 +98,9 @@ void MoveMaskCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
if (writer.cel()) { if (writer.cel()) {
// Rotate content // Rotate content
Transaction transaction(writer.context(), "Shift Pixels"); Tx tx(writer.context(), "Shift Pixels");
transaction.execute(new cmd::ShiftMaskedCel(writer.cel(), delta.x, delta.y)); tx(new cmd::ShiftMaskedCel(writer.cel(), delta.x, delta.y));
transaction.commit(); tx.commit();
} }
update_screen_for_document(writer.document()); update_screen_for_document(writer.document());
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -18,7 +18,7 @@
#include "app/tools/active_tool.h" #include "app/tools/active_tool.h"
#include "app/tools/ink.h" #include "app/tools/ink.h"
#include "app/tools/tool_box.h" #include "app/tools/tool_box.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/context_bar.h" #include "app/ui/context_bar.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/editor/select_box_state.h" #include "app/ui/editor/select_box_state.h"
@ -113,9 +113,9 @@ void NewBrushCommand::onQuickboxEnd(Editor* editor, const gfx::Rect& rect, ui::M
try { try {
ContextWriter writer(UIContext::instance(), 250); ContextWriter writer(UIContext::instance(), 250);
if (writer.cel()) { if (writer.cel()) {
Transaction transaction(writer.context(), "Clear"); Tx tx(writer.context(), "Clear");
transaction.execute(new cmd::ClearRect(writer.cel(), rect)); tx(new cmd::ClearRect(writer.cel(), rect));
transaction.commit(); tx.commit();
} }
} }
catch (const std::exception& ex) { catch (const std::exception& ex) {

View File

@ -17,7 +17,7 @@
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/doc_view.h" #include "app/ui/doc_view.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/main_window.h" #include "app/ui/main_window.h"
@ -90,8 +90,8 @@ void NewFrameCommand::onExecute(Context* context)
Doc* document(writer.document()); Doc* document(writer.document());
Sprite* sprite(writer.sprite()); Sprite* sprite(writer.sprite());
{ {
Transaction transaction(writer.context(), friendlyName()); Tx tx(writer.context(), friendlyName());
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
switch (m_content) { switch (m_content) {
@ -179,7 +179,7 @@ void NewFrameCommand::onExecute(Context* context)
} }
} }
transaction.commit(); tx.commit();
} }
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -13,7 +13,7 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/context.h" #include "app/context.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/frame_tag_window.h" #include "app/ui/frame_tag_window.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "doc/frame_tag.h" #include "doc/frame_tag.h"
@ -73,10 +73,10 @@ void NewFrameTagCommand::onExecute(Context* context)
{ {
ContextWriter writer(reader); ContextWriter writer(reader);
Transaction transaction(writer.context(), "New Frames Tag"); Tx tx(writer.context(), "New Frames Tag");
transaction.execute(new cmd::AddFrameTag(writer.sprite(), frameTag.get())); tx(new cmd::AddFrameTag(writer.sprite(), frameTag.get()));
frameTag.release(); frameTag.release();
transaction.commit(); tx.commit();
} }
App::instance()->timeline()->invalidate(); App::instance()->timeline()->invalidate();

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -18,7 +18,7 @@
#include "app/find_widget.h" #include "app/find_widget.h"
#include "app/load_widget.h" #include "app/load_widget.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/main_window.h" #include "app/ui/main_window.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/ui_context.h" #include "app/ui_context.h"
@ -177,10 +177,10 @@ void NewLayerCommand::onExecute(Context* context)
Layer* layer = nullptr; Layer* layer = nullptr;
{ {
Transaction transaction( Tx tx(
writer.context(), writer.context(),
std::string("New ") + layerPrefix()); std::string("New ") + layerPrefix());
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
bool afterBackground = false; bool afterBackground = false;
switch (m_type) { switch (m_type) {
@ -236,7 +236,7 @@ void NewLayerCommand::onExecute(Context* context)
if (sameParents == selLayers.size()) { if (sameParents == selLayers.size()) {
for (Layer* newChild : selLayers.toLayerList()) { for (Layer* newChild : selLayers.toLayerList()) {
transaction.execute( tx(
new cmd::MoveLayer(newChild, layer, new cmd::MoveLayer(newChild, layer,
static_cast<LayerGroup*>(layer)->lastLayer())); static_cast<LayerGroup*>(layer)->lastLayer()));
} }
@ -311,7 +311,7 @@ void NewLayerCommand::onExecute(Context* context)
} }
} }
transaction.commit(); tx.commit();
} }
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -13,7 +13,7 @@
#include "app/commands/params.h" #include "app/commands/params.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/palettes.h" #include "app/modules/palettes.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "ui/manager.h" #include "ui/manager.h"
@ -65,9 +65,9 @@ void PaletteSizeCommand::onExecute(Context* context)
palette.resize(MID(1, ncolors, std::numeric_limits<int>::max())); palette.resize(MID(1, ncolors, std::numeric_limits<int>::max()));
ContextWriter writer(reader); ContextWriter writer(reader);
Transaction transaction(context, "Palette Size", ModifyDocument); Tx tx(context, "Palette Size", ModifyDocument);
transaction.execute(new cmd::SetPalette(writer.sprite(), frame, &palette)); tx(new cmd::SetPalette(writer.sprite(), frame, &palette));
transaction.commit(); tx.commit();
set_current_palette(&palette, false); set_current_palette(&palette, false);
ui::Manager::getDefault()->invalidate(); ui::Manager::getDefault()->invalidate();

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -13,7 +13,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -49,8 +49,8 @@ void RemoveFrameCommand::onExecute(Context* context)
Doc* document(writer.document()); Doc* document(writer.document());
Sprite* sprite(writer.sprite()); Sprite* sprite(writer.sprite());
{ {
Transaction transaction(writer.context(), "Remove Frame"); Tx tx(writer.context(), "Remove Frame");
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
const Site* site = writer.site(); const Site* site = writer.site();
if (site->inTimeline() && if (site->inTimeline() &&
!site->selectedFrames().empty()) { !site->selectedFrames().empty()) {
@ -62,7 +62,7 @@ void RemoveFrameCommand::onExecute(Context* context)
api.removeFrame(sprite, writer.frame()); api.removeFrame(sprite, writer.frame());
} }
transaction.commit(); tx.commit();
} }
update_screen_for_document(document); update_screen_for_document(document);
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -15,7 +15,7 @@
#include "app/context.h" #include "app/context.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/loop_tag.h" #include "app/loop_tag.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/frame_tag.h" #include "doc/frame_tag.h"
@ -77,9 +77,9 @@ void RemoveFrameTagCommand::onExecute(Context* context)
if (!foundTag) if (!foundTag)
return; return;
Transaction transaction(writer.context(), "Remove Frame Tag"); Tx tx(writer.context(), "Remove Frame Tag");
transaction.execute(new cmd::RemoveFrameTag(sprite, foundTag)); tx(new cmd::RemoveFrameTag(sprite, foundTag));
transaction.commit(); tx.commit();
App::instance()->timeline()->invalidate(); App::instance()->timeline()->invalidate();
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -14,7 +14,7 @@
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "doc/layer.h" #include "doc/layer.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -52,8 +52,8 @@ void RemoveLayerCommand::onExecute(Context* context)
Doc* document(writer.document()); Doc* document(writer.document());
Sprite* sprite(writer.sprite()); Sprite* sprite(writer.sprite());
{ {
Transaction transaction(writer.context(), "Remove Layer"); Tx tx(writer.context(), "Remove Layer");
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
const Site* site = writer.site(); const Site* site = writer.site();
if (site->inTimeline() && if (site->inTimeline() &&
@ -87,7 +87,7 @@ void RemoveLayerCommand::onExecute(Context* context)
api.removeLayer(layer); api.removeLayer(layer);
} }
transaction.commit(); tx.commit();
} }
update_screen_for_document(document); update_screen_for_document(document);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2017 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -15,7 +15,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/transaction.h" #include "app/tx.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/slice.h" #include "doc/slice.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -83,16 +83,16 @@ void RemoveSliceCommand::onExecute(Context* context)
ContextWriter writer(reader, 500); ContextWriter writer(reader, 500);
Doc* document(writer.document()); Doc* document(writer.document());
Sprite* sprite(writer.sprite()); Sprite* sprite(writer.sprite());
Transaction transaction(writer.context(), "Remove Slice"); Tx tx(writer.context(), "Remove Slice");
Slice* slice = const_cast<Slice*>(foundSlice); Slice* slice = const_cast<Slice*>(foundSlice);
if (slice->size() > 1) { if (slice->size() > 1) {
transaction.execute(new cmd::SetSliceKey(slice, frame, SliceKey())); tx(new cmd::SetSliceKey(slice, frame, SliceKey()));
} }
else { else {
transaction.execute(new cmd::RemoveSlice(sprite, slice)); tx(new cmd::RemoveSlice(sprite, slice));
} }
transaction.commit(); tx.commit();
document->notifyGeneralUpdate(); document->notifyGeneralUpdate();
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -12,7 +12,7 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/mask.h" #include "doc/mask.h"
#include "doc/sprite.h" #include "doc/sprite.h"
@ -49,9 +49,9 @@ void ReselectMaskCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
Doc* document(writer.document()); Doc* document(writer.document());
{ {
Transaction transaction(writer.context(), "Reselect", DoesntModifyDocument); Tx tx(writer.context(), "Reselect", DoesntModifyDocument);
transaction.execute(new cmd::ReselectMask(document)); tx(new cmd::ReselectMask(document));
transaction.commit(); tx.commit();
} }
document->generateMaskBoundaries(); document->generateMaskBoundaries();

View File

@ -20,7 +20,7 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/sprite_job.h" #include "app/sprite_job.h"
#include "app/tools/tool_box.h" #include "app/tools/tool_box.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
@ -79,7 +79,7 @@ protected:
// [working thread] // [working thread]
void onJob() override { void onJob() override {
DocApi api = document()->getApi(transaction()); DocApi api = document()->getApi(tx());
// 1) Rotate cel positions // 1) Rotate cel positions
for (Cel* cel : m_cels) { for (Cel* cel : m_cels) {
@ -91,7 +91,7 @@ protected:
gfx::RectF bounds = cel->boundsF(); gfx::RectF bounds = cel->boundsF();
rotate_rect(bounds); rotate_rect(bounds);
if (cel->boundsF() != bounds) if (cel->boundsF() != bounds)
transaction().execute(new cmd::SetCelBoundsF(cel, bounds)); tx()(new cmd::SetCelBoundsF(cel, bounds));
} }
else { else {
gfx::Rect bounds = cel->bounds(); gfx::Rect bounds = cel->bounds();
@ -120,7 +120,7 @@ protected:
// cancel all the operation? // cancel all the operation?
if (isCanceled()) if (isCanceled())
return; // Transaction destructor will undo all operations return; // Tx destructor will undo all operations
} }
// rotate mask // rotate mask

View File

@ -17,7 +17,7 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/snap_to_grid.h" #include "app/snap_to_grid.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "doc/mask.h" #include "doc/mask.h"
#include "fmt/format.h" #include "fmt/format.h"
@ -93,11 +93,11 @@ void SelectTileCommand::onExecute(Context* ctx)
} }
// Set the new mask // Set the new mask
Transaction transaction(writer.context(), Tx tx(writer.context(),
friendlyName(), friendlyName(),
DoesntModifyDocument); DoesntModifyDocument);
transaction.execute(new cmd::SetMask(doc, mask.get())); tx(new cmd::SetMask(doc, mask.get()));
transaction.commit(); tx.commit();
doc->generateMaskBoundaries(); doc->generateMaskBoundaries();
update_screen_for_document(doc); update_screen_for_document(doc);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -17,7 +17,7 @@
#include "app/commands/params.h" #include "app/commands/params.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/loop_tag.h" #include "app/loop_tag.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/timeline/timeline.h" #include "app/ui/timeline/timeline.h"
#include "doc/frame_tag.h" #include "doc/frame_tag.h"
@ -108,16 +108,16 @@ void SetLoopSectionCommand::onExecute(Context* ctx)
loopTag = create_loop_tag(begin, end); loopTag = create_loop_tag(begin, end);
ContextWriter writer(ctx); ContextWriter writer(ctx);
Transaction transaction(writer.context(), "Add Loop"); Tx tx(writer.context(), "Add Loop");
transaction.execute(new cmd::AddFrameTag(sprite, loopTag)); tx(new cmd::AddFrameTag(sprite, loopTag));
transaction.commit(); tx.commit();
} }
else if (loopTag->fromFrame() != begin || else if (loopTag->fromFrame() != begin ||
loopTag->toFrame() != end) { loopTag->toFrame() != end) {
ContextWriter writer(ctx); ContextWriter writer(ctx);
Transaction transaction(writer.context(), "Set Loop Range"); Tx tx(writer.context(), "Set Loop Range");
transaction.execute(new cmd::SetFrameTagRange(loopTag, begin, end)); tx(new cmd::SetFrameTagRange(loopTag, begin, end));
transaction.commit(); tx.commit();
} }
else { else {
Command* cmd = Commands::instance()->byId(CommandId::FrameTagProperties()); Command* cmd = Commands::instance()->byId(CommandId::FrameTagProperties());
@ -127,9 +127,9 @@ void SetLoopSectionCommand::onExecute(Context* ctx)
else { else {
if (loopTag) { if (loopTag) {
ContextWriter writer(ctx); ContextWriter writer(ctx);
Transaction transaction(writer.context(), "Remove Loop"); Tx tx(writer.context(), "Remove Loop");
transaction.execute(new cmd::RemoveFrameTag(sprite, loopTag)); tx(new cmd::RemoveFrameTag(sprite, loopTag));
transaction.commit(); tx.commit();
} }
} }

View File

@ -14,7 +14,7 @@
#include "app/file_selector.h" #include "app/file_selector.h"
#include "app/ini_file.h" #include "app/ini_file.h"
#include "app/modules/palettes.h" #include "app/modules/palettes.h"
#include "app/transaction.h" #include "app/tx.h"
#include "doc/palette.h" #include "doc/palette.h"
#include "ui/alert.h" #include "ui/alert.h"
#include "ui/manager.h" #include "ui/manager.h"
@ -37,10 +37,10 @@ void SetPaletteCommand::onExecute(Context* context)
ContextWriter writer(context); ContextWriter writer(context);
if (writer.document()) { if (writer.document()) {
Transaction transaction(writer.context(), "Set Palette"); Tx tx(writer.context(), "Set Palette");
writer.document()->getApi(transaction) writer.document()->getApi(tx)
.setPalette(writer.sprite(), writer.frame(), m_palette); .setPalette(writer.sprite(), writer.frame(), m_palette);
transaction.commit(); tx.commit();
} }
set_current_palette(m_palette, false); set_current_palette(m_palette, false);

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2017 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -13,7 +13,7 @@
#include "app/cmd/set_user_data.h" #include "app/cmd/set_user_data.h"
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/slice_window.h" #include "app/ui/slice_window.h"
#include "base/convert_to.h" #include "base/convert_to.h"
#include "doc/slice.h" #include "doc/slice.h"
@ -85,16 +85,16 @@ void SlicePropertiesCommand::onExecute(Context* context)
{ {
ContextWriter writer(reader, 500); ContextWriter writer(reader, 500);
Transaction transaction(writer.context(), "Slice Properties"); Tx tx(writer.context(), "Slice Properties");
Slice* slice = const_cast<Slice*>(foundSlice); Slice* slice = const_cast<Slice*>(foundSlice);
std::string name = window.nameValue(); std::string name = window.nameValue();
if (slice->name() != name) if (slice->name() != name)
transaction.execute(new cmd::SetSliceName(slice, name)); tx(new cmd::SetSliceName(slice, name));
if (slice->userData() != window.userDataValue()) if (slice->userData() != window.userDataValue())
transaction.execute(new cmd::SetUserData(slice, window.userDataValue())); tx(new cmd::SetUserData(slice, window.userDataValue()));
if (key->bounds() != window.boundsValue() || if (key->bounds() != window.boundsValue() ||
key->center() != window.centerValue() || key->center() != window.centerValue() ||
@ -103,10 +103,10 @@ void SlicePropertiesCommand::onExecute(Context* context)
newKey.setBounds(window.boundsValue()); newKey.setBounds(window.boundsValue());
newKey.setCenter(window.centerValue()); newKey.setCenter(window.centerValue());
newKey.setPivot(window.pivotValue()); newKey.setPivot(window.pivotValue());
transaction.execute(new cmd::SetSliceKey(slice, frame, newKey)); tx(new cmd::SetSliceKey(slice, frame, newKey));
} }
transaction.commit(); tx.commit();
writer.document()->notifyGeneralUpdate(); writer.document()->notifyGeneralUpdate();
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -14,7 +14,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_button.h" #include "app/ui/color_button.h"
#include "app/util/pixel_ratio.h" #include "app/util/pixel_ratio.h"
#include "base/bind.h" #include "base/bind.h"
@ -136,16 +136,16 @@ void SpritePropertiesCommand::onExecute(Context* context)
if (index != sprite->transparentColor() || if (index != sprite->transparentColor() ||
pixelRatio != sprite->pixelRatio()) { pixelRatio != sprite->pixelRatio()) {
Transaction transaction(writer.context(), "Change Sprite Properties"); Tx tx(writer.context(), "Change Sprite Properties");
DocApi api = writer.document()->getApi(transaction); DocApi api = writer.document()->getApi(tx);
if (index != sprite->transparentColor()) if (index != sprite->transparentColor())
api.setSpriteTransparentColor(sprite, index); api.setSpriteTransparentColor(sprite, index);
if (pixelRatio != sprite->pixelRatio()) if (pixelRatio != sprite->pixelRatio())
transaction.execute(new cmd::SetPixelRatio(sprite, pixelRatio)); tx(new cmd::SetPixelRatio(sprite, pixelRatio));
transaction.commit(); tx.commit();
update_screen_for_document(writer.document()); update_screen_for_document(writer.document());
} }

View File

@ -72,7 +72,7 @@ protected:
// [working thread] // [working thread]
void onJob() override { void onJob() override {
DocApi api = writer().document()->getApi(transaction()); DocApi api = writer().document()->getApi(tx());
int cels_count = 0; int cels_count = 0;
for (Cel* cel : sprite()->uniqueCels()) { // TODO add size() member function to CelsRange for (Cel* cel : sprite()->uniqueCels()) { // TODO add size() member function to CelsRange
@ -89,7 +89,7 @@ protected:
// Resize the cel bounds only if it's from a reference layer // Resize the cel bounds only if it's from a reference layer
if (cel->layer()->isReference()) { if (cel->layer()->isReference()) {
gfx::RectF newBounds = scale_rect<double>(cel->boundsF()); gfx::RectF newBounds = scale_rect<double>(cel->boundsF());
transaction().execute(new cmd::SetCelBoundsF(cel, newBounds)); tx()(new cmd::SetCelBoundsF(cel, newBounds));
} }
else { else {
// Change its location // Change its location
@ -118,7 +118,7 @@ protected:
// Cancel all the operation? // Cancel all the operation?
if (isCanceled()) if (isCanceled())
return; // Transaction destructor will undo all operations return; // Tx destructor will undo all operations
} }
// Resize mask // Resize mask
@ -170,8 +170,7 @@ protected:
newKey.setPivot(gfx::Point(scale_x(newKey.pivot().x), newKey.setPivot(gfx::Point(scale_x(newKey.pivot().x),
scale_y(newKey.pivot().y))); scale_y(newKey.pivot().y)));
transaction().execute( tx()(new cmd::SetSliceKey(slice, k.frame(), newKey));
new cmd::SetSliceKey(slice, k.frame(), newKey));
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -13,7 +13,7 @@
#include "app/commands/command.h" #include "app/commands/command.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/layer.h" #include "doc/layer.h"
@ -47,7 +47,7 @@ void UnlinkCelCommand::onExecute(Context* context)
Doc* document(writer.document()); Doc* document(writer.document());
bool nonEditableLayers = false; bool nonEditableLayers = false;
{ {
Transaction transaction(writer.context(), "Unlink Cel"); Tx tx(writer.context(), "Unlink Cel");
const Site* site = writer.site(); const Site* site = writer.site();
if (site->inTimeline() && if (site->inTimeline() &&
@ -66,7 +66,7 @@ void UnlinkCelCommand::onExecute(Context* context)
for (frame_t frame : site->selectedFrames().reversed()) { for (frame_t frame : site->selectedFrames().reversed()) {
Cel* cel = layerImage->cel(frame); Cel* cel = layerImage->cel(frame);
if (cel && cel->links()) if (cel && cel->links())
transaction.execute(new cmd::UnlinkCel(cel)); tx(new cmd::UnlinkCel(cel));
} }
} }
} }
@ -74,13 +74,13 @@ void UnlinkCelCommand::onExecute(Context* context)
Cel* cel = writer.cel(); Cel* cel = writer.cel();
if (cel && cel->links()) { if (cel && cel->links()) {
if (cel->layer()->isEditableHierarchy()) if (cel->layer()->isEditableHierarchy())
transaction.execute(new cmd::UnlinkCel(writer.cel())); tx(new cmd::UnlinkCel(writer.cel()));
else else
nonEditableLayers = true; nonEditableLayers = true;
} }
} }
transaction.commit(); tx.commit();
} }
if (nonEditableLayers) if (nonEditableLayers)

View File

@ -17,14 +17,14 @@ SpriteJob::SpriteJob(const ContextReader& reader, const char* jobName)
, m_writer(reader, 500) , m_writer(reader, 500)
, m_document(m_writer.document()) , m_document(m_writer.document())
, m_sprite(m_writer.sprite()) , m_sprite(m_writer.sprite())
, m_transaction(m_writer.context(), jobName, ModifyDocument) , m_tx(m_writer.context(), jobName, ModifyDocument)
{ {
} }
SpriteJob::~SpriteJob() SpriteJob::~SpriteJob()
{ {
if (!isCanceled()) if (!isCanceled())
m_transaction.commit(); m_tx.commit();
} }
void SpriteJob::onJob() void SpriteJob::onJob()

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2017 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -11,7 +11,7 @@
#include "app/context.h" #include "app/context.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/job.h" #include "app/job.h"
#include "app/transaction.h" #include "app/tx.h"
#include "render/task_delegate.h" #include "render/task_delegate.h"
#include <functional> #include <functional>
@ -27,7 +27,7 @@ public:
ContextWriter& writer() { return m_writer; } ContextWriter& writer() { return m_writer; }
Doc* document() const { return m_document; } Doc* document() const { return m_document; }
Sprite* sprite() const { return m_sprite; } Sprite* sprite() const { return m_sprite; }
Transaction& transaction() { return m_transaction; } Tx& tx() { return m_tx; }
template<typename T> template<typename T>
void startJobWithCallback(T&& callback) { void startJobWithCallback(T&& callback) {
@ -47,7 +47,7 @@ private:
ContextWriter m_writer; ContextWriter m_writer;
Doc* m_document; Doc* m_document;
Sprite* m_sprite; Sprite* m_sprite;
Transaction m_transaction; Tx m_tx;
// Default implementation calls the given function in // Default implementation calls the given function in
// startJob(). Anyway you can just extended the SpriteJob and // startJob(). Anyway you can just extended the SpriteJob and

View File

@ -34,7 +34,7 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/modules/palettes.h" #include "app/modules/palettes.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_spectrum.h" #include "app/ui/color_spectrum.h"
#include "app/ui/color_tint_shade_tone.h" #include "app/ui/color_tint_shade_tone.h"
#include "app/ui/color_wheel.h" #include "app/ui/color_wheel.h"
@ -541,7 +541,7 @@ void ColorBar::onRemapButtonClick()
if (sprite) { if (sprite) {
ASSERT(sprite->pixelFormat() == IMAGE_INDEXED); ASSERT(sprite->pixelFormat() == IMAGE_INDEXED);
Transaction transaction(writer.context(), "Remap Colors", ModifyDocument); Tx tx(writer.context(), "Remap Colors", ModifyDocument);
bool remapPixels = true; bool remapPixels = true;
if (remap.isFor8bit()) { if (remap.isFor8bit()) {
@ -553,7 +553,7 @@ void ColorBar::onRemapButtonClick()
} }
if (remap.isInvertible(usedEntries)) { if (remap.isInvertible(usedEntries)) {
transaction.execute(new cmd::RemapColors(sprite, remap)); tx(new cmd::RemapColors(sprite, remap));
remapPixels = false; remapPixels = false;
} }
} }
@ -565,17 +565,17 @@ void ColorBar::onRemapButtonClick()
ImageRef newImage(Image::createCopy(celImage.get())); ImageRef newImage(Image::createCopy(celImage.get()));
doc::remap_image(newImage.get(), remap); doc::remap_image(newImage.get(), remap);
transaction.execute(new cmd::ReplaceImage( tx(new cmd::ReplaceImage(
sprite, celImage, newImage)); sprite, celImage, newImage));
} }
} }
color_t oldTransparent = sprite->transparentColor(); color_t oldTransparent = sprite->transparentColor();
color_t newTransparent = remap[oldTransparent]; color_t newTransparent = remap[oldTransparent];
if (oldTransparent != newTransparent) if (oldTransparent != newTransparent)
transaction.execute(new cmd::SetTransparentColor(sprite, newTransparent)); tx(new cmd::SetTransparentColor(sprite, newTransparent));
transaction.commit(); tx.commit();
} }
update_screen_for_document(writer.document()); update_screen_for_document(writer.document());
hideRemap(); hideRemap();
@ -625,9 +625,9 @@ void ColorBar::setPalette(const doc::Palette* newPalette, const std::string& act
frame_t frame = writer.frame(); frame_t frame = writer.frame();
if (sprite && if (sprite &&
newPalette->countDiff(sprite->palette(frame), nullptr, nullptr)) { newPalette->countDiff(sprite->palette(frame), nullptr, nullptr)) {
Transaction transaction(writer.context(), actionText, ModifyDocument); Tx tx(writer.context(), actionText, ModifyDocument);
transaction.execute(new cmd::SetPalette(sprite, frame, newPalette)); tx(new cmd::SetPalette(sprite, frame, newPalette));
transaction.commit(); tx.commit();
} }
} }
catch (base::Exception& e) { catch (base::Exception& e) {
@ -647,10 +647,10 @@ void ColorBar::setTransparentIndex(int index)
sprite->pixelFormat() == IMAGE_INDEXED && sprite->pixelFormat() == IMAGE_INDEXED &&
int(sprite->transparentColor()) != index) { int(sprite->transparentColor()) != index) {
// TODO merge this code with SpritePropertiesCommand // TODO merge this code with SpritePropertiesCommand
Transaction transaction(writer.context(), "Set Transparent Color"); Tx tx(writer.context(), "Set Transparent Color");
DocApi api = writer.document()->getApi(transaction); DocApi api = writer.document()->getApi(tx);
api.setSpriteTransparentColor(sprite, index); api.setSpriteTransparentColor(sprite, index);
transaction.commit(); tx.commit();
update_screen_for_document(writer.document()); update_screen_for_document(writer.document());
} }
@ -1180,9 +1180,9 @@ void ColorBar::updateCurrentSpritePalette(const char* operationName)
cmd->execute(UIContext::instance()); cmd->execute(UIContext::instance());
} }
else { else {
Transaction transaction(writer.context(), operationName, ModifyDocument); Tx tx(writer.context(), operationName, ModifyDocument);
transaction.execute(cmd); tx(cmd);
transaction.commit(); tx.commit();
} }
} }
} }

View File

@ -24,7 +24,7 @@
#include "app/modules/editors.h" #include "app/modules/editors.h"
#include "app/modules/palettes.h" #include "app/modules/palettes.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_customization_delegate.h" #include "app/ui/editor/editor_customization_delegate.h"
#include "app/ui/editor/editor_view.h" #include "app/ui/editor/editor_view.h"
@ -559,19 +559,19 @@ bool DocView::onClear(Context* ctx)
return false; return false;
{ {
Transaction transaction(writer.context(), "Clear"); Tx tx(writer.context(), "Clear");
transaction.execute(new cmd::ClearMask(writer.cel())); tx(new cmd::ClearMask(writer.cel()));
// If the cel wasn't deleted by cmd::ClearMask, we trim it. // If the cel wasn't deleted by cmd::ClearMask, we trim it.
if (writer.cel() && if (writer.cel() &&
writer.cel()->layer()->isTransparent()) writer.cel()->layer()->isTransparent())
transaction.execute(new cmd::TrimCel(writer.cel())); tx(new cmd::TrimCel(writer.cel()));
if (visibleMask && if (visibleMask &&
!Preferences::instance().selection.keepSelectionAfterClear()) !Preferences::instance().selection.keepSelectionAfterClear())
transaction.execute(new cmd::DeselectMask(document)); tx(new cmd::DeselectMask(document));
transaction.commit(); tx.commit();
} }
if (visibleMask) if (visibleMask)

View File

@ -15,7 +15,7 @@
#include "app/context_access.h" #include "app/context_access.h"
#include "app/doc_api.h" #include "app/doc_api.h"
#include "app/doc_range.h" #include "app/doc_range.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_customization_delegate.h" #include "app/ui/editor/editor_customization_delegate.h"
#include "app/ui/main_window.h" #include "app/ui/main_window.h"
@ -148,8 +148,8 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg)
if (modified) { if (modified) {
{ {
ContextWriter writer(m_reader, 1000); ContextWriter writer(m_reader, 1000);
Transaction transaction(writer.context(), "Cel Movement", ModifyDocument); Tx tx(writer.context(), "Cel Movement", ModifyDocument);
DocApi api = document->getApi(transaction); DocApi api = document->getApi(tx);
gfx::Point intOffset = intCelOffset(); gfx::Point intOffset = intCelOffset();
// And now we move the cel (or all selected range) to the new position. // And now we move the cel (or all selected range) to the new position.
@ -163,7 +163,7 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg)
celBounds.w *= m_celScale.w; celBounds.w *= m_celScale.w;
celBounds.h *= m_celScale.h; celBounds.h *= m_celScale.h;
} }
transaction.execute(new cmd::SetCelBoundsF(cel, celBounds)); tx(new cmd::SetCelBoundsF(cel, celBounds));
} }
else { else {
api.setCelPosition(writer.sprite(), cel, api.setCelPosition(writer.sprite(), cel,
@ -183,7 +183,7 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg)
document->mask()->bounds().y + intOffset.y); document->mask()->bounds().y + intOffset.y);
} }
transaction.commit(); tx.commit();
} }
// Redraw all editors. We've to notify all views about this // Redraw all editors. We've to notify all views about this

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2017 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -12,7 +12,7 @@
#include "app/cmd/set_mask_position.h" #include "app/cmd/set_mask_position.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
@ -55,9 +55,9 @@ EditorState::LeaveAction MovingSelectionState::onLeaveState(Editor* editor, Edit
{ {
ContextWriter writer(UIContext::instance(), 1000); ContextWriter writer(UIContext::instance(), 1000);
Transaction transaction(writer.context(), "Move Selection Edges", DoesntModifyDocument); Tx tx(writer.context(), "Move Selection Edges", DoesntModifyDocument);
transaction.execute(new cmd::SetMaskPosition(doc, newOrigin)); tx(new cmd::SetMaskPosition(doc, newOrigin));
transaction.commit(); tx.commit();
} }
doc->resetTransformation(); doc->resetTransformation();

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2017 David Capello // Copyright (C) 2017-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -12,7 +12,7 @@
#include "app/cmd/set_slice_key.h" #include "app/cmd/set_slice_key.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/ui_context.h" #include "app/ui_context.h"
@ -43,15 +43,15 @@ bool MovingSliceState::onMouseUp(Editor* editor, MouseMessage* msg)
{ {
{ {
ContextWriter writer(UIContext::instance(), 1000); ContextWriter writer(UIContext::instance(), 1000);
Transaction transaction(writer.context(), "Slice Movement", ModifyDocument); Tx tx(writer.context(), "Slice Movement", ModifyDocument);
doc::SliceKey newKey = m_key; doc::SliceKey newKey = m_key;
m_hit.slice()->insert(editor->frame(), m_keyStart); m_hit.slice()->insert(editor->frame(), m_keyStart);
transaction.execute(new cmd::SetSliceKey(m_hit.slice(), tx(new cmd::SetSliceKey(m_hit.slice(),
editor->frame(), editor->frame(),
newKey)); newKey));
transaction.commit(); tx.commit();
} }
editor->backToPreviousState(); editor->backToPreviousState();

View File

@ -22,7 +22,7 @@
#include "app/modules/gfx.h" #include "app/modules/gfx.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/pref/preferences.h" #include "app/pref/preferences.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
@ -251,16 +251,16 @@ void cut(ContextWriter& writer)
} }
else { else {
{ {
Transaction transaction(writer.context(), "Cut"); Tx tx(writer.context(), "Cut");
transaction.execute(new cmd::ClearMask(writer.cel())); tx(new cmd::ClearMask(writer.cel()));
ASSERT(writer.cel()); ASSERT(writer.cel());
if (writer.cel() && if (writer.cel() &&
writer.cel()->layer()->isTransparent()) writer.cel()->layer()->isTransparent())
transaction.execute(new cmd::TrimCel(writer.cel())); tx(new cmd::TrimCel(writer.cel()));
transaction.execute(new cmd::DeselectMask(writer.document())); tx(new cmd::DeselectMask(writer.document()));
transaction.commit(); tx.commit();
} }
writer.document()->generateMaskBoundaries(); writer.document()->generateMaskBoundaries();
update_screen_for_document(writer.document()); update_screen_for_document(writer.document());
@ -406,8 +406,8 @@ void paste()
return; return;
} }
Transaction transaction(UIContext::instance(), "Paste Cels"); Tx tx(UIContext::instance(), "Paste Cels");
DocApi api = dstDoc->getApi(transaction); DocApi api = dstDoc->getApi(tx);
// Add extra frames if needed // Add extra frames if needed
while (dstFrameFirst+srcRange.frames() > dstSpr->totalFrames()) while (dstFrameFirst+srcRange.frames() > dstSpr->totalFrames())
@ -480,7 +480,7 @@ void paste()
} }
} }
transaction.commit(); tx.commit();
editor->invalidate(); editor->invalidate();
break; break;
} }
@ -498,8 +498,8 @@ void paste()
break; break;
} }
Transaction transaction(UIContext::instance(), "Paste Frames"); Tx tx(UIContext::instance(), "Paste Frames");
DocApi api = dstDoc->getApi(transaction); DocApi api = dstDoc->getApi(tx);
auto srcLayers = srcSpr->allBrowsableLayers(); auto srcLayers = srcSpr->allBrowsableLayers();
auto dstLayers = dstSpr->allBrowsableLayers(); auto dstLayers = dstSpr->allBrowsableLayers();
@ -532,7 +532,7 @@ void paste()
++dstFrame; ++dstFrame;
} }
transaction.commit(); tx.commit();
editor->invalidate(); editor->invalidate();
break; break;
} }
@ -541,8 +541,8 @@ void paste()
if (srcDoc->colorMode() != dstDoc->colorMode()) if (srcDoc->colorMode() != dstDoc->colorMode())
throw std::runtime_error("You cannot copy layers of document with different color modes"); throw std::runtime_error("You cannot copy layers of document with different color modes");
Transaction transaction(UIContext::instance(), "Paste Layers"); Tx tx(UIContext::instance(), "Paste Layers");
DocApi api = dstDoc->getApi(transaction); DocApi api = dstDoc->getApi(tx);
// Remove children if their parent is selected so we only // Remove children if their parent is selected so we only
// copy the parent. // copy the parent.
@ -583,7 +583,7 @@ void paste()
srcDoc->copyLayerContent(srcLayer, dstDoc, newLayer); srcDoc->copyLayerContent(srcLayer, dstDoc, newLayer);
} }
transaction.commit(); tx.commit();
editor->invalidate(); editor->invalidate();
break; break;
} }

View File

@ -14,7 +14,7 @@
#include "app/console.h" #include "app/console.h"
#include "app/context_access.h" #include "app/context_access.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/transaction.h" #include "app/tx.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "doc/cel.h" #include "doc/cel.h"
#include "doc/document.h" #include "doc/document.h"
@ -120,9 +120,9 @@ void select_layer_boundaries(Layer* layer,
} }
} }
Transaction transaction(writer.context(), "Select Layer Boundaries", DoesntModifyDocument); Tx tx(writer.context(), "Select Layer Boundaries", DoesntModifyDocument);
transaction.execute(new cmd::SetMask(doc, &newMask)); tx(new cmd::SetMask(doc, &newMask));
transaction.commit(); tx.commit();
doc->resetTransformation(); doc->resetTransformation();
doc->generateMaskBoundaries(); doc->generateMaskBoundaries();