| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2001-2018 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifdef HAVE_CONFIG_H |
| 8 | #include "config.h" |
| 9 | #endif |
| 10 | |
| 11 | #include "app/commands/cmd_set_palette.h" |
| 12 | #include "app/context_access.h" |
| 13 | #include "app/doc_api.h" |
| 14 | #include "app/file_selector.h" |
| 15 | #include "app/ini_file.h" |
| 16 | #include "app/modules/palettes.h" |
| 17 | #include "app/tx.h" |
| 18 | #include "doc/palette.h" |
| 19 | #include "ui/alert.h" |
| 20 | #include "ui/manager.h" |
| 21 | |
| 22 | namespace app { |
| 23 | |
| 24 | using namespace ui; |
| 25 | |
| 26 | SetPaletteCommand::SetPaletteCommand() |
| 27 | : Command(CommandId::SetPalette(), CmdRecordableFlag) |
| 28 | , m_palette(NULL) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | void SetPaletteCommand::onExecute(Context* context) |
| 33 | { |
| 34 | ASSERT(m_palette); |
| 35 | if (!m_palette) |
| 36 | return; |
| 37 | |
| 38 | ContextWriter writer(context); |
| 39 | if (writer.document()) { |
| 40 | Tx tx(writer.context(), "Set Palette"); |
| 41 | writer.document()->getApi(tx) |
| 42 | .setPalette(writer.sprite(), writer.frame(), m_palette); |
| 43 | tx.commit(); |
| 44 | } |
| 45 | set_current_palette(m_palette, false); |
| 46 | |
| 47 | // Redraw the entire screen |
| 48 | if (context->isUIAvailable()) |
| 49 | ui::Manager::getDefault()->invalidate(); |
| 50 | } |
| 51 | |
| 52 | Command* CommandFactory::createSetPaletteCommand() |
| 53 | { |
| 54 | return new SetPaletteCommand; |
| 55 | } |
| 56 | |
| 57 | } // namespace app |
| 58 |