undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoStudio::core::ProjectManager Class Reference

Singleton service that manages the lifecycle of an undoProject. More...

#include <ProjectManager.hpp>

Collaboration diagram for undoStudio::core::ProjectManager:
Collaboration graph

Public Types

using OnProjectChanged = std::function< void()>
 

Public Member Functions

bool createProject (const std::string &parentDir, const std::string &name)
 Create a new project in parentDir/name/ and scaffold all folders.
 
bool openProject (const std::string &projectDir)
 Open an existing project from projectDir.
 
void closeProject ()
 Close the current project and reset all state.
 
bool saveProject ()
 Write all project configuration files to disk.
 
bool isProjectOpen () const
 
const ProjectConfig & getConfig () const
 
const std::vector< PLCConfig > & getPLCs () const
 
const std::vector< TaskConfig > & getTasks () const
 
std::string getProjectPath () const
 
std::string getProjectName () const
 
Strictness getStrictness () const
 Semantic strictness declared by the open project (Strict when none is open)
 
const std::vector< std::string > & recentProjects () const
 The projects opened most recently, newest first.
 
size_t maxRecentProjects () const
 How many projects the list keeps.
 
void setMaxRecentProjects (size_t count)
 Set how many projects the list keeps.
 
void rememberProject (const std::string &projectPath)
 Put a project at the head of the list, or move it there if it was there.
 
void forgetProject (const std::string &projectPath)
 Take a project out of the list.
 
void clearRecentProjects ()
 Empty the list.
 
void loadRecents () const
 Read the list from the state file, once.
 
bool addPLC (const std::string &name, const std::string &description="")
 
bool removePLC (const std::string &name)
 
bool renamePLC (const std::string &oldName, const std::string &newName)
 
bool hasPLC (const std::string &name) const
 
bool addTask (const TaskConfig &task)
 
bool removeTask (const std::string &name)
 
bool updateTask (const TaskConfig &task)
 
const TaskConfig * findTask (const std::string &name) const
 
TaskConfig * findTask (const std::string &name)
 
bool setExports (const std::string &plcName, const std::vector< std::string > &programs)
 
std::vector< std::string > getExports (const std::string &plcName) const
 
std::string configDir () const
 .undoProject/
 
std::string undoCorePath () const
 undoCore/
 
std::string tasksPath () const
 undoCore/tasks/
 
std::string undoLogicPath () const
 undoLogic/
 
std::string sharedLibsPath () const
 
std::string sharedGVLsPath () const
 
std::string sharedDUTsPath () const
 
std::string sharedPOUsPath () const
 
std::string plcPath (const std::string &plcName) const
 undoLogic/undoPLC_X/
 
std::string plcLibsPath (const std::string &plcName) const
 
std::string plcGVLsPath (const std::string &plcName) const
 
std::string plcDUTsPath (const std::string &plcName) const
 
std::string plcPOUsPath (const std::string &plcName) const
 
std::string plcExportsPath (const std::string &plcName) const
 
std::string taskFilePath (const std::string &taskName) const
 undoCore/tasks/taskName.json
 
NodeRole classifyPath (const std::string &path) const
 Classify a filesystem path relative to the open project.
 
bool isConfigFile (const std::string &path) const
 Whether a path is a configuration file this service owns.
 
std::string ownerPLC (const std::string &path) const
 Find which PLC a path belongs to.
 
void setOnProjectChanged (OnProjectChanged cb)
 

Static Public Member Functions

static ProjectManager & getInstance ()
 

Static Public Attributes

static constexpr size_t kDefaultMaxRecent = 10
 How many projects are kept when nothing has been configured.
 
static constexpr size_t kMinRecentLimit = 1
 The least and the most a configured limit may be.
 
static constexpr size_t kMaxRecentLimit = 100
 

Private Member Functions

 ProjectManager ()=default
 
 ~ProjectManager ()=default
 
 ProjectManager (const ProjectManager &)=delete
 
ProjectManager & operator= (const ProjectManager &)=delete
 
bool readProjectJSON ()
 
bool readPLCsJSON ()
 
bool readTasksJSON ()
 
bool readExportsJSON (const std::string &plcName)
 
bool writeProjectJSON () const
 
bool writePLCsJSON () const
 
bool writeTasksJSON () const
 
