1// Aseprite
2// Copyright (C) 2019-2021 Igara Studio S.A.
3// Copyright (C) 2001-2018 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifndef APP_UI_CONTEXT_H_INCLUDED
9#define APP_UI_CONTEXT_H_INCLUDED
10#pragma once
11
12#include "app/closed_docs.h"
13#include "app/context.h"
14#include "app/docs_observer.h"
15
16#include <vector>
17
18namespace app {
19 class DocView;
20 class Editor;
21
22 typedef std::vector<DocView*> DocViews;
23 typedef std::vector<Editor*> Editors;
24
25 class UIContext : public app::Context {
26 public:
27 static UIContext* instance() { return m_instance; }
28
29 UIContext();
30 virtual ~UIContext();
31
32 bool isUIAvailable() const override;
33
34 DocView* activeView() const;
35 void setActiveView(DocView* documentView);
36
37 DocView* getFirstDocView(Doc* document) const override;
38 DocViews getAllDocViews(Doc* document) const;
39 Editors getAllEditorsIncludingPreview(Doc* document) const;
40
41 // Returns the current editor. It can be null.
42 Editor* activeEditor();
43
44 // Returns the active editor for the given document, or creates a
45 // new one if it's necessary.
46 Editor* getEditorFor(Doc* document);
47
48 bool hasClosedDocs();
49 void reopenLastClosedDoc();
50 std::vector<Doc*> getAndRemoveAllClosedDocs();
51
52 protected:
53 void onAddDocument(Doc* doc) override;
54 void onRemoveDocument(Doc* doc) override;
55 void onGetActiveSite(Site* site) const override;
56 void onSetActiveDocument(Doc* doc, bool notify) override;
57 void onSetActiveLayer(doc::Layer* layer) override;
58 void onSetActiveFrame(const doc::frame_t frame) override;
59 void onSetRange(const DocRange& range) override;
60 void onSetSelectedColors(const doc::PalettePicks& picks) override;
61 void onSetSelectedTiles(const doc::PalettePicks& picks) override;
62 void onCloseDocument(Doc* doc) override;
63
64 private:
65 DocView* m_lastSelectedView;
66 ClosedDocs m_closedDocs;
67
68 static UIContext* m_instance;
69 };
70
71} // namespace app
72
73#endif
74