undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoAppEditor.hpp
Go to the documentation of this file.
1
23#pragma once
24
25#include <string>
26#include <vector>
27#include <filesystem>
28#include <map>
29
30// ProjectManager: project-level service
32
33// Include all sub-app headers
35#include "undoAppST.hpp"
36#include "undoAppJSON.hpp"
37#include "undoAppText.hpp"
38#include "undoAppCpp.hpp"
39
40namespace undoApp {
41namespace Editor {
42
44
48enum class FileType {
49 None,
50 ST,
51 JSON,
52 Text,
53 Cpp
54};
55
60{
61 std::string name;
62 std::string path;
64 std::vector<FileNode> children;
65 bool expanded = false;
66 bool isDragging = false;
67 NodeRole role = NodeRole::Generic;
68};
69
74{
75 std::string path;
76 std::string text;
77};
78
83{
84public:
87
90
92 bool initialize();
93
95 void shutdown();
96
99
102
104 std::string getCurrentFilePath() const { return m_currentFilePath; }
105
127 void openFile(const std::string& path, bool pin = true);
128
130 void closeFile();
131
134
137
139 void loadWorkspace(const std::string& path);
140
141 // ============================================================================
142 // Project management (undoProject mode)
143 // ============================================================================
144
146 void createProject(const std::string& parentDir, const std::string& name);
147
149 void openProject(const std::string& projectDir);
150
153
155 bool isProjectOpen() const;
156
157private:
158 // ============================================================================
159 // File tree management
160 // ============================================================================
161
163 void buildFileTree(FileNode& node, const std::string& root);
164
167
169 void createNewFile(const std::string& parentPath, const std::string& name);
170
172 void createNewFolder(const std::string& parentPath, const std::string& name);
173
175 void deleteFile(const std::string& path);
176
185 void renameFile(const std::string& oldPath, const std::string& newName);
186
193 void moveFile(const std::string& sourcePath, const std::string& destDir);
194
197
199 void createNewGenericFile(const std::string& parentPath, const std::string& name);
200
203
205 void openFileAsText(const std::string& path);
206
214 void openFileAsTree(const std::string& path);
215
216 // ============================================================================
217 // Helper functions
218 // ============================================================================
219
221 std::string toLower(std::string s);
222
223 void expandToPath(FileNode& node, const std::string& targetPath);
224
225 // ============================================================================
226 // Member variables
227 // ============================================================================
228
229 bool m_initialized = false;
231 std::string m_currentFilePath;
232
237
245 std::map<std::string, ST::STDocument> m_stStashes;
246 std::map<std::string, StashedText> m_textStashes;
247 std::map<std::string, StashedText> m_cppStashes;
248 std::map<std::string, JSON::JSONDocument> m_jsonStashes;
249
251 static constexpr size_t kNoIndex = static_cast<size_t>(-1);
252
256
261 void stashActiveDocument(bool keep);
262
271
280
283 void loadActiveDocument(const std::string& path);
284
286 void switchToTab(const std::string& path);
287
289 void closeTab(const std::string& path);
290
291
292
294 size_t documentIndex(const std::string& path) const;
295
300 void openDocument(const std::string& path, DocKind kind, bool pin);
301
310 void followPathChange(const std::string& oldPath, const std::string& newPath);
311
314 void closeDocumentsUnder(const std::string& path);
315
318 void dropStashes(const std::string& path);
319
321 std::string neighbourAfterClose(const std::string& path) const;
322
323 // Workspace management
324 std::string m_workspacePath;
326
327 // POU creation popup state
328 bool m_showNewPOUPopup = false;
330 std::string m_newPOUName;
331 std::string m_newItemParent;
334
335 // Folder creation popup state
337 std::string m_newItemName;
338 bool m_showNewFilePopup = false;
339 std::string m_newFileName;
340 std::string m_newFileParent;
341
342 // Rename popup state
343 bool m_showRenamePopup = false;
344 std::string m_renamePath;
345
346// Delete confirmation state
349
350 // Fallback workspace picker, for when neither tinyfiledialogs nor zenity is
351 // available. A modal of the app's own, so it has to be drawn by the panel.
353 char m_workspaceDialogPath[1024] = {};
354
355 // Drag and drop state
356 std::string m_draggedItemPath;
357 bool m_isDragging = false;
358
359 // ============================================================================
360 // Project mode state
361 // ============================================================================
362
363 bool m_isProjectMode = false;
364
365 // "New Project" popup
367 char m_newProjectParent[1024] = {};
368 char m_newProjectName[256] = {};
369 // Fields for project.json
370 char m_newProjectAuthor[256] = {};
371 char m_newProjectArch[64] = {"x86_64"};
372
373 // "Add PLC" popup
374 bool m_showAddPLCPopup = false;
375 char m_addPLCName[256] = {};
376 char m_addPLCDesc[512] = {};
377
378 // "Add Task" popup
379 bool m_showAddTaskPopup = false;
380 char m_addTaskName[256] = {};
381 char m_addTaskPLC[256] = {};
384 int m_addTaskCPU = -1;
385
386 // "Rename PLC" popup
389 char m_renamePLCNewName[256] = {};
390
391 // "Delete PLC" confirmation
394
395 // "Edit Task" popup (re-uses Add fields; set to existing task on open)
398};
399
400} // namespace Editor
401} // namespace undoApp
undoProject management service for undoStudio
Main application class for the Workspace and file routing.
Definition undoAppEditor.hpp:83
void refreshFileTree()
Refresh the file tree.
FileType m_currentFileType
Definition undoAppEditor.hpp:230
void renderWorkspacePanel()
Render the Workspace panel (file tree and workspace management)
char m_newProjectName[256]
Definition undoAppEditor.hpp:368
bool m_showNewFolderPopup
Definition undoAppEditor.hpp:336
bool m_showAddPLCPopup
Definition undoAppEditor.hpp:374
bool m_showRenamePLCPopup
Definition undoAppEditor.hpp:387
void closeTab(const std::string &path)
Close a tab, moving to the one beside it if it was the active one.
std::map< std::string, StashedText > m_cppStashes
Definition undoAppEditor.hpp:247
std::string m_newFileName
Definition undoAppEditor.hpp:339
int m_addTaskPriority
Definition undoAppEditor.hpp:383
void renderFileTree(FileNode &node)
Recursively render the file tree.
bool isProjectOpen() const
True if an undoProject is currently open.
std::string m_newPOUName
Definition undoAppEditor.hpp:330
void openDocument(const std::string &path, DocKind kind, bool pin)
Open a file with a chosen backend, through the tab bar and the model.
char m_addTaskPLC[256]
Definition undoAppEditor.hpp:381
char m_addTaskName[256]
Definition undoAppEditor.hpp:380
bool m_isDragging
Definition undoAppEditor.hpp:357
char m_addPLCName[256]
Definition undoAppEditor.hpp:375
void loadActiveDocument(const std::string &path)
Put a file into the editor its backend owns.
bool m_showNewFilePopup
Definition undoAppEditor.hpp:338
void shutdown()
Shutdown the editor plugin and release resources.
std::string m_deletePLCPending
Definition undoAppEditor.hpp:393
std::string m_newItemName
Definition undoAppEditor.hpp:337
char m_renamePLCNewName[256]
Definition undoAppEditor.hpp:389
bool m_showWorkspaceDialog
Definition undoAppEditor.hpp:352
void followPathChange(const std::string &oldPath, const std::string &newPath)
Follow a file that was renamed or moved on disk.
std::string m_workspacePath
Definition undoAppEditor.hpp:324
void openFile(const std::string &path, bool pin=true)
Open a file using the appropriate backend for its extension.
std::string m_renamePath
Definition undoAppEditor.hpp:344
bool m_isProjectMode
Definition undoAppEditor.hpp:363
void openWorkspaceDialog()
Open a native folder selection dialog.
char m_newProjectAuthor[256]
Definition undoAppEditor.hpp:370
void renameFile(const std::string &oldPath, const std::string &newName)
Rename a file or folder.
bool initialize()
Initialize the editor plugin (called by PluginManager)
void loadWorkspace(const std::string &path)
Load a workspace from the given path.
void closeDocumentsUnder(const std::string &path)
Close every tab under a path, including the files inside a folder.
void createNewFolder(const std::string &parentPath, const std::string &name)
Create a new folder in the workspace.
void createNewGenericFile(const std::string &parentPath, const std::string &name)
Create generic file.
int m_addTaskCycleMs
Definition undoAppEditor.hpp:382
std::string m_newItemParent
Definition undoAppEditor.hpp:331
char m_newProjectParent[1024]
Definition undoAppEditor.hpp:367
void saveActiveDocument()
Write the file on screen back to disk, whichever kind it is.
void openFileAsTree(const std::string &path)
Open a JSON file in the tree viewer, whatever it opens as by default.
ST::POUType m_newPOUType
Definition undoAppEditor.hpp:329
void createProject(const std::string &parentDir, const std::string &name)
Create a new undoProject.
void refreshDirtyState()
Ask the backend on screen whether the file has unsaved changes.
void renderEditorPanel()
Render the unified "Editor" panel by dispatching to the active backend.
char m_newProjectArch[64]
Definition undoAppEditor.hpp:371
char m_addPLCDesc[512]
Definition undoAppEditor.hpp:376
bool m_showDeletePLCConfirm
Definition undoAppEditor.hpp:392
void expandToPath(FileNode &node, const std::string &targetPath)
bool m_showRenamePopup
Definition undoAppEditor.hpp:343
void renderFileTabs()
Draw the bar of open files above whichever editor is showing.
std::map< std::string, JSON::JSONDocument > m_jsonStashes
Definition undoAppEditor.hpp:248
bool m_showNewPOUPopup
Definition undoAppEditor.hpp:328
OpenDocuments m_open
Definition undoAppEditor.hpp:236
void closeProject()
Close the current undoProject.
void moveFile(const std::string &sourcePath, const std::string &destDir)
Move a file to a destination directory.
static EditorApp & getInstance()
Get the singleton instance of EditorApp.
void openFileAsText(const std::string &path)
Open a JSON file as plain text (bypass JSON viewer)
bool m_initialized
Definition undoAppEditor.hpp:229
void closeFile()
Close the currently open file.
void switchToTab(const std::string &path)
Bring a tab to the front, restoring what it held.
std::string m_newPOUReturnType
Definition undoAppEditor.hpp:332
void createNewFile(const std::string &parentPath, const std::string &name)
Create a new file with ST template (POU)
std::string neighbourAfterClose(const std::string &path) const
The tab to show after closing one.
bool m_showAddTaskPopup
Definition undoAppEditor.hpp:379
std::string m_newFileParent
Definition undoAppEditor.hpp:340
int m_addTaskCPU
Definition undoAppEditor.hpp:384
std::string m_deletePendingPath
Definition undoAppEditor.hpp:348
char m_workspaceDialogPath[1024]
Definition undoAppEditor.hpp:353
std::string getCurrentFilePath() const
Get the path of the currently open file (empty when none)
Definition undoAppEditor.hpp:104
void openProject(const std::string &projectDir)
Open an existing undoProject from projectDir.
bool m_showPOUReturnType
Definition undoAppEditor.hpp:333
void deleteFile(const std::string &path)
Delete a file or folder (shows confirmation popup)
static DocKind docKindFor(FileType type)
Which backend a document kind belongs to.
FileNode m_rootNode
Definition undoAppEditor.hpp:325
FileType getCurrentFileType() const
Get the type of the currently open file.
Definition undoAppEditor.hpp:101
std::map< std::string, StashedText > m_textStashes
Definition undoAppEditor.hpp:246
void dropStashes(const std::string &path)
Forget everything stashed for a path.
void stashActiveDocument(bool keep)
Take the file on screen out of its backend, into its own stash.
std::string m_editTaskOriginalName
Definition undoAppEditor.hpp:397
bool m_showDeleteConfirmation
Definition undoAppEditor.hpp:347
std::map< std::string, ST::STDocument > m_stStashes
Definition undoAppEditor.hpp:245
size_t documentIndex(const std::string &path) const
Where a file sits in the open list.
std::string m_currentFilePath
Definition undoAppEditor.hpp:231
bool m_showEditTaskPopup
Definition undoAppEditor.hpp:396
static FileType fileTypeFor(DocKind kind)
bool m_showNewProjectPopup
Definition undoAppEditor.hpp:366
static constexpr size_t kNoIndex
Says "not found", for a lookup that may genuinely have no answer.
Definition undoAppEditor.hpp:251
std::string toLower(std::string s)
Get the file extension in lowercase.
void registerPanels()
Register the unified "Editor" panel and "Workspace" panel with ImGuiManager.
std::string m_draggedItemPath
Definition undoAppEditor.hpp:356
std::string m_renamePLCOldName
Definition undoAppEditor.hpp:388
void buildFileTree(FileNode &node, const std::string &root)
Build a hierarchical file tree from a directory path.
The set of open files, at most one of them a preview.
Definition undoAppOpenDocuments.hpp:87
FileType
The kind of file currently open in the editor.
Definition undoAppEditor.hpp:48
POUType
Enumeration of POU (Program Organization Unit) types.
Definition undoAppST.hpp:42
Definition undoAppCpp.hpp:26
DocKind
Which backend a document belongs to.
Definition undoAppOpenDocuments.hpp:49
NodeRole
Definition ProjectManager.hpp:112
Node structure for the file tree representation.
Definition undoAppEditor.hpp:60
bool expanded
Definition undoAppEditor.hpp:65
NodeRole role
Semantic role within an undoProject.
Definition undoAppEditor.hpp:67
bool isDirectory
Definition undoAppEditor.hpp:63
bool isDragging
Definition undoAppEditor.hpp:66
std::string path
Definition undoAppEditor.hpp:62
std::vector< FileNode > children
Definition undoAppEditor.hpp:64
std::string name
Definition undoAppEditor.hpp:61
One plain-text or C++ document, held while another file is in the editor.
Definition undoAppEditor.hpp:74
std::string path
Definition undoAppEditor.hpp:75
std::string text
Definition undoAppEditor.hpp:76
Header of the C/C++ editor backend.
Header of the JSON Viewer undoApp.
Which files are open, and which of them is only a preview.
Header of the Structured Text editor undoApp.
Header of the plain-text editor undoApp.