mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 13:37:42 -05:00
feat: Initial work rework current project system
This commit is contained in:
57
lib/libimhex/include/hex/project/project.hpp
Normal file
57
lib/libimhex/include/hex/project/project.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex.hpp>
|
||||
#include <hex/api/localization_manager.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
namespace hex::proj {
|
||||
|
||||
class Content {
|
||||
public:
|
||||
explicit Content(UnlocalizedString type, std::string name)
|
||||
: m_type(std::move(type)), m_name(std::move(name)) { }
|
||||
|
||||
void setData(std::string data) { m_data = std::move(data); }
|
||||
const std::string& getData() const { return m_data; }
|
||||
|
||||
const std::string& getName() const { return m_name; }
|
||||
void setName(std::string name) { m_name = std::move(name); }
|
||||
|
||||
const UnlocalizedString& getType() const { return m_type; }
|
||||
|
||||
bool isOpen() const { return m_open; }
|
||||
void setOpen(bool open) { m_open = open; }
|
||||
|
||||
bool isEmpty() const { return m_data.empty(); }
|
||||
|
||||
private:
|
||||
UnlocalizedString m_type;
|
||||
std::string m_name;
|
||||
std::string m_data;
|
||||
bool m_open = false;
|
||||
};
|
||||
|
||||
class Project {
|
||||
public:
|
||||
explicit Project(std::string name) : m_name(std::move(name)) {}
|
||||
Project(const Project &) = delete;
|
||||
Project(Project &&) = delete;
|
||||
~Project();
|
||||
|
||||
Project &operator=(const Project &) = delete;
|
||||
Project &operator=(Project &&) = delete;
|
||||
|
||||
const std::string &getName() const { return m_name; }
|
||||
|
||||
void addContent(UnlocalizedString type);
|
||||
const std::list<std::unique_ptr<Content>>& getContents() const { return m_contents; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::list<std::unique_ptr<Content>> m_contents;
|
||||
};
|
||||
|
||||
}
|
||||
43
lib/libimhex/include/hex/project/project_manager.hpp
Normal file
43
lib/libimhex/include/hex/project/project_manager.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <hex.hpp>
|
||||
#include <hex/project/project.hpp>
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
|
||||
namespace hex::proj {
|
||||
|
||||
class ProjectManager {
|
||||
ProjectManager() = default;
|
||||
|
||||
public:
|
||||
static void createProject(std::string name);
|
||||
static void loadProject(const std::filesystem::path &path);
|
||||
static void removeProject(const Project &project);
|
||||
|
||||
using LoadFunction = std::function<void(const Content&)>;
|
||||
using StoreFunction = std::function<void(Content&)>;
|
||||
|
||||
struct ContentHandler {
|
||||
UnlocalizedString type;
|
||||
bool allowMultiple = false;
|
||||
LoadFunction load;
|
||||
StoreFunction store;
|
||||
};
|
||||
|
||||
static void registerContentHandler(ContentHandler handler);
|
||||
static const std::list<ContentHandler>& getContentHandlers();
|
||||
static const ContentHandler* getContentHandler(const UnlocalizedString &typeName);
|
||||
|
||||
static const std::list<std::unique_ptr<Project>> &getProjects();
|
||||
|
||||
static void storeContent(Content &content);
|
||||
static void loadContent(Content &content);
|
||||
|
||||
static Content* getLoadedContent(const UnlocalizedString &type);
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user