bool writeExportsJSON (const std::string &plcName) const
 
bool writeTaskDetailJSON (const TaskConfig &t) const
 
bool scaffoldProject (const std::string &path, const std::string &name)
 
bool scaffoldPLC (const std::string &plcPath)
 
void notifyChanged ()
 

Static Private Member Functions

static bool mkdirs (const std::string &path)
 
static std::string today ()
 

Private Attributes

bool m_isOpen = false
 
std::string m_projectPath
 
ProjectConfig m_config
 
std::vector< PLCConfig > m_plcs
 
std::vector< TaskConfig > m_tasks
 
std::vector< std::string > m_recentProjects
 
bool m_recentsLoaded = false
 
std::map< std::string, std::vector< std::string > > m_exports
 
OnProjectChanged m_onChanged
 

Detailed Description

Singleton service that manages the lifecycle of an undoProject.

Member Typedef Documentation

◆ OnProjectChanged

Constructor & Destructor Documentation

◆ ProjectManager() [1/2]

undoStudio::core::ProjectManager::ProjectManager ( )
privatedefault

◆ ~ProjectManager()

undoStudio::core::ProjectManager::~ProjectManager ( )
privatedefault

◆ ProjectManager() [2/2]

undoStudio::core::ProjectManager::ProjectManager ( const ProjectManager &  )
privatedelete

Member Function Documentation

◆ addPLC()

bool undoStudio::core::ProjectManager::addPLC ( const std::string &  name,
const std::string &  description = "" 
)

◆ addTask()

bool undoStudio::core::ProjectManager::addTask ( const TaskConfig &  task)

◆ classifyPath()

NodeRole undoStudio::core::ProjectManager::classifyPath ( const std::string &  path) const

Classify a filesystem path relative to the open project.

Returns
NodeRole enum value; NodeRole::Generic if not in a project

◆ clearRecentProjects()

void undoStudio::core::ProjectManager::clearRecentProjects ( )

Empty the list.

◆ closeProject()

void undoStudio::core::ProjectManager::closeProject ( )

Close the current project and reset all state.

◆ configDir()

std::string undoStudio::core::ProjectManager::configDir ( ) const

.undoProject/

◆ createProject()

bool undoStudio::core::ProjectManager::createProject ( const std::string &  parentDir,
const std::string &  name 
)

Create a new project in parentDir/name/ and scaffold all folders.

Parameters
parentDirParent directory (must exist)
nameProject name (becomes the folder name and project.json name)
Returns
true on success

◆ findTask() [1/2]

TaskConfig * undoStudio::core::ProjectManager::findTask ( const std::string &  name)

◆ findTask() [2/2]

const TaskConfig * undoStudio::core::ProjectManager::findTask ( const std::string &  name) const

◆ forgetProject()

void undoStudio::core::ProjectManager::forgetProject ( const std::string &  projectPath)

Take a project out of the list.

Parameters
projectPathAbsolute path of the project

◆ getConfig()

const ProjectConfig & undoStudio::core::ProjectManager::getConfig ( ) const
inline

◆ getExports()

std::vector< std::string > undoStudio::core::ProjectManager::getExports ( const std::string &  plcName) const

◆ getInstance()

ProjectManager & undoStudio::core::ProjectManager::getInstance ( )
static

◆ getPLCs()

const std::vector< PLCConfig > & undoStudio::core::ProjectManager::getPLCs ( ) const
inline

◆ getProjectName()

std::string undoStudio::core::ProjectManager::getProjectName ( ) const
inline

◆ getProjectPath()

std::string undoStudio::core::ProjectManager::getProjectPath ( ) const
inline

◆ getStrictness()

Strictness undoStudio::core::ProjectManager::getStrictness ( ) const
inline

Semantic strictness declared by the open project (Strict when none is open)

◆ getTasks()

const std::vector< TaskConfig > & undoStudio::core::ProjectManager::getTasks ( ) const
inline

◆ hasPLC()

bool undoStudio::core::ProjectManager::hasPLC ( const std::string &  name) const

◆ isConfigFile()

bool undoStudio::core::ProjectManager::isConfigFile ( const std::string &  path) const

Whether a path is a configuration file this service owns.

Returns
true for .undoProject files, undoCore/tasks files, and the exports.json of a PLC

