Support import
parent
66ccfcc17c
commit
4ec86937fd
|
@ -20,21 +20,6 @@
|
|||
<object class="GtkButtonBox">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="ExportExit">
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="always_show_image">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="ExportRun">
|
||||
<property name="label">gtk-apply</property>
|
||||
|
@ -66,7 +51,7 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkComboBoxText">
|
||||
<object class="GtkComboBoxText" id="ExportType">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="active">0</property>
|
||||
|
@ -82,7 +67,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkFileChooserButton">
|
||||
<object class="GtkFileChooserButton" id="ExportTarget">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="action">select-folder</property>
|
||||
|
@ -195,7 +180,7 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<object class="GtkButton" id="ImportButton">
|
||||
<property name="label" translatable="yes">Import</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
|
@ -227,7 +212,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<object class="GtkButton" id="InfoButton">
|
||||
<property name="label">gtk-info</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <gtkmm.h>
|
||||
#include "mainWindow.hpp"
|
||||
#include <sirEdit/main.hpp>
|
||||
#include <list>
|
||||
#include <fstream>
|
||||
#include <unordered_map>
|
||||
#include <sirEdit/main.hpp>
|
||||
#include <sirEdit/data/tools.hpp>
|
||||
|
@ -245,6 +245,40 @@ class MainWindow {
|
|||
this->__toolsPopover->show_all();
|
||||
}
|
||||
|
||||
//
|
||||
// Import
|
||||
//
|
||||
// User should save the file
|
||||
void __importTools() {
|
||||
auto chooser = Gtk::FileChooserNative::create("SIR-File", Gtk::FILE_CHOOSER_ACTION_OPEN);
|
||||
switch(chooser->run()) {
|
||||
case Gtk::RESPONSE_ACCEPT:
|
||||
// Copy file
|
||||
std::string folderName = tmpnam(nullptr);
|
||||
{
|
||||
char buffer[256];
|
||||
int readed;
|
||||
std::ofstream outLocal(folderName, std::ios::out | std::ios::binary);
|
||||
auto tmp = chooser->get_file()->read();
|
||||
while((readed = tmp->read(buffer, 256)) != 0)
|
||||
outLocal.write(buffer, readed);
|
||||
tmp->close();
|
||||
}
|
||||
|
||||
// Open file
|
||||
{
|
||||
auto newSpec = getSir(folderName);
|
||||
SpecModify own;
|
||||
own.types = this->__serializer->getTypes();
|
||||
own.updateFields();
|
||||
std::vector<Tool*> toolsToAdd;
|
||||
std::vector<const Type*> tmp = {newSpec->getTypes().begin(), newSpec->getTypes().end()};
|
||||
for(auto& i : newSpec->getTools())
|
||||
toolsToAdd.push_back(new Tool(move(own.parseTool(*i, tmp))));
|
||||
this->__transitions.importTools(toolsToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
MainWindow(unique_ptr<sirEdit::data::Serializer> serializer, Glib::RefPtr<Gio::File> file) : __transitions(*serializer) {
|
||||
// Builder
|
||||
|
@ -261,6 +295,15 @@ class MainWindow {
|
|||
// Notebook
|
||||
this->__builder->get_widget("Notebook", this->__notebook);
|
||||
|
||||
// Import
|
||||
{
|
||||
Gtk::Button* button;
|
||||
this->__builder->get_widget("ImportButton", button);
|
||||
button->signal_clicked().connect([this]() -> void {
|
||||
this->__importTools();
|
||||
});
|
||||
}
|
||||
|
||||
// Export
|
||||
{
|
||||
Gtk::Button* button;
|
||||
|
|
Loading…
Reference in New Issue