Add tab groups
parent
55e1faa514
commit
e19ed602dd
|
@ -88,6 +88,54 @@
|
|||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkPaned">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="width_request">300</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="ClassList">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="search_column">0</property>
|
||||
<property name="enable_grid_lines">vertical</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="width_request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="ItemList">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">True</property>
|
||||
<property name="shrink">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -147,52 +195,26 @@
|
|||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkPaned">
|
||||
<object class="GtkNotebook" id="Notebook">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="width_request">300</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="ClassList">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="search_column">0</property>
|
||||
<property name="enable_grid_lines">vertical</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">False</property>
|
||||
</packing>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="width_request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="ItemList">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">True</property>
|
||||
<property name="shrink">False</property>
|
||||
</packing>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
|
|
@ -39,4 +39,19 @@ namespace sirEdit::data {
|
|||
|
||||
static std::shared_ptr<Serializer> openFile(const std::string& file);
|
||||
};
|
||||
|
||||
class HistoricalView {
|
||||
private:
|
||||
View staticView;
|
||||
std::shared_ptr<void> data;
|
||||
|
||||
public:
|
||||
HistoricalView(View view);
|
||||
|
||||
const View& getStaticView() const {
|
||||
return this->staticView;
|
||||
}
|
||||
|
||||
void addTool(Tool tool);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#include <sirEdit/data/serialize.hpp>
|
||||
#include <list>
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
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>());
|
||||
}
|
||||
|
||||
void sirEdit::data::HistoricalView::addTool(Tool tool) {
|
||||
this->staticView = this->staticView.addTool(tool);
|
||||
}
|
|
@ -11,42 +11,7 @@ using namespace std;
|
|||
static Glib::RefPtr<Gtk::Builder>* _mainWindowBuild = new Glib::RefPtr<Gtk::Builder>();
|
||||
static Glib::RefPtr<Gtk::Builder>& mainWindowBuild = *_mainWindowBuild;
|
||||
|
||||
class TypeListModel : public Gtk::TreeModel::ColumnRecord
|
||||
{
|
||||
public:
|
||||
Gtk::TreeModelColumn<size_t> data_id;
|
||||
Gtk::TreeModelColumn<Glib::ustring> data_name;
|
||||
|
||||
TypeListModel() {
|
||||
this->add(data_id);
|
||||
this->add(data_name);
|
||||
}
|
||||
};
|
||||
static TypeListModel typeListModel;
|
||||
static Glib::RefPtr<Gtk::TreeStore> typeListData;
|
||||
|
||||
class FieldListModel : public Gtk::TreeModel::ColumnRecord
|
||||
{
|
||||
public:
|
||||
Gtk::TreeModelColumn<Glib::ustring> data_name;
|
||||
|
||||
FieldListModel() {
|
||||
this->add(data_name);
|
||||
}
|
||||
};
|
||||
static FieldListModel fieldListModel;
|
||||
static Glib::RefPtr<Gtk::TreeStore> fieldListData;
|
||||
|
||||
static list<sirEdit::data::View> views;
|
||||
|
||||
inline void buildTreeSubRows(Gtk::TreeStore::Row& row, const sirEdit::data::Type* super) {
|
||||
for(auto& i : super->getSubTypes()) {
|
||||
Gtk::TreeStore::Row tmp = *(typeListData->append(row.children()));
|
||||
tmp[typeListModel.data_id] = i->getID();
|
||||
tmp[typeListModel.data_name] = i->getName();
|
||||
buildTreeSubRows(tmp, i);
|
||||
}
|
||||
}
|
||||
static sirEdit::data::HistoricalView* views;
|
||||
|
||||
extern void sirEdit::gui::openMainWindow(shared_ptr<sirEdit::data::Serializer> serializer, Glib::RefPtr<Gio::File> file) {
|
||||
// Load window when required
|
||||
|
@ -54,54 +19,11 @@ extern void sirEdit::gui::openMainWindow(shared_ptr<sirEdit::data::Serializer> s
|
|||
mainWindowBuild = Gtk::Builder::create_from_file("data/gui/mainWindow.glade");
|
||||
|
||||
// First view
|
||||
views.push_back(move(serializer->getView()));
|
||||
views = new sirEdit::data::HistoricalView(move(serializer->getView()));
|
||||
|
||||
// Types and field lists
|
||||
{
|
||||
Gtk::TreeView* treeView;
|
||||
mainWindowBuild->get_widget("ClassList", treeView);
|
||||
typeListData = Gtk::TreeStore::create(typeListModel);
|
||||
typeListData->set_sort_column(typeListModel.data_name, Gtk::SortType::SORT_ASCENDING);
|
||||
if(!typeListData)
|
||||
throw;
|
||||
|
||||
{
|
||||
for(auto& i : views.begin()->getBaseTypes()) {
|
||||
Gtk::TreeStore::Row tmp = *(typeListData->append());
|
||||
tmp[typeListModel.data_id] = i->getID();
|
||||
tmp[typeListModel.data_name] = i->getName();
|
||||
buildTreeSubRows(tmp, i);
|
||||
}
|
||||
}
|
||||
|
||||
treeView->set_model(typeListData);
|
||||
treeView->set_search_column(typeListModel.data_name);
|
||||
treeView->append_column("Types", typeListModel.data_name);
|
||||
treeView->set_activate_on_single_click(true);
|
||||
treeView->expand_all();
|
||||
//treeView->set_expander_column(typeListModel.data_name);
|
||||
|
||||
Gtk::TreeView* fields;
|
||||
mainWindowBuild->get_widget("ItemList", fields);
|
||||
fieldListData = Gtk::TreeStore::create(fieldListModel);
|
||||
fieldListData->set_sort_column(fieldListModel.data_name, Gtk::SortType::SORT_ASCENDING);
|
||||
fields->set_model(fieldListData);
|
||||
fields->set_search_column(fieldListModel.data_name);
|
||||
fields->append_column("Name", fieldListModel.data_name);
|
||||
|
||||
treeView->signal_row_activated().connect([serializer, fields](const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) -> void {
|
||||
Gtk::TreeModel::iterator iter = typeListData->get_iter(path);
|
||||
if(iter) {
|
||||
Gtk::TreeModel::Row row = *iter;
|
||||
fieldListData->clear();
|
||||
sirEdit::data::TypeWithFields* type = static_cast<sirEdit::data::TypeWithFields*>(serializer->getView().getTypes()[row[typeListModel.data_id]].get());
|
||||
for(auto& i: type->getFields()) {
|
||||
Gtk::TreeStore::Row tmp = *(fieldListData->append());
|
||||
tmp[fieldListModel.data_name] = i.getName();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Notebook
|
||||
Gtk::Notebook* notebook;
|
||||
mainWindowBuild->get_widget("Notebook", notebook);
|
||||
|
||||
// Tools pop-up
|
||||
{
|
||||
|
@ -112,7 +34,7 @@ extern void sirEdit::gui::openMainWindow(shared_ptr<sirEdit::data::Serializer> s
|
|||
mainWindowBuild->get_widget("ToolsPopup", toolsPopover);
|
||||
mainWindowBuild->get_widget("ToolsList", toolsList);
|
||||
|
||||
toolsButton->signal_clicked().connect([toolsList, toolsPopover, serializer]() -> void {
|
||||
toolsButton->signal_clicked().connect([toolsList, toolsPopover, serializer, notebook]() -> void {
|
||||
// Clear list
|
||||
{
|
||||
auto tmp = toolsList->get_children();
|
||||
|
@ -124,10 +46,18 @@ extern void sirEdit::gui::openMainWindow(shared_ptr<sirEdit::data::Serializer> s
|
|||
|
||||
// Rebuild list
|
||||
{
|
||||
auto& view = (--views.end())->getTools();
|
||||
sirEdit::data::View view = views->getStaticView();
|
||||
auto& tools = view.getTools();
|
||||
size_t pos = 0;
|
||||
for(auto& i : view) {
|
||||
Gtk::Label* name = new Gtk::Label(i.getName());
|
||||
for(auto& i : tools) {
|
||||
Gtk::Button* name = new Gtk::Button(i.getName());
|
||||
name->set_border_width(0);
|
||||
std::string tmp_name = i.getName();
|
||||
name->signal_clicked().connect([tmp_name, notebook, view]() -> void {
|
||||
Gtk::Label* label = new Gtk::Label(tmp_name);
|
||||
Gtk::Widget* content = createToolEdit(tmp_name, view);
|
||||
notebook->append_page(*content, *label);
|
||||
});
|
||||
toolsList->insert(*name, pos);
|
||||
pos++;
|
||||
}
|
||||
|
@ -184,7 +114,7 @@ extern void sirEdit::gui::openMainWindow(shared_ptr<sirEdit::data::Serializer> s
|
|||
// Dialog finished
|
||||
toolFinish->signal_clicked().connect([newToolDialog, toolName]() -> void {
|
||||
newToolDialog->hide();
|
||||
views.push_back(move((--views.end())->addTool({toolName->get_text()})));
|
||||
views->addTool({toolName->get_text()});
|
||||
// TODO: Open new tool view
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,4 +4,5 @@
|
|||
|
||||
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, const sirEdit::data::View view);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
#include "mainWindow.hpp"
|
||||
#include <gtkmm.h>
|
||||
|
||||
//
|
||||
// Model for type list
|
||||
//
|
||||
class TypeListModel : public Gtk::TreeModel::ColumnRecord
|
||||
{
|
||||
public:
|
||||
Gtk::TreeModelColumn<size_t> data_id;
|
||||
Gtk::TreeModelColumn<Glib::ustring> data_name;
|
||||
|
||||
TypeListModel() {
|
||||
this->add(data_id);
|
||||
this->add(data_name);
|
||||
}
|
||||
};
|
||||
static TypeListModel typeListModel;
|
||||
static Glib::RefPtr<Gtk::TreeStore> typeListData;
|
||||
|
||||
//
|
||||
// Field tree
|
||||
//
|
||||
class FieldListModel : public Gtk::TreeModel::ColumnRecord
|
||||
{
|
||||
public:
|
||||
Gtk::TreeModelColumn<Glib::ustring> data_name;
|
||||
|
||||
FieldListModel() {
|
||||
this->add(data_name);
|
||||
}
|
||||
};
|
||||
static FieldListModel fieldListModel;
|
||||
static Glib::RefPtr<Gtk::TreeStore> fieldListData;
|
||||
|
||||
inline void buildTreeSubRows(Gtk::TreeStore::Row& row, const sirEdit::data::Type* super) {
|
||||
for(auto& i : super->getSubTypes()) {
|
||||
Gtk::TreeStore::Row tmp = *(typeListData->append(row.children()));
|
||||
tmp[typeListModel.data_id] = i->getID();
|
||||
tmp[typeListModel.data_name] = i->getName();
|
||||
buildTreeSubRows(tmp, i);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Show widget
|
||||
//
|
||||
extern Gtk::Widget* sirEdit::gui::createToolEdit(std::string name, const sirEdit::data::View view) {
|
||||
// Generate panes
|
||||
Gtk::Paned* paned = new Gtk::HPaned();
|
||||
Gtk::ScrolledWindow* scrollable_left = new Gtk::ScrolledWindow();
|
||||
scrollable_left->set_size_request(300, 200);
|
||||
paned->pack1(*scrollable_left, false, false);
|
||||
Gtk::ScrolledWindow* scrollable_right = new Gtk::ScrolledWindow();
|
||||
paned->pack2(*scrollable_right, true, false);
|
||||
|
||||
// Add tree views
|
||||
Gtk::TreeView* view_left = new Gtk::TreeView();
|
||||
scrollable_left->add(*view_left);
|
||||
Gtk::TreeView* view_right = new Gtk::TreeView();
|
||||
scrollable_right->add(*view_right);
|
||||
|
||||
// Types and field lists
|
||||
{
|
||||
typeListData = Gtk::TreeStore::create(typeListModel);
|
||||
typeListData->set_sort_column(typeListModel.data_name, Gtk::SortType::SORT_ASCENDING);
|
||||
if(!typeListData)
|
||||
throw;
|
||||
|
||||
{
|
||||
for(auto& i : view.getBaseTypes()) {
|
||||
Gtk::TreeStore::Row tmp = *(typeListData->append());
|
||||
tmp[typeListModel.data_id] = i->getID();
|
||||
tmp[typeListModel.data_name] = i->getName();
|
||||
buildTreeSubRows(tmp, i);
|
||||
}
|
||||
}
|
||||
|
||||
view_left->set_model(typeListData);
|
||||
view_left->set_search_column(typeListModel.data_name);
|
||||
view_left->append_column("Types", typeListModel.data_name);
|
||||
auto nameColumn = view_left->get_column(0);
|
||||
view_left->set_activate_on_single_click(true);
|
||||
view_left->expand_all();
|
||||
view_left->set_expander_column(*nameColumn);
|
||||
|
||||
fieldListData = Gtk::TreeStore::create(fieldListModel);
|
||||
fieldListData->set_sort_column(fieldListModel.data_name, Gtk::SortType::SORT_ASCENDING);
|
||||
view_right->set_model(fieldListData);
|
||||
view_right->set_search_column(fieldListModel.data_name);
|
||||
view_right->append_column("Name", fieldListModel.data_name);
|
||||
|
||||
view_left->signal_row_activated().connect([view](const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) -> void {
|
||||
Gtk::TreeModel::iterator iter = typeListData->get_iter(path);
|
||||
if(iter) {
|
||||
Gtk::TreeModel::Row row = *iter;
|
||||
fieldListData->clear();
|
||||
sirEdit::data::TypeWithFields* type = static_cast<sirEdit::data::TypeWithFields*>(view.getTypes()[row[typeListModel.data_id]].get());
|
||||
for(auto& i: type->getFields()) {
|
||||
Gtk::TreeStore::Row tmp = *(fieldListData->append());
|
||||
tmp[fieldListModel.data_name] = i.getName();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Return paned
|
||||
paned->show_all();
|
||||
return paned;
|
||||
}
|
Loading…
Reference in New Issue