The editor asks, because these are JSON and so open in the JSON viewer, which shows a tree and cannot be typed into. exports.json in particular is a file the user is told to edit by hand, so it is opened as text instead of as a picture of itself.

◆ isProjectOpen()

bool undoStudio::core::ProjectManager::isProjectOpen ( ) const
inline

◆ loadRecents()

void undoStudio::core::ProjectManager::loadRecents ( ) const

Read the list from the state file, once.

Const because it is a cache: reading the list does not change what the list is, and recentProjects() is const and has to be able to fill it.

◆ maxRecentProjects()

size_t undoStudio::core::ProjectManager::maxRecentProjects ( ) const

How many projects the list keeps.

Read from the state file and clamped to kMinRecentLimit..kMaxRecentLimit. Clamped rather than refused because the file is the IDE's own and is edited by hand when something has gone wrong with it: a limit of zero would leave a list that can never be filled, and one of ten thousand would make every frame after a project is opened walk a list nobody asked for.

◆ mkdirs()

bool undoStudio::core::ProjectManager::mkdirs ( const std::string &  path)
staticprivate

◆ notifyChanged()

void undoStudio::core::ProjectManager::notifyChanged ( )
inlineprivate

◆ openProject()

bool undoStudio::core::ProjectManager::openProject ( const std::string &  projectDir)

Open an existing project from projectDir.

Parameters
projectDirDirectory that contains .undoProject/
Returns
true on success

◆ operator=()

ProjectManager & undoStudio::core::ProjectManager::operator= ( const ProjectManager &  )
privatedelete

◆ ownerPLC()

std::string undoStudio::core::ProjectManager::ownerPLC ( const std::string &  path) const

Find which PLC a path belongs to.

Returns
PLC name, or "" if the path is not inside any PLC sub-tree

◆ plcDUTsPath()

std::string undoStudio::core::ProjectManager::plcDUTsPath ( const std::string &  plcName) const

◆ plcExportsPath()

std::string undoStudio::core::ProjectManager::plcExportsPath ( const std::string &  plcName) const

◆ plcGVLsPath()

std::string undoStudio::core::ProjectManager::plcGVLsPath ( const std::string &  plcName) const

◆ plcLibsPath()

std::string undoStudio::core::ProjectManager::plcLibsPath ( const std::string &  plcName) const

◆ plcPath()

std::string undoStudio::core::ProjectManager::plcPath ( const std::string &  plcName) const

undoLogic/undoPLC_X/

◆ plcPOUsPath()

std::string undoStudio::core::ProjectManager::plcPOUsPath ( const std::string &  plcName) const

◆ readExportsJSON()

bool undoStudio::core::ProjectManager::readExportsJSON ( const std::string &  plcName)
private

◆ readPLCsJSON()

bool undoStudio::core::ProjectManager::readPLCsJSON ( )
private

◆ readProjectJSON()

bool undoStudio::core::ProjectManager::readProjectJSON ( )
private

◆ readTasksJSON()

bool undoStudio::core::ProjectManager::readTasksJSON ( )
private

◆ recentProjects()

const std::vector< std::string > & undoStudio::core::ProjectManager::recentProjects ( ) const
inline

The projects opened most recently, newest first.

Returns
Absolute paths, at most maxRecentProjects() of them

Remembered so they can be offered as a list. A project is not reopened on its own: the IDE starting with somebody's project already on disk is a surprise, and a list is one click away from the same place.

Reading the list is what pulls it off disk, on the first call of the run. It has to be here rather than in the code that opens or forgets a project: those are the only calls that used to load it, so a run in which nobody opened anything showed an empty list while the entries sat in the file. That reads as a lost history, and the history was in the state file the whole time.

◆ rememberProject()

void undoStudio::core::ProjectManager::rememberProject ( const std::string &  projectPath)

Put a project at the head of the list, or move it there if it was there.

Parameters
projectPathAbsolute path of the project

◆ removePLC()

bool undoStudio::core::ProjectManager::removePLC ( const std::string &  name)

◆ removeTask()

bool undoStudio::core::ProjectManager::removeTask ( const std::string &  name)

◆ renamePLC()

bool undoStudio::core::ProjectManager::renamePLC ( const std::string &  oldName,
const std::string &  newName 
)

◆ saveProject()

bool undoStudio::core::ProjectManager::saveProject ( )

