Skip to content

Commit e558658

Browse files
committed
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
1 parent 9efd841 commit e558658

File tree

255 files changed

+6530
-6276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+6530
-6276
lines changed

TODO.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343

4444
# Refactoring
4545

46+
* Remove unused skin parts
47+
* Make one level of layers (folders should modify only timeline/UI)
48+
* rename undo2 to undo
4649
* Convert doc::PixelFormat to a enum class
4750
* Add doc::Spec with width/height/channels/ColorMode/ncolors
4851
* Convert doc::LayerIndex -> typedef int doc::layer_t;

data/gui.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@
624624
<item command="BackgroundFromLayer" text="&amp;Background from Layer" />
625625
<item command="LayerFromBackground" text="&amp;Layer from Background" />
626626
<separator />
627-
<item command="DuplicateLayer" text="&amp;Duplicate..." />
627+
<item command="DuplicateLayer" text="&amp;Duplicate" />
628628
<item command="MergeDownLayer" text="&amp;Merge Down" />
629629
<item command="FlattenLayers" text="&amp;Flatten" />
630630
</menu>

data/pref.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<!-- Aseprite -->
2+
<!-- Copyright (C) 2014-2015 by David Capello -->
13
<?xml version="1.0" encoding="utf-8"?>
24
<preferences>
35

@@ -60,8 +62,9 @@
6062
<option id="expand_menubar_on_mouseover" type="bool" default="false" migrate="Options.ExpandMenuBarOnMouseover" />
6163
</section>
6264
<section id="undo" text="Undo">
63-
<option id="size_limit" type="int" default="0" />
64-
<option id="goto_modified" type="bool" default="false" />
65+
<option id="size_limit" type="int" default="64" />
66+
<option id="goto_modified" type="bool" default="true" />
67+
<option id="allow_nonlinear_history" type="bool" default="false" />
6568
</section>
6669
<section id="editor" text="Editor">
6770
<option id="zoom_with_scroll_wheel" type="bool" default="false" form="" />

data/widgets/options.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- Aseprite -->
2-
<!-- Copyright (C) 2001-2014 by David Capello -->
2+
<!-- Copyright (C) 2001-2015 by David Capello -->
33
<gui>
44
<window id="options" text="Preferences">
55
<vbox>
@@ -86,15 +86,16 @@
8686
<!-- Undo -->
8787
<vbox id="section_undo">
8888
<separator text="Undo" horizontal="true" />
89-
<box horizontal="true">
89+
<hbox>
9090
<label text="Undo Limit:" />
9191
<entry id="undo_size_limit" maxsize="4" tooltip="Limit of memory to be used&#10;for undo information per sprite.&#10;Specified in megabytes." />
9292
<label text="MB" />
93-
</box>
93+
</hbox>
9494

95-
<box horizontal="true">
95+
<vbox>
9696
<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." />
97-
</box>
97+
<check id="undo_allow_nonlinear_history" text="Allow non-linear history." />
98+
</vbox>
9899
</vbox>
99100

100101
<!-- Experimental -->

src/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Aseprite
2-
# Copyright (C) 2001-2014 David Capello
2+
# Copyright (C) 2001-2015 David Capello
33

44
add_definitions(-DHAVE_CONFIG_H)
55

