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
Showing with 6,530 additions and 6,276 deletions.
  1. +3 −0 TODO.md
  2. +1 −1 data/gui.xml
  3. +5 −2 data/pref.xml
  4. +6 −5 data/widgets/options.xml
  5. +1 −3 src/CMakeLists.txt
  6. +1 −2 src/README.md
  7. +52 −34 src/app/CMakeLists.txt
  8. +116 −0 src/app/cmd.cpp
  9. +62 −0 src/app/cmd.h
  10. +11 −0 src/app/cmd/README.md
  11. +97 −0 src/app/cmd/add_cel.cpp
  12. +36 −26 src/app/{undoers/add_layer.h → cmd/add_cel.h}
  13. +91 −0 src/app/cmd/add_frame.cpp
  14. +27 −20 src/app/{undoers/add_palette.h → cmd/add_frame.h}
  15. +102 −0 src/app/cmd/add_layer.cpp
  16. +62 −0 src/app/cmd/add_layer.h
  17. +32 −18 src/app/{undoers → cmd}/add_palette.cpp
  18. +31 −27 src/app/{undoers/set_total_frames.h → cmd/add_palette.h}
  19. +110 −0 src/app/cmd/background_from_layer.cpp
  20. +17 −15 src/app/{undoers/undoer_base.h → cmd/background_from_layer.h}
  21. +29 −20 src/app/{undoers/add_cel.cpp → cmd/clear_cel.cpp}
  22. +51 −0 src/app/cmd/clear_cel.h
  23. +54 −0 src/app/cmd/clear_image.cpp
  24. +52 −0 src/app/cmd/clear_image.h
  25. +131 −0 src/app/cmd/clear_mask.cpp
  26. +62 −0 src/app/cmd/clear_mask.h
  27. +44 −0 src/app/cmd/configure_background.cpp
  28. +12 −23 src/app/{undoers/set_cel_position.h → cmd/configure_background.h}
  29. +131 −0 src/app/cmd/copy_cel.cpp
  30. +22 −22 src/app/{undoers/set_cel_frame.h → cmd/copy_cel.h}
  31. +66 −0 src/app/cmd/copy_frame.cpp
  32. +52 −0 src/app/cmd/copy_frame.h
  33. +99 −0 src/app/cmd/copy_rect.cpp
  34. +61 −0 src/app/cmd/copy_rect.h
  35. +96 −0 src/app/cmd/copy_region.cpp
  36. +58 −0 src/app/cmd/copy_region.h
  37. +60 −0 src/app/cmd/deselect_mask.cpp
  38. +52 −0 src/app/cmd/deselect_mask.h
  39. +97 −0 src/app/cmd/flatten_layers.cpp
  40. +42 −0 src/app/cmd/flatten_layers.h
  41. +57 −0 src/app/cmd/flip_image.cpp
  42. +61 −0 src/app/cmd/flip_image.h
  43. +66 −0 src/app/cmd/flip_mask.cpp
  44. +52 −0 src/app/cmd/flip_mask.h
  45. +70 −0 src/app/cmd/flip_masked_cel.cpp
  46. +54 −0 src/app/cmd/flip_masked_cel.h
  47. +51 −0 src/app/cmd/layer_from_background.cpp
  48. +41 −0 src/app/cmd/layer_from_background.h
  49. +146 −0 src/app/cmd/move_cel.cpp
  50. +54 −0 src/app/cmd/move_cel.h
  51. +67 −0 src/app/cmd/move_layer.cpp
  52. +51 −0 src/app/cmd/move_layer.h
  53. +7 −8 src/app/{undoers → cmd}/object_io.cpp
  54. +12 −23 src/app/{undoers → cmd}/object_io.h
  55. +16 −18 src/app/{undoers/set_cel_opacity.cpp → cmd/remove_cel.cpp}
  56. +42 −0 src/app/cmd/remove_cel.h
  57. +81 −0 src/app/cmd/remove_frame.cpp
  58. +53 −0 src/app/cmd/remove_frame.h
  59. +16 −18 src/app/{undoers/set_layer_name.cpp → cmd/remove_layer.cpp}
  60. +42 −0 src/app/cmd/remove_layer.h
  61. +51 −0 src/app/cmd/remove_palette.cpp
  62. +42 −0 src/app/cmd/remove_palette.h
  63. +80 −0 src/app/cmd/replace_image.cpp
  64. +62 −0 src/app/cmd/replace_image.h
  65. +64 −0 src/app/cmd/reselect_mask.cpp
  66. +52 −0 src/app/cmd/reselect_mask.h
  67. +28 −20 src/app/{undoers/remove_cel.cpp → cmd/set_cel_frame.cpp}
  68. +51 −0 src/app/cmd/set_cel_frame.h
  69. +61 −0 src/app/cmd/set_cel_opacity.cpp
  70. +51 −0 src/app/cmd/set_cel_opacity.h
  71. +25 −19 src/app/{undoers/add_layer.cpp → cmd/set_cel_position.cpp}
  72. +51 −0 src/app/cmd/set_cel_position.h
  73. +23 −21 src/app/{undoers → cmd}/set_frame_duration.cpp
  74. +53 −0 src/app/cmd/set_frame_duration.h
  75. +46 −0 src/app/cmd/set_layer_flags.cpp
  76. +51 −0 src/app/cmd/set_layer_flags.h
  77. +12 −20 src/app/{undoers/set_layer_flags.cpp → cmd/set_layer_name.cpp}
  78. +27 −28 src/app/{undoers/set_layer_flags.h → cmd/set_layer_name.h}
  79. +77 −0 src/app/cmd/set_mask.cpp
  80. +30 −20 src/app/{undoers/set_mask_position.h → cmd/set_mask.h}
  81. +56 −0 src/app/cmd/set_mask_position.cpp
  82. +53 −0 src/app/cmd/set_mask_position.h
  83. +75 −0 src/app/cmd/set_palette.cpp
  84. +63 −0 src/app/cmd/set_palette.h
  85. +142 −0 src/app/cmd/set_pixel_format.cpp
  86. +63 −0 src/app/cmd/set_pixel_format.h
  87. +26 −23 src/app/{undoers/set_mask_position.cpp → cmd/set_sprite_size.cpp}
  88. +53 −0 src/app/cmd/set_sprite_size.h
  89. +23 −19 src/app/{undoers/set_sprite_pixel_format.cpp → cmd/set_total_frames.cpp}
  90. +52 −0 src/app/cmd/set_total_frames.h
  91. +20 −19 src/app/{undoers/set_total_frames.cpp → cmd/set_transparent_color.cpp}
  92. +52 −0 src/app/cmd/set_transparent_color.h
  93. +9 −23 src/app/{undoers/set_cel_position.cpp → cmd/with_cel.cpp}
  94. +15 −22 src/app/{undoers/set_cel_opacity.h → cmd/with_cel.h}
  95. +41 −0 src/app/cmd/with_document.cpp
  96. +41 −0 src/app/cmd/with_document.h
  97. +43 −0 src/app/cmd/with_image.cpp
  98. +45 −0 src/app/cmd/with_image.h
  99. +46 −0 src/app/cmd/with_layer.cpp
  100. +15 −22 src/app/{undoers/add_cel.h → cmd/with_layer.h}
  101. +43 −0 src/app/cmd/with_palette.cpp
  102. +45 −0 src/app/cmd/with_palette.h
  103. +9 −23 src/app/{undoers/set_sprite_size.cpp → cmd/with_sprite.cpp}
  104. +15 −22 src/app/{undoers/set_sprite_size.h → cmd/with_sprite.h}
  105. +70 −0 src/app/cmd_sequence.cpp
  106. +18 −16 src/app/{objects_container_impl.h → cmd_sequence.h}
  107. +82 −0 src/app/cmd_transaction.cpp
  108. +57 −0 src/app/cmd_transaction.h
  109. +6 −6 src/app/commands/cmd_background_from_layer.cpp
  110. +5 −5 src/app/commands/cmd_canvas_size.cpp
  111. +6 −6 src/app/commands/cmd_cel_properties.cpp
  112. +5 −5 src/app/commands/cmd_change_pixel_format.cpp
  113. +8 −10 src/app/commands/cmd_clear.cpp
  114. +7 −7 src/app/commands/cmd_clear_cel.cpp
  115. +8 −8 src/app/commands/cmd_crop.cpp
  116. +6 −6 src/app/commands/cmd_deselect_mask.cpp
  117. +5 −7 src/app/commands/cmd_duplicate_layer.cpp
  118. +7 −7 src/app/commands/cmd_export_sprite_sheet.cpp
  119. +5 −5 src/app/commands/cmd_flatten_layers.cpp
  120. +17 −26 src/app/commands/cmd_flip.cpp
  121. +7 −6 src/app/commands/cmd_frame_properties.cpp
  122. +5 −5 src/app/commands/cmd_import_sprite_sheet.cpp
  123. +17 −15 src/app/commands/cmd_invert_mask.cpp
  124. +5 −5 src/app/commands/cmd_layer_from_background.cpp
  125. +6 −11 src/app/commands/cmd_load_mask.cpp
  126. +9 −12 src/app/commands/cmd_mask_all.cpp
  127. +6 −14 src/app/commands/cmd_mask_by_color.cpp
  128. +12 −16 src/app/commands/cmd_mask_content.cpp
  129. +21 −36 src/app/commands/cmd_merge_down_layer.cpp
  130. +5 −6 src/app/commands/cmd_move_mask.cpp
  131. +9 −6 src/app/commands/cmd_new_frame.cpp
  132. +5 −5 src/app/commands/cmd_new_layer.cpp
  133. +5 −5 src/app/commands/cmd_new_layer_set.cpp
  134. +8 −9 src/app/commands/cmd_options.cpp
  135. +19 −22 src/app/commands/cmd_palette_editor.cpp
  136. +7 −6 src/app/commands/cmd_remove_frame.cpp
  137. +7 −6 src/app/commands/cmd_remove_layer.cpp
  138. +6 −11 src/app/commands/cmd_reselect_mask.cpp
  139. +6 −6 src/app/commands/cmd_rotate.cpp
  140. +5 −5 src/app/commands/cmd_set_palette.cpp
  141. +5 −5 src/app/commands/cmd_sprite_properties.cpp
  142. +6 −6 src/app/commands/cmd_sprite_size.cpp
  143. +31 −14 src/app/commands/cmd_undo.cpp
  144. +11 −18 src/app/commands/filters/filter_manager_impl.cpp
  145. +3 −2 src/app/commands/filters/filter_manager_impl.h
  146. +6 −2 src/app/context.cpp
  147. +2 −2 src/app/context.h
  148. +41 −5 src/app/document.cpp
  149. +9 −8 src/app/document.h
  150. +77 −869 src/app/document_api.cpp
  151. +12 −31 src/app/document_api.h
  152. +5 −2 src/app/document_api_tests.cpp
  153. +4 −5 src/app/document_exporter.cpp
  154. +8 −8 src/app/document_range_ops.cpp
  155. +68 −69 src/app/document_range_tests.cpp
  156. +73 −58 src/app/document_undo.cpp
  157. +30 −43 src/app/document_undo.h
  158. +0 −92 src/app/objects_container_impl.cpp
  159. +0 −88 src/app/objects_container_impl_tests.cpp
  160. +2 −9 src/app/settings/settings.h
  161. +1 −21 src/app/settings/ui_settings_impl.cpp
  162. +1 −7 src/app/settings/ui_settings_impl.h
  163. +2 −10 src/app/test_context.h
  164. +13 −15 src/app/tools/inks.h
  165. +2 −1 src/app/tools/tool_loop.h
  166. +107 −0 src/app/transaction.cpp
  167. +26 −41 src/app/{undo_transaction.h → transaction.h}
  168. +8 −14 src/app/ui/color_selector.cpp
  169. +5 −5 src/app/ui/editor/moving_cel_state.cpp
  170. +22 −23 src/app/ui/editor/pixels_movement.cpp
  171. +8 −4 src/app/ui/editor/pixels_movement.h
  172. +21 −20 src/app/ui/editor/tool_loop_impl.cpp
  173. +1 −2 src/app/ui/status_bar.cpp
  174. +2 −2 src/app/ui/timeline.cpp
  175. +1 −2 src/app/ui_context.cpp
  176. +0 −139 src/app/undo_transaction.cpp
  177. +0 −69 src/app/undoers/add_frame.cpp
  178. +0 −55 src/app/undoers/add_frame.h
  179. +0 −61 src/app/undoers/close_group.cpp
  180. +0 −64 src/app/undoers/close_group.h
  181. +0 −62 src/app/undoers/dirty_area.cpp
  182. +0 −58 src/app/undoers/dirty_area.h
  183. +0 −74 src/app/undoers/flip_image.cpp
  184. +0 −57 src/app/undoers/flip_image.h
  185. +0 −80 src/app/undoers/image_area.cpp
  186. +0 −56 src/app/undoers/image_area.h
  187. +0 −91 src/app/undoers/modified_region.cpp
  188. +0 −62 src/app/undoers/modified_region.h
  189. +0 −62 src/app/undoers/move_layer.cpp
  190. +0 −52 src/app/undoers/move_layer.h
  191. +0 −62 src/app/undoers/open_group.cpp
  192. +0 −63 src/app/undoers/open_group.h
  193. +0 −72 src/app/undoers/remap_palette.cpp
  194. +0 −58 src/app/undoers/remap_palette.h
  195. +0 −58 src/app/undoers/remove_cel.h
  196. +0 −72 src/app/undoers/remove_frame.cpp
  197. +0 −58 src/app/undoers/remove_frame.h
  198. +0 −69 src/app/undoers/remove_layer.cpp
  199. +0 −61 src/app/undoers/remove_layer.h
  200. +0 −64 src/app/undoers/remove_palette.cpp
  201. +0 −58 src/app/undoers/remove_palette.h
  202. +0 −73 src/app/undoers/replace_image.cpp
  203. +0 −60 src/app/undoers/replace_image.h
  204. +0 −59 src/app/undoers/set_cel_frame.cpp
  205. +0 −53 src/app/undoers/set_frame_duration.h
  206. +0 −53 src/app/undoers/set_layer_name.h
  207. +0 −70 src/app/undoers/set_mask.cpp
  208. +0 −54 src/app/undoers/set_mask.h
  209. +0 −73 src/app/undoers/set_palette_colors.cpp
  210. +0 −62 src/app/undoers/set_palette_colors.h
  211. +0 −51 src/app/undoers/set_sprite_pixel_format.h
  212. +0 −56 src/app/undoers/set_sprite_transparent_color.cpp
  213. +0 −51 src/app/undoers/set_sprite_transparent_color.h
  214. +17 −18 src/app/util/clipboard.cpp
  215. +24 −55 src/app/util/expand_cel_canvas.cpp
  216. +4 −6 src/app/util/expand_cel_canvas.h
  217. +1 −3 src/doc/CMakeLists.txt
  218. +1 −2 src/doc/algo.cpp
  219. +11 −2 src/doc/cel.cpp
  220. +3 −1 src/doc/cel.h
  221. +2 −8 src/doc/context.cpp
  222. +1 −4 src/doc/context.h
  223. +0 −196 src/doc/dirty.cpp
  224. +0 −90 src/doc/dirty.h
  225. +0 −108 src/doc/dirty_io.cpp
  226. +0 −22 src/doc/dirty_io.h
  227. +1 −2 src/doc/doc.h
  228. +26 −3 src/doc/layer.cpp
  229. +6 −1 src/doc/layer.h
  230. +37 −43 src/doc/mask.cpp
  231. +5 −2 src/doc/mask.h
  232. +59 −2 src/doc/object.cpp
  233. +15 −4 src/doc/object.h
  234. +27 −1 src/doc/primitives.cpp
  235. +0 −23 src/doc/settings.h
  236. +20 −3 src/doc/sprite.cpp
  237. +10 −4 src/doc/sprite.h
  238. +5 −2 src/doc/sprite_position.h
  239. +5 −2 src/doc/sprites.cpp
  240. +0 −6 src/undo/CMakeLists.txt
  241. +0 −20 src/undo/LICENSE.txt
  242. +0 −4 src/undo/README.md
  243. +0 −24 src/undo/modification.h
  244. +0 −17 src/undo/object_id.h
  245. +0 −85 src/undo/objects_container.h
  246. +0 −22 src/undo/undo_exception.h
  247. +0 −226 src/undo/undo_history.cpp
  248. +0 −81 src/undo/undo_history.h
  249. +0 −53 src/undo/undoer.h
  250. +0 −34 src/undo/undoers_collector.h
  251. +0 −110 src/undo/undoers_stack.cpp
  252. +0 −73 src/undo/undoers_stack.h
  253. +0 −9 src/undo2/undo_history.cpp
  254. +0 −6 src/undo2/undo_history.h
  255. +0 −37 src/undo2/undo_tests.cpp