Write all project configuration files to disk.

◆ scaffoldPLC()

bool undoStudio::core::ProjectManager::scaffoldPLC ( const std::string &  plcPath)
private

◆ scaffoldProject()

bool undoStudio::core::ProjectManager::scaffoldProject ( const std::string &  path,
const std::string &  name 
)
private

◆ setExports()

bool undoStudio::core::ProjectManager::setExports ( const std::string &  plcName,
const std::vector< std::string > &  programs 
)

◆ setMaxRecentProjects()

void undoStudio::core::ProjectManager::setMaxRecentProjects ( size_t  count)

Set how many projects the list keeps.

Parameters
countThe new limit, clamped the same way maxRecentProjects() is

◆ setOnProjectChanged()

void undoStudio::core::ProjectManager::setOnProjectChanged ( OnProjectChanged  cb)
inline

◆ sharedDUTsPath()

std::string undoStudio::core::ProjectManager::sharedDUTsPath ( ) const

◆ sharedGVLsPath()

std::string undoStudio::core::ProjectManager::sharedGVLsPath ( ) const

◆ sharedLibsPath()

std::string undoStudio::core::ProjectManager::sharedLibsPath ( ) const

◆ sharedPOUsPath()

std::string undoStudio::core::ProjectManager::sharedPOUsPath ( ) const

◆ taskFilePath()

std::string undoStudio::core::ProjectManager::taskFilePath ( const std::string &  taskName) const

undoCore/tasks/taskName.json

◆ tasksPath()

std::string undoStudio::core::ProjectManager::tasksPath ( ) const

undoCore/tasks/

◆ today()

std::string undoStudio::core::ProjectManager::today ( )
staticprivate

◆ undoCorePath()

std::string undoStudio::core::ProjectManager::undoCorePath ( ) const

undoCore/

◆ undoLogicPath()

std::string undoStudio::core::ProjectManager::undoLogicPath ( ) const

undoLogic/

◆ updateTask()

bool undoStudio::core::ProjectManager::updateTask ( const TaskConfig &  task)

◆ writeExportsJSON()

bool undoStudio::core::ProjectManager::writeExportsJSON ( const std::string &  plcName) const
private

◆ writePLCsJSON()

bool undoStudio::core::ProjectManager::writePLCsJSON ( ) const
private

◆ writeProjectJSON()

bool undoStudio::core::ProjectManager::writeProjectJSON ( ) const
private

◆ writeTaskDetailJSON()

bool undoStudio::core::ProjectManager::writeTaskDetailJSON ( const TaskConfig &  t) const
private

◆ writeTasksJSON()

bool undoStudio::core::ProjectManager::writeTasksJSON ( ) const
private

Member Data Documentation

◆ kDefaultMaxRecent

constexpr size_t undoStudio::core::ProjectManager::kDefaultMaxRecent = 10
staticconstexpr

How many projects are kept when nothing has been configured.

◆ kMaxRecentLimit

constexpr size_t undoStudio::core::ProjectManager::kMaxRecentLimit = 100
staticconstexpr

◆ kMinRecentLimit

constexpr size_t undoStudio::core::ProjectManager::kMinRecentLimit = 1
staticconstexpr

The least and the most a configured limit may be.

◆ m_config

ProjectConfig undoStudio::core::ProjectManager::m_config
private

◆ m_exports

std::map<std::string, std::vector<std::string> > undoStudio::core::ProjectManager::m_exports
private

◆ m_isOpen

bool undoStudio::core::ProjectManager::m_isOpen = false
private

◆ m_onChanged

OnProjectChanged undoStudio::core::ProjectManager::m_onChanged
private

◆ m_plcs

std::vector<PLCConfig> undoStudio::core::ProjectManager::m_plcs
private

◆ m_projectPath

std::string undoStudio::core::ProjectManager::m_projectPath
private

◆ m_recentProjects

std::vector<std::string> undoStudio::core::ProjectManager::m_recentProjects
mutableprivate

Opened projects, newest first. Mutable because reading the list fills it, and reading is const.

◆ m_recentsLoaded

bool undoStudio::core::ProjectManager::m_recentsLoaded = false
mutableprivate

◆ m_tasks

std::vector<TaskConfig> undoStudio::core::ProjectManager::m_tasks
private

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