Skip to content
Permalink
Browse files
Replace undo impl: replace undoers with cmds
Undoers were little objects to swap/revert an action. They didn't
execute the action itself, they just revert its previous state. Now
undoers were replaced with cmds: A cmd is an object that
executes/undoes/redoes just one action.

Changes:
* Remove old undo library and app/objects_container_impl.cpp
  (now we use the doc::ObjectId directly to store undo info)
* Remove all Undoers from app/undoers/
* Replace DocumentApi impl with little Cmds in app/cmd/, these
  cmds handle execute/undo/redo of each action at the logic layer
* Remove doc::Dirty object
* Remove doc::Settings: all undo configuration is in the app side
* Move undo options from app:ISettings to app::Preferences
* Rename UndoTransaction to Transaction
* Create a CmdSequence to store a sequence of Cmds (as now the new
  undo library doesn't support open/close groups)
* Add doc::get<T>(ObjectId) function to get any kind of object
  from the doc library by its ID
* Add Cel::document() and Sprite::document() members
* Add Sprite::cels(frame_t) to get all cels in the given frame
* Add Layer::displaceFrames() member function
* Move the "allow non-linear history" flag from undo2::UndoHistory
  to app::DocumentUndo
  • Loading branch information
dacap committed Jan 19, 2015
1 parent 9efd841 commit e55865843e20d42bca3b3505ba49e529ee25193a
Show file tree
Hide file tree
Showing 255 changed files with 6,530 additions and 6,276 deletions.
@@ -43,6 +43,9 @@

# Refactoring

* Remove unused skin parts
* Make one level of layers (folders should modify only timeline/UI)
* rename undo2 to undo
* Convert doc::PixelFormat to a enum class
* Add doc::Spec with width/height/channels/ColorMode/ncolors
* Convert doc::LayerIndex -> typedef int doc::layer_t;
@@ -624,7 +624,7 @@
<item command="BackgroundFromLayer" text="&amp;Background from Layer" />
<item command="LayerFromBackground" text="&amp;Layer from Background" />
<separator />
<item command="DuplicateLayer" text="&amp;Duplicate..." />
<item command="DuplicateLayer" text="&amp;Duplicate" />
<item command="MergeDownLayer" text="&amp;Merge Down" />
<item command="FlattenLayers" text="&amp;Flatten" />
</menu>
@@ -1,3 +1,5 @@
<!-- Aseprite -->
<!-- Copyright (C) 2014-2015 by David Capello -->
<?xml version="1.0" encoding="utf-8"?>
<preferences>

@@ -60,8 +62,9 @@
<option id="expand_menubar_on_mouseover" type="bool" default="false" migrate="Options.ExpandMenuBarOnMouseover" />
</section>
<section id="undo" text="Undo">
<option id="size_limit" type="int" default="0" />
<option id="goto_modified" type="bool" default="false" />
<option id="size_limit" type="int" default="64" />
<option id="goto_modified" type="bool" default="true" />
<option id="allow_nonlinear_history" type="bool" default="false" />
</section>
<section id="editor" text="Editor">
<option id="zoom_with_scroll_wheel" type="bool" default="false" form="" />
@@ -1,5 +1,5 @@
<!-- Aseprite -->
<!-- Copyright (C) 2001-2014 by David Capello -->
<!-- Copyright (C) 2001-2015 by David Capello -->
<gui>
<window id="options" text="Preferences">
<vbox>
@@ -86,15 +86,16 @@
<!-- Undo -->
<vbox id="section_undo">
<separator text="Undo" horizontal="true" />
<box horizontal="true">
<hbox>
<label text="Undo Limit:" />
<entry id="undo_size_limit" maxsize="4" tooltip="Limit of memory to be used&#10;for undo information per sprite.&#10;Specified in megabytes." />
<label text="MB" />
</box>
</hbox>

<box horizontal="true">
<vbox>
<check id="undo_goto_modified" text="Go to modified frame/layer" tooltip="When it's enabled each time you undo/redo&#10;the current frame &amp; layer will be modified&#10;to focus the undid/redid change." />
</box>
<check id="undo_allow_nonlinear_history" text="Allow non-linear history." />
</vbox>
</vbox>

<!-- Experimental -->
@@ -1,5 +1,5 @@
# Aseprite
# Copyright (C) 2001-2014 David Capello
# Copyright (C) 2001-2015 David Capello

add_definitions(-DHAVE_CONFIG_H)

@@ -30,7 +30,6 @@ set(aseprite_libraries
doc-lib
render-lib
scripting-lib
undo-lib
undo2-lib
filters-lib
ui-lib
@@ -220,7 +219,6 @@ add_subdirectory(gfx)
add_subdirectory(scripting)
add_subdirectory(she)
add_subdirectory(ui)
add_subdirectory(undo)
add_subdirectory(undo2)

add_subdirectory(app)
@@ -18,8 +18,7 @@ because they don't depend on any other component.
* [css](css/): Pseudo-style sheet library.
* [gfx](gfx/): Abstract graphics structures like point, size, rectangle, region, color, etc.
* [scripting](scripting/): JavaScript engine ([V8](https://code.google.com/p/v8/)).
* [undo](undo/): Generic library to manage undo history of undoable actions.
* [undo2](undo2/): New library to replace the old undo system.
* [undo2](undo2/): Generic library to manage a history of undoable commands.

## Level 1

@@ -1,5 +1,5 @@
# Aseprite
# Copyright (C) 2001-2014 David Capello
# Copyright (C) 2001-2015 David Capello

######################################################################
# Generate source files from widget XML files
@@ -53,6 +53,56 @@ add_library(app-lib
app_render.cpp
backup.cpp
check_update.cpp
cmd.cpp
cmd/add_cel.cpp
cmd/add_frame.cpp
cmd/add_layer.cpp
cmd/add_palette.cpp
cmd/background_from_layer.cpp
cmd/clear_cel.cpp
cmd/clear_image.cpp
cmd/clear_mask.cpp
cmd/configure_background.cpp
cmd/copy_cel.cpp
cmd/copy_frame.cpp
cmd/copy_rect.cpp
cmd/copy_region.cpp
cmd/deselect_mask.cpp
cmd/flatten_layers.cpp
cmd/flip_image.cpp
cmd/flip_mask.cpp
cmd/flip_masked_cel.cpp
cmd/layer_from_background.cpp
cmd/move_cel.cpp
cmd/move_layer.cpp
cmd/object_io.cpp
cmd/remove_cel.cpp
cmd/remove_frame.cpp
cmd/remove_layer.cpp
cmd/remove_palette.cpp
cmd/replace_image.cpp
cmd/reselect_mask.cpp
cmd/set_cel_frame.cpp
cmd/set_cel_opacity.cpp
cmd/set_cel_position.cpp
cmd/set_frame_duration.cpp
cmd/set_layer_flags.cpp
cmd/set_layer_name.cpp
cmd/set_mask.cpp
cmd/set_mask_position.cpp
cmd/set_palette.cpp
cmd/set_pixel_format.cpp
cmd/set_sprite_size.cpp
cmd/set_total_frames.cpp
cmd/set_transparent_color.cpp
cmd/with_cel.cpp
cmd/with_document.cpp
cmd/with_image.cpp
cmd/with_layer.cpp
cmd/with_palette.cpp
cmd/with_sprite.cpp
cmd_sequence.cpp
cmd_transaction.cpp
color.cpp
color_picker.cpp
color_swatches.cpp
@@ -189,7 +239,6 @@ add_library(app-lib
modules/gfx.cpp
modules/gui.cpp
modules/palettes.cpp
objects_container_impl.cpp
pref/preferences.cpp
project.cpp
recent_files.cpp
@@ -206,6 +255,7 @@ add_library(app-lib
tools/shade_table.cpp
tools/tool_box.cpp
tools/tool_loop_manager.cpp
transaction.cpp
ui/app_menuitem.cpp
ui/button_set.cpp
ui/color_bar.cpp
@@ -262,38 +312,6 @@ add_library(app-lib
ui/workspace.cpp
ui/workspace_part.cpp
ui_context.cpp
undo_transaction.cpp
undoers/add_cel.cpp
undoers/add_frame.cpp
undoers/add_layer.cpp
undoers/add_palette.cpp
undoers/close_group.cpp
undoers/dirty_area.cpp
undoers/flip_image.cpp
undoers/image_area.cpp
undoers/modified_region.cpp
undoers/move_layer.cpp
undoers/object_io.cpp
undoers/open_group.cpp
undoers/remap_palette.cpp
undoers/remove_cel.cpp
undoers/remove_frame.cpp
undoers/remove_layer.cpp
undoers/remove_palette.cpp
undoers/replace_image.cpp
undoers/set_cel_frame.cpp
undoers/set_cel_opacity.cpp
undoers/set_cel_position.cpp
undoers/set_frame_duration.cpp
undoers/set_layer_flags.cpp
undoers/set_layer_name.cpp
undoers/set_mask.cpp
undoers/set_mask_position.cpp
undoers/set_palette_colors.cpp
undoers/set_sprite_pixel_format.cpp
undoers/set_sprite_size.cpp
undoers/set_sprite_transparent_color.cpp
undoers/set_total_frames.cpp
util/autocrop.cpp
util/boundary.cpp
util/clipboard.cpp
@@ -0,0 +1,116 @@
/* Aseprite
* Copyright (C) 2001-2015 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "app/cmd.h"

namespace app {

Cmd::Cmd()
#if _DEBUG
: m_state(State::NotExecuted)
#endif
{
}

Cmd::~Cmd()
{
}

void Cmd::execute(Context* ctx)
{
ASSERT(m_state == State::NotExecuted);

m_ctx = ctx;

onExecute();
onFireNotifications();

#if _DEBUG
m_state = State::Executed;
#endif
}

void Cmd::undo()
{
ASSERT(m_state == State::Executed || m_state == State::Redone);

onUndo();
onFireNotifications();