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 #ifndef APP_UI_CONTEXT_H_INCLUDED
8 #define APP_UI_CONTEXT_H_INCLUDED
9 #pragma once
10 
11 #include "app/context.h"
12 #include "app/docs_observer.h"
13 
14 namespace app {
15   class DocView;
16   class Editor;
17 
18   typedef std::vector<DocView*> DocViews;
19   typedef std::vector<Editor*> Editors;
20 
21   class UIContext : public app::Context {
22   public:
instance()23     static UIContext* instance() { return m_instance; }
24 
25     UIContext();
26     virtual ~UIContext();
27 
28     bool isUIAvailable() const override;
29 
30     DocView* activeView() const;
31     void setActiveView(DocView* documentView);
32 
33     DocView* getFirstDocView(Doc* document) const override;
34     DocViews getAllDocViews(Doc* document) const;
35     Editors getAllEditorsIncludingPreview(Doc* document) const;
36 
37     // Returns the current editor. It can be null.
38     Editor* activeEditor();
39 
40     // Returns the active editor for the given document, or creates a
41     // new one if it's necessary.
42     Editor* getEditorFor(Doc* document);
43 
44   protected:
45     void onAddDocument(Doc* doc) override;
46     void onRemoveDocument(Doc* doc) override;
47     void onGetActiveSite(Site* site) const override;
48     void onSetActiveDocument(Doc* doc) override;
49 
50   private:
51     DocView* m_lastSelectedView;
52     static UIContext* m_instance;
53   };
54 
55 } // namespace app
56 
57 #endif
58