undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoApp::Editor::EditorApp Class Reference

Main application class for the Workspace and file routing. More...

#include <undoAppEditor.hpp>

Collaboration diagram for undoApp::Editor::EditorApp:
Collaboration graph

Public Member Functions

void renderFileTabs ()
 Draw the bar of open files above whichever editor is showing.
 
bool initialize ()
 Initialize the editor plugin (called by PluginManager)
 
void shutdown ()
 Shutdown the editor plugin and release resources.
 
void registerPanels ()
 Register the unified "Editor" panel and "Workspace" panel with ImGuiManager.
 
FileType getCurrentFileType () const
 Get the type of the currently open file.
 
std::string getCurrentFilePath () const
 Get the path of the currently open file (empty when none)
 
void openFile (const std::string &path, bool pin=true)
 Open a file using the appropriate backend for its extension.
 
void closeFile ()
 Close the currently open file.
 
void renderEditorPanel ()
 Render the unified "Editor" panel by dispatching to the active backend.
 
void renderWorkspacePanel ()
 Render the Workspace panel (file tree and workspace management)
 
void loadWorkspace (const std::string &path)
 Load a workspace from the given path.
 
void createProject (const std::string &parentDir, const std::string &name)
 Create a new undoProject.
 
void openProject (const std::string &projectDir)
 Open an existing undoProject from projectDir.
 
void closeProject ()
 Close the current undoProject.
 
bool isProjectOpen () const
 True if an undoProject is currently open.
 

Static Public Member Functions

static EditorApp & getInstance ()
 Get the singleton instance of EditorApp.
 

Private Member Functions

void buildFileTree (FileNode &node, const std::string &root)
 Build a hierarchical file tree from a directory path.
 
void renderFileTree (FileNode &node)
 Recursively render the file tree.
 
void createNewFile (const std::string &parentPath, const std::string &name)
 Create a new file with ST template (POU)
 
void createNewFolder (const std::string &parentPath, const std::string &name)
 Create a new folder in the workspace.
 
void deleteFile (const std::string &path)
 Delete a file or folder (shows confirmation popup)
 
void renameFile (const std::string &oldPath, const std::string &newName)
 Rename a file or folder.
 
void moveFile (const std::string &sourcePath, const std::string &destDir)
 Move a file to a destination directory.
 
void openWorkspaceDialog ()
 Open a native folder selection dialog.
 
void createNewGenericFile (const std::string &parentPath, const std::string &name)
 Create generic file.
 
void refreshFileTree ()
 Refresh the file tree.
 
void openFileAsText (const std::string &path)
 Open a JSON file as plain text (bypass JSON viewer)
 
void openFileAsTree (const std::string &path)
 Open a JSON file in the tree viewer, whatever it opens as by default.
 
std::string toLower (std::string s)
 Get the file extension in lowercase.
 
void expandToPath (FileNode &node, const std::string &targetPath)
 
void stashActiveDocument (bool keep)
 Take the file on screen out of its backend, into its own stash.
 
void refreshDirtyState ()
 Ask the backend on screen whether the file has unsaved changes.
 
void saveActiveDocument ()
 Write the file on screen back to disk, whichever kind it is.
 
void loadActiveDocument (const std::string &path)
 Put a file into the editor its backend owns.
 
void switchToTab (const std::string &path)
 Bring a tab to the front, restoring what it held.
 
void closeTab (const std::string &path)
 Close a tab, moving to the one beside it if it was the active one.
 
size_t documentIndex (const std::string &path) const
 Where a file sits in the open list.
 
void openDocument (const std::string &path, DocKind kind, bool pin)
 Open a file with a chosen backend, through the tab bar and the model.
 
void followPathChange (const std::string &oldPath, const std::string &newPath)
 Follow a file that was renamed or moved on disk.
 
void closeDocumentsUnder (const std::string &path)
 Close every tab under a path, including the files inside a folder.
 
void dropStashes (const std::string &path)
 Forget everything stashed for a path.
 
std::string neighbourAfterClose (const std::string &path) const
 The tab to show after closing one.
 

Static Private Member Functions

static DocKind docKindFor (FileType type)
 Which backend a document kind belongs to.
 
static FileType fileTypeFor (DocKind kind)
 

Private Attributes

bool m_initialized = false
 
FileType m_currentFileType = FileType::None
 
std::string m_currentFilePath
 
OpenDocuments m_open
 
std::map< std::string, ST::STDocument > m_stStashes
 
std::map< std::string, StashedText > m_textStashes
 
