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/app.h"
12#include "app/commands/command.h"
13#include "app/pref/preferences.h"
14#include "app/ui/keyboard_shortcuts.h"
15#include "app/ui/main_window.h"
16#include "ui/ui.h"
17
18#include "advanced_mode.xml.h"
19
20#include <cstdio>
21
22namespace app {
23
24using namespace ui;
25
26class AdvancedModeCommand : public Command {
27public:
28 AdvancedModeCommand();
29
30protected:
31 void onExecute(Context* context) override;
32};
33
34AdvancedModeCommand::AdvancedModeCommand()
35 : Command(CommandId::AdvancedMode(), CmdUIOnlyFlag)
36{
37}
38
39void AdvancedModeCommand::onExecute(Context* context)
40{
41 // Switch advanced mode.
42 MainWindow* mainWindow = App::instance()->mainWindow();
43 MainWindow::Mode oldMode = mainWindow->getMode();
44 MainWindow::Mode newMode = oldMode;
45
46 switch (oldMode) {
47 case MainWindow::NormalMode:
48 newMode = MainWindow::ContextBarAndTimelineMode;
49 break;
50 case MainWindow::ContextBarAndTimelineMode:
51 newMode = MainWindow::EditorOnlyMode;
52 break;
53 case MainWindow::EditorOnlyMode:
54 newMode = MainWindow::NormalMode;
55 break;
56 }
57
58 mainWindow->setMode(newMode);
59
60 auto& pref = Preferences::instance();
61
62 if (oldMode == MainWindow::NormalMode &&
63 pref.advancedMode.showAlert()) {
64 KeyPtr key = KeyboardShortcuts::instance()->command(this->id().c_str());
65 if (!key->accels().empty()) {
66 app::gen::AdvancedMode window;
67
68 window.warningLabel()->setTextf("You can go back pressing \"%s\" key.",
69 key->accels().front().toString().c_str());
70
71 window.openWindowInForeground();
72
73 pref.advancedMode.showAlert(!window.donotShow()->isSelected());
74 }
75 }
76}
77
78Command* CommandFactory::createAdvancedModeCommand()
79{
80 return new AdvancedModeCommand;
81}
82
83} // namespace app
84