Refactor undo_clear_redo/set_label/get_next_*_label -> Undo::clearRedo/etc.

This commit is contained in:
David Capello 2010-09-19 17:44:06 -03:00
parent 9924e0fb43
commit 3ec3bbbef8
19 changed files with 42 additions and 44 deletions

View File

@ -143,7 +143,7 @@ void CelPropertiesCommand::onExecute(Context* context)
if (cel_writer != NULL &&
cel_writer->opacity != new_opacity) {
if (sprite_writer->getUndo()->isEnabled()) {
undo_set_label(sprite_writer->getUndo(), "Cel Opacity Change");
sprite_writer->getUndo()->setLabel("Cel Opacity Change");
undo_int(sprite_writer->getUndo(), (GfxObj *)cel_writer, &cel_writer->opacity);
}

View File

@ -69,7 +69,7 @@ static Layer* duplicate_layer(Sprite* sprite)
{
/* open undo */
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Layer Duplication");
sprite->getUndo()->setLabel("Layer Duplication");
undo_open(sprite->getUndo());
}

View File

@ -76,7 +76,7 @@ void InvertMaskCommand::onExecute(Context* context)
/* undo */
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Mask Invert");
sprite->getUndo()->setLabel("Mask Invert");
undo_set_mask(sprite->getUndo(), sprite);
}

View File

@ -85,7 +85,7 @@ void LoadMaskCommand::onExecute(Context* context)
// undo
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Mask Load");
sprite->getUndo()->setLabel("Mask Load");
undo_set_mask(sprite->getUndo(), sprite);
}

View File

@ -58,7 +58,7 @@ void MaskAllCommand::onExecute(Context* context)
/* undo */
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Mask All");
sprite->getUndo()->setLabel("Mask All");
undo_set_mask(sprite->getUndo(), sprite);
}

View File

@ -81,7 +81,7 @@ void MergeDownLayerCommand::onExecute(Context* context)
dst_layer = sprite->getCurrentLayer()->get_prev();
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Merge Down Layer");
sprite->getUndo()->setLabel("Merge Down Layer");
undo_open(sprite->getUndo());
}

View File

@ -78,7 +78,7 @@ void NewCelCommand::onExecute(Context* context)
image_index = stock_add_image(current_sprite->stock, image);
if (undo_is_enabled(current_sprite->undo)) {
undo_set_label(current_sprite->undo, "New Cel");
current_sprite->undo->setLabel("New Cel");
undo_open(current_sprite->undo);
undo_add_image(current_sprite->undo,
current_sprite->stock, image_index);

View File

@ -510,7 +510,7 @@ static void sort_command(JWidget widget)
// TODO The following code is unreadable, move this to Undoable class
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Sort Palette");
sprite->getUndo()->setLabel("Sort Palette");
undo_open(sprite->getUndo());
// Remove the current palette in the current frame

View File

@ -58,7 +58,7 @@ void RedoCommand::onExecute(Context* context)
app_get_statusbar()
->showTip(1000, "Redid %s",
undo_get_next_redo_label(sprite->getUndo()));
sprite->getUndo()->getNextRedoLabel());
sprite->getUndo()->doRedo();
sprite->generateMaskBoundaries();

View File

@ -64,7 +64,7 @@ void ReselectMaskCommand::onExecute(Context* context)
/* undo */
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Mask Reselection");
sprite->getUndo()->setLabel("Mask Reselection");
undo_set_mask(sprite->getUndo(), sprite);
}

View File

@ -58,7 +58,7 @@ void UndoCommand::onExecute(Context* context)
app_get_statusbar()
->showTip(1000, "Undid %s",
undo_get_next_undo_label(sprite->getUndo()));
sprite->getUndo()->getNextUndoLabel());
sprite->getUndo()->doUndo();
sprite->generateMaskBoundaries();

View File

@ -134,7 +134,7 @@ void dialogs_mask_color(Sprite* sprite)
/* undo */
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Mask by Color");
sprite->getUndo()->setLabel("Mask by Color");
undo_set_mask(sprite->getUndo(), sprite);
}

View File

