-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfd3ec8
commit ecee935
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#pragma once | ||
|
||
#include "tactile/base/prelude.hpp" | ||
#include "tactile/core/document/document.hpp" | ||
#include "tactile/core/document/document_manager.hpp" | ||
|
||
namespace tactile { | ||
|
||
struct Settings; | ||
|
||
namespace ui { | ||
class Language; | ||
} // namespace ui | ||
|
||
/// \addtogroup Model | ||
/// \{ | ||
|
||
/** | ||
* Provides the top-level API for the core document model. | ||
* | ||
* \details | ||
* Due to the nature of how Dear ImGui works, the model only allows using one | ||
* language per editor session. This is to avoid issues regarding the handling | ||
* of translated strings. | ||
*/ | ||
class Model final | ||
{ | ||
public: | ||
/** | ||
* Creates a model. | ||
* | ||
* \param settings The associated settings. | ||
* \param language The language that will be used throughout this session. | ||
*/ | ||
Model(const Settings* settings, const ui::Language* language); | ||
|
||
/** | ||
* Returns the associated document manager. | ||
* | ||
* \return | ||
* A document manager. | ||
*/ | ||
[[nodiscard]] | ||
auto get_document_manager() -> DocumentManager&; | ||
|
||
/** | ||
* \copydoc get_documents() | ||
*/ | ||
[[nodiscard]] | ||
auto get_document_manager() const -> const DocumentManager&; | ||
|
||
/** | ||
* Returns the currently active document, if any. | ||
* | ||
* \return | ||
* A pointer to the active document; a null pointer if there is none. | ||
*/ | ||
[[nodiscard]] | ||
auto get_current_document() -> IDocument*; | ||
|
||
/** | ||
* \copydoc get_current_document() | ||
*/ | ||
[[nodiscard]] | ||
auto get_current_document() const -> const IDocument*; | ||
|
||
/** | ||
* Returns the associated settings. | ||
* | ||
* \return | ||
* A pointer to the settings. | ||
*/ | ||
[[nodiscard]] | ||
auto get_settings() const -> const Settings&; | ||
|
||
/** | ||
* Returns the language used in this session. | ||
* | ||
* \return | ||
* A language. | ||
*/ | ||
[[nodiscard]] | ||
auto get_language() const -> const ui::Language&; | ||
|
||
private: | ||
const Settings* mSettings {}; | ||
const ui::Language* mLanguage {}; | ||
DocumentManager mDocuments {}; | ||
}; | ||
|
||
/// \} | ||
|
||
} // namespace tactile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#include "tactile/core/model/model.hpp" | ||
|
||
#include "tactile/core/debug/validation.hpp" | ||
|
||
namespace tactile { | ||
|
||
Model::Model(const Settings* settings, const ui::Language* language) | ||
: mSettings {require_not_null(settings, "null settings")}, | ||
mLanguage {require_not_null(language, "null language")} | ||
{} | ||
|
||
auto Model::get_document_manager() -> DocumentManager& | ||
{ | ||
return mDocuments; | ||
} | ||
|
||
auto Model::get_document_manager() const -> const DocumentManager& | ||
{ | ||
return mDocuments; | ||
} | ||
|
||
auto Model::get_current_document() -> IDocument* | ||
{ | ||
return mDocuments.get_current_document(); | ||
} | ||
|
||
auto Model::get_current_document() const -> const IDocument* | ||
{ | ||
return mDocuments.get_current_document(); | ||
} | ||
|
||
auto Model::get_settings() const -> const Settings& | ||
{ | ||
return *mSettings; | ||
} | ||
|
||
auto Model::get_language() const -> const ui::Language& | ||
{ | ||
return *mLanguage; | ||
} | ||
|
||
} // namespace tactile |