yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
project_file_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_CODE_PROJECT_FILE_EDITOR_H_
2#define YAZE_APP_EDITOR_CODE_PROJECT_FILE_EDITOR_H_
3
4#include <functional>
5#include <string>
6#include <vector>
7
8#include "absl/status/status.h"
10#include "core/project.h"
11
12namespace yaze {
13namespace editor {
14
15class ToastManager;
16
18 std::string filepath;
19 std::string text;
20 bool initialized = false;
21 bool active = false;
22 bool modified = false;
23 bool show_validation = true;
24 std::vector<std::string> validation_errors;
25};
26
38 public:
39 using SaveGuardCallback = std::function<absl::Status(
40 const std::string& filepath, const std::string& contents)>;
41 using SaveCompleteCallback = std::function<absl::Status(
42 const std::string& filepath, const std::string& contents)>;
43
45
46 void Draw();
47
51 absl::Status LoadFile(const std::string& filepath);
52
56 absl::Status SaveFile();
57
61 absl::Status SaveFileAs(const std::string& filepath);
62
66 bool IsModified() const { return modified_; }
67
71 const std::string& filepath() const { return filepath_; }
72 bool IsInitialized() const { return initialized_; }
73
75 void RestoreState(const ProjectFileEditorState& state,
76 project::YazeProject* project);
78
82 void set_active(bool active) { active_ = active; }
83
87 bool* active() { return &active_; }
88 bool is_active() const { return active_; }
89
93 void SetToastManager(ToastManager* toast_manager) {
94 toast_manager_ = toast_manager;
95 }
97 save_guard_callback_ = std::move(callback);
98 }
100 save_complete_callback_ = std::move(callback);
101 }
102
103 // New/Open must never discard a modified draft implicitly.
104 absl::Status CanReplaceDocument() const;
105
109 absl::Status NewFile();
110
114 void SetProject(project::YazeProject* project) { project_ = project; }
115
116 private:
120 absl::Status ImportLabelsFromZScream();
121
123 void ValidateContent();
125 std::string GetDocumentText() const;
126
128 std::string filepath_;
129 bool initialized_ = false;
130 bool active_ = false;
131 bool modified_ = false;
132 bool show_validation_ = true;
133 std::vector<std::string> validation_errors_;
138};
139
140} // namespace editor
141} // namespace yaze
142
143#endif // YAZE_APP_EDITOR_CODE_PROJECT_FILE_EDITOR_H_
Editor for .yaze project files with syntax highlighting and validation.
bool * active()
Get pointer to active state for ImGui.
absl::Status SaveFileAs(const std::string &filepath)
Save to a new file path.
absl::Status LoadFile(const std::string &filepath)
Load a project file into the editor.
void SetProject(project::YazeProject *project)
Set the project pointer for label import operations.
ProjectFileEditorState CaptureState() const
bool IsModified() const
Get whether the file has unsaved changes.
void RestoreState(const ProjectFileEditorState &state, project::YazeProject *project)
void set_active(bool active)
Set whether the editor window is active.
std::vector< std::string > validation_errors_
absl::Status SaveFile()
Save the current editor contents to disk.
absl::Status ImportLabelsFromZScream()
Import labels from a ZScream DefaultNames.txt file.
SaveCompleteCallback save_complete_callback_
absl::Status NewFile()
Create a new empty project file.
void ResetForProject(project::YazeProject *project)
std::function< absl::Status( const std::string &filepath, const std::string &contents)> SaveCompleteCallback
void SetSaveCompleteCallback(SaveCompleteCallback callback)
void SetToastManager(ToastManager *toast_manager)
Set toast manager for notifications.
const std::string & filepath() const
Get the current filepath.
void SetSaveGuardCallback(SaveGuardCallback callback)
std::function< absl::Status( const std::string &filepath, const std::string &contents)> SaveGuardCallback
std::vector< std::string > validation_errors
Modern project structure with comprehensive settings consolidation.
Definition project.h:172