@ -250,8 +250,7 @@ void effect_apply(Effect* effect)
if (!cancelled) {
// Undo stuff
if (effect->sprite->getUndo()->isEnabled()) {
undo_set_label(effect->sprite->getUndo(),
effect->effect_data->label);
effect->sprite->getUndo()->setLabel(effect->effect_data->label);
undo_image(effect->sprite->getUndo(), effect->src,
effect->x, effect->y, effect->w, effect->h);
}

View File

@ -324,9 +324,6 @@ bool Undo::canRedo() const
return !jlist_empty(this->redo_stream->chunks);
}
//////////////////////////////////////////////////////////////////////
// General undo routines
void Undo::doUndo()
{
run_undo(this, DO_UNDO);
@ -337,40 +334,42 @@ void Undo::doRedo()
run_undo(this, DO_REDO);
}
void undo_clear_redo(Undo* undo)
void Undo::clearRedo()
{
ASSERT(undo);
if (!jlist_empty(undo->redo_stream->chunks)) {
undo_stream_free(undo->redo_stream);
undo->redo_stream = undo_stream_new(undo);
if (!jlist_empty(this->redo_stream->chunks)) {
undo_stream_free(this->redo_stream);
this->redo_stream = undo_stream_new(this);
}
}
void undo_set_label(Undo* undo, const char *label)
void Undo::setLabel(const char* label)
{
undo->label = label;
this->label = label;
}
const char *undo_get_next_undo_label(const Undo* undo)
const char* Undo::getNextUndoLabel() const
{
UndoChunk* chunk;
ASSERT(undo->canUndo());
ASSERT(this->canUndo());
chunk = reinterpret_cast<UndoChunk*>(jlist_first_data(undo->undo_stream->chunks));
chunk = reinterpret_cast<UndoChunk*>(jlist_first_data(this->undo_stream->chunks));
return chunk->label;
}
const char *undo_get_next_redo_label(const Undo* undo)
const char* Undo::getNextRedoLabel() const
{
UndoChunk* chunk;
ASSERT(undo->canRedo());
ASSERT(this->canRedo());
chunk = reinterpret_cast<UndoChunk*>(jlist_first_data(undo->redo_stream->chunks));
chunk = reinterpret_cast<UndoChunk*>(jlist_first_data(this->redo_stream->chunks));
return chunk->label;
}
//////////////////////////////////////////////////////////////////////
// General undo routines
static void run_undo(Undo* undo, int state)
{
UndoStream* undo_stream = ((state == DO_UNDO)? undo->undo_stream:
@ -385,7 +384,7 @@ static void run_undo(Undo* undo, int state)
if (!chunk)
break;
undo_set_label(undo, chunk->label);
undo->setLabel(chunk->label);
(undo_actions[chunk->type].invert)(redo_stream, chunk, state);
if (chunk->type == UNDO_TYPE_OPEN)
@ -483,7 +482,7 @@ static void update_undo(Undo* undo)
undo->diff_count++;
/* reset the "redo" stream */
undo_clear_redo(undo);
undo->clearRedo();
if (out_of_group(undo->undo_stream)) {
int groups = count_undo_groups(undo->undo_stream);

View File

@ -66,14 +66,14 @@ public:
void doUndo();
void doRedo();
void clearRedo();
void setLabel(const char* label);
const char* getNextUndoLabel() const;
const char* getNextRedoLabel() const;
};
void undo_clear_redo(Undo* undo);
void undo_set_label(Undo* undo, const char *label);
const char* undo_get_next_undo_label(const Undo* undo);
const char* undo_get_next_redo_label(const Undo* undo);
void undo_open(Undo* undo);
void undo_close(Undo* undo);
void undo_data(Undo* undo, GfxObj *gfxobj, void *data, int size);

View File

@ -51,7 +51,7 @@ Undoable::Undoable(SpriteWriter& sprite, const char* label)
m_enabledFlag = m_sprite->getUndo()->isEnabled();
if (isEnabled()) {
undo_set_label(m_sprite->getUndo(), label);
m_sprite->getUndo()->setLabel(label);
undo_open(m_sprite->getUndo());
}
}
@ -69,7 +69,7 @@ Undoable::~Undoable()
// clear the redo (sorry to the user, here we lost the old redo
// information)
undo_clear_redo(m_sprite->getUndo());
m_sprite->getUndo()->clearRedo();
}
}
}

View File

@ -70,7 +70,7 @@ void move_cel(SpriteWriter& sprite)
dst_cel = static_cast<LayerImage*>(dst_layer)->getCel(dst_frame);
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Move Cel");
sprite->getUndo()->setLabel("Move Cel");
undo_open(sprite->getUndo());
undo_set_layer(sprite->getUndo(), sprite);
@ -157,7 +157,7 @@ void copy_cel(SpriteWriter& sprite)
dst_cel = static_cast<LayerImage*>(dst_layer)->getCel(dst_frame);
if (sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Move Cel");
sprite->getUndo()->setLabel("Move Cel");
undo_open(sprite->getUndo());
undo_set_layer(sprite->getUndo(), sprite);

View File

@ -153,7 +153,7 @@ int interactive_move_layer(int mode, bool use_undo, int (*callback)())
/* the position was changed */
if (!editor->editor_click_cancel()) {
if (use_undo && sprite->getUndo()->isEnabled()) {
undo_set_label(sprite->getUndo(), "Cel Movement");
sprite->getUndo()->setLabel("Cel Movement");
undo_open(sprite->getUndo());
undo_int(sprite->getUndo(), (GfxObj *)cel, &cel->x);
undo_int(sprite->getUndo(), (GfxObj *)cel, &cel->y);

View File

@ -1902,7 +1902,7 @@ public:
// Set undo label for any kind of undo used in the whole loop
if (m_sprite->getUndo()->isEnabled())
undo_set_label(m_sprite->getUndo(), m_tool->getText().c_str());
m_sprite->getUndo()->setLabel(m_tool->getText().c_str());
}
~ToolLoopImpl()