View
@@ -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;
View
@@ -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>
View
@@ -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="" />
View
@@ -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 -->
View
@@ -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)
View
@@ -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
View
@@ -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
View
@@ -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();
#if _DEBUG
m_state = State::Undone;
#endif
}
void Cmd::redo()
{
ASSERT(m_state == State::Undone);
onRedo();
onFireNotifications();
#if _DEBUG
m_state = State::Redone;
#endif
}
std::string Cmd::label() const
{
return onLabel();
}
size_t Cmd::memSize() const
{
return onMemSize();
}
void Cmd::onExecute()
{
// Do nothing
}
void Cmd::onUndo()
{
// Do nothing
}
void Cmd::onRedo()
{
// By default onRedo() uses onExecute() implementation
onExecute();
}
void Cmd::onFireNotifications()
{
// Do nothing
}
std::string Cmd::onLabel() const
{
return "";
}
size_t Cmd::onMemSize() const {
return sizeof(*this);
}
} // namespace app
View
@@ -0,0 +1,62 @@
/* 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
*/
#ifndef APP_CMD_H_INCLUDED
#define APP_CMD_H_INCLUDED
#pragma once
#include "doc/sprite_position.h"
#include "undo2/undo_command.h"
#include <string>
namespace app {
class Context;
class Cmd : public undo2::UndoCommand {
public:
Cmd();
virtual ~Cmd();
void execute(Context* ctx);
void undo() override;
void redo() override;
std::string label() const;
size_t memSize() const;
Context* context() const { return m_ctx; }
protected:
virtual void onExecute();
virtual void onUndo();
virtual void onRedo();
virtual void onFireNotifications();
virtual std::string onLabel() const;
virtual size_t onMemSize() const;
private:
Context* m_ctx;
#if _DEBUG
enum class State { NotExecuted, Executed, Undone, Redone };
State m_state;
#endif
};
} // namespace app
#endif
Oops, something went wrong.

0 comments on commit e558658

Please sign in to comment.