@@ -30,7 +30,6 @@ set(aseprite_libraries
3030
doc-lib
3131
render-lib
3232
scripting-lib
33-
undo-lib
3433
undo2-lib
3534
filters-lib
3635
ui-lib
@@ -220,7 +219,6 @@ add_subdirectory(gfx)
220219
add_subdirectory(scripting)
221220
add_subdirectory(she)
222221
add_subdirectory(ui)
223-
add_subdirectory(undo)
224222
add_subdirectory(undo2)
225223

226224
add_subdirectory(app)

src/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ because they don't depend on any other component.
1818
* [css](css/): Pseudo-style sheet library.
1919
* [gfx](gfx/): Abstract graphics structures like point, size, rectangle, region, color, etc.
2020
* [scripting](scripting/): JavaScript engine ([V8](https://code.google.com/p/v8/)).
21-
* [undo](undo/): Generic library to manage undo history of undoable actions.
22-
* [undo2](undo2/): New library to replace the old undo system.
21+
* [undo2](undo2/): Generic library to manage a history of undoable commands.
2322

2423
## Level 1
2524

src/app/CMakeLists.txt

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Aseprite
2-
# Copyright (C) 2001-2014 David Capello
2+
# Copyright (C) 2001-2015 David Capello
33

44
######################################################################
55
# Generate source files from widget XML files
@@ -53,6 +53,56 @@ add_library(app-lib
5353
app_render.cpp
5454
backup.cpp
5555
check_update.cpp
56+
cmd.cpp
57+
cmd/add_cel.cpp
58+
cmd/add_frame.cpp
59+
cmd/add_layer.cpp
60+
cmd/add_palette.cpp
61+
cmd/background_from_layer.cpp
62+
cmd/clear_cel.cpp
63+
cmd/clear_image.cpp
64+
cmd/clear_mask.cpp
65+
cmd/configure_background.cpp
66+
cmd/copy_cel.cpp
67+
cmd/copy_frame.cpp
68+
cmd/copy_rect.cpp
69+
cmd/copy_region.cpp
70+
cmd/deselect_mask.cpp
71+
cmd/flatten_layers.cpp
72+
cmd/flip_image.cpp
73+
cmd/flip_mask.cpp
74+
cmd/flip_masked_cel.cpp
75+
cmd/layer_from_background.cpp
76+
cmd/move_cel.cpp
77+
cmd/move_layer.cpp
78+
cmd/object_io.cpp
79+
cmd/remove_cel.cpp
80+
cmd/remove_frame.cpp
81+
cmd/remove_layer.cpp
82+
cmd/remove_palette.cpp
83+
cmd/replace_image.cpp
84+
cmd/reselect_mask.cpp
85+
cmd/set_cel_frame.cpp
86+
cmd/set_cel_opacity.cpp
87+
cmd/set_cel_position.cpp
88+
cmd/set_frame_duration.cpp
89+
cmd/set_layer_flags.cpp
90+
cmd/set_layer_name.cpp
91+
cmd/set_mask.cpp
92+
cmd/set_mask_position.cpp
93+
cmd/set_palette.cpp
94+
cmd/set_pixel_format.cpp
95+
cmd/set_sprite_size.cpp
96+
cmd/set_total_frames.cpp
97+
cmd/set_transparent_color.cpp
98+
cmd/with_cel.cpp
99+
cmd/with_document.cpp
100+
cmd/with_image.cpp
101+
cmd/with_layer.cpp
102+
cmd/with_palette.cpp
103+
cmd/with_sprite.cpp
104+
cmd_sequence.cpp
105+
cmd_transaction.cpp
56106
color.cpp
57107
color_picker.cpp
58108
color_swatches.cpp
@@ -189,7 +239,6 @@ add_library(app-lib
189239
modules/gfx.cpp
190240
modules/gui.cpp
191241
modules/palettes.cpp
192-
objects_container_impl.cpp
193242
pref/preferences.cpp
194243
project.cpp
195244
recent_files.cpp
@@ -206,6 +255,7 @@ add_library(app-lib
206255
tools/shade_table.cpp
207256
tools/tool_box.cpp
208257
tools/tool_loop_manager.cpp
258+
transaction.cpp
209259
ui/app_menuitem.cpp
210260
ui/button_set.cpp
211261
ui/color_bar.cpp
@@ -262,38 +312,6 @@ add_library(app-lib
262312
ui/workspace.cpp
263313
ui/workspace_part.cpp
264314
ui_context.cpp
265-
undo_transaction.cpp
266-
undoers/add_cel.cpp
267-
undoers/add_frame.cpp
268-
undoers/add_layer.cpp
269-
undoers/add_palette.cpp
270-
undoers/close_group.cpp
271-
undoers/dirty_area.cpp
272-
undoers/flip_image.cpp
273-
undoers/image_area.cpp
274-
undoers/modified_region.cpp
275-
undoers/move_layer.cpp
276-
undoers/object_io.cpp
277-
undoers/open_group.cpp
278-
undoers/remap_palette.cpp
279-
undoers/remove_cel.cpp
280-
undoers/remove_frame.cpp
281-
undoers/remove_layer.cpp
282-
undoers/remove_palette.cpp
283-
undoers/replace_image.cpp
284-
undoers/set_cel_frame.cpp
285-
undoers/set_cel_opacity.cpp
286-
undoers/set_cel_position.cpp
287-
undoers/set_frame_duration.cpp
288-
undoers/set_layer_flags.cpp
289-
undoers/set_layer_name.cpp
290-
undoers/set_mask.cpp
291-
undoers/set_mask_position.cpp
292-
undoers/set_palette_colors.cpp
293-
undoers/set_sprite_pixel_format.cpp
294-
undoers/set_sprite_size.cpp
295-
undoers/set_sprite_transparent_color.cpp
296-
undoers/set_total_frames.cpp
297315
util/autocrop.cpp
298316
util/boundary.cpp
299317
util/clipboard.cpp

src/app/cmd.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/* Aseprite
2+
* Copyright (C) 2001-2015 David Capello
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
#ifdef HAVE_CONFIG_H
20+
#include "config.h"
21+
#endif
22+
23+
#include "app/cmd.h"
24+
25+
namespace app {
26+
27+
Cmd::Cmd()
28+
#if _DEBUG
29+
: m_state(State::NotExecuted)
30+
#endif
31+
{
32+
}
33+
34+
Cmd::~Cmd()
35+
{
36+
}
37+
38+
void Cmd::execute(Context* ctx)
39+
{
40+
ASSERT(m_state == State::NotExecuted);
41+
42+
m_ctx = ctx;
43+
44+
onExecute();
45+
onFireNotifications();
46+
47+
#if _DEBUG
48+
m_state = State::Executed;
49+
#endif
50+
}
51+
52+
void Cmd::undo()
53+
{
54+
ASSERT(m_state == State::Executed || m_state == State::Redone);
55+
56+
onUndo();
57+
onFireNotifications();
58+
59+
#if _DEBUG
60+
m_state = State::Undone;
61+
#endif
62+
}
63+
64+
void Cmd::redo()
65+
{
66+
ASSERT(m_state == State::Undone);
67+
68+
onRedo();
69+
onFireNotifications();
70+
71+
#if _DEBUG
72+
m_state = State::Redone;
73+
#endif
74+
}
75+
76+
std::string Cmd::label() const
77+
{
78+
return onLabel();
79+
}
80+
81+
size_t Cmd::memSize() const
82+
{
83+
return onMemSize();
84+
}
85+
86+
void Cmd::onExecute()
87+
{
88+
// Do nothing
89+
}
90+
91+
void Cmd::onUndo()
92+
{
93+
// Do nothing
94+
}
95+
96+
void Cmd::onRedo()
97+
{
98+
// By default onRedo() uses onExecute() implementation
99+
onExecute();
100+
}
101+
102+
void Cmd::onFireNotifications()
103+
{
104+
// Do nothing
105+
}
106+
107+
std::string Cmd::onLabel() const
108+
{
109+
return "";
110+
}
111+
112+
size_t Cmd::onMemSize() const {
113+
return sizeof(*this);
114+
}
115+
116+
} // namespace app

src/app/cmd.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* Aseprite
2+
* Copyright (C) 2001-2015 David Capello
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
#ifndef APP_CMD_H_INCLUDED
20+
#define APP_CMD_H_INCLUDED
21+
#pragma once
22+
23+
#include "doc/sprite_position.h"
24+
#include "undo2/undo_command.h"
25+
26+
#include <string>
27+
28+
namespace app {
29+
class Context;
30+
31+
class Cmd : public undo2::UndoCommand {
32+
public:
33+
Cmd();
34+
virtual ~Cmd();
35+
36+
void execute(Context* ctx);
37+
void undo() override;
38+
void redo() override;
39+
std::string label() const;
40+
size_t memSize() const;
41+
42+
Context* context() const { return m_ctx; }
43+
44+
protected:
45+
virtual void onExecute();
46+
virtual void onUndo();
47+
virtual void onRedo();
48+
virtual void onFireNotifications();
49+
virtual std::string onLabel() const;
50+
virtual size_t onMemSize() const;
51+
52+
private:
53+
Context* m_ctx;
54+
#if _DEBUG
55+
enum class State { NotExecuted, Executed, Undone, Redone };
56+
State m_state;
57+
#endif
58+
};
59+
60+
} // namespace app
61+
62+
#endif

0 commit comments

Comments
 (0)