Update serializer system
parent
7dbb40104d
commit
2f98e1f291
|
@ -10,60 +10,152 @@
|
|||
|
||||
|
||||
namespace sirEdit::data {
|
||||
class Serializer;
|
||||
class View {
|
||||
private:
|
||||
std::shared_ptr<void> __raw;
|
||||
|
||||
View(std::shared_ptr<void> raw);
|
||||
|
||||
public:
|
||||
const std::vector<Type*>& getTypes() const;
|
||||
const std::vector<Type*>& getBaseTypes() const;
|
||||
const std::vector<Tool>& getTools() const;
|
||||
|
||||
View addTool(Tool tool) const;
|
||||
|
||||
bool saveToFile();
|
||||
|
||||
friend sirEdit::data::Serializer;
|
||||
};
|
||||
|
||||
class Transactions;
|
||||
class Serializer {
|
||||
private:
|
||||
std::shared_ptr<void> __raw_data;
|
||||
std::vector<Type*> types;
|
||||
std::vector<Type*> baseTypes;
|
||||
std::vector<Tool*> tools;
|
||||
|
||||
Serializer(std::shared_ptr<void> data) : __raw_data(std::move(data)) {}
|
||||
void updateTypeInfo(Type* type) {
|
||||
Type* tmp = const_cast<Type*>(getSuper(*type));
|
||||
if(tmp != nullptr)
|
||||
tmp->getSubTypes().push_back(type);
|
||||
else
|
||||
this->baseTypes.push_back(type);
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateRelationships() {
|
||||
// Get data
|
||||
{
|
||||
this->types.clear();
|
||||
this->getBaseTypes([this](Type* type) -> void {
|
||||
this->types.push_back(type);
|
||||
type->getSubTypes().clear();
|
||||
});
|
||||
this->tools.clear();
|
||||
this->getBaseTools([this](Tool* tool) -> void {
|
||||
this->tools.push_back(tool);
|
||||
});
|
||||
}
|
||||
|
||||
// Create new subtype information
|
||||
for(auto& i : this->types)
|
||||
this->updateTypeInfo(i);
|
||||
}
|
||||
|
||||
virtual void addBaseType(Type* type) = 0;
|
||||
virtual void addBaseTool(Tool* tool) = 0;
|
||||
virtual void getBaseTypes(std::function<void(Type*)> callbackFunc) = 0;
|
||||
virtual void getBaseTools(std::function<void(Tool*)> callbackFunc) = 0;
|
||||
public:
|
||||
Serializer(const Serializer&) = delete;
|
||||
Serializer& operator =(const Serializer&) = delete;
|
||||
Serializer() {}
|
||||
virtual ~Serializer() {}
|
||||
|
||||
View getView() { return View(this->__raw_data); }
|
||||
void addType(Type* type) {
|
||||
this->types.push_back(type);
|
||||
this->updateTypeInfo(type);
|
||||
this->addBaseType(type);
|
||||
}
|
||||
void addTool(Tool* tool) {
|
||||
this->tools.push_back(tool);
|
||||
this->addBaseTool(tool);
|
||||
}
|
||||
virtual void save() = 0;
|
||||
|
||||
static std::shared_ptr<Serializer> openFile(const std::string& file);
|
||||
const std::vector<Type*>& getTypes() const {
|
||||
return this->types;
|
||||
}
|
||||
const std::vector<Type*>& getBaseTypes() const {
|
||||
return this->baseTypes;
|
||||
}
|
||||
const std::vector<Tool*>& getTools() const {
|
||||
return this->tools;
|
||||
}
|
||||
|
||||
friend Transactions;
|
||||
};
|
||||
|
||||
class HistoricalView {
|
||||
extern std::unique_ptr<Serializer> getSir(std::string path);
|
||||
|
||||
class Transactions {
|
||||
private:
|
||||
View staticView;
|
||||
std::shared_ptr<void> data;
|
||||
Serializer& serializer;
|
||||
std::vector<std::function<void()>> change_callback;
|
||||
|
||||
public:
|
||||
HistoricalView(View view);
|
||||
~HistoricalView();
|
||||
|
||||
const View& getStaticView() const {
|
||||
return this->staticView;
|
||||
template<class T>
|
||||
inline void updateCall(T& list) {
|
||||
for(auto& i : list)
|
||||
i();
|
||||
}
|
||||
|
||||
void updateSubtypes(const Tool& tool, const Type& type, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type) {
|
||||
for(auto& i : type.getSubTypes()) {
|
||||
auto tmp = tool.getTypeTransitiveState(type);
|
||||
if(tmp >= TYPE_STATE::READ) {
|
||||
callback_type(type, tmp, tool.getTypeSetState(type));
|
||||
updateSubtypes(tool, *i, callback_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
Transactions(Serializer& serializer) : serializer(serializer) {}
|
||||
|
||||
void addChangeCallback(std::function<void()> func) {
|
||||
this->change_callback.push_back(std::move(func));
|
||||
}
|
||||
|
||||
void addTool(Tool tool);
|
||||
void setFieldStatus(const Tool& tool, const Type& type, const Field& field, FIELD_STATE state, const std::function<void(const Type&, const Field&, FIELD_STATE, FIELD_STATE)>& callback_field, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type);
|
||||
void setTypeStatus(const Tool& tool, const Type& type, TYPE_STATE state, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type);
|
||||
const Serializer& getData() const {
|
||||
return this->serializer;
|
||||
}
|
||||
|
||||
void addTool(Tool tool) {
|
||||
this->serializer.addTool(new Tool(std::move(tool)));
|
||||
updateCall(this->change_callback);
|
||||
}
|
||||
void setFieldStatus(const Tool& tool, const Type& type, const Field& field, FIELD_STATE state, const std::function<void(const Type&, const Field&, FIELD_STATE, FIELD_STATE)>& callback_field, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type) {
|
||||
// Set state
|
||||
FIELD_STATE old = tool.getFieldSetState(field, type);
|
||||
const_cast<Tool&>(tool).setFieldState(type, field, state);
|
||||
|
||||
// Callback field
|
||||
{
|
||||
callback_field(type, field, tool.getFieldTransitiveState(field), state);
|
||||
}
|
||||
|
||||
// Callback type
|
||||
{
|
||||
const Type* tmp_type = &type;
|
||||
while(tmp_type != nullptr) {
|
||||
callback_type(*tmp_type, tool.getTypeTransitiveState(*tmp_type), tool.getTypeSetState(*tmp_type));
|
||||
tmp_type = getSuper(*tmp_type);
|
||||
}
|
||||
}
|
||||
updateCall(this->change_callback);
|
||||
}
|
||||
void setTypeStatus(const Tool& tool, const Type& type, TYPE_STATE state, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type) {
|
||||
// Set type state
|
||||
TYPE_STATE oldTrans = tool.getTypeTransitiveState(type);
|
||||
const_cast<Tool&>(tool).setTypeState(type, state);
|
||||
|
||||
// Callback
|
||||
TYPE_STATE newTrans = tool.getTypeTransitiveState(type);
|
||||
callback_type(type, newTrans, state);
|
||||
{
|
||||
// Update super classes
|
||||
const Type* current = getSuper(type);
|
||||
while(current != nullptr) {
|
||||
callback_type(*current, tool.getTypeTransitiveState(*current), tool.getTypeSetState(*current));
|
||||
current = getSuper(*current);
|
||||
}
|
||||
}
|
||||
if(oldTrans == TYPE_STATE::DELETE || newTrans == TYPE_STATE::DELETE) {
|
||||
// Update sub classes
|
||||
updateSubtypes(tool, type, callback_type);
|
||||
}
|
||||
updateCall(this->change_callback);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -71,9 +71,13 @@ namespace sirEdit::data {
|
|||
std::string& getName() { return this->__name; }
|
||||
std::string& getDescription() { return this->__description; }
|
||||
std::string& getCommand() { return this->__command; }
|
||||
std::unordered_map<const Field*, std::unordered_map<const Type*, FIELD_STATE>>& getStatesFields() { return this->__statesFields; }
|
||||
std::unordered_map<const Type*, std::tuple<uint64_t, TYPE_STATE>>& getStatesTypes() { return this->__statesType; }
|
||||
const std::string& getName() const { return this->__name; }
|
||||
const std::string& getDescription() const { return this->__description; }
|
||||
const std::string& getCommand() const{ return this->__command; }
|
||||
const std::unordered_map<const Field*, std::unordered_map<const Type*, FIELD_STATE>>& getStatesFields() const { return this->__statesFields; }
|
||||
const std::unordered_map<const Type*, std::tuple<uint64_t, TYPE_STATE>>& getStatesTypes() const { return this->__statesType; }
|
||||
|
||||
//
|
||||
// Get type/field states
|
||||
|
|
|
@ -8,44 +8,6 @@
|
|||
#include <iostream>
|
||||
|
||||
namespace sirEdit::utils {
|
||||
template<class SOURCE>
|
||||
inline std::string _getName(SOURCE* type) {
|
||||
std::string result;
|
||||
for(int i = 0; i < type->getName()->getParts()->size(); i++)
|
||||
result += type->getName()->getParts()->get(i).string->c_str();
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class SOURCE>
|
||||
inline std::unique_ptr<sirEdit::data::TypeWithFields> _loadFields(SOURCE* source) {
|
||||
if(source == nullptr)
|
||||
throw std::invalid_argument("Source is null pointer");
|
||||
std::vector<sirEdit::data::Field> fields;
|
||||
fields.resize(source->getFields()->size());
|
||||
size_t counter = 0;
|
||||
for(sir::FieldLike* i : *(source->getFields())) {
|
||||
fields[counter] = std::move(sirEdit::data::Field(_getName(i), "", "")); // TODO: Add comments and type
|
||||
counter++;
|
||||
}
|
||||
return std::move(std::make_unique<sirEdit::data::TypeWithFields>(_getName(source), "", fields)); // TODO: Add comments
|
||||
}
|
||||
inline std::shared_ptr<sirEdit::data::Type> genBaseType(sir::UserdefinedType* uf) {
|
||||
std::string skillType = uf->skillName();
|
||||
std::shared_ptr<sirEdit::data::Type> result;
|
||||
if(skillType == sir::ClassType::typeName) {
|
||||
std::unique_ptr<sirEdit::data::TypeWithFields> fields = std::move(_loadFields(static_cast<sir::ClassType*>(uf)));
|
||||
result = std::move(std::make_shared<sirEdit::data::TypeClass>(*(fields.get()), std::vector<sirEdit::data::TypeInterface*>(), nullptr));
|
||||
}
|
||||
else if(skillType == sir::InterfaceType::typeName) {
|
||||
std::unique_ptr<sirEdit::data::TypeWithFields> fields = std::move(_loadFields(static_cast<sir::InterfaceType*>(uf)));
|
||||
result = std::make_shared<sirEdit::data::TypeInterface>(*(fields.get()), std::vector<sirEdit::data::TypeInterface*>(), nullptr);
|
||||
std::cout << "Test: " << sirEdit::data::getSuper(*result.get()) << std::endl;
|
||||
}
|
||||
else
|
||||
throw std::invalid_argument(std::string("Unknown skill class type ") + skillType);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class TARGET, class SOURCE>
|
||||
inline void _addInterfaces(TARGET* target, SOURCE* source, std::unordered_map<sir::UserdefinedType*, sirEdit::data::Type*>& types) {
|
||||
size_t counter = 0;
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
#include <sirEdit/data/serialize.hpp>
|
||||
#include <list>
|
||||
#include <functional>
|
||||
|
||||
#include <sirEdit/main.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace sirEdit;
|
||||
using namespace sirEdit::data;
|
||||
|
||||
struct HistoricalData {
|
||||
size_t counter = 0;
|
||||
};
|
||||
|
||||
sirEdit::data::HistoricalView::HistoricalView(View view) : staticView(move(view)) {
|
||||
this->data = static_pointer_cast<void>(make_shared<HistoricalData>());
|
||||
}
|
||||
sirEdit::data::HistoricalView::~HistoricalView() {
|
||||
// TODO: Check that thread stopped and all is safed
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void updateCall(T& list) {
|
||||
for(auto& i : list)
|
||||
i();
|
||||
}
|
||||
|
||||
void sirEdit::data::HistoricalView::addTool(Tool tool) {
|
||||
this->staticView = this->staticView.addTool(tool);
|
||||
updateCall(this->change_callback);
|
||||
}
|
||||
void sirEdit::data::HistoricalView::setFieldStatus(const Tool& tool, const Type& type, const Field& field, FIELD_STATE state, const std::function<void(const Type&, const Field&, FIELD_STATE, FIELD_STATE)>& callback_field, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type) {
|
||||
// Set state
|
||||
FIELD_STATE old = tool.getFieldSetState(field, type);
|
||||
const_cast<Tool&>(tool).setFieldState(type, field, state);
|
||||
|
||||
// Callback field
|
||||
{
|
||||
callback_field(type, field, tool.getFieldTransitiveState(field), state);
|
||||
}
|
||||
|
||||
// Callback type
|
||||
{
|
||||
const Type* tmp_type = &type;
|
||||
while(tmp_type != nullptr) {
|
||||
callback_type(*tmp_type, tool.getTypeTransitiveState(*tmp_type), tool.getTypeSetState(*tmp_type));
|
||||
tmp_type = getSuper(*tmp_type);
|
||||
}
|
||||
}
|
||||
updateCall(this->change_callback);
|
||||
}
|
||||
|
||||
inline void updateSubtypes(const Tool& tool, const Type& type, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type) {
|
||||
for(auto& i : type.getSubTypes()) {
|
||||
auto tmp = tool.getTypeTransitiveState(type);
|
||||
if(tmp >= TYPE_STATE::READ) {
|
||||
callback_type(type, tmp, tool.getTypeSetState(type));
|
||||
updateSubtypes(tool, *i, callback_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sirEdit::data::HistoricalView::setTypeStatus(const Tool& tool, const Type& type, TYPE_STATE state, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type) {
|
||||
// Set type state
|
||||
TYPE_STATE oldTrans = tool.getTypeTransitiveState(type);
|
||||
const_cast<Tool&>(tool).setTypeState(type, state);
|
||||
|
||||
// Callback
|
||||
TYPE_STATE newTrans = tool.getTypeTransitiveState(type);
|
||||
callback_type(type, newTrans, state);
|
||||
{
|
||||
// Update super classes
|
||||
const Type* current = getSuper(type);
|
||||
while(current != nullptr) {
|
||||
callback_type(*current, tool.getTypeTransitiveState(*current), tool.getTypeSetState(*current));
|
||||
current = getSuper(*current);
|
||||
}
|
||||
}
|
||||
if(oldTrans == TYPE_STATE::DELETE || newTrans == TYPE_STATE::DELETE) {
|
||||
// Update sub classes
|
||||
updateSubtypes(tool, type, callback_type);
|
||||
}
|
||||
updateCall(this->change_callback);
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
#include <File.h>
|
||||
#include <TypesOfType.h>
|
||||
#include <sirEdit/main.hpp>
|
||||
#include <sirEdit/data/serialize.hpp>
|
||||
#include <sirEdit/utils/conver.hpp>
|
||||
#include <unordered_map>
|
||||
#include <tuple>
|
||||
#include <functional>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace sir::api;
|
||||
using namespace sirEdit::data;
|
||||
using namespace std;
|
||||
|
||||
//
|
||||
// Serializer (read/write)
|
||||
//
|
||||
|
||||
inline void checkSuper(const Type* type) {
|
||||
auto tmp = getSuper(*type);
|
||||
if(tmp != nullptr)
|
||||
checkSuper(tmp);
|
||||
}
|
||||
|
||||
class RawData {
|
||||
public:
|
||||
unique_ptr<SkillFile> skillFile;
|
||||
std::string file;
|
||||
vector<shared_ptr<Type>> allTypes;
|
||||
|
||||
vector<Type*> allTypesAccess;
|
||||
vector<Type*> baseTypes;
|
||||
|
||||
RawData(SkillFile* sf, std::string file) : skillFile(sf), file(move(file)) {
|
||||
// Load Typs
|
||||
{
|
||||
// Phase 1: gen Types
|
||||
this->allTypes.resize(sf->UserdefinedType->size());
|
||||
this->allTypesAccess.resize(sf->UserdefinedType->size());
|
||||
size_t counter = 0;
|
||||
unordered_map<sir::UserdefinedType*, size_t> types;
|
||||
for(sir::UserdefinedType& i : sf->UserdefinedType->all()) {
|
||||
this->allTypes[counter] = move(sirEdit::utils::genBaseType(&i));
|
||||
this->allTypes[counter]->getID() = counter;
|
||||
this->allTypesAccess[counter] = this->allTypes[counter].get();
|
||||
cout << "Address " << getSuper(*this->allTypesAccess[counter]) << endl;
|
||||
types[&i] = counter;
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
||||
for(auto& i: this->allTypes)
|
||||
checkSuper(i.get());
|
||||
|
||||
// Phase 2: reference types
|
||||
{
|
||||
// Prepare
|
||||
unordered_map<sir::UserdefinedType*, Type*> lookupTypes;
|
||||
for(auto i : types)
|
||||
lookupTypes[i.first] = this->allTypes[i.second].get();
|
||||
|
||||
// Add interfaces
|
||||
for(auto& i : sf->InterfaceType->all())
|
||||
if(i.getSuper() != nullptr) {
|
||||
lookupTypes[i.getSuper()]->getSubTypes().push_back(lookupTypes[&i]);
|
||||
dynamic_cast<TypeInterface*>(lookupTypes[&i])->getSuper() = lookupTypes[i.getSuper()];
|
||||
}
|
||||
else
|
||||
dynamic_cast<TypeInterface*>(lookupTypes[&i])->getSuper() = nullptr;
|
||||
|
||||
// Add classes
|
||||
for(auto &i : sf->ClassType->all())
|
||||
if(i.getSuper() != nullptr) {
|
||||
lookupTypes[i.getSuper()]->getSubTypes().push_back(lookupTypes[&i]);
|
||||
dynamic_cast<TypeClass*>(lookupTypes[&i])->getSuper() = lookupTypes[i.getSuper()];
|
||||
}
|
||||
else
|
||||
dynamic_cast<TypeClass*>(lookupTypes[&i])->getSuper() = nullptr;
|
||||
}
|
||||
|
||||
// Pahse 3: search unreferenced
|
||||
for(auto& i : this->allTypes) {
|
||||
bool good = true;
|
||||
for(auto& j : this->allTypes) {
|
||||
for(auto& k : j->getSubTypes())
|
||||
if(k == i.get()) {
|
||||
good = false;
|
||||
break;
|
||||
}
|
||||
if(!good)
|
||||
break;
|
||||
}
|
||||
if(good)
|
||||
this->baseTypes.push_back(i.get());
|
||||
}
|
||||
|
||||
// Phase 4: Check super
|
||||
for(auto& i: this->allTypes)
|
||||
checkSuper(i.get());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern shared_ptr<Serializer> sirEdit::data::Serializer::openFile(const string& file) {
|
||||
SkillFile* sf = SkillFile::open(file);
|
||||
Serializer* result = new Serializer(std::move(std::static_pointer_cast<void>(std::make_shared<RawData>(sf, file))));
|
||||
return move(shared_ptr<Serializer>(result));
|
||||
}
|
||||
|
||||
//
|
||||
// View access
|
||||
//
|
||||
struct ViewData {
|
||||
shared_ptr<RawData> raw;
|
||||
|
||||
vector<Tool> tools;
|
||||
};
|
||||
|
||||
sirEdit::data::View::View(shared_ptr<void> raw) {
|
||||
this->__raw = move(static_pointer_cast<void>(make_shared<ViewData>((ViewData) {move(static_pointer_cast<RawData>(raw)), {}})));
|
||||
}
|
||||
|
||||
extern const vector<Type*>& sirEdit::data::View::getTypes() const {
|
||||
return static_pointer_cast<ViewData>(this->__raw)->raw->allTypesAccess;
|
||||
}
|
||||
extern const vector<Type*>& sirEdit::data::View::getBaseTypes() const {
|
||||
return static_pointer_cast<ViewData>(this->__raw)->raw->baseTypes;
|
||||
}
|
||||
extern const vector<Tool>& sirEdit::data::View::getTools() const {
|
||||
return static_pointer_cast<ViewData>(this->__raw)->tools;
|
||||
}
|
||||
|
||||
extern View sirEdit::data::View::addTool(Tool tool) const {
|
||||
auto viewData = static_pointer_cast<ViewData>(this->__raw);
|
||||
View result = {viewData->raw};
|
||||
auto newViewData = static_pointer_cast<ViewData>(result.__raw);
|
||||
|
||||
// New tools list
|
||||
{
|
||||
newViewData->tools.resize(viewData->tools.size() + 1);
|
||||
size_t i = 0;
|
||||
for(auto& j : viewData->tools) {
|
||||
newViewData->tools[i] = j;
|
||||
i++;
|
||||
}
|
||||
newViewData->tools[viewData->tools.size()] = tool;
|
||||
}
|
||||
|
||||
return move(result);
|
||||
}
|
||||
|
||||
extern bool sirEdit::data::View::saveToFile() {
|
||||
ViewData* viewData = static_pointer_cast<ViewData>(this->__raw).get();
|
||||
|
||||
// Remoe old tools
|
||||
for(auto& i: *(viewData->raw->skillFile->Tool)) {
|
||||
// TODO: delete
|
||||
}
|
||||
|
||||
// Add tools
|
||||
for(auto& i : viewData->tools) {
|
||||
sir::Tool* tool = viewData->raw->skillFile->Tool->add();
|
||||
{
|
||||
auto tmp = viewData->raw->skillFile->strings->add(i.getName().c_str());
|
||||
tool->setName(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// Save
|
||||
viewData->raw->skillFile->flush();
|
||||
return true;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <sirEdit/main.hpp>
|
||||
|
@ -7,6 +8,8 @@
|
|||
|
||||
#include "mainWindow.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static thread* _loader_thread = new thread();
|
||||
|
@ -33,12 +36,17 @@ inline void loadFileThread(Gtk::Window* mainWindow, Gtk::Window* popup, Glib::Re
|
|||
}
|
||||
|
||||
// Open file
|
||||
auto serializer = sirEdit::data::Serializer::openFile(fileName);
|
||||
std::unique_ptr<sirEdit::data::Serializer> serializer = std::move(sirEdit::data::getSir(fileName));
|
||||
std::mutex mutex;
|
||||
std::condition_variable cv;
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
|
||||
// Send update
|
||||
sirEdit::runInGui([mainWindow, popup, serializer, file]() -> void {
|
||||
sirEdit::runInGui([mainWindow, popup, &serializer, file, &cv, &mutex]() -> void {
|
||||
// Open windows
|
||||
sirEdit::gui::openMainWindow(serializer, file);
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
sirEdit::gui::openMainWindow(std::move(static_cast<std::unique_ptr<sirEdit::data::Serializer>&>(serializer)), file);
|
||||
cv.notify_one();
|
||||
|
||||
// Close windows
|
||||
if(popup)
|
||||
|
@ -48,6 +56,7 @@ inline void loadFileThread(Gtk::Window* mainWindow, Gtk::Window* popup, Glib::Re
|
|||
mainWindow->close();
|
||||
}
|
||||
});
|
||||
cv.wait(lock);
|
||||
}
|
||||
|
||||
extern void sirEdit::loadFile(Gtk::Window* window, Gtk::FileChooserNative* chooser) {
|
||||
|
|
|
@ -29,9 +29,9 @@ class MainWindow {
|
|||
private:
|
||||
Glib::RefPtr<Gtk::Builder> __builder;
|
||||
|
||||
shared_ptr<Serializer> __serializer;
|
||||
unique_ptr<Serializer> __serializer;
|
||||
Glib::RefPtr<Gio::File> __file;
|
||||
HistoricalView __historicalView;
|
||||
Transactions __transitions;
|
||||
|
||||
unordered_map<string, int> __tabs;
|
||||
Gtk::Notebook* __notebook;
|
||||
|
@ -53,7 +53,7 @@ class MainWindow {
|
|||
labelBox->pack_start(*label);
|
||||
labelBox->pack_end(*closeButon);
|
||||
labelBox->show_all();
|
||||
Gtk::Widget* content = createToolEdit(tool.getName(), this->__historicalView);
|
||||
Gtk::Widget* content = createToolEdit(tool.getName(), this->__transitions);
|
||||
auto tmp = this->__notebook->append_page(*content, *labelBox);
|
||||
this->__tabs[tool.getName()] = tmp;
|
||||
this->__notebook->set_current_page(tmp);
|
||||
|
@ -74,7 +74,7 @@ class MainWindow {
|
|||
|
||||
// Rebuild list
|
||||
{
|
||||
sirEdit::data::View view = this->__historicalView.getStaticView();
|
||||
const sirEdit::data::Serializer& view = this->__transitions.getData();
|
||||
auto& tools = view.getTools();
|
||||
size_t pos = 0;
|
||||
for(auto& i : tools) {
|
||||
|
@ -82,7 +82,7 @@ class MainWindow {
|
|||
{
|
||||
Gtk::HBox* top = Gtk::manage(new Gtk::HBox());
|
||||
{
|
||||
Gtk::Label* tmp = Gtk::manage(new Gtk::Label(i.getName()));
|
||||
Gtk::Label* tmp = Gtk::manage(new Gtk::Label(i->getName()));
|
||||
tmp->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
|
||||
Gtk::Button* button = Gtk::manage(new Gtk::Button());
|
||||
button->set_image(*tmp);
|
||||
|
@ -90,10 +90,10 @@ class MainWindow {
|
|||
top->pack_start(*(button), true, true);
|
||||
button->set_relief(Gtk::RELIEF_NONE);
|
||||
button->signal_clicked().connect([&i, this]() -> void {
|
||||
if(this->__tabs.find(i.getName()) == this->__tabs.end())
|
||||
this->__create_tab(const_cast<Tool&>(i));
|
||||
if(this->__tabs.find(i->getName()) == this->__tabs.end())
|
||||
this->__create_tab(*const_cast<Tool*>(i));
|
||||
else
|
||||
this->__notebook->set_current_page(this->__tabs[i.getName()]);
|
||||
this->__notebook->set_current_page(this->__tabs[i->getName()]);
|
||||
this->__toolsPopover->hide();
|
||||
});
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ class MainWindow {
|
|||
main->pack_start(*top, true, true);
|
||||
}
|
||||
{
|
||||
Gtk::Label* description = Gtk::manage(new Gtk::Label(i.getDescription()));
|
||||
Gtk::Label* description = Gtk::manage(new Gtk::Label(i->getDescription()));
|
||||
description->set_line_wrap_mode(Pango::WrapMode::WRAP_CHAR);
|
||||
description->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
|
||||
description->set_lines(1);
|
||||
|
@ -135,12 +135,12 @@ class MainWindow {
|
|||
}
|
||||
|
||||
public:
|
||||
MainWindow(shared_ptr<sirEdit::data::Serializer> serializer, Glib::RefPtr<Gio::File> file) : __historicalView(serializer->getView()) {
|
||||
MainWindow(unique_ptr<sirEdit::data::Serializer> serializer, Glib::RefPtr<Gio::File> file) : __transitions(*serializer) {
|
||||
// Builder
|
||||
this->__builder = Gtk::Builder::create_from_file("data/gui/mainWindow.glade");
|
||||
|
||||
// Gen historical view
|
||||
this->__serializer = serializer;
|
||||
this->__serializer = std::move(serializer);
|
||||
this->__file = file;
|
||||
|
||||
// Notebook
|
||||
|
@ -200,8 +200,8 @@ class MainWindow {
|
|||
return;
|
||||
}
|
||||
|
||||
for(auto i : this->__historicalView.getStaticView().getTools())
|
||||
if(i.getName() == text) {
|
||||
for(auto i : this->__transitions.getData().getTools())
|
||||
if(i->getName() == text) {
|
||||
toolFinish->set_sensitive(false);
|
||||
return;
|
||||
}
|
||||
|
@ -215,13 +215,13 @@ class MainWindow {
|
|||
// Dialog finished
|
||||
toolFinish->signal_clicked().connect([this, newToolDialog, toolName, toolDescription, toolCommand]() -> void {
|
||||
newToolDialog->hide();
|
||||
this->__historicalView.addTool({toolName->get_text(), toolDescription->get_buffer()->get_text(), toolCommand->get_buffer()->get_text()});
|
||||
this->__transitions.addTool({toolName->get_text(), toolDescription->get_buffer()->get_text(), toolCommand->get_buffer()->get_text()});
|
||||
// TODO: Open new tool view
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
this->__notebook->append_page(*(Gtk::manage(createOverview(this->__historicalView))), "Overview");
|
||||
this->__notebook->append_page(*(Gtk::manage(createOverview(this->__transitions))), "Overview");
|
||||
}
|
||||
|
||||
// TODO: Remove prototype
|
||||
|
@ -387,6 +387,6 @@ class MainWindow {
|
|||
|
||||
static shared_ptr<MainWindow> mainWindow;
|
||||
|
||||
extern void sirEdit::gui::openMainWindow(shared_ptr<sirEdit::data::Serializer> serializer, Glib::RefPtr<Gio::File> file) {
|
||||
mainWindow = move(make_shared<MainWindow>(serializer, file));
|
||||
extern void sirEdit::gui::openMainWindow(std::unique_ptr<sirEdit::data::Serializer> serializer, Glib::RefPtr<Gio::File> file) {
|
||||
mainWindow = move(make_shared<MainWindow>(std::move(serializer), file));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <gtkmm.h>
|
||||
|
||||
namespace sirEdit::gui {
|
||||
extern void openMainWindow(std::shared_ptr<sirEdit::data::Serializer> serializer, Glib::RefPtr<Gio::File> file);
|
||||
extern Gtk::Widget* createToolEdit(std::string name,sirEdit::data::HistoricalView& historicalView);
|
||||
extern Gtk::Widget* createOverview(sirEdit::data::HistoricalView& historicalView);
|
||||
extern void openMainWindow(std::unique_ptr<sirEdit::data::Serializer> serializer, Glib::RefPtr<Gio::File> file);
|
||||
extern Gtk::Widget* createToolEdit(std::string name,sirEdit::data::Transactions& historicalView);
|
||||
extern Gtk::Widget* createOverview(sirEdit::data::Transactions& historicalView);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ static FieldModel fieldModel;
|
|||
|
||||
class Overview : public Gtk::VBox {
|
||||
private:
|
||||
HistoricalView& view;
|
||||
Transactions& transactions;
|
||||
|
||||
// Stack
|
||||
Gtk::Stack stack;
|
||||
|
@ -180,20 +180,20 @@ class Overview : public Gtk::VBox {
|
|||
void updateToolData() {
|
||||
this->tool_view.get_selection()->unselect_all();
|
||||
this->tool_store->clear();
|
||||
for(auto& i : this->view.getStaticView().getTools()) {
|
||||
for(auto& i : this->transactions.getData().getTools()) {
|
||||
// Checks
|
||||
if(this->hide_unused_tool.property_active().get_value() && this->__cache_used_tools.find(&i) == this->__cache_used_tools.end())
|
||||
if(this->hide_unused_tool.property_active().get_value() && this->__cache_used_tools.find(i) == this->__cache_used_tools.end())
|
||||
continue;
|
||||
if(this->hide_inactive_tool.property_active().get_value() && !this->isToolActive(&i))
|
||||
if(this->hide_inactive_tool.property_active().get_value() && !this->isToolActive(i))
|
||||
continue;
|
||||
|
||||
// Insert
|
||||
auto tmp = *(this->tool_store->append());
|
||||
tmp[toolModel.data_name] = i.getName();
|
||||
tmp[toolModel.data_active] = this->isToolActive(&i);
|
||||
tmp[toolModel.data_used] = this->__cache_used_tools.find(&i) != this->__cache_used_tools.end();
|
||||
tmp[toolModel.data_tool] = const_cast<Tool*>(&i);
|
||||
if(this->__cache_selected_tools.find(&i) != this->__cache_selected_tools.end())
|
||||
tmp[toolModel.data_name] = i->getName();
|
||||
tmp[toolModel.data_active] = this->isToolActive(i);
|
||||
tmp[toolModel.data_used] = this->__cache_used_tools.find(i) != this->__cache_used_tools.end();
|
||||
tmp[toolModel.data_tool] = const_cast<Tool*>(i);
|
||||
if(this->__cache_selected_tools.find(i) != this->__cache_selected_tools.end())
|
||||
this->tool_view.get_selection()->select(tmp);
|
||||
}
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ class Overview : public Gtk::VBox {
|
|||
{
|
||||
Gtk::TreeStore::Row tmp;
|
||||
std::list<Gtk::TreeStore::Path> toSelect;
|
||||
for(auto& i : this->view.getStaticView().getBaseTypes())
|
||||
for(auto& i : this->transactions.getData().getBaseTypes())
|
||||
this->__genTypeItem<true>(*(this->type_store.get()), tmp, i, toSelect);
|
||||
this->type_view.expand_all();
|
||||
for(auto& i : toSelect)
|
||||
|
@ -331,7 +331,7 @@ class Overview : public Gtk::VBox {
|
|||
}
|
||||
|
||||
public:
|
||||
Overview(HistoricalView& view) : Gtk::VBox(), view(view) {
|
||||
Overview(Transactions& transactions) : Gtk::VBox(), transactions(transactions) {
|
||||
// Init Stack
|
||||
this->stack_switcher.set_stack(this->stack);
|
||||
this->pack_start(this->stack_switcher, false, true);
|
||||
|
@ -411,14 +411,14 @@ class Overview : public Gtk::VBox {
|
|||
this->update_all();
|
||||
|
||||
// Change notification
|
||||
this->view.addChangeCallback([this]() -> void {
|
||||
this->transactions.addChangeCallback([this]() -> void {
|
||||
this->update_all();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
namespace sirEdit::gui {
|
||||
Gtk::Widget* createOverview(HistoricalView& historicalView) {
|
||||
return new Overview(historicalView);
|
||||
Gtk::Widget* createOverview(Transactions& transactions) {
|
||||
return new Overview(transactions);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ class Tab : public Gtk::HPaned
|
|||
private:
|
||||
Tool& tool;
|
||||
Type* currentType;
|
||||
HistoricalView& historicalView;
|
||||
Transactions& transactions;
|
||||
|
||||
Glib::RefPtr<Gtk::TreeStore> typeListData;
|
||||
Glib::RefPtr<Gtk::TreeStore> fieldListData;
|
||||
|
@ -224,9 +224,9 @@ class Tab : public Gtk::HPaned
|
|||
if(iter) {
|
||||
// Find type
|
||||
Gtk::TreeModel::Row row = *iter;
|
||||
if(this->historicalView.getStaticView().getTypes().size() <= row[typeListModel.data_id])
|
||||
if(this->transactions.getData().getTypes().size() <= row[typeListModel.data_id])
|
||||
throw; // That should NEVER happen!
|
||||
const sirEdit::data::Type* type = this->historicalView.getStaticView().getTypes()[row[typeListModel.data_id]];
|
||||
const sirEdit::data::Type* type = this->transactions.getData().getTypes()[row[typeListModel.data_id]];
|
||||
this->currentType = const_cast<Type*>(type);
|
||||
|
||||
// Generate list
|
||||
|
@ -244,10 +244,10 @@ class Tab : public Gtk::HPaned
|
|||
if(iter) {
|
||||
// Find type
|
||||
Gtk::TreeModel::Row row = *iter;
|
||||
const sirEdit::data::Type* type = this->historicalView.getStaticView().getTypes().at(row[typeListModel.data_id]);
|
||||
const sirEdit::data::Type* type = this->transactions.getData().getTypes().at(row[typeListModel.data_id]);
|
||||
|
||||
// Update row
|
||||
this->historicalView.setTypeStatus(this->tool, *const_cast<Type*>(type), state, [this](const Type& type, TYPE_STATE transitive, TYPE_STATE set) -> void {
|
||||
this->transactions.setTypeStatus(this->tool, *const_cast<Type*>(type), state, [this](const Type& type, TYPE_STATE transitive, TYPE_STATE set) -> void {
|
||||
this->typeUpdate(this->type_lookup[&type], transitive, set);
|
||||
});
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ class Tab : public Gtk::HPaned
|
|||
throw; // That should NEVER happen!
|
||||
|
||||
// Set field state
|
||||
this->historicalView.setFieldStatus(this->tool, *(this->currentType), *(field->second), state, [this, &id](const Type& type, const Field& field, FIELD_STATE tool_state, FIELD_STATE type_state) -> void {
|
||||
this->transactions.setFieldStatus(this->tool, *(this->currentType), *(field->second), state, [this, &id](const Type& type, const Field& field, FIELD_STATE tool_state, FIELD_STATE type_state) -> void {
|
||||
this->fieldUpdate(*(this->fieldListData->get_iter(id)), tool_state, type_state);
|
||||
}, [this, &id](const Type& type, TYPE_STATE tool_state, TYPE_STATE set_state) -> void {
|
||||
this->typeUpdate(this->type_lookup.find(&type)->second, tool_state, set_state);
|
||||
|
@ -273,10 +273,7 @@ class Tab : public Gtk::HPaned
|
|||
}
|
||||
|
||||
public:
|
||||
Tab(Tool& tool, HistoricalView& historicalView) : tool(tool), historicalView(historicalView), HPaned() {
|
||||
// General
|
||||
const View& view = this->historicalView.getStaticView();
|
||||
|
||||
Tab(Tool& tool, Transactions& transactions) : tool(tool), transactions(transactions), HPaned() {
|
||||
// Generate panes
|
||||
this->scrollable_left.set_size_request(300, 200);
|
||||
this->scrollable_left.add(this->view_left);
|
||||
|
@ -294,7 +291,7 @@ class Tab : public Gtk::HPaned
|
|||
|
||||
// Generate type tree
|
||||
{
|
||||
for(auto& i : view.getBaseTypes()) {
|
||||
for(auto& i : transactions.getData().getBaseTypes()) {
|
||||
Gtk::TreeStore::Row tmp = *(typeListData->append());
|
||||
tmp[typeListModel.data_id] = i->getID();
|
||||
tmp[typeListModel.data_name] = i->getName();
|
||||
|
@ -443,17 +440,17 @@ class Tab : public Gtk::HPaned
|
|||
//
|
||||
// Show widget
|
||||
//
|
||||
extern Gtk::Widget* sirEdit::gui::createToolEdit(std::string name, HistoricalView& historicalView) {
|
||||
extern Gtk::Widget* sirEdit::gui::createToolEdit(std::string name, Transactions& transitions) {
|
||||
// Search tool
|
||||
Tool* tool = nullptr;
|
||||
for(auto& i : historicalView.getStaticView().getTools())
|
||||
if(i.getName() == name)
|
||||
tool = const_cast<Tool*>(&i);
|
||||
for(auto& i : transitions.getData().getTools())
|
||||
if(i->getName() == name)
|
||||
tool = const_cast<Tool*>(i);
|
||||
if(tool == nullptr)
|
||||
throw; // That should NEVER happen.
|
||||
|
||||
// Create tab
|
||||
Tab* tab = new Tab(*tool, historicalView);
|
||||
Tab* tab = new Tab(*tool, transitions);
|
||||
tab->show_all();
|
||||
return tab;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ using namespace std;
|
|||
|
||||
namespace sirEdit {
|
||||
Gtk::Application* mainApplication;
|
||||
sirEdit::data::HistoricalView* views = nullptr;
|
||||
static Glib::Dispatcher* dispatcher;
|
||||
static list<std::function<void()>> dispatcher_funcs;
|
||||
static mutex dispatcher_mutex;
|
||||
|
@ -65,8 +64,6 @@ int main(int args, char** argv) {
|
|||
sirEdit::gui::runStartupWindow();
|
||||
});
|
||||
auto reuslt = application->run(args, argv);
|
||||
if(sirEdit::views != nullptr)
|
||||
delete sirEdit::views;
|
||||
return reuslt;
|
||||
|
||||
// GTK startup
|
||||
|
|
Loading…
Reference in New Issue