| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2001-2017 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 "ui/ui.h" |
| 12 | |
| 13 | #include "app/app.h" |
| 14 | #include "app/commands/command.h" |
| 15 | #include "app/commands/params.h" |
| 16 | #include "app/context.h" |
| 17 | #include "app/ui/main_window.h" |
| 18 | #include "app/ui/timeline/timeline.h" |
| 19 | |
| 20 | namespace app { |
| 21 | |
| 22 | class TimelineCommand : public Command { |
| 23 | public: |
| 24 | TimelineCommand(); |
| 25 | |
| 26 | protected: |
| 27 | bool onNeedsParams() const override { return true; } |
| 28 | void onLoadParams(const Params& params) override; |
| 29 | void onExecute(Context* context) override; |
| 30 | bool onChecked(Context* ctx) override; |
| 31 | |
| 32 | bool m_open; |
| 33 | bool m_close; |
| 34 | bool m_switch; |
| 35 | }; |
| 36 | |
| 37 | TimelineCommand::TimelineCommand() |
| 38 | : Command(CommandId::Timeline(), CmdUIOnlyFlag) |
| 39 | { |
| 40 | m_open = true; |
| 41 | m_close = false; |
| 42 | m_switch = false; |
| 43 | } |
| 44 | |
| 45 | void TimelineCommand::onLoadParams(const Params& params) |
| 46 | { |
| 47 | m_open = params.get_as<bool>("open"); |
| 48 | m_close = params.get_as<bool>("close"); |
| 49 | m_switch = params.get_as<bool>("switch"); |
| 50 | } |
| 51 | |
| 52 | void TimelineCommand::onExecute(Context* context) |
| 53 | { |
| 54 | bool visible = App::instance()->mainWindow()->getTimelineVisibility(); |
| 55 | bool newVisible = visible; |
| 56 | |
| 57 | if (m_switch) |
| 58 | newVisible = !visible; |
| 59 | else if (m_close) |
| 60 | newVisible = false; |
| 61 | else if (m_open) |
| 62 | newVisible = true; |
| 63 | |
| 64 | if (visible != newVisible) |
| 65 | App::instance()->mainWindow()->setTimelineVisibility(newVisible); |
| 66 | } |
| 67 | |
| 68 | bool TimelineCommand::onChecked(Context* ctx) { |
| 69 | MainWindow* mainWin = App::instance()->mainWindow(); |
| 70 | if (!mainWin) |
| 71 | return false; |
| 72 | |
| 73 | Timeline* timelineWin = mainWin->getTimeline(); |
| 74 | return (timelineWin && timelineWin->isVisible()); |
| 75 | } |
| 76 | |
| 77 | Command* CommandFactory::createTimelineCommand() |
| 78 | { |
| 79 | return new TimelineCommand; |
| 80 | } |
| 81 | |
| 82 | } // namespace app |
| 83 |