std::map< std::string, StashedText > m_cppStashes
 
std::map< std::string, JSON::JSONDocument > m_jsonStashes
 
std::string m_workspacePath
 
FileNode m_rootNode
 
bool m_showNewPOUPopup = false
 
ST::POUType m_newPOUType = ST::POUType::Program
 
std::string m_newPOUName
 
std::string m_newItemParent
 
std::string m_newPOUReturnType
 
bool m_showPOUReturnType = false
 
bool m_showNewFolderPopup = false
 
std::string m_newItemName
 
bool m_showNewFilePopup = false
 
std::string m_newFileName
 
std::string m_newFileParent
 
bool m_showRenamePopup = false
 
std::string m_renamePath
 
bool m_showDeleteConfirmation = false
 
std::string m_deletePendingPath
 
bool m_showWorkspaceDialog = false
 
char m_workspaceDialogPath [1024] = {}
 
std::string m_draggedItemPath
 
bool m_isDragging = false
 
bool m_isProjectMode = false
 
bool m_showNewProjectPopup = false
 
char m_newProjectParent [1024] = {}
 
char m_newProjectName [256] = {}
 
char m_newProjectAuthor [256] = {}
 
char m_newProjectArch [64] = {"x86_64"}
 
bool m_showAddPLCPopup = false
 
char m_addPLCName [256] = {}
 
char m_addPLCDesc [512] = {}
 
bool m_showAddTaskPopup = false
 
char m_addTaskName [256] = {}
 
char m_addTaskPLC [256] = {}
 
int m_addTaskCycleMs = 1
 
int m_addTaskPriority = 80
 
int m_addTaskCPU = -1
 
bool m_showRenamePLCPopup = false
 
std::string m_renamePLCOldName
 
char m_renamePLCNewName [256] = {}
 
bool m_showDeletePLCConfirm = false
 
std::string m_deletePLCPending
 
bool m_showEditTaskPopup = false
 
std::string m_editTaskOriginalName
 

Static Private Attributes

static constexpr size_t kNoIndex = static_cast<size_t>(-1)
 Says "not found", for a lookup that may genuinely have no answer.
 

Detailed Description

Main application class for the Workspace and file routing.

Member Function Documentation

◆ buildFileTree()

void undoApp::Editor::EditorApp::buildFileTree ( FileNode &  node,
const std::string &  root 
)
private

Build a hierarchical file tree from a directory path.

◆ closeDocumentsUnder()

void undoApp::Editor::EditorApp::closeDocumentsUnder ( const std::string &  path)
private

Close every tab under a path, including the files inside a folder.

Parameters
pathFile or folder that is gone

◆ closeFile()

void undoApp::Editor::EditorApp::closeFile ( )

Close the currently open file.

◆ closeProject()

void undoApp::Editor::EditorApp::closeProject ( )

Close the current undoProject.

◆ closeTab()

void undoApp::Editor::EditorApp::closeTab ( const std::string &  path)
private

Close a tab, moving to the one beside it if it was the active one.

◆ createNewFile()

void undoApp::Editor::EditorApp::createNewFile ( const std::string &  parentPath,
const std::string &  name 
)
private

Create a new file with ST template (POU)

◆ createNewFolder()

void undoApp::Editor::EditorApp::createNewFolder ( const std::string &  parentPath,
const std::string &  name 
)
private

Create a new folder in the workspace.

◆ createNewGenericFile()

void undoApp::Editor::EditorApp::createNewGenericFile ( const std::string &  parentPath,
const std::string &  name 
)
private

Create generic file.

◆ createProject()

void undoApp::Editor::EditorApp::createProject ( const std::string &  parentDir,
const std::string &  name 
)

Create a new undoProject.

◆ deleteFile()

void undoApp::Editor::EditorApp::deleteFile ( const std::string &  path)
private

Delete a file or folder (shows confirmation popup)

◆ docKindFor()

static DocKind undoApp::Editor::EditorApp::docKindFor ( FileType  type)
staticprivate

Which backend a document kind belongs to.

◆ documentIndex()

size_t undoApp::Editor::EditorApp::documentIndex ( const std::string &  path) const
private

Where a file sits in the open list.

◆ dropStashes()

void undoApp::Editor::EditorApp::dropStashes ( const std::string &  path)
private

Forget everything stashed for a path.

Parameters
pathPath to drop

◆ expandToPath()

void undoApp::Editor::EditorApp::expandToPath ( FileNode &  node,
const std::string &  targetPath 
)
private

◆ fileTypeFor()

static FileType undoApp::Editor::EditorApp::fileTypeFor ( DocKind  kind)
staticprivate

◆ followPathChange()

void undoApp::Editor::EditorApp::followPathChange ( const std::string &  oldPath,
const std::string &  newPath 
)
private

Follow a file that was renamed or moved on disk.

The one place that knows what a path change means: the tab and its stash are keyed by path, the editor on screen saves to the path it was given, and the recent files list points at a file that is no longer there. Anything holding a path and left behind is now pointing at two different files.

Parameters
oldPathPath the file was known by
newPathPath it now has

◆ getCurrentFilePath()

std::string undoApp::Editor::EditorApp::getCurrentFilePath ( ) const
inline

Get the path of the currently open file (empty when none)

◆ getCurrentFileType()

FileType undoApp::Editor::EditorApp::getCurrentFileType ( ) const
inline

Get the type of the currently open file.

◆ getInstance()

static EditorApp & undoApp::Editor::EditorApp::getInstance ( )
static

Get the singleton instance of EditorApp.

◆ initialize()

bool undoApp::Editor::EditorApp::initialize ( )

Initialize the editor plugin (called by PluginManager)

◆ isProjectOpen()

bool undoApp::Editor::EditorApp::isProjectOpen ( ) const

True if an undoProject is currently open.

◆ loadActiveDocument()

void undoApp::Editor::EditorApp::loadActiveDocument ( const std::string &  path)
private

Put a file into the editor its backend owns.

Parameters
pathThe file to show

◆ loadWorkspace()

void undoApp::Editor::EditorApp::loadWorkspace ( const std::string &  path)

Load a workspace from the given path.

◆ moveFile()

void undoApp::Editor::EditorApp::moveFile ( const std::string &  sourcePath,
const std::string &  destDir 
)
private

Move a file to a destination directory.

Tracks the open documents under the new path for the same reason a rename does: the tab, the stash and the editor all hold the path, not the file.

Parameters
sourcePathPath of the file to move
destDirDirectory to move it into

◆ neighbourAfterClose()

std::string undoApp::Editor::EditorApp::neighbourAfterClose ( const std::string &  path) const
private

The tab to show after closing one.

◆ openDocument()

void undoApp::Editor::EditorApp::openDocument ( const std::string &  path,
DocKind  kind,
bool  pin 
)
private

Open a file with a chosen backend, through the tab bar and the model.

Parameters
pathFile to open
kindWhich backend holds it
pinWhether the file keeps its tab

◆ openFile()

void undoApp::Editor::EditorApp::openFile ( const std::string &  path,
bool  pin = true 
)

Open a file using the appropriate backend for its extension.

Every route into the editor ends up here, which is what makes this the one place that knows a file was looked at, and the one place that decides whether the open was browsing or deliberate.

Also records the file in the recent files list, so that a file opened here and then closed is still reachable afterwards.

Parameters
pathFile to open
pinWhether the file keeps its tab. True by default, because a file somebody asked to see should still be there when they ask for another one: with a single click into the tree opening a preview, the file being read vanished the moment the next click landed, and what to do about that — double click it, remember to click twice — is not something to leave to a user who is trying to read code. False is for a caller that is deliberately browsing and wants the file to give way to the next one; the tab bar marks such a tab with a tilde.

◆ openFileAsText()

void undoApp::Editor::EditorApp::openFileAsText ( const std::string &  path)
private

Open a JSON file as plain text (bypass JSON viewer)

◆ openFileAsTree()

void undoApp::Editor::EditorApp::openFileAsTree ( const std::string &  path)
private

Open a JSON file in the tree viewer, whatever it opens as by default.

The other half of openFileAsText, and it exists for the same reason. A project's own configuration opens as text because it is the file the user is told to edit by hand, and a tree has nothing to type into; but exports.json is nested and reads badly flat, and the tree is how you look at it. One file, one tab, whichever of the two the file was opened with.

◆ openProject()

void undoApp::Editor::EditorApp::openProject ( const std::string &  projectDir)

Open an existing undoProject from projectDir.

◆ openWorkspaceDialog()

void undoApp::Editor::EditorApp::openWorkspaceDialog ( )
private

Open a native folder selection dialog.

◆ refreshDirtyState()

void undoApp::Editor::EditorApp::refreshDirtyState ( )
private

Ask the backend on screen whether the file has unsaved changes.

The tab bar's mark is drawn from this, once a frame. Answering it here rather than where the text changes is what makes the mark mean one thing: it appears when there is something to lose and goes away when the file has been written.

◆ refreshFileTree()

void undoApp::Editor::EditorApp::refreshFileTree ( )
private

Refresh the file tree.

◆ registerPanels()

void undoApp::Editor::EditorApp::registerPanels ( )

Register the unified "Editor" panel and "Workspace" panel with ImGuiManager.

◆ renameFile()

void undoApp::Editor::EditorApp::renameFile ( const std::string &  oldPath,
const std::string &  newName 
)
private

Rename a file or folder.

A rename of a file that is open moves its tab, its stash and the editor on screen with it. The tab is keyed by path, and a save writes to the path the editor was told about, so a rename that left those behind would show a name that is not there and save a second copy where the file used to be.

Parameters
oldPathPath of the file or folder to rename
newNameThe new name, in the same folder

◆ renderEditorPanel()

void undoApp::Editor::EditorApp::renderEditorPanel ( )

Render the unified "Editor" panel by dispatching to the active backend.

◆ renderFileTabs()

void undoApp::Editor::EditorApp::renderFileTabs ( )

Draw the bar of open files above whichever editor is showing.

◆ renderFileTree()

void undoApp::Editor::EditorApp::renderFileTree ( FileNode &  node)
private

Recursively render the file tree.

◆ renderWorkspacePanel()

void undoApp::Editor::EditorApp::renderWorkspacePanel ( )

Render the Workspace panel (file tree and workspace management)

◆ saveActiveDocument()

void undoApp::Editor::EditorApp::saveActiveDocument ( )
private

Write the file on screen back to disk, whichever kind it is.

The route the save key takes, and the only one that covers every kind: the ST editor draws its own panel and its own save button, so a shortcut handled where the text backends are dispatched from never reached an .st file.

◆ shutdown()

void undoApp::Editor::EditorApp::shutdown ( )

Shutdown the editor plugin and release resources.

◆ stashActiveDocument()

void undoApp::Editor::EditorApp::stashActiveDocument ( bool  keep)
private

Take the file on screen out of its backend, into its own stash.

Parameters
keepWhether it is a tab rather than a preview about to be reused, in which case it is pinned. Not a statement about unsaved changes: that is what the editors are asked about, in refreshDirtyState().

◆ switchToTab()

void undoApp::Editor::EditorApp::switchToTab ( const std::string &  path)
private

Bring a tab to the front, restoring what it held.

◆ toLower()

std::string undoApp::Editor::EditorApp::toLower ( std::string  s)
private

Get the file extension in lowercase.

Member Data Documentation

◆ kNoIndex

constexpr size_t undoApp::Editor::EditorApp::kNoIndex = static_cast<size_t>(-1)
staticconstexprprivate

Says "not found", for a lookup that may genuinely have no answer.

◆ m_addPLCDesc

char undoApp::Editor::EditorApp::m_addPLCDesc[512] = {}
private

◆ m_addPLCName

char undoApp::Editor::EditorApp::m_addPLCName[256] = {}
private

◆ m_addTaskCPU

int undoApp::Editor::EditorApp::m_addTaskCPU = -1
private

◆ m_addTaskCycleMs

int undoApp::Editor::EditorApp::m_addTaskCycleMs = 1
private

◆ m_addTaskName

char undoApp::Editor::EditorApp::m_addTaskName[256] = {}
private

◆ m_addTaskPLC

char undoApp::Editor::EditorApp::m_addTaskPLC[256] = {}
private

◆ m_addTaskPriority

int undoApp::Editor::EditorApp::m_addTaskPriority = 80
private

◆ m_cppStashes

std::map<std::string, StashedText> undoApp::Editor::EditorApp::m_cppStashes
private

◆ m_currentFilePath

std::string undoApp::Editor::EditorApp::m_currentFilePath
private

◆ m_currentFileType

FileType undoApp::Editor::EditorApp::m_currentFileType = FileType::None
private

◆ m_deletePendingPath

std::string undoApp::Editor::EditorApp::m_deletePendingPath
private

◆ m_deletePLCPending

std::string undoApp::Editor::EditorApp::m_deletePLCPending
private

◆ m_draggedItemPath

std::string undoApp::Editor::EditorApp::m_draggedItemPath
private

◆ m_editTaskOriginalName

std::string undoApp::Editor::EditorApp::m_editTaskOriginalName
private

◆ m_initialized

bool undoApp::Editor::EditorApp::m_initialized = false
private

◆ m_isDragging

bool undoApp::Editor::EditorApp::m_isDragging = false
private

◆ m_isProjectMode

bool undoApp::Editor::EditorApp::m_isProjectMode = false
private

◆ m_jsonStashes

std::map<std::string, JSON::JSONDocument> undoApp::Editor::EditorApp::m_jsonStashes
private

◆ m_newFileName

std::string undoApp::Editor::EditorApp::m_newFileName
private

◆ m_newFileParent

std::string undoApp::Editor::EditorApp::m_newFileParent
private

◆ m_newItemName

std::string undoApp::Editor::EditorApp::m_newItemName
private

◆ m_newItemParent

std::string undoApp::Editor::EditorApp::m_newItemParent
private

◆ m_newPOUName

std::string undoApp::Editor::EditorApp::m_newPOUName
private

◆ m_newPOUReturnType

std::string undoApp::Editor::EditorApp::m_newPOUReturnType
private

◆ m_newPOUType

ST::POUType undoApp::Editor::EditorApp::m_newPOUType = ST::POUType::Program
private

◆ m_newProjectArch

char undoApp::Editor::EditorApp::m_newProjectArch[64] = {"x86_64"}
private

◆ m_newProjectAuthor

char undoApp::Editor::EditorApp::m_newProjectAuthor[256] = {}
private

◆ m_newProjectName

char undoApp::Editor::EditorApp::m_newProjectName[256] = {}
private

◆ m_newProjectParent

char undoApp::Editor::EditorApp::m_newProjectParent[1024] = {}
private

◆ m_open

OpenDocuments undoApp::Editor::EditorApp::m_open
private

The files that are open, and which is only a preview. See the header of undoAppOpenDocuments.hpp for why there is one preview slot rather than a tab per file opened.

◆ m_renamePath

std::string undoApp::Editor::EditorApp::m_renamePath
private

◆ m_renamePLCNewName

char undoApp::Editor::EditorApp::m_renamePLCNewName[256] = {}
private

◆ m_renamePLCOldName

std::string undoApp::Editor::EditorApp::m_renamePLCOldName
private

◆ m_rootNode

FileNode undoApp::Editor::EditorApp::m_rootNode
private

◆ m_showAddPLCPopup

bool undoApp::Editor::EditorApp::m_showAddPLCPopup = false
private

◆ m_showAddTaskPopup

bool undoApp::Editor::EditorApp::m_showAddTaskPopup = false
private

◆ m_showDeleteConfirmation

bool undoApp::Editor::EditorApp::m_showDeleteConfirmation = false
private

◆ m_showDeletePLCConfirm

bool undoApp::Editor::EditorApp::m_showDeletePLCConfirm = false
private

◆ m_showEditTaskPopup

bool undoApp::Editor::EditorApp::m_showEditTaskPopup = false
private

◆ m_showNewFilePopup

bool undoApp::Editor::EditorApp::m_showNewFilePopup = false
private

◆ m_showNewFolderPopup

bool undoApp::Editor::EditorApp::m_showNewFolderPopup = false
private

◆ m_showNewPOUPopup

bool undoApp::Editor::EditorApp::m_showNewPOUPopup = false
private

◆ m_showNewProjectPopup

bool undoApp::Editor::EditorApp::m_showNewProjectPopup = false
private

◆ m_showPOUReturnType

bool undoApp::Editor::EditorApp::m_showPOUReturnType = false
private

◆ m_showRenamePLCPopup

bool undoApp::Editor::EditorApp::m_showRenamePLCPopup = false
private

◆ m_showRenamePopup

bool undoApp::Editor::EditorApp::m_showRenamePopup = false
private

◆ m_showWorkspaceDialog

bool undoApp::Editor::EditorApp::m_showWorkspaceDialog = false
private

◆ m_stStashes

std::map<std::string, ST::STDocument> undoApp::Editor::EditorApp::m_stStashes
private

What each open file's editor holds while another file is in its place.

Keyed by path, not by position in m_open. A preview being dropped shortens that list, so anything indexed beside it slides against the wrong file; a path cannot. A tab that is still open has to come back showing its own text — the unsaved half of every change exists nowhere else — and this is where that text waits.

◆ m_textStashes

std::map<std::string, StashedText> undoApp::Editor::EditorApp::m_textStashes
private

◆ m_workspaceDialogPath

char undoApp::Editor::EditorApp::m_workspaceDialogPath[1024] = {}
private

◆ m_workspacePath

std::string undoApp::Editor::EditorApp::m_workspacePath
private

The documentation for this class was generated from the following file: