ApplicationContext.hpp
1 #pragma once
2 #include <score/application/ApplicationComponents.hpp>
3 
4 namespace score
5 {
6 class ApplicationComponents;
7 struct ApplicationSettings;
8 class SettingsDelegateModel;
9 class DocumentManager;
10 class MenuManager;
11 class ToolbarManager;
12 class ActionManager;
13 struct DocumentList;
14 struct DocumentContext;
23 struct SCORE_LIB_BASE_EXPORT ApplicationContext
24 {
25  explicit ApplicationContext(
27  const std::vector<std::unique_ptr<score::SettingsDelegateModel>>&);
28  ApplicationContext(const ApplicationContext&) = delete;
30  ApplicationContext& operator=(const ApplicationContext&) = delete;
31 
33 
39  template <typename T>
40  T& settings() const
41  {
42  for(auto& elt : this->m_settings)
43  {
44  if(auto c = dynamic_cast<T*>(elt.get()))
45  {
46  return *c;
47  }
48  }
49 
50  SCORE_ABORT;
51  throw;
52  }
53 
59  const auto& addons() const { return components.addons(); }
60 
66  template <typename T>
67  const T& interfaces() const
68  {
69  return components.interfaces<T>();
70  }
71 
83  auto instantiateUndoCommand(const CommandData& cmd) const
84  {
85  return components.instantiateUndoCommand(cmd);
86  }
87 
88  const score::DocumentContext* currentDocument() const noexcept;
89 
91  const score::ApplicationSettings& applicationSettings;
92 
93  const score::ApplicationComponents& components;
94 
95  DocumentList& documents;
96 
97 private:
98  const std::vector<std::unique_ptr<score::SettingsDelegateModel>>& m_settings;
99 };
100 
101 // By default this is defined in score::Application
102 SCORE_LIB_BASE_EXPORT const ApplicationContext& AppContext();
103 }
Definition: ApplicationComponents.hpp:68
Definition: SettingsDelegateModel.hpp:16
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Used to access all the application-wide state and structures.
Definition: ApplicationContext.hpp:24
const auto & addons() const
List of all the registered addons.
Definition: ApplicationContext.hpp:59
const T & interfaces() const
Access to a specific interface list.
Definition: ApplicationContext.hpp:67
auto instantiateUndoCommand(const CommandData &cmd) const
instantiateUndoCommand Is used to generate a Command from its serialized data.
Definition: ApplicationContext.hpp:83
T & settings() const
Access a specific Settings model instance.
Definition: ApplicationContext.hpp:40
Load-time settings.
Definition: ApplicationSettings.hpp:17
Utility class for the serialization and deserialization of commands.
Definition: CommandData.hpp:14
Definition: DocumentContext.hpp:18
Definition: DocumentManager